Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\controllers\online_courses;
- use app\controllers\AppController;
- use app\models\App;
- use app\models\asterisk\OnlineCoursesAutodialler;
- use app\models\Billing;
- use app\models\BillingStatus;
- use app\models\CrmLibrary;
- use app\models\online_courses\Calendar;
- use app\models\online_courses\ClientContacts;
- use app\models\online_courses\ClientDeviceSearch;
- use app\models\online_courses\ClientPayment;
- use app\models\ClientPaymentCard;
- use app\models\online_courses\ClientGroups;
- use app\models\online_courses\Clients;
- use app\models\online_courses\ClientsSearch;
- use app\models\online_courses\CourseLead;
- use app\models\online_courses\Courses;
- use app\models\online_courses\Discount;
- use app\models\online_courses\Group;
- use app\models\online_courses\Lectures;
- use app\models\online_courses\LogProgramSearch;
- use app\models\tech_support\Client;
- use app\models\tech_support\ClientInvoices;
- use app\models\tech_support\ClientPaymentNotPaid;
- use app\models\tech_support\ClientPaymentStatus;
- use app\models\tech_support\InfoLog;
- use app\models\tech_support\OnlineCoursesOffer;
- use app\models\tech_support\Petitions;
- use app\services\data_option\CrmCityDataOption;
- use app\services\data_option\CrmLibraryDataOption;
- use app\services\data_option\FactoryArrayDataOption;
- use app\services\data_option\online_courses\ClientContactsDataOption;
- use app\services\data_option\online_courses\ClientGroupDataOption;
- use app\services\data_option\online_courses\CoursesDataOption;
- use app\services\data_option\online_courses\UserListDataOption;
- use app\services\data_option\OnlineCoursesDataOption;
- use app\services\online_course\client\FactoryProvider;
- use app\services\online_course\client\mail\ClientGroupMail;
- //use app\services\online_course\client\ZnayooClientService;
- use Carbon\Carbon;
- use Yii;
- use yii\data\ActiveDataProvider;
- use yii\filters\AccessControl;
- use yii\filters\VerbFilter;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Html;
- use yii\web\NotFoundHttpException;
- use yii\web\Response;
- use yii\widgets\ActiveForm;
- use yii2mod\editable\EditableAction;
- class ClientsController extends AppController
- {
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::class,
- 'actions' => [
- 'add-final' => ['POST'],
- ],
- ],
- 'access' => [
- 'class' => AccessControl::class,
- 'rules' => [
- [
- 'actions' => [
- 'index',
- 'get-emails',
- 'save-client',
- 'offer',
- 'translate',
- 'change_name',
- 'change-all-first-name-heb',
- 'transfer-heb-name',
- 'render-grid-client-log-program',
- 'get-course-groups-list',
- 'get-group-lectures-list',
- 'show-translate-name-modal',
- ],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- [
- 'actions' => ['create'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- [
- 'actions' => ['update'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- [
- 'actions' => ['add'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- [
- 'actions' => ['autodialler-view'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- [
- 'actions' => ['change-group'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- [
- 'actions' => ['delete-group-client'],
- 'allow' => true,
- 'roles' => ['DeleteGroupClientCourses'],
- ],
- [
- 'actions' => ['delete-client-autodial'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- [
- 'actions' => [
- 'add-client-autodial',
- 'validation',
- 'add-client-course',
- 'add-final',
- 'update-mail',
- 'get-current-mail',
- 'get-client-offer',
- 'client-type-payment-course',
- 'course-client-petition-create'
- ],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- [
- 'actions' => ['add-lead-course'],
- 'allow' => true,
- 'roles' => ['ClientsAddLeadCourses'],
- ],
- [
- 'actions' => ['view'],
- 'allow' => true,
- 'roles' => ['@'], // ViewCardClientOnlineCourses
- ],
- [
- 'actions' => ['update-client'],
- 'allow' => true,
- 'roles' => ['@'], // UpdateCardClientOnlineCourses
- ],
- [
- 'actions' => ['client-contact'],
- 'allow' => true,
- 'roles' => ['@'], // IndexClientContactOnlineCourses
- ],
- [
- 'actions' => ['create-client-contact'],
- 'allow' => true,
- 'roles' => ['@'], // CreateClientContactOnlineCourses
- ],
- [
- 'actions' => ['update-client-contact'],
- 'allow' => true,
- 'roles' => ['@'], // UpdateClientContactOnlineCourses
- ],
- [
- 'actions' => ['delete-client-contact'],
- 'allow' => true,
- 'roles' => ['@'], // DeleteClientContactOnlineCourses
- ],
- [
- 'actions' => ['get-form-modal-add-final'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- [
- 'actions' => ['save-data-add-final'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- [
- 'actions' => ['show-number-and-comm', 'change-comment-on-number', 'change-number-client'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- ];
- }
- public function actions()
- {
- return [
- 'change_name' => [
- 'class' => EditableAction::class,
- 'modelClass' => Clients::class,
- ],
- ];
- }
- public function actionChangeAllFirstNameHeb()
- {
- $request = Yii::$app->request->post();
- $condition = ['and',
- ['=', 'first_name', $request['search_first_name']],
- ['or',
- ['=', 'first_name_heb', ''],
- ['IS', 'first_name_heb', null],
- ],
- ];
- $result = Clients::updateAll(
- ['first_name_heb' => $request['add_new_first_name_heb']],
- $condition
- );
- if (0 == $result) {
- return false;
- }
- return true;
- }
- public function actionTransferHebName(int $id)
- {
- // HistoryTechSupport::$npp = CrmHistory::find()->max('npp') + 1;
- $model = $this->findModel($id);
- if ($model->transferHebName()) {
- return \json_encode('1');
- }
- return true;
- }
- public function actionView($id)
- {
- $modelClients = $this->findModel($id);
- $model_tech_support_client = Client::findOne(['course_client_id'=>$id]);
- // Контакты
- $contacts_email = ClientContacts::find()
- ->where(['disabled' => 0])
- ->andFilterWhere(['client_id' => $id])
- ->andFilterWhere(['type_id' => 2]);
- $contactsEmailProvider = new ActiveDataProvider(['query' => $contacts_email]);
- //-------------------------------------------------------
- $contacts_email_main = ClientContacts::find()
- ->where(['disabled' => 0])
- ->andFilterWhere(['client_id' => $id])
- ->andFilterWhere(['type_id' => 2])
- ->andFilterWhere(['main' => 1]);
- $contactsEmailMainProvider = new ActiveDataProvider(['query' => $contacts_email_main]);
- //-------------------------------------------------------
- $contacts_fax = ClientContacts::find()
- ->where(['disabled' => 0])
- ->andFilterWhere(['client_id' => $id])
- ->andFilterWhere(['type_id' => 4]);
- $contactsFaxProvider = new ActiveDataProvider(['query' => $contacts_fax]);
- //-------------------------------------------------------
- $contacts_home = ClientContacts::find()
- ->where(['disabled' => 0])
- ->andFilterWhere(['client_id' => $id])
- ->andFilterWhere(['type_id' => 3]);
- $contactsHomeProvider = new ActiveDataProvider(['query' => $contacts_home]);
- $contactsHomeProvider->sort->attributes['main'] = [
- 'desc' => ['main' => \SORT_DESC],
- ];
- //-------------------------------------------------------
- $contacts_mobile = ClientContacts::find()
- ->where(['disabled' => 0])
- ->andFilterWhere(['client_id' => $id])
- ->andFilterWhere(['type_id' => 1]);
- $contactsMobileProvider = new ActiveDataProvider(['query' => $contacts_mobile]);
- $contactsMobileProvider->sort->attributes['main'] = [
- 'desc' => ['main' => \SORT_DESC],
- ];
- // Вкладка Курсы
- $nowDate = Carbon::now()->format('Y-m-d');
- $clientPastCoursesProvider = new ActiveDataProvider([
- 'query' => ClientGroups::find()
- ->joinWith(['client c'])
- ->where(['c.id' => $id])
- ->orderBy(['online_courses.client_groups.id' => \SORT_DESC]),
- ]);
- $clientGroups = \array_values(ArrayHelper::map(
- $clientPastCoursesProvider->getModels(),
- 'id',
- function ($query) {
- return $query->groupId->courses_id;
- }
- ));
- $finalGroups = ClientGroups::find()->joinWith(['client', 'groupId'])
- ->where(['online_courses.clients.id' => $id])
- ->andWhere(['online_courses.group.type_id' => 0])->all();
- $finalGroup = ArrayHelper::map($finalGroups, function ($item) {
- return $item->groupId->courses_id;
- }, function ($item) {
- return $item->groupId->courses_id;
- });
- $paymentCourses = [];
- $clientNewCoursesProvider = new ActiveDataProvider([
- 'query' => Courses::find()
- ->andWhere(['>=', 'DATE(date_end)', $nowDate])
- ->andWhere(['NOT IN', 'courses.id', $clientGroups])
- ->andWhere(['courses.status_id' => Courses::STATUS_COURSE_AVAILABLE])
- ->orderBy(['courses.id' => \SORT_DESC]),
- ]);
- $dataStatus = [];
- foreach ($modelClients->clientsOffer as $item) {
- $dataStatus[$item->course_id] = ['name' => $item->statusNane->name, 'id' => $item->status_id, 'rejection_comm' => $item->rejection_comm];
- }
- $courses_id_with_offer_statuses_refused = [];
- foreach ($dataStatus as $key => $value) {
- if (\in_array($value['id'], [OnlineCoursesOffer::STATUS_CLIENT_COURSE_REFUSE, OnlineCoursesOffer::STATUS_CLIENT_COURSE_REFUSE_AFTER_AGREE, OnlineCoursesOffer::STATUS_CLIENT_COURSE_REFUSE_AFTER_MAYBE])) {
- \array_push($courses_id_with_offer_statuses_refused, $key);
- }
- }
- $clientRefusedCoursesProvider = new ActiveDataProvider([
- 'query' => Courses::find()
- ->andWhere(['IN', 'courses.id', $courses_id_with_offer_statuses_refused])
- ->andWhere(['courses.status_id' => Courses::STATUS_COURSE_ARCHIVE])
- ->orderBy(['courses.id' => \SORT_DESC])
- ]);
- $clientUnpaidCoursesProvider = new ActiveDataProvider([
- 'query' => ClientGroups::find()
- ->joinWith(['clientPayment occp'])
- ->where(['client_id' => $id])
- ->andWhere(['occp.date_pay' => null])
- ->andWhere(['IN', 'occp.status_id', [ClientPaymentStatus::STATUS_CARD_PAY_WAIT, ClientPaymentStatus::STATUS_ACCOUNT_PAY_WAIT]])
- ->orderBy(['online_courses.client_groups.id' => \SORT_DESC]),
- ]);
- $modelClientGroup = new ClientGroups();
- // таб Заявки
- $petition = new Petitions();
- // таб Устройства клиента
- $clientDeviceSearch = new ClientDeviceSearch();
- $dataProviderClientDevice = $clientDeviceSearch->search(Yii::$app->request->get(), $id);
- return $this->render('view', [
- 'modelClients' => $modelClients,
- 'modelClientsTechSupport' => $model_tech_support_client,
- // Модальное окно "Контакты"
- 'contactsEmailProvider' => $contactsEmailProvider,
- 'contactsEmailMainProvider' => $contactsEmailMainProvider,
- 'contactsFaxProvider' => $contactsFaxProvider,
- 'contactsHomeProvider' => $contactsHomeProvider,
- 'contactsMobileProvider' => $contactsMobileProvider,
- // Курсы
- 'clientPastCoursesProvider' => $clientPastCoursesProvider,
- 'clientNewCoursesProvider' => $clientNewCoursesProvider,
- 'clientRefusedCoursesProvider' => $clientRefusedCoursesProvider,
- 'clientUnpaidCoursesProvider' => $clientUnpaidCoursesProvider,
- 'paymentCourses' => $paymentCourses,
- 'finalGroup' => $finalGroup,
- 'dataStatus' => $dataStatus,
- 'modelClientGroup' => $modelClientGroup,
- // Заявки
- 'petition' => $petition,
- // Устройства клиента
- 'clientDeviceSearch' => $clientDeviceSearch,
- 'dataProviderClientDevice' => $dataProviderClientDevice,
- ]);
- }
- public function actionUpdateClient($id)
- {
- $post = \Yii::$app->request->post();
- if (!$post) {
- Clients::setSettingLogg('tz', 'online_courses', 'Clients', Yii::$app->request->url);
- }
- $modelClients = $this->findModel($id);
- $factory = new FactoryArrayDataOption([
- 'city' => new CrmCityDataOption(),
- ]);
- if ($post && $modelClients->load($post)) {
- if ($modelClients->save()) {
- if (!empty($modelClients->tech_support_client_id)) {
- if (null !== ($modelClient = Client::findModel($modelClients->tech_support_client_id))) {
- $modelClient->comm_courses = $modelClients->comm_courses;
- $modelClient->save();
- }
- }
- return $this->redirect(['view', 'id' => $id]);
- }
- }
- return $this->render('update-client', [
- 'modelClients' => $modelClients,
- 'factory' => $factory,
- ]);
- }
- public function actionClientContact($client_id)
- {
- if (Yii::$app->user->isGuest) {
- $this->goHome();
- }
- $modelClients = $this->findModel($client_id);
- $client_contacts = ClientContacts::find()->andFilterWhere(['client_id' => $client_id]);
- $dataProvider = new ActiveDataProvider(['query' => $client_contacts]);
- return $this->render('client-contact/index', [
- 'dataProvider' => $dataProvider,
- 'modelClients' => $modelClients,
- ]);
- }
- public function actionCreateClientContact($client_id)
- {
- if (Yii::$app->user->isGuest) {
- $this->goHome();
- }
- $model = new ClientContacts();
- $modelClients = $this->findModel($client_id);
- $post = Yii::$app->request->post();
- if ($model->load($post)) {
- //HistoryTechSupport::$npp = CrmHistory::find()->max('npp') + 1;
- $model->name = \trim($post['ClientContacts']['name']);
- if ($model->save()) {
- return $this->redirect(['client-contact', 'client_id' => $client_id]);
- }
- }
- return $this->render('client-contact/create', [
- 'model' => $model,
- 'modelClients' => $modelClients,
- ]);
- }
- public function actionUpdateClientContact($id, $client_id, $type)
- {
- if (Yii::$app->user->isGuest) {
- $this->goHome();
- }
- if (!Yii::$app->request->post() && $type != "fax") {
- ClientContacts::setSettingLogg('name', $type, Yii::$app->request->url);
- }
- $model = $this->findModelClientContacts($id);
- $modelClients = $this->findModel($client_id);
- if ($model->load(Yii::$app->request->post())) {
- //HistoryTechSupport::$npp = CrmHistory::find()->max('npp') + 1;
- $model->name = trim($model->name);
- if ($model->save()) {
- return $this->redirect(['client-contact', 'client_id' => $client_id]);
- }
- }
- return $this->render('client-contact/update', [
- 'model' => $model,
- 'modelClients' => $modelClients,
- ]);
- }
- public function actionDeleteClientContact($id, $client_id)
- {
- if (Yii::$app->user->isGuest) {
- $this->goHome();
- }
- //HistoryTechSupport::$npp = CrmHistory::find()->max('npp') + 1;
- $this->findModelClientContacts($id)->delete();
- return $this->redirect(['client-contact', 'client_id' => $client_id]);
- }
- public function actionIndex()
- {
- $searchModel = new ClientsSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->get(), 'index');
- if (!empty(Yii::$app->request->queryParams) && !empty($searchModel->getSearch())) {
- InfoLog::saveSearch(InfoLog::cleanText($searchModel->getSearch()), Yii::$app->request->url);
- }
- return $this->render('index', [
- 'dataProvider' => $dataProvider,
- 'searchModel' => $searchModel,
- ]);
- }
- public function actionTranslate()
- {
- $searchModel = new ClientsSearch();
- $dataProvider = $searchModel->translate(Yii::$app->request->queryParams);
- return $this->render('translate', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
- public function actionCreate($group_id, $courses_id)
- {
- $model = new Clients();
- $model_client_groups = new ClientGroups();
- return $this->getUpdate($model, $group_id, $courses_id, 'create', $model_client_groups);
- }
- public function actionUpdate($id, $group_id, $courses_id, $key_redirect)
- {
- if (!Yii::$app->request->post()) {
- ClientGroups::setSettingLogg(
- ['youtube_email_contact_id', 'mailing_email_contact_id'],
- 'online_courses',
- 'Clients',
- Yii::$app->request->url
- );
- }
- $model = $this->findModel($id);
- return $this->getUpdate($model, $group_id, $courses_id, 'update', $key_redirect);
- }
- private function getUpdate($model, $group_id, $courses_id, $action, $key_redirect, $model_client_groups = null)
- {
- $post = Yii::$app->request->post();
- $course = Courses::findOne(['id' => $courses_id]);
- $group = Group::findOne(['id' => $group_id]);
- $modelClientPayment = new ClientPayment();
- $dataOption = new FactoryArrayDataOption([
- 'client_contacts' => new ClientContactsDataOption($model->id),
- ]);
- $model_client_groups = ClientGroups::find()
- ->where(['client_id' => $model->id])
- ->andWhere(['group_id' => $group_id])
- ->one();
- $youtube_email_contact_id = $model_client_groups->youtube_email_contact_id;
- $mailing_email_contact_id = $model_client_groups->mailing_email_contact_id;
- if (!empty($post)) {
- $newEmail = $post['ClientGroups']['youtube_email_contact'] ?? null;
- $transferType = $post['confirm_transfer_type'] ?? null;
- $confirmTransfer = $post['confirm_transfer'] ?? null;
- if (
- Yii::$app->request->isAjax &&
- $newEmail &&
- $newEmail !== $youtube_email_contact_id &&
- !$confirmTransfer
- ) {
- Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- Yii::$app->response->data = [
- 'status' => 'confirm',
- 'oldEmail' => $youtube_email_contact_id,
- 'newEmail' => $newEmail,
- ];
- return;
- }
- if (
- $newEmail &&
- $newEmail !== $youtube_email_contact_id &&
- $confirmTransfer === '1'
- ) {
- try {
- $znayooService = new \app\services\online_course\client\znayoo\ZnayooClientService();
- if ($transferType === 'transfer') {
- $znayooService->transferCoursesToAnotherEmail(
- $youtube_email_contact_id,
- $newEmail,
- $model->first_name,
- $model->last_name,
- $model->tz
- );
- } elseif ($transferType === 'create_new') {
- $newUser = $znayooService->ensureUserExists(
- $newEmail,
- $model->first_name,
- $model->last_name,
- $model->tz
- );
- $znayooService->assignUserToCourse($newUser['id'], $course);
- $model_client_groups->youtube_email_contact_id = $youtube_email_contact_id;
- }
- } catch (\Throwable $e) {
- Yii::$app->session->setFlash('error', "Ошибка при обработке переноса: " . $e->getMessage());
- }
- }
- $oldNumber = $model_client_groups->number;
- $provider = (new FactoryProvider())->getProvider();
- $modelClientPaymentCard = new ClientPaymentCard();
- $serviceClient = new $provider(
- $model,
- $model_client_groups,
- $modelClientPaymentCard,
- $modelClientPayment
- );
- $serviceClient->update();
- $now = \Carbon\Carbon::now();
- if (trim($model_client_groups->number) != $oldNumber && trim($model_client_groups->number) != '') {
- OnlineCoursesAutodialler::updateAll(
- ['phone_number' => $model_client_groups->number],
- "client_id = $model_client_groups->client_id and calldate > '$now' and group_id = $model_client_groups->group_id"
- );
- } elseif (trim($model_client_groups->number) == '') {
- OnlineCoursesAutodialler::deleteAll(
- "client_id = $model_client_groups->client_id and calldate > '$now' and group_id = $model_client_groups->group_id"
- );
- }
- $updateMail = new ClientGroupMail(
- $post,
- $model_client_groups,
- $model,
- $youtube_email_contact_id,
- $mailing_email_contact_id
- );
- $updateMail->updateAllMail();
- if (Yii::$app->request->isAjax) {
- Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- $redirectUrl = null;
- if (Yii::$app->authManager->getAssignment('tsAgent', Yii::$app->user->identity->id)) {
- $redirectUrl = \yii\helpers\Url::to(['/online_courses/courses/update', 'id' => $courses_id]);
- } elseif ('update' == $action) {
- if ($key_redirect == 'update_in_course') {
- $redirectUrl = \yii\helpers\Url::to(['/online_courses/courses/update', 'id' => $courses_id, '#' => 'tab-5']);
- } elseif ($key_redirect == 'update_in_client_card') {
- $redirectUrl = \yii\helpers\Url::to(['/online_courses/clients/view', 'id' => $model->id, '#' => 'tab-2-2']);
- } elseif ($key_redirect == 'update_in_course_group') {
- $redirectUrl = \yii\helpers\Url::to([
- '/online_courses/group/update',
- 'id' => $group_id,
- 'courses_id' => $courses_id,
- '#' => 'tab-2'
- ]);
- }
- }
- Yii::$app->response->data = [
- 'status' => 'success',
- 'message' => 'Данные успешно сохранены.',
- 'redirect' => $redirectUrl,
- ];
- return;
- }
- }
- $query = ClientGroups::find()
- ->where([
- 'AND',
- ['client_id' => $model->id],
- ['<>', 'group_id', $group_id]
- ])
- ->andWhere(['IS NOT', 'device_id', null])
- ->orderBy(['id' => SORT_DESC])
- ->limit(5);
- $clientGroupDataProvider = new \yii\data\ActiveDataProvider(['query' => $query]);
- return $this->render($action, [
- 'model' => $model,
- 'course' => $course,
- 'group' => $group,
- 'model_client_groups' => $model_client_groups,
- 'dataOption' => $dataOption,
- 'clientGroupDataProvider' => $clientGroupDataProvider,
- ]);
- }
- public function actionAdd($courses_id, $param, $client_id = null)
- {
- $provider = (new FactoryProvider())->getProvider($param);
- $currentUser = Yii::$app->user->identity->getId();
- $model = new Clients();
- $model_client_groups = new ClientGroups();
- $modelClientPaymentCard = new ClientPaymentCard();
- $modelClientPayment = new ClientPayment();
- $serviceClient = new $provider($model, $model_client_groups, $modelClientPaymentCard, $modelClientPayment);
- $modelClientContact = new ClientContacts();
- $model_client_groups->shikuf_eska_date = \Carbon\Carbon::now()->format('Y-m-d');
- $model_client_groups->shikuf_eska_user_id = $currentUser;
- $model_client_groups->user_add_id = $currentUser;
- $model_client_groups->client_id = $client_id;
- $course = Courses::findOne(['id' => $courses_id]);
- $modelOnlineCoursesOffer = new OnlineCoursesOffer();
- $modelOffer = null;
- if (!empty($courses_id) && !empty($client_id)) {
- $modelOffer = $serviceClient->getCourseLead($client_id, $courses_id);
- if ($modelOffer) {
- $model_client_groups->user_add_id = '';
- }
- }
- $dataOptions = new FactoryArrayDataOption([
- 'clientGroups' => new ClientGroupDataOption($courses_id),
- 'userList' => new UserListDataOption($modelOffer),
- ]);
- return $this->renderAjax(
- 'add_view_modal/main',
- $serviceClient->render($param)->getParams($client_id) +
- [
- 'model' => $model,
- 'model_client_groups' => $model_client_groups,
- 'dataOptions' => $dataOptions,
- 'courses_id' => $courses_id,
- 'param' => $param,
- 'valueProject' => '',
- 'course' => $course,
- 'modelClientPaymentCard' => $modelClientPaymentCard,
- 'modelClientContact' => $modelClientContact,
- 'listProjects' => ['SC' => 'SC', 'DEF' => 'Клиент курсов', 'NEW' => 'Новый клиент', 'IPL' => 'IPL'],
- 'modelClientPayment' => $modelClientPayment,
- 'modelOnlineCoursesOffer' => $modelOnlineCoursesOffer,
- 'modelOffer' => $modelOffer,
- ]
- );
- }
- public function actionAddFinal()
- {
- $post = Yii::$app->request->post();
- if (!empty($post)) {
- $groupModel = Group::find()->where(['courses_id' => $post['course_id']])->andWhere(['type_id' => 0])->one();
- if (!empty($groupModel)) {
- $model_client_groups = new ClientGroups();
- $model_client_groups->group_id = $groupModel->id;
- $model_client_groups->client_id = $post['client_id'];
- $model_client_groups->user_add_id = Yii::$app->user->identity->id;
- $model_client_groups->user_add_date_d = Carbon::now();
- $model_client_groups->youtube_email_contact_id = $post['youtube_email'];
- $model_client_groups->mailing_email_contact_id = $post['mail_email'];
- $model_client_groups->save();
- return true;
- }
- }
- return false;
- }
- public function actionSaveClient($courses_id, $param)
- {
- $post = Yii::$app->request->post();
- if (!empty($post)) {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- try {
- $email = $post['ClientGroups']['youtube_email_contact'] ?? null;
- $course = Courses::findOne($courses_id);
- if (!$course) {
- throw new \Exception("Курс с ID {$courses_id} не найден.");
- }
- $clientId = $post['ClientGroups']['client_id'] ?? null;
- if (!$clientId) {
- throw new \Exception("ID клиента не передан.");
- }
- $client = \app\models\tech_support\Client::findOne($clientId);
- if (!$client) {
- throw new \Exception("Клиент с ID {$clientId} не найден.");
- }
- if (!empty($email)) {
- $znayoo = new \app\services\online_course\client\znayoo\ZnayooClientService();
- $znUser = $znayoo->ensureUserExists(
- $email,
- $client->first_name,
- $client->last_name,
- $client->tz
- );
- $znayoo->assignUserToCourse($znUser['id'], $course);
- }
- $model = new Clients();
- $model_client_groups = new ClientGroups();
- $provider = (new FactoryProvider())->getProvider($post['Clients']['clientCompany']);
- $serviceClient = new $provider(
- $model,
- $model_client_groups,
- new ClientPaymentCard(),
- new ClientPayment()
- );
- $serviceClient->create();
- return [
- 'url' => $serviceClient->render($param)->redirectUrl(
- $post['ClientGroups']['client_id'],
- $post['ClientGroups']['group_id'],
- $courses_id
- ),
- 'success' => 'Клиент успешно записан на курс',
- ];
- } catch (\Exception $e) {
- return [
- 'error' => $e->getMessage(),
- ];
- }
- }
- }
- /**
- * @param $client_id
- * @param $group_id
- * @param $courses_id
- * @return string|Response
- */
- public function actionChangeGroup($client_id, $group_id, $courses_id)
- {
- $model_client_groups = ClientGroups::findOne(['client_id' => $client_id, 'group_id' => $group_id]);
- $post = Yii::$app->request->post();
- $dataOptions = new FactoryArrayDataOption([
- 'OnlineCourses' => new OnlineCoursesDataOption(null, $group_id, $courses_id),
- ]);
- if ($post && $model_client_groups->load($post)) {
- $model_client_groups->save();
- $this->updateOnlineCoursesAutodialler($client_id, $group_id, $courses_id, $model_client_groups);
- return $this->redirect(['/online_courses/group/update', 'id' => $group_id, 'courses_id' => $courses_id]);
- }
- return $this->renderAjax('change-group', [
- 'model_client_groups' => $model_client_groups,
- 'dataOptions' => $dataOptions,
- ]);
- }
- public function actionAutodiallerView($client_id)
- {
- $dataProvider = new ActiveDataProvider([
- 'query' => OnlineCoursesAutodialler::find()->where(['client_id' => $client_id]),
- ]);
- return $this->renderAjax('autodialler-view', [
- 'dataProvider' => $dataProvider,
- ]);
- }
- protected function findModel($id)
- {
- if (null !== ($model = Clients::findOne($id))) {
- return $model;
- }
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- public static function findModelClientContacts($id)
- {
- if (null !== ($model = ClientContacts::findOne($id))) {
- return $model;
- }
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- public function actionGetEmails($client_id, $project_id, $course_id, $user_can)
- {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- $provider = (new FactoryProvider())->getProvider($project_id);
- $model = new Clients();
- $model_client_groups = new ClientGroups();
- $modelClientPaymentCard = new ClientPaymentCard();
- $modelClientPayment = new ClientPayment();
- $serviceClient = new $provider($model, $model_client_groups, $modelClientPaymentCard, $modelClientPayment);
- if ($project_id == 'SC') {
- $client_id_check = Clients::find()->where(['tech_support_client_id'=>$client_id])->select('id')->asArray()->one();
- $checkPayment = $this->checkPaymentClient($client_id_check['id']);
- }
- if ($project_id == 'DEF') {
- $checkPayment = $this->checkPaymentClient($client_id);
- }
- if ($project_id == 'IPL') {
- $client_id_check = Clients::find()->where(['ipl_client_id' => $client_id])->select('id')->asArray()->one();
- $checkPayment = $this->checkPaymentClient($client_id_check['id']);
- }
- $accept = 1;
- if (\count($checkPayment) >= 2 && $user_can == 0) {
- $accept = 0;
- return 'to_many';
- }
- if (isset($client_id) && $accept == 1) {
- $contacts = $serviceClient->getClientContactProject()::find()
- ->andWhere(['client_id' => $client_id])
- ->all();
- $contactsEmail = [];
- $contactsNumber = [];
- foreach ($contacts as $value) {
- if ($value instanceof ClientContacts || $value instanceof \app\models\ClientContacts) {
- if ($value['typeId']['name'] == 'email') {
- $contactsEmail[] = $value;
- }
- if ($value['typeId']['name'] == 'phone_home' || $value['typeId']['name'] == 'phone_mobile') {
- $contactsNumber[] = $value;
- }
- } else {
- if ($value['type'] == 'email') {
- $contactsEmail[] = $value;
- }
- if ($value['type'] == 'phone_home' || $value['type'] == 'phone_mobile') {
- $contactsNumber[] = $value;
- }
- }
- }
- $modelClientCard = $serviceClient->getCardInBilling($client_id);
- $select = isset($contactsEmail[0]) ? $contactsEmail[0]->name : null;
- $modelClient = $serviceClient->getClient()::findOne(['id' => $client_id]);
- $groups = $serviceClient->getClientGroup($client_id, $course_id);
- if (null == $modelClient) {
- return ['error' => 'Клиент не найден'];
- }
- $arrContact = ArrayHelper::map($contactsEmail, 'name', 'name');
- $arrContactYoutube = \array_filter($arrContact, function ($item) {
- return \preg_match('/^[\w.+\-]+@gmail\.com$/', $item);
- });
- if (!empty($contactsNumber)) {
- $arrNumber = ArrayHelper::map($contactsNumber, 'name', 'name');
- }
- $lead = $client_id_type = 'client_id';
- if ($modelClient instanceof Client) {
- $client_id_type = 'techsupport_client_id';
- $lead = "tech_support_client_id";
- }
- $arrCourseLead = [];
- $prices = [];
- $user_lead_id = "";
- $arrCourseLead = [];
- $modelCourse = Courses::findOne($course_id);
- if ($modelClient instanceof \app\models\Client) {
- if (null !== $modelCourse) {
- if (isset($modelClient->techSupportClient->id) && !empty($modelClient->techSupportClient->id) && in_array(
- $modelClient->techSupportClient->status_id,
- [2, 9]
- )) {
- $prices = $modelCourse->getPrice(
- $course_id,
- $modelClient->techSupportClient->id,
- 'techsupport_client_id'
- );
- $model_course_lead = CourseLead::find()
- ->where(['course_id' => $course_id])
- ->andWhere(['tech_support_client_id' => $modelClient->id])
- ->one();
- if (!empty($model_course_lead)) {
- $user_lead_id = $model_course_lead->user_lead_id;
- $arrCourseLead = [$user_lead_id => $model_course_lead->crmUser->first_name . ' ' . $model_course_lead->crmUser->last_name];
- }
- } else {
- $data = Discount::find()
- ->where(['course_id' => $course_id])
- ->andWhere(['type_id' => 1])
- ->orderBy(['id' => \SORT_DESC])
- ->one();
- $prices = [
- [
- 'label' => $data->priceType->name . " " . $data['price'] . " шек",
- 'value' => $data['price'],
- 'special_sale' => 0
- ]
- ];
- }
- }
- } else {
- if (null !== $modelCourse) {
- $prices = $modelCourse->getPrice($course_id, $modelClient->id, $client_id_type);
- }
- $model_course_lead = CourseLead::find()
- ->where(['course_id' => $course_id])
- ->andWhere([$lead => $modelClient->id])
- ->one();
- if (!empty($model_course_lead)) {
- $user_lead_id = $model_course_lead->user_lead_id;
- $arrCourseLead = [$user_lead_id =>
- $model_course_lead->crmUser->first_name . ' ' . $model_course_lead->crmUser->last_name
- ];
- }
- }
- return [
- 'option' => Html::renderSelectOptions(
- $select,
- $arrContact,
- $o
- ),
- 'option_youtube' => Html::renderSelectOptions(
- $select,
- $arrContactYoutube,
- $o
- ),
- 'arrNumber' => Html::renderSelectOptions(
- '',
- $arrNumber,
- $o
- ),
- 'clientData' => [
- 'name' => $modelClient->last_name . ' ' . $modelClient->first_name,
- 'tz' => $modelClient->tz,
- 'is_sabbath' => $modelClient->is_sabbath,
- ],
- 'clientPaymentCard' => $modelClientCard,
- 'clientPayment' => $modelClientPayment,
- 'prices' => $prices,
- 'groups' => $groups,
- 'userLeadId' => $user_lead_id,
- 'userLeadSelect' => Html::renderSelectOptions(
- $user_lead_id,
- $arrCourseLead,
- $o
- ),
- 'key_accept' => $accept,
- ];
- }
- return '';
- }
- public function actionDeleteGroupClient()
- {
- Yii::$app->response->format = Response::FORMAT_JSON;
- $post = Yii::$app->request->post();
- $model = ClientGroups::findOne($post['id']);
- if (!$model) {
- throw new \Exception("Группа клиента с ID {$post['id']} не найдена.");
- }
- // $znayoo = new \app\services\online_course\client\znayoo\ZnayooClientService();
- //
- // try {
- // $znayoo->removeUserFromCourse($model->youtube_email_contact_id, $model->course);
- // } catch (\Throwable $e) {
- // throw new \Exception("Не удалось удалить клиента с курса в Znayoo: " . $e->getMessage());
- // }
- $offerModel = new OnlineCoursesOffer();
- $current_source_id = ClientPayment::find()
- ->select(['id'])
- ->where(['client_group_id' => $model->id])
- ->one();
- $modelClientPayment = ClientPayment::findOne($current_source_id);
- if ($modelClientPayment) {
- $modelInvoice = ClientInvoices::findOne($modelClientPayment->client_invoice_id);
- if ($modelInvoice) {
- if ($modelInvoice->payment_period_closed != 1 && $modelInvoice->unchangeable_number_flag != 1) {
- $this->updateNotPaid($modelInvoice);
- }
- }
- }
- $clientPaymentModel = ClientPayment::find()
- ->alias('occp')
- ->select(['occ.tech_support_client_id as tech_support_client_id', 'occ.tz as client_course_tz',
- 'occp.card_id', 'occp.shovar', 'occp.amount',
- 'occp.date_pay', 'occp.date_d', 'occp.status_id',])
- ->leftJoin('online_courses.client_groups occg', 'occp.client_group_id=occg.id')
- ->leftJoin('online_courses.clients occ', 'occg.client_id=occ.id')
- ->where(['occp.client_group_id' => $post['id']])
- ->andWhere(['IN', 'occp.status_id', [4,7,16]])
- ->all();
- if ($clientPaymentModel) {
- foreach ($clientPaymentModel as $item) {
- $clientPaymentCardModel = ClientPaymentCard::find()->where(['id' => $item['card_id']])->one();
- $card_number = $clientPaymentCardModel['number'];
- $four_numbers = \substr($card_number, -4);
- $clientPaymentNotPaidModel = new ClientPaymentNotPaid();
- $clientPaymentNotPaidModel->client_id = App::TECH_SUPPORT_900000 + $item['tech_support_client_id'];
- $clientPaymentNotPaidModel->tz = $item['client_course_tz'];
- $clientPaymentNotPaidModel->number = $four_numbers;
- $clientPaymentNotPaidModel->shovar = $item['shovar'];
- $clientPaymentNotPaidModel->amount = $item['amount'];
- $clientPaymentNotPaidModel->date_pay = $item['date_pay'];
- $clientPaymentNotPaidModel->date_d = $item['date_d'];
- $clientPaymentNotPaidModel->status_id = ClientPaymentNotPaid::STATUS_NOT_DONE;
- $clientPaymentNotPaidModel->reason_library_id = CrmLibrary::CLIENT_PAYMENT_NOT_PAID_AFTER_COURSE;
- $clientPaymentNotPaidModel->client_payment_status_id =
- ClientPaymentStatus::STATUS_EASY_CARD_DEAL_WENT_THROUGH;
- $clientPaymentNotPaidModel->save();
- }
- }
- if ($offerModel) {
- $offerModel->client_id = $model->client->tech_support_client_id;
- $offerModel->course_id = $model->course->id;
- $offerModel->status_id = 130;
- $offerModel->agent_call_id = \Yii::$app->user->identity->getId();
- $offerModel->call_date = Carbon::now();
- $offerModel->save();
- }
- $modelLead = CourseLead::find()
- ->where(['client_id' => $model->client_id])
- ->andWhere(['course_id' => $model->course->id])
- ->one();
- if (!empty($modelLead)) {
- $modelLead->delete();
- }
- // Here was checking of OnlineCoursesAutodialler::checkDelete($courseId, $groupId, $calldate = null, $clientId).
- // Regarding issue of A.Ferenets this check don't need in business process.
- ClientPayment::deleteAll(['client_group_id' => $model->id]);
- OnlineCoursesAutodialler::deleteAll([
- 'client_id' => $model->client_id,
- 'group_id' => $model->group_id,
- 'course_id' => $model->groupId->courses_id,
- ]);
- $modelBilling = Billing::find()
- ->select(['id'])
- ->where(['course_client_id' => $model->client_id])
- ->andWhere(['source_id' => $current_source_id])
- ->andWhere([
- 'IN',
- 'status_id',
- [
- BillingStatus::NOT_DONE,
- BillingStatus::SERUV,
- BillingStatus::CARD_PROBLEM,
- BillingStatus::CANCELED
- ]
- ])
- ->asArray()
- ->all();
- $billing_ids_array = [];
- if (!empty($modelBilling)) {
- foreach ($modelBilling as $billing_item) {
- $billing_ids_array[] = $billing_item['id'];
- }
- }
- if (!empty($billing_ids_array)) {
- Billing::deleteAll(['id' => $billing_ids_array]);
- }
- return $model->delete();
- }
- public function actionOffer($courses_id, $param, $client_id)
- {
- $model = new OnlineCoursesOffer();
- $post = Yii::$app->request->post();
- $provider = (new FactoryProvider())->getProvider($param);
- $modelClient = new Clients();
- $model_client_groups = new ClientGroups();
- $modelClientPaymentCard = new ClientPaymentCard();
- $modelClientPayment = new ClientPayment();
- $serviceClient =
- new $provider($modelClient, $model_client_groups, $modelClientPaymentCard, $modelClientPayment);
- $modelLast = $serviceClient->courseOffer($courses_id, $client_id);
- $dataOptions = new FactoryArrayDataOption([
- 'CrmLibrary' => new CrmLibraryDataOption($modelLast->status_id),
- ]);
- if ($model->load($post) || $post['refuse-shikuf']) {
- return $serviceClient->saveOffer($courses_id, $client_id, $post);
- }
- return $this->renderAjax(
- 'add_view_modal/offer',
- [
- 'model' => $model,
- 'dataOptions' => $dataOptions,
- ]
- );
- }
- public function actionDeleteClientAutodial()
- {
- $post = Yii::$app->request->post();
- $model = ClientGroups::findOne($post['id']);
- if ((0 == OnlineCoursesAutodialler::checkDeleteAutoDial(
- $model->groupId->courses_id,
- $model->group_id,
- null,
- $model->client_id
- )) && (1 == $model->autoudialler_flag)) {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- $model->autoudialler_flag = 1;
- $model->save();
- return OnlineCoursesAutodialler::updateAll(
- [
- 'autodialler_del' => 1,
- 'user_id_del' => \Yii::$app->user->identity->getId(),
- 'date_del' => Carbon::now(),
- ],
- ['and',
- ['=', 'client_id', $model->client_id],
- ['=', 'group_id', $model->group_id],
- ['is', 'calldate_done', null],
- ]
- );
- }
- public function actionAddClientAutodial()
- {
- $post = Yii::$app->request->post();
- $model = ClientGroups::findOne($post['id']);
- if (0 > OnlineCoursesAutodialler::checkDeleteAutoDial(
- $model->groupId->courses_id,
- $model->group_id,
- null,
- $model->client_id
- )) {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- $model->autoudialler_flag = null;
- $model->save();
- return OnlineCoursesAutodialler::updateAll(
- [
- 'autodialler_del' => null,
- 'user_id_del' => null,
- 'date_del' => null,
- ],
- ['and',
- ['=', 'client_id', $model->client_id],
- ['=', 'group_id', $model->group_id],
- ['is', 'calldate_done', null],
- ]
- );
- }
- public function actionValidation()
- {
- $model = new Clients();
- $post = Yii::$app->request->post();
- if (Yii::$app->request->isAjax && $model->load($post)) {
- Yii::$app->response->format = Response::FORMAT_JSON;
- return ActiveForm::validate($model);
- }
- }
- public function actionAddClientCourse($client_id)
- {
- $dataOptions = new FactoryArrayDataOption([
- 'Course' => new CoursesDataOption(),
- ]);
- return $this->renderAjax(
- 'add_view_modal/course',
- [
- 'client_id' => $client_id,
- 'dataOptions' => $dataOptions,
- ]
- );
- }
- public function actionGetClientOffer($courses_id, $client_id)
- {
- $model = $this->findModel($client_id);
- $resultCourseOffer = OnlineCoursesOffer::findAgreeOffer(
- $courses_id,
- $client_id,
- $model
- );
- if (!empty($resultCourseOffer)) {
- return $resultCourseOffer;
- }
- $resultCourseLead = CourseLead::getLead(
- $courses_id,
- $client_id,
- $model
- );
- if (!empty($resultCourseLead)) {
- return $resultCourseLead;
- }
- $resultClientGroups = ClientGroups::findByCourse(
- $courses_id,
- $client_id
- );
- if (!empty($resultClientGroups)) {
- return $resultClientGroups;
- }
- return false;
- }
- public function actionUpdateMail($client_id, $mail_id)
- {
- $post = Yii::$app->request->post();
- $email = $post['ClientContacts']['name'] ?? null;
- if ($email) {
- $existing = ClientContacts::findOne([
- 'name' => $email,
- 'client_id' => $client_id,
- 'disabled' => 1,
- ]);
- if ($existing) {
- ClientContacts::updateAll(
- ['disabled' => 1],
- ['and', ['client_id' => $client_id], ['type_id' => 2], ['<>', 'name', $email]]
- );
- $existing->disabled = 0;
- $existing->active = 1;
- $existing->status = 1;
- $existing->save();
- return $existing->name;
- }
- if (!empty($mail_id) && $mail_id !== 'new' && $mail_id !== 'null') {
- $old = ClientContacts::findOne([
- 'name' => $mail_id,
- 'client_id' => $client_id,
- 'type_id' => 2,
- 'disabled' => 0,
- ]);
- if ($old) {
- $old->disabled = 1;
- $old->active = 0;
- $old->status = 0;
- $old->save();
- }
- }
- $modelNew = new ClientContacts([
- 'client_id' => $client_id,
- 'active' => 1,
- 'main' => 0,
- 'status' => 1,
- 'type_id' => 2,
- 'disabled' => 0,
- ]);
- if ($modelNew->load($post)) {
- $modelNew->data = $modelNew->name;
- if ($modelNew->save()) {
- return $modelNew->name;
- }
- }
- }
- return $this->renderAjax('add_view_modal/mail_update', [
- 'model' => new ClientContacts(),
- ]);
- }
- public function actionAddLeadCourse()
- {
- Yii::$app->response->format = Response::FORMAT_JSON;
- $post = Yii::$app->request->post();
- $model = $this->findModel($post['client_id']);
- if (!empty($post) && !empty($model)) {
- if (
- !OnlineCoursesOffer::findAgreeOffer(
- $post['course_id'],
- $post['client_id'],
- $model
- )
- && !CourseLead::getLead(
- $post['course_id'],
- $post['client_id'],
- $model
- )
- && !ClientGroups::findByCourse(
- $post['course_id'],
- $post['client_id']
- )
- ) {
- $onlineCourseOffer = new CourseLead();
- $onlineCourseOffer->tech_support_client_id = $model->tech_support_client_id;
- $onlineCourseOffer->client_id = $model->id;
- $onlineCourseOffer->course_id = $post['course_id'];
- $onlineCourseOffer->user_lead_id = \Yii::$app->user->identity->getId();
- $onlineCourseOffer->date_d = Carbon::now();
- $onlineCourseOffer->save();
- }
- return true;
- }
- return false;
- }
- public function actionGetCurrentMail($client_id, $group_id)
- {
- Yii::$app->response->format = Response::FORMAT_JSON;
- $contactArr = [];
- $mails = ClientGroups::find()
- ->select('youtube_email_contact_id, mailing_email_contact_id')
- ->where(['client_id' => $client_id])
- ->andWhere(['group_id' => $group_id])
- ->asArray()
- ->one();
- $contacts = ClientContacts::find()
- ->select('name')
- ->where(['client_id' => $client_id])
- ->andWhere(['type_id' => 2])
- ->andWhere(['<>', 'disabled', '1'])
- ->asArray()
- ->all();
- foreach ($contacts as $contact) {
- \array_push($contactArr, $contact['name']);
- }
- foreach ($mails as $key => $value) {
- if (false !== \array_search($value, $contactArr)) {
- $mails[$key] = $value;
- } else {
- $mails[$key] = null;
- }
- }
- return $mails;
- }
- public function actionClientTypePaymentCourse($course_client_id, $course_id)
- {
- $query = Clients::unpaidClientCoursesQuery($course_client_id, $course_id);
- return $query['bank_account_status'];
- }
- public function actionCourseClientPetitionCreate($courses_client_id, $course_id)
- {
- $modelClient = Clients::findOne([$courses_client_id]);
- return $this->renderAjax(
- '/online_courses/courses/view/modal_new_petition',
- [
- 'modelClient' => $modelClient,
- 'course_id_for_petition' => $course_id,
- ]
- );
- }
- public function actionGetCourseGroupsList($course_id, $course_client_id)
- {
- if (empty($course_id)) {
- return \json_encode(false);
- }
- $groups = Group::find()
- ->alias('g')
- ->select(['g.id as group_id', 'g.group_name as name'])
- ->leftJoin('online_courses.client_groups occg', 'g.id=occg.group_id')
- ->where(['g.courses_id' => $course_id])
- ->andWhere(['occg.client_id' => $course_client_id])
- ->andWhere(['<>', 'type_id', 0])
- ->andWhere(['NOT LIKE', 'group_name', 'В записи'])
- ->asArray()
- ->all();
- $groups_list = [];
- foreach ($groups as $item) {
- $groups_list[$item['group_id']] = $item['name'];
- }
- return \json_encode($groups_list);
- }
- public function actionGetGroupLecturesList($course_client_id, $group_id)
- {
- if (empty($group_id)) {
- return \json_encode(false);
- }
- $lectures = Lectures::find()
- ->alias('l')
- ->select(['l.id', 'l.name'])
- ->leftJoin('online_courses.calendar occ', 'l.id=occ.lecture_id')
- ->andWhere(['occ.group_id' => $group_id])
- ->asArray()
- ->all();
- $lecture_list = [];
- foreach ($lectures as $item) {
- $lecture_list[$item['id']] = $item['name'];
- }
- return \json_encode($lecture_list);
- }
- public function actionRenderGridClientLogProgram($course_client_id, $lecture_id)
- {
- if (empty($lecture_id)) {
- return false;
- }
- $logProgramSearch = new LogProgramSearch();
- $dataProviderLogProgram = $logProgramSearch->search(Yii::$app->request->get(), $course_client_id);
- return $this->renderAjax('_grid_client_log_program', [
- 'dataProviderLogProgram' => $dataProviderLogProgram,
- ]);
- }
- public function actionShowTranslateNameModal()
- {
- return $this->renderAjax('/online_courses/clients/_translate_name_modal');
- }
- public function actionShowNumberAndComm($client_course_id, $course_group_id)
- {
- $numberAndComment = ClientGroups::find()
- ->where(['client_groups.id'=>$client_course_id])
- ->andWhere(['group_id' => $course_group_id]);
- $dataProvider = new ActiveDataProvider(['query' => $numberAndComment]);
- return $this->renderAjax('numberAndComment', ['dataProvider' => $dataProvider]);
- }
- public function actionChangeCommentOnNumber($client_course_id, $course_group_id)
- {
- $model = ClientGroups::find()
- ->where(['client_groups.id'=>$client_course_id])
- ->andWhere(['group_id' => $course_group_id])
- ->one();
- $post = Yii::$app->request->post();
- if ($post && $model->load($post)) {
- $model->save();
- $return = $model->comment_on_number . '<div class="tooltip-demo grid-button">' .
- Html::a('', null, [
- 'class' => 'glyphicon glyphicon-pencil',
- 'data-toggle' => 'tooltip',
- 'style' => 'float:right',
- 'data-client_id' => $model->id,
- 'data-group_id' => $model->group_id,
- 'onclick' => 'changeCommentOnNumber($(this))',
- ]) . '</div>';
- return '<span id="change_comment">' . $return . '</span>';
- } else {
- return $this->renderAjax('change-comment-on-number', [
- 'model' => $model,
- ]);
- }
- }
- public function actionChangeNumberClient($client_course_id, $course_group_id, $client_id)
- {
- $contacts = ClientContacts::find()->where(['client_id' => $client_id])->all();
- $changeField = 'Ручнной ввод';
- $numbers = [];
- foreach ($contacts as $contact) {
- if (strstr($contact['name'], '@') == false) {
- $numbers[$contact['name']] = $contact['name'];
- }
- }
- $numbers[] = $changeField;
- $model = ClientGroups::find()
- ->where(['client_groups.id' => $client_course_id])
- ->andWhere(['group_id' => $course_group_id])
- ->one();
- $post = Yii::$app->request->post();
- if ($post && $model->load($post)) {
- if ($model->number != null) {
- $model->save();
- }
- if ($model->number_client != null) {
- $model->number = $model->number_client;
- $model->save();
- }
- $return = $model->number . '<div class="tooltip-demo grid-button">' .
- Html::a('', null, [
- 'class' => 'glyphicon glyphicon-pencil',
- 'data-toggle' => 'tooltip',
- 'style' => 'float:right',
- 'data-client_id_course' => $model->id,
- 'data-group_id' => $model->group_id,
- 'data-client_id' => $model->client_id,
- 'onclick' => 'changeNumberClient($(this))'
- ]) . '</div>';
- return '<span id="change_number_in_cg">' . $return . '</span>';
- } else {
- return $this->renderAjax('change-number-client', [
- 'model' => $model,
- 'contacts' => $numbers,
- ]);
- }
- }
- /**
- * Displaying the form in the body of the modal window "Recording a client to the Graduation group"
- *
- * @param $course_client_id
- * @return string
- */
- public function actionGetFormModalAddFinal($course_client_id)
- {
- $model_client = Clients::findOne(['id' => $course_client_id]);
- $client_courses = $model_client->getCoursId()->all();
- $client_courses_list = [];
- if (!empty($client_courses)) {
- foreach ($client_courses as $client_course) {
- $check_final = ClientGroups::checkClientInFinalGroup($client_course->id, $course_client_id);
- if (!$check_final) {
- $client_courses_list[$client_course->id] = $client_course->courses_name;
- }
- }
- }
- return $this->renderPartial('/online_courses/clients/add_view_modal/_modal_client_add_final', [
- 'model_client' => $model_client,
- 'course_client_id' => $course_client_id,
- 'client_courses_list' => $client_courses_list,
- ]);
- }
- /**
- * Adding a client to the "Graduation" group for the selected course from the List of all course clients
- *
- * @return bool
- */
- public function actionSaveDataAddFinal()
- {
- $post = Yii::$app->request->post();
- if (!empty($post['course_id'])) {
- $group_final = Group::find()
- ->where(['courses_id' => $post['course_id']])
- ->andWhere(['type_id' => 0])
- ->one();
- $current_client_groups =
- ClientGroups::getClientGroupByCourseId($post['course_id'], $post['course_client_id']);
- if (!empty($group_final)) {
- $new_client_groups = new ClientGroups();
- $new_client_groups->group_id = $group_final->id;
- $new_client_groups->client_id = $post['course_client_id'];
- $new_client_groups->user_add_id = Yii::$app->user->identity->id;
- $new_client_groups->user_add_date_d = Carbon::now();
- $new_client_groups->youtube_email_contact_id = $current_client_groups['youtube_email_contact_id'];
- $new_client_groups->mailing_email_contact_id = $current_client_groups['mailing_email_contact_id'];
- $new_client_groups->save();
- return true;
- }
- }
- return false;
- }
- /**
- * Course auto-calling update
- *
- * @param $client_id
- * @param $group_id
- * @param $courses_id
- * @param ClientGroups $model_client_groups
- * @return void
- * @throws \yii\db\Exception
- */
- private function updateOnlineCoursesAutodialler(
- $client_id,
- $group_id,
- $courses_id,
- ClientGroups $model_client_groups
- ) {
- $group_ids_arr = Group::getMainGroupIds($courses_id);
- $check_group_in_recording = Group::checkGroupInRecording($group_id);
- if (\in_array($model_client_groups->group_id, $group_ids_arr)) {
- $date_now = Carbon::now()->format('Y-m-d');
- if (!$check_group_in_recording) {
- $current_calendars = Calendar::find()
- ->where(['course_id' => $courses_id])
- ->andWhere(['group_id' => $group_id])
- ->andWhere(['>=', 'DATE(date)', $date_now])
- ->asArray()
- ->all();
- $current_calendars_arr = [];
- if (!empty($current_calendars)) {
- foreach ($current_calendars as $item) {
- $current_calendars_arr[$item['lecture_id']] = $item['date'] . ' ' . $item['time'];
- }
- }
- }
- $new_calendars = Calendar::find()
- ->where(['course_id' => $courses_id])
- ->andWhere(['group_id' => $model_client_groups->group_id]) // new group
- ->andWhere(['>=', 'DATE(date)', $date_now])
- ->asArray()
- ->all();
- $calendars_arr = [];
- if (!empty($new_calendars)) {
- if ($check_group_in_recording) {
- $insertData = [];
- $client_phone_number = ClientContacts::find()
- ->where(['client_id' => $client_id])
- ->andWhere(['OR',
- ['type_id' => 1],
- ['main' => 1]
- ])
- ->orderBy(['id' => \SORT_DESC])
- ->one();
- if (!empty($client_phone_number)) {
- foreach ($new_calendars as $item) {
- \array_push($insertData, [$client_id, $client_phone_number->name, $item['date'] . ' ' . $item['time'], $item['group_id'], $item['course_id']]);
- }
- Yii::$app->db->createCommand()->batchInsert(
- 'aster_number.online_courses_autodialler',
- ['client_id', 'phone_number', 'calldate', 'group_id', 'course_id'],
- $insertData
- )->execute();
- }
- } else {
- foreach ($new_calendars as $item) {
- if (\array_key_exists($item['lecture_id'], $current_calendars_arr)) {
- $calendars_arr[$current_calendars_arr[$item['lecture_id']]] = $item['date'] . ' ' . $item['time'];
- }
- }
- $online_courses_autodialler = OnlineCoursesAutodialler::find()
- ->where(['client_id' => $client_id])
- ->andWhere(['group_id' => $group_id])
- ->andWhere(['course_id' => $courses_id])
- ->andWhere(['>=', 'DATE(calldate)', $date_now])
- ->asArray()
- ->all();
- if (!empty($online_courses_autodialler) && !empty($calendars_arr)) {
- foreach ($online_courses_autodialler as $item) {
- if (\array_key_exists($item['calldate'], $calendars_arr)) {
- OnlineCoursesAutodialler::updateAll(
- [
- 'calldate' => $calendars_arr[$item['calldate']],
- 'group_id' => $model_client_groups->group_id
- ],
- ['id' => $item['id']]
- );
- }
- }
- }
- }
- }
- }
- }
- private static function checkPaymentClient($client_id)
- {
- return ClientGroups::find()
- ->where(['client_id' => $client_id])
- ->andWhere(['pay_debt' => null])
- ->asArray()
- ->all();
- }
- private function updateNotPaid(ClientInvoices $model_not_paid)
- {
- $model_not_paid->status_id = ClientPaymentNotPaid::STATUS_NOT_DONE;
- $model_not_paid->payment_description = "";
- $model_not_paid->assignment_payment = "";
- $model_not_paid->save(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment