public function __construct($serviceLocator, $options = null) { parent::__construct('fTransaction'); $this->setServiceLocator($serviceLocator); $this->setAttribute('method', 'post'); $filter = $this->getInputFilter(); $basicGroup = new DisplayGroup('basicGroup'); $this->add($basicGroup); $companyId = $this->addElementCompany('companyId', $basicGroup, ['required' => true]); $applyDate = new Text('applyDate'); $applyDate->setLabel('Ngày hạch toán:'); $applyDate->setAttribute('class', 'datepicker'); $this->add($applyDate); $basicGroup->addElement($applyDate); $applyDate->setValue(DateBase::toDisplayDate(DateBase::getCurrentDate())); $filter->add(array('name' => 'applyDate', 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true, 'options' => array('messages' => array('isEmpty' => 'Bạn chưa nhập ngày hạch toán')))))); $description = new Text('description'); $description->setLabel('Nội dung:'); $this->add($description); $basicGroup->addElement($description); $filter->add(array('name' => 'description', 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true, 'options' => array('messages' => array('isEmpty' => 'Bạn chưa nhập nội dung phiếu thu')))))); $accountId = new Select('accountId'); $accountId->setLabel('Quỹ thu:'); $accountId->setValueOptions(['' => '- Quỹ thu -']); $this->loadAccountingAccount($accountId, $companyId); $this->add($accountId); $basicGroup->addElement($accountId); $filter->add(array('name' => 'accountId', 'required' => true, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Digits')), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true, 'options' => array('messages' => array('isEmpty' => 'Bạn chưa nhập quỹ thu'))), array('name' => 'InArray', 'break_chain_on_failure' => true, 'options' => array('haystack' => array_keys($accountId->getValueOptions()), 'messages' => array('notInArray' => 'Bạn chưa nhập quỹ thu')))))); $items = new Hidden('items'); $this->add($items); $filter->add(array('name' => 'items', 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true, 'options' => array('messages' => array('isEmpty' => 'Bạn chưa nhập chi tiết các khoản thu')))))); $this->add(array('name' => 'afterSubmit', 'type' => 'radio', 'attributes' => array('value' => '/accounting/transaction/addreqrecieve'), 'options' => array('layout' => 'fluid', 'clearBefore' => true, 'label' => 'Sau khi lưu dữ liệu:', 'value_options' => array('/accounting/transaction/addreqrecieve' => 'Tiếp tục nhập', '/accounting/transaction/index' => 'Hiện danh sách vừa nhập')))); $this->add(array('name' => 'btnSubmit', 'options' => array('clearBefore' => true), 'attributes' => array('type' => 'button', 'value' => 'Lưu', 'id' => 'btnSave', 'class' => 'btn btn-primary'))); }
public function findmentorAction() { if (!$this->getRequest()->isPost()) { return $this->page404(); } $data = $this->getRequest()->getPost(); $form = new SearchDetail($this->getServiceLocator()); $form->setData($data); if ($form->isValid()) { $user = new User(); $user->setEmail($data['email']); $activeKey = md5($user->getEmail() . DateBase::getCurrentDateTime()); $user->setActiveKey($activeKey); $user->setRole(User::ROLE_MEMBER); $user->setCreatedDateTime(DateBase::getCurrentDateTime()); $user->setCreatedDate(DateBase::getCurrentDate()); /** @var \User\Model\UserMapper $userMapper */ $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper'); if (!$userMapper->isExistedEmail($user)) { $userMapper->save($user); Uri::autoLink('/user/user/sendemail', ['email' => $data['email'], 'activeKey' => $user->getActiveKey()]); $this->getJsonModel()->setVariables(['code' => 2, 'data' => 'Email kích hoạt tài khoản đã được gửi đến địa chỉ email của bạn. Kiểm tra hòm thư và làm theo hướng dẫn đễ kích hoạt tài khoản.']); return $this->getJsonModel(); } return $this->getViewModel(); } else { $this->getJsonModel()->setVariables(['code' => 1, 'data' => $form->getErrorMessagesList()]); } return $this->getJsonModel(); }
public function googleAction() { $request = $this->getRequest(); if (trim($request->getQuery('redirect'))) { $_SESSION['redirect'] = trim($request->getQuery('redirect')); } $viewModel = new ViewModel(); $viewModel->setTerminal(true); $response = $this->getResponse(); /* @var $googleLogin \User\Service\GoogleLogin */ require_once 'Google/Client.php'; require_once 'Google/Service/Oauth2.php'; require_once 'Google/Http/REST.php'; require_once 'Google/Http/Request.php'; require_once 'Google/Service/Resource.php'; require_once 'Google/Auth/OAuth2.php'; $config = $this->getServiceLocator()->get('Config'); $clientId = $config['login']['google']['clientId']; $clientSecret = $config['login']['google']['clientSecret']; $url = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://'; $url .= $_SERVER['HTTP_HOST'] . '/user/signin/google'; $client = new \Google_Client(); $client->setApplicationName('MyFirstTest'); $client->setClientId($clientId); $client->setClientSecret($clientSecret); $client->setRedirectUri($url); $client->setScopes(array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/plus.me')); $error = $this->getRequest()->getQuery('error'); if ($error) { echo '<script>window.close()</script>'; } $code = $this->getRequest()->getQuery('code'); if ($code) { $client->authenticate($code); $_SESSION['access_token'] = $client->getAccessToken(); $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); } else { $authUrl = $client->createAuthUrl(); return $this->redirect()->toUrl(filter_var($authUrl, FILTER_SANITIZE_URL)); } //TODO: xoa vi cam giac dau co can if (isset($_SESSION['access_token'])) { $client->setAccessToken($_SESSION['access_token']); } if ($client->isAccessTokenExpired()) { $authUrl = $client->createAuthUrl(); return $this->redirect()->toUrl(filter_var($authUrl, FILTER_SANITIZE_URL)); } //End TODO if ($client->getAccessToken()) { $oauth2 = new \Google_Service_Oauth2($client); $userInfoPlus = $oauth2->userinfo->get(); $_SESSION['access_token'] = $client->getAccessToken(); if (!$userInfoPlus->getEmail()) { echo '<script>window.opener.alert("Không tồn tại thông tin Email của tài khoản trên");window.close()</script>'; } $arrResponse = array('email' => $userInfoPlus->getEmail(), 'name' => $userInfoPlus->getName()); $user = new User(); $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper'); $serviceUser = $this->getServiceLocator()->get('User\\Service\\User'); if (!$serviceUser->authenticateGoogle($arrResponse['email'])) { $user->setActive('1'); $user->setEmail($arrResponse['email']); $user->setRole(\User\Model\User::ROLE_MEMBER); $user->setFullName($arrResponse['name']); $user->setCreatedDate(DateBase::getCurrentDate()); $user->setCreatedDateTime(DateBase::getCurrentDateTime()); $userMapper->save($user); // check nếu user đó đã dc mời tham gia dự án sẽ gắn luôn nó với dự án $projectUser = new \Work\Model\ProjectUser(); $projectUser->setUserEmail($user->getEmail()); $projectUser->setUserId($user->getId()); $projectUserMapper = $this->getServiceLocator()->get('\\Work\\Model\\ProjectUserMapper'); $projectUserMapper->updateUserId($projectUser); $this->redirect()->toUrl($url); } else { // check nếu user đó đã dc mời tham gia dự án sẽ gắn luôn nó với dự án $projectUser = new \Work\Model\ProjectUser(); $projectUser->setUserEmail($serviceUser->getUser()->getEmail()); $projectUser->setUserId($serviceUser->getUser()->getId()); $projectUserMapper = $this->getServiceLocator()->get('\\Work\\Model\\ProjectUserMapper'); $projectUserMapper->updateUserId($projectUser); if (!$_SESSION['redirect']) { return $this->redirect()->toUrl('/'); } else { $redirect = $_SESSION['redirect']; unset($_SESSION['redirect']); return $this->redirect()->toUrl($redirect); } } } else { $this->redirect()->toUrl($client->createAuthUrl()); } return $response; }
public function signupemailAction() { $viewModels = new ViewModel(); if (!$this->getRequest()->isPost()) { $viewModels->setTemplate('error/404'); return $viewModels; } if ($this->getRequest()->isPost()) { $email = $this->getRequest()->getPost('email'); $user = new User(); $user->setEmail($email); $activeKey = md5($user->getEmail() . DateBase::getCurrentDateTime()); $user->setActiveKey($activeKey); $user->setRole(User::ROLE_MEMBER); $user->setCreatedDateTime(DateBase::getCurrentDateTime()); $user->setCreatedDate(DateBase::getCurrentDate()); /** @var \User\Model\UserMapper $userMapper */ $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper'); $jsonModel = new JsonModel(); if (!$userMapper->isExistedEmail($user)) { $userMapper->save($user); Uri::autoLink('/user/user/sendemail', ['email' => $email, 'activeKey' => $user->getActiveKey()]); $jsonModel->setVariables(['code' => 2, 'data' => 'Email kích hoạt tài khoản đã được gửi đến địa chỉ email của bạn. Kiểm tra hòm thư và làm theo hướng dẫn đễ kích hoạt tài khoản.']); } else { $jsonModel->setVariables(['code' => 1, 'data' => 'Email này đã được đăng ký, bạn vui lòng đăng nhập.']); } } return $jsonModel; }
public function updateaccountproductAction() { set_time_limit(300); $dbAdapter = $this->getServiceLocator()->get('dbAdapter'); /* @var $dbSql \Zend\Db\Sql\Sql */ $dbSql = $this->getServiceLocator()->get('dbSql'); $update = $dbSql->update(\Crm\Model\Account\ProductMapper::TABLE_NAME); $update->set(['status' => \Crm\Model\Account\Product::STATUS_EXPRIRED]); $update->where(['expiredDate < ?' => DateBase::getCurrentDate()]); $query = $dbSql->buildSqlString($update); $result = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); echo 'done'; die; }
/** * @param \User\Model\User $user */ public function signup(\User\Model\User $user) { $user->setSalt(substr(md5(time() . rand(2000, 5000)), 0, 20)); $user->setCreatedDate(DateBase::getCurrentDate()); $user->setCreatedDateTime(DateBase::getCurrentDateTime()); $user->setPassword(md5($user->getSalt() . $user->getPassword())); $user->setRegisteredDate(date('Y-m-d')); $user->setRegisteredFrom(str_replace('www.', '', strtolower($_SERVER['HTTP_HOST']))); $user->setActiveKey(md5($user->getUsername() . $user->getPassword() . time())); $user->setActiveLink('http://' . $_SERVER['HTTP_HOST'] . '/user/active?u=' . $user->getUsername() . '&c=' . $user->getActiveKey()); $user->setRole(\User\Model\User::ROLE_MEMBER); $sl = $this->getServiceLocator(); $translator = $this->getServiceLocator()->get('translator'); /** @var $mapper \User\Model\UserMapper */ $mapper = $sl->get('User\\Model\\Usermapper'); $mapper->save($user); }
/** * Lập phiếu xin chi */ public function addreqpaymentAction() { $form = new \Accounting\Form\Transaction\ReqRecieve($this->getServiceLocator()); $this->getViewModel()->setVariable('form', $form); $companyId = $this->getRequest()->getPost('companyId'); if (!$this->user()->getUser()->isAdmin()) { $companyId = $this->user()->getCompanyId(); } $expenseCategory = new \Accounting\Model\ExpenseCategory(); $expenseCategory->setCompanyId($companyId); $expenseCategoryMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\ExpenseCategoryMapper'); $tree = new \Home\Model\Tree(); $categoryValueOptions = $tree->toSelectBoxArray($expenseCategoryMapper->fetchAll($expenseCategory)); $this->getViewModel()->setVariable('categoryValueOptions', $categoryValueOptions); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { $formData = $form->getData(); $transaction = new \Accounting\Model\Transaction(); $transaction->exchangeArray($formData); $transaction->setType(\Accounting\Model\Transaction::TYPE_PAYMENT); $transaction->setCreatedDate(DateBase::getCurrentDate()); $transaction->setCreatedDateTime(DateBase::getCurrentDateTime()); $transaction->setCreatedById($this->user()->getIdentity()); $transaction->setStatus(\Accounting\Model\Transaction::STATUS_NEW); $transactionMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\TransactionMapper'); $transactionMapper->save($transaction); $itemMapper = $this->getServiceLocator()->get('\\Accounting\\Model\\Transaction\\ItemMapper'); if (isset($formData['itemData']) && count($formData['itemData'])) { foreach ($formData['itemData'] as $itemData) { $item = new \Accounting\Model\Transaction\Item(); $item->exchangeArray($itemData); $item->setTransactionId($transaction->getId()); $item->setStatus($transaction->getStatus()); $item->setTransactionDate($transaction->getApplyDate()); $itemMapper->save($item); } } if ($form->get('afterSubmit')->getValue()) { return $this->redirect()->toUrl($form->get('afterSubmit')->getValue()); } return $this->redirect()->toUrl('/accounting/transaction/index'); } } return $this->getViewModel(); }
public function fixapierror20150626Action() { set_time_limit(300); $dbSql = $this->getServiceLocator()->get('dbSql'); $dbAdapter = $this->getServiceLocator()->get('dbAdapter'); /*@var $dbAdapter \Zend\Db\Adapter\Adapter */ $fromDate = '2015-06-26 00:00:00'; $toDate = '2015-06-30 00:00:00'; $defaultSupporter = 21; // lấy ra các lead do api tạo thành trong khoảng từ 26/6 -> 29/6 (arr1) $select = $dbSql->select(['l' => \Crm\Model\LeadMapper::TABLE_NAME]); $select->where(['createdById' => 1]); $select->where(['createdDateTime >= ?' => $fromDate]); $select->where(['createdDateTime <= ?' => $toDate]); $query = $dbSql->buildSqlString($select); echo $query; echo '<br/>'; echo '<br/>'; $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); $leadIds = []; $leads = []; if ($rows->count()) { foreach ($rows->toArray() as $row) { $leadIds[$row['id']] = $row['id']; } } unset($select); unset($rows); // thêm ra các lead có yêu cầu tính năng hoặc đăng kí dùng thử trong đoạn thời gian này $select = $dbSql->select(['a' => \Crm\Model\ActivityMapper::TABLE_NAME]); $select->columns(['leadId']); $select->where(['accountId IS NULL']); $select->where(['createdById' => 1]); $select->where(['type' => [\Crm\Model\Activity::TYPE_CUSTOMER_REQUEST, \Crm\Model\Activity::TYPE_REGISTER_FOR_TRIAL]]); $select->where(['createdDateTime >= ?' => $fromDate]); $select->where(['createdDateTime <= ?' => $toDate]); $query = $dbSql->buildSqlString($select); echo $query; echo '<br/>'; echo '<br/>'; $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if ($rows->count()) { foreach ($rows->toArray() as $row) { if (!isset($leadIds[$row['leadId']])) { $leadIds[$row['leadId']] = $row['leadId']; } } } unset($select); unset($rows); // loại trừ trong số lead này các lead mà lan đang năm giữ (arr2) $select = $dbSql->select(['l' => \Crm\Model\LeadMapper::TABLE_NAME]); $select->join(['lu' => \Crm\Model\Lead\UserMapper::TABLE_NAME], 'l.id=lu.leadId', []); $select->columns(['id']); $select->where(['leadId' => $leadIds]); $select->where(['lu.userId' => $defaultSupporter]); $select->group(['l.id']); $query = $dbSql->buildSqlString($select); echo $query; echo '<br/>'; echo '<br/>'; $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if ($rows->count()) { foreach ($rows->toArray() as $row) { if (isset($leadIds[$row['id']])) { unset($leadIds[$row['id']]); } } } unset($select); unset($rows); // loaij trừ các leadId trong số đó mà có bất cứ hành động nào ko thuộc (nhận, bàn giao, yêu cầu tính năng, tự đăng kí, yêu cầu gọi) $select = $dbSql->select(['a' => \Crm\Model\ActivityMapper::TABLE_NAME]); $select->columns(['leadId']); $select->where(['leadId' => $leadIds]); $select->where(new NotIn('type', [\Crm\Model\Activity::TYPE_ASSIGN_LEAD, \Crm\Model\Activity::TYPE_SELF_ASSIGN_LEAD, \Crm\Model\Activity::TYPE_REQUEST_PHONECALL, \Crm\Model\Activity::TYPE_CUSTOMER_REQUEST, \Crm\Model\Activity::TYPE_REGISTER_FOR_TRIAL])); $select->where(['companyId' => 1]); $select->group(['leadId']); $query = $dbSql->buildSqlString($select); echo $query; echo '<br/>'; echo '<br/>'; $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if ($rows->count()) { foreach ($rows->toArray() as $row) { if (isset($leadIds[$row['leadId']])) { unset($leadIds[$row['leadId']]); } } } unset($select); unset($rows); // với mỗi leadId này, gỡ hết user ra, gắn lại cho Lan + thêm yêu cầu gọi cho cái lan if (count($leadIds)) { $activityMapper = $this->getServiceLocator()->get('\\Crm\\Model\\ActivityMapper'); $leadMapper = $this->getServiceLocator()->get('\\Crm\\Model\\LeadMapper'); foreach ($leadIds as $leadId) { // xóa action nhận - bàn giao của lead này $delete = $dbSql->delete(\Crm\Model\ActivityMapper::TABLE_NAME); $delete->where(['leadId' => $leadId]); $delete->where(['companyId' => 1]); $delete->where(['type' => [\Crm\Model\Activity::TYPE_ASSIGN_LEAD, \Crm\Model\Activity::TYPE_SELF_ASSIGN_LEAD]]); $delete->where(['relatedUserId != ?' => $defaultSupporter]); $query = $dbSql->buildSqlString($delete); $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); // xóa user đang chăm sóc lead này $delete = $dbSql->delete(\Crm\Model\Lead\UserMapper::TABLE_NAME); $delete->where(['leadId' => $leadId]); $delete->where(['companyId' => 1]); $delete->where(['userId != ?' => $defaultSupporter]); $query = $dbSql->buildSqlString($delete); $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); // lay ra lead $lead = new \Crm\Model\Lead(); $lead->setId($leadId); $leadMapper->get($lead); // thêm action yêu cầu gọi cho Lan $activity = new \Crm\Model\Activity(); $activity->setLeadId($leadId); $activity->setCompanyId(1); $activity->setType(\Crm\Model\Activity::TYPE_REQUEST_PHONECALL); $activity->setStatus(\Crm\Model\Activity::STATUS_SUCCESS); $activity->setTitle('Bổ sung xác nhận dùng thử 26/6 - 30/6'); $content = []; if ($lead->getNhanhStoreId()) { $content[] = '<b>nhanhStoreId: </b>' . $lead->getNhanhStoreId(); } if ($lead->getNhanhStoreName()) { $content[] = '<b>nhanhStoreName: </b>' . $lead->getNhanhStoreName(); } $activity->setContent(count($content) ? implode('<br/>', $content) : null); $activity->setCreatedById(1); $activity->setCreatedDate(DateBase::getCurrentDate()); $activity->setCreatedDateTime(DateBase::getCurrentDateTime()); $activity->setRelatedUserId($defaultSupporter); $activityMapper->save($activity); //gắn cho lan $leadUser = new \Crm\Model\Lead\User(); $leadUser->setLeadId($leadId); $leadUser->setCompanyId(1); $leadUser->setUserId($defaultSupporter); $leadUser->setType(\Crm\Model\Lead\User::TYPE_SALE); $leadUserMapper = $this->getServiceLocator()->get('\\Crm\\Model\\Lead\\UserMapper'); if (!$leadUserMapper->isExisted($leadUser)) { $leadUser->setCreatedById(1); $leadUser->setCreatedDateTime(DateBase::getCurrentDateTime()); $leadUserMapper->save($leadUser); } //update lại companyStatus + lastActivity $leadCompany = new \Crm\Model\Lead\Company(); $leadCompany->setLeadId($leadId); $leadCompany->setCompanyId(1); $leadCompanyMapper = $this->getServiceLocator()->get('\\Crm\\Model\\Lead\\CompanyMapper'); $leadCompanyMapper->isExisted($leadCompany); $leadCompany->setLastActivityDateTime(DateBase::getCurrentDateTime()); $leadCompany->setStatus(\Crm\Model\Lead\Company::STATUS_BELONG); $leadCompanyMapper->save($leadCompany); echo 'update lead : <b>' . $leadId . '</b><br/>'; } } die; }
public function addAction() { /** @var \Zend\Http\Request $request */ $request = $this->getRequest(); $sl = $this->getServiceLocator(); /* @var $cityMapper \Address\Model\CityMapper */ $cityMapper = $sl->get('Address\\Model\\CityMapper'); $city = new \Address\Model\City(); /* @var $districtMapper \Address\Model\DistrictMapper */ $districtMapper = $sl->get('Address\\Model\\DistrictMapper'); $district = new \Address\Model\District(); $districts = array(); if (!!($cityId = $request->getPost('cityId'))) { $district->setCityId($cityId); $districts = $districtMapper->fetchAll($district); } $form = new \System\Form\User\Add($this->getServiceLocator()); $form->setCities($city->toSelectBoxArray($cityMapper->fetchAll())); $form->setDistricts($district->toSelectBoxArray($districts)); if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost(); $form->setData($data); if ($form->isValid()) { $user = new User(); $user->exchangeArray($form->getData()); $user->setSalt($user->generateSalt()); $user->setPassword($user->createPassword()); if (!$user->getRole()) { $user->setRole(User::ROLE_GUEST); } if ($user->getBirthdate()) { $user->setBirthdate(DateBase::toCommonDate($user->getBirthdate())); } $user->setActive(1); $user->setCreatedById($this->user()->getIdentity()); $user->setCreatedDate(DateBase::getCurrentDate()); $user->setCreatedDateTime(DateBase::getCurrentDateTime()); $userMapper = $this->getServiceLocator()->get('\\User\\Model\\UserMapper'); $userMapper->save($user); if ($form->get('afterSubmit')->getValue()) { return $this->redirect()->toUrl($form->get('afterSubmit')->getValue()); } } } $viewModel = new ViewModel(); $viewModel->setVariable('form', $form); return $viewModel; }
public function fixaddlead20150630Action() { $fromDateTime = '2015-06-26 00:00:00'; $toDateTime = '2015-06-29 00:00:00'; //@TODO fix cung nguoi dc yeu cau laf Thanh Lan $relatedUserId = 21; if ($this->getRequest()->isPost()) { $formValidate = new \System\Form\Api\LeadValidate($this->getServiceLocator()); $dataToPopulate = $this->getRequest()->getPost(); //@TODO: fix cứng cho nhanh đã $dataToPopulate['companyId'] = 1; $formValidate->setData($dataToPopulate); if ($formValidate->isValid()) { $formData = $formValidate->getData(); $isNew = true; $accountId = null; $campaignId = null; $createdDateTime = $this->getRequest()->getPost('createdDateTime'); //Tạo mới thông tin nếu chưa có $lead = new \Crm\Model\Lead(); $lead->exchangeArray($formData); $lead->setSource(\Crm\Model\Lead::SOURCE_WEB); if ($lead->getSourceReference()) { $lead->setSourceReference(substr($lead->getSourceReference(), 0, 220)); } $lead->setCreatedById(1); $lead->setCreatedDate(DateBase::getCurrentDate()); $lead->setCreatedDateTime(DateBase::getCurrentDateTime()); $lead->setDescription('Khách hàng tự đăng kí dùng thử trên nhanh.vn'); $leadMapper = $this->getServiceLocator()->get('\\Crm\\Model\\LeadMapper'); if (!$leadMapper->isExisted($lead)) { $referSource = []; $content = []; $isVaild = false; if (isset($formData['utm_source']) && $formData['utm_source']) { $referSource[] = $formData['utm_source']; $content[] = '<b>utm_source: </b>' . $formData['utm_source']; $isVaild = true; } else { $referSource[] = ''; $content[] = '<b>utm_source: </b>'; } if (isset($formData['utm_medium']) && $formData['utm_medium']) { $referSource[] = $formData['utm_medium']; $content[] = '<b>utm_medium: </b>' . $formData['utm_medium']; $isVaild = true; } else { $referSource[] = ''; $content[] = '<b>utm_medium: </b>'; } if (isset($formData['utm_campaign']) && $formData['utm_campaign']) { $referSource[] = $formData['utm_campaign']; $content[] = '<b>utm_campaign: </b>' . $formData['utm_campaign']; $isVaild = true; } else { $referSource[] = ''; $content[] = '<b>utm_campaign: </b>'; } if (isset($formData['utm_term']) && $formData['utm_term']) { $content[] = '<b>utm_term: </b>' . $formData['utm_term']; } else { $content[] = '<b>utm_term: </b>'; } if (isset($formData['utm_content']) && $formData['utm_content']) { $content[] = '<b>utm_content: </b>' . $formData['utm_content']; } else { $content[] = '<b>utm_content: </b>'; } if ($isVaild) { $campaign = new \Crm\Model\Campaign(); $campaign->setCode(implode('_', $referSource)); $campaign->setCompanyId($lead->getCompanyId()); $campaignMapper = $this->getServiceLocator()->get('\\Crm\\Model\\CampaignMapper'); if ($campaignMapper->isExistedCode($campaign) === false) { $campaign->setStartDate(DateBase::getCurrentDate()); $today = new \DateTime(); $today->add(new \DateInterval('P12M')); $campaign->setEndDate($today->format(DateBase::COMMON_DATE_FORMAT)); $campaign->setName($campaign->getCode()); $campaign->setContent(implode('<br/>', $content)); $campaign->setCreatedById(1); $campaign->setCreatedDateTime(DateBase::getCurrentDateTime()); $campaignMapper->save($campaign); } $campaignId = $campaign->getId(); $lead->setSource(\Crm\Model\Lead::SOURCE_MARKETING_CAMPAIGN); $lead->setDescription(implode('<br/>', $content)); $lead->setCampaignId($campaignId); } $leadMapper->save($lead); } else { if ($lead->getOption('tableExisted') == 'lead') { $dbAdapter = $this->getServiceLocator()->get('dbAdapter'); /* @var $dbSql \Zend\Db\Sql\Sql */ $dbSql = $this->getServiceLocator()->get('dbSql'); // check nếu đã tồn tại yêu cầu dùng thử trong khoảng thời gian cần check thì sẽ kiểm tra lại // nếu có hành động bàn giao cho người khác Lan nhưng ko có bất kì hành động j sau đó thì xóa đi $select = $dbSql->select(['a' => \Crm\Model\ActivityMapper::TABLE_NAME]); $select->where(['leadId' => $lead->getId()]); $select->where(['companyId' => $lead->getCompanyId()]); $select->where(['type' => [\Crm\Model\Activity::TYPE_CUSTOMER_REQUEST, \Crm\Model\Activity::TYPE_REGISTER_FOR_TRIAL]]); $select->where(['createdDateTime >= ?' => $fromDateTime]); $select->where(['createdDateTime >= ?' => $createdDateTime]); //$select->where(['createdDateTime <= ?' => $toDateTime]); $query = $dbSql->buildSqlString($select); $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if ($rows->count()) { return $this->getJsonModel()->setVariables(['code' => 1, 'messages' => 'sended']); } //check thông tin có dc ai nhận sau thời điểm bắn về ko $select = $dbSql->select(['a' => \Crm\Model\ActivityMapper::TABLE_NAME]); $select->where(['leadId' => $lead->getId()]); $select->where(['companyId' => $lead->getCompanyId()]); $select->where(['type' => [\Crm\Model\Activity::TYPE_ASSIGN_LEAD, \Crm\Model\Activity::TYPE_SELF_ASSIGN_LEAD]]); $select->where(['createdById != ?' => $relatedUserId]); $select->where(['createdDateTime >= ?' => $fromDateTime]); $select->where(['createdDateTime >= ?' => $createdDateTime]); //$select->where(['createdDateTime <= ?' => $toDateTime]); $select->order(['createdDateTime ASC']); $select->limit(1); $query = $dbSql->buildSqlString($select); $rows = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if ($rows->count()) { // nếu có, check tiếp có hành động nào sau đấy ko $row = (array) $rows->current(); $select = $dbSql->select(['a' => \Crm\Model\ActivityMapper::TABLE_NAME]); $select->where(['leadId' => $lead->getId()]); $select->where(['companyId' => $lead->getCompanyId()]); $select->where(new NotIn('type', ['\\Crm\\Model\\Activity::TYPE_ASSIGN_LEAD, \\Crm\\Model\\Activity::TYPE_SELF_ASSIGN_LEAD'])); $select->where(['createdDateTime > ?' => $row['createdDateTime']]); $select->limit(1); $query = $dbSql->buildSqlString($select); $row2 = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); if (!$row2->count()) { // nếu chỉ nhận về mà ko có bất kì hành động j, // Xóa các lead user dc tạo trong khoảng thời gian từ lúc bắn về đến hết thời điểm check $delete = $dbSql->delete(\Crm\Model\Lead\UserMapper::TABLE_NAME); $delete->where(['leadId' => $lead->getId()]); $delete->where(['companyId' => $lead->getCompanyId()]); $delete->where(['userId != ?' => $relatedUserId]); $delete->where(['createdDateTime > ?' => $createdDateTime]); $delete->where(['createdDateTime <= ?' => $toDateTime]); $query = $dbSql->buildSqlString($delete); $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); // xóa các activities nhận chăm sóc $delete = $dbSql->delete(\Crm\Model\ActivityMapper::TABLE_NAME); $delete->where(['leadId' => $lead->getId()]); $delete->where(['companyId' => $lead->getCompanyId()]); $delete->where(['createdById != ?' => $relatedUserId]); $delete->where(['type' => [\Crm\Model\Activity::TYPE_ASSIGN_LEAD, \Crm\Model\Activity::TYPE_SELF_ASSIGN_LEAD]]); $delete->where(['createdDateTime > ?' => $createdDateTime]); $delete->where(['createdDateTime <= ?' => $toDateTime]); $query = $dbSql->buildSqlString($delete); $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE); } } } $isNew = false; if ($lead->getOption('tableExisted') == 'account') { $accountId = $lead->getOption('accountId'); } } //Update nguồn cho leadCompany $leadCompany = new \Crm\Model\Lead\Company(); $leadCompany->setCompanyId($lead->getCompanyId()); $leadCompany->setLeadId($lead->getId()); $leadCompany->setAccountId($accountId); if ($campaignId) { $leadCompany->setSource(\Crm\Model\Lead::SOURCE_MARKETING_CAMPAIGN); $leadCompany->setSourceCampaignId($campaignId); $leadCompany->setSourceReference($lead->getSourceReference()); } elseif ($isNew) { $leadCompany->setSource(\Crm\Model\Lead::SOURCE_WEB); if ($lead->getSourceReference()) { $leadCompany->setSourceReference($lead->getSourceReference()); } else { $leadCompany->setSourceReference('nhanh.vn'); } } $leadCompany->setStatus(\Crm\Model\Lead\Company::STATUS_FREE); $leadCompanyMapper = $this->getServiceLocator()->get('\\Crm\\Model\\Lead\\CompanyMapper'); //Nếu leadCompany đã tồn tại (thông tin đã được sử dụng với cty đang check) thì chỉ update lastActivityDateTime $leadCompanyMapper->isExisted($leadCompany); $leadCompany->setLastActivityDateTime(DateBase::getCurrentDateTime()); $leadCompanyMapper->save($leadCompany); //Log hành động yêu cầu dùng thử của khách hàng $activity = new \Crm\Model\Activity(); $activity->setLeadId($lead->getId()); $activity->setAccountId($accountId); $activity->setCompanyId($lead->getCompanyId()); $activity->setType(\Crm\Model\Activity::TYPE_REGISTER_FOR_TRIAL); $activity->setStatus(\Crm\Model\Activity::STATUS_SUCCESS); //$activity->setTitle('Đăng kí dùng thử '.$formData['service']) ; $activity->setTitle($formData['title'] ?: 'Đăng kí dùng thử ' . $formData['service']); $activity->setContent($formData['note'] ?: null); $activity->setCreatedById(1); $activity->setCreatedDate(DateBase::toFormat($createdDateTime, DateBase::COMMON_DATE_FORMAT)); $activity->setCreatedDateTime($createdDateTime); $activityMapper = $this->getServiceLocator()->get('\\Crm\\Model\\ActivityMapper'); $activityMapper->save($activity); $activityMapper->updateLeadId($activity); //Check lại 1 lần nữa trạng thái của leadCompany là thả nổi hay đã có KD $leadCompanyMapper->updateStatus($leadCompany); //Nếu là thả nổi (tức là vừa dc tạo hoặc đang thả nổi) thì tạo 1 yêu cầu gọi cho chăm sóc mặc định và gắn cho cham sóc mặc định if ($leadCompany->getStatus() == \Crm\Model\Lead\Company::STATUS_FREE) { $activity = new \Crm\Model\Activity(); $activity->setLeadId($lead->getId()); $activity->setAccountId($accountId); $activity->setCompanyId($lead->getCompanyId()); $activity->setType(\Crm\Model\Activity::TYPE_REQUEST_PHONECALL); $activity->setStatus(\Crm\Model\Activity::STATUS_SUCCESS); $activity->setTitle('Gọi xác nhận yêu cầu dùng thử'); $activity->setCreatedById(1); $activity->setCreatedDate(DateBase::toFormat($createdDateTime, DateBase::COMMON_DATE_FORMAT)); $activity->setCreatedDateTime($createdDateTime); $activity->setRelatedUserId($relatedUserId); $activityMapper->save($activity); $leadUser = new \Crm\Model\Lead\User(); $leadUser->setLeadId($lead->getId()); $leadUser->setAccountId($accountId); $leadUser->setCompanyId($lead->getCompanyId()); $leadUser->setType(\Crm\Model\Lead\User::TYPE_SALE); $leadUser->setUserId($relatedUserId); $leadUser->setCreatedById(1); $leadUser->setCreatedDateTime(DateBase::getCurrentDateTime()); $leadUserMapper = $this->getServiceLocator()->get('\\Crm\\Model\\Lead\\UserMapper'); if (!$leadUserMapper->isExisted($leadUser)) { $leadUserMapper->save($leadUser); } $leadCompanyMapper->updateColumns(['status' => \Crm\Model\Lead\Company::STATUS_BELONG], $leadCompany); } return $this->getJsonModel()->setVariable('code', 1); } return $this->getJsonModel()->setVariables(['code' => 0, 'messages' => [$formValidate->getMessages()]]); } return $this->getJsonModel()->setVariables(['code' => 0, 'messages' => ['']]); }