/** * @param Object $obj * @param string|null $thumbnail * @return string */ public static function getViewPath($obj, $thumbnail = null) { switch ($obj) { case $obj instanceof \User\Model\User: if (!$obj->getCreatedDateTime()) { return '/media/users/default/' . $obj->getId() . '/'; } $datePath = DateBase::toFormat($obj->getCreatedDateTime(), 'Ymd'); return '/media/user/' . $datePath . '/' . $obj->getId() . '/' . $obj->getAvatar(); break; } return ''; }
private function uploadAnnouncementFile() { $form = new \Company\Form\AnnouncementFile($this->getServiceLocator()); $jsonModel = new JsonModel(); if ($this->getRequest()->isPost()) { $dataPopulate = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getQuery()->toArray(), $this->getRequest()->getFiles()->toArray()); $form->setData($dataPopulate); if ($form->isValid()) { if ($this->getRequest()->getPost('announcementId') && $this->getRequest()->getPost('companyId')) { $form->addFileUploadRenameFilter($this->getRequest()->getPost('announcementId'), $this->getRequest()->getPost('companyId')); } elseif ($this->getRequest()->getQuery('announcementId') && $this->getRequest()->getQuery('companyId')) { $form->addFileUploadRenameFilter($this->getRequest()->getQuery('announcementId'), $this->getRequest()->getQuery('companyId')); } else { $form->addFileUploadRenameFilter('temp'); } $announcementFile = new \Company\Model\AnnouncementFile(); $announcementFile->exchangeArray($form->getData()); $announcementFileMapper = $this->getServiceLocator()->get('\\Company\\Model\\AnnouncementFileMapper'); if (!$announcementFileMapper->isExisted($announcementFile)) { $announcementFile->setCreatedById($this->user()->getIdentity()); $oldname = Uri::getSavePath($announcementFile); $announcementFile->setFilePath(DateBase::toFormat(DateBase::getCurrentDateTime(), 'Ymd')); $announcementFile->setCreatedDateTime(DateBase::getCurrentDateTime()); $newname = Uri::getSavePath($announcementFile); if (!file_exists($newname)) { $oldmask = umask(0); mkdir($newname, 0777, true); umask($oldmask); } rename($oldname . '/' . $announcementFile->getFileName(), $newname . '/' . $announcementFile->getFileName()); $announcementFileMapper->save($announcementFile); } $jsonModel->setVariables(['code' => 1, 'data' => ['id' => $announcementFile->getId()]]); } else { $jsonModel->setVariables(['code' => 0, 'messages' => $form->getMessagesForUpload()]); } } else { $jsonModel->setVariables(['code' => 0, 'messages' => ['phải là request post']]); } return $jsonModel; }
/** * @author DuongNq * @return \Zend\View\Model\JsonModel */ public function avatarAction() { $formData = $this->getRequest()->getPost()->toArray(); /** @var \User\Model\User $user */ $user = new User(); $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper'); $user = $userMapper->get($this->user()->getIdentity()); $uri = new \Home\Service\Uri(); $datePath = DateBase::toFormat($user->getCreatedDateTime(), 'Ymd'); if (!file_exists(MEDIA_PATH . '/user/' . $datePath . '/')) { mkdir(MEDIA_PATH . '/user/' . $datePath . '/'); chmod(MEDIA_PATH . '/user/' . $datePath . '/', 0777); } if (!file_exists($uri->getSavePath($user))) { mkdir($uri->getSavePath($user)); chmod($uri->getSavePath($user), 0777); } $avatarFiles = scandir($uri->getSavePath($user)); for ($i = 2; $i < count($avatarFiles); $i++) { if ($user->getAvatar() != $avatarFiles[$i]) { unlink(MEDIA_PATH . '/user/avatar/' . $avatarFiles[$i]); } } $file = $this->params()->fromFiles(); $form = new \User\Form\ProfileFile('fileUpload'); $form->addInputFilter($user); $tempFile = null; foreach ($file as $key => $fileInfo) { $fileInfo['name'] = time() . rand(1, 1000) . '.' . pathinfo($fileInfo['name'], PATHINFO_EXTENSION); $formData['fileUpload'] = $fileInfo; if (getimagesize($fileInfo['tmp_name'])[0] != 119 && getimagesize($fileInfo['tmp_name'])[0] != 119) { if (!$this->smart_resize_image($fileInfo['tmp_name'], null, 119, 119)) { $json = new JsonModel(); $json->setVariables(['code' => 1, 'messages' => 'Ảnh bị lỗi, mời bạn thử ảnh khác']); return $json; } } $form->setData($formData); if ($form->isValid()) { $data = $form->getData(); $user->setAvatar($data['fileUpload']['name']); $userMapper->save($user); } else { // Form not valid, but file uploads might be valid... // Get the temporary file information to show the user in the view $fileErrors = $form->get('fileUpload')->getMessages(); $json = new JsonModel($fileErrors); return $json; if (empty($fileErrors)) { $tempFile = $form->get('fileUpload')->getValue(); } } } $variables = array('code' => 0, 'path' => $uri->getViewPath($user)); $json = new JsonModel($variables); return $json; }
/** * @param Object $obj * @param string|null $thumbnail * @return string */ public static function getViewPath($obj, $thumbnail = null) { switch ($obj) { case $obj instanceof \Crm\Model\Contract\File: if ($obj->getFileName()) { return '/media/contracts/' . $obj->getContractId() . '/' . $obj->getFileName(); } break; case $obj instanceof \Hrm\Model\Recruitment\Candidate: $filePath = DateBase::createFromFormat(DateBase::COMMON_DATE_FORMAT, $obj->getCreatedDate())->format('Ymd'); return '/media/hrm/candidate/' . $filePath . '/' . $obj->getFileName(); break; case $obj instanceof \Work\Model\TaskFile: $filePath = DateBase::createFromFormat(DateBase::COMMON_DATETIME_FORMAT, $obj->getCreatedDateTime())->format('Ymd'); return '/media/work/attachfile/' . $filePath . '/' . $obj->getTaskId() . '/' . $obj->getFileName(); break; case $obj instanceof \Work\Model\MeetingFile: $filePath = DateBase::createFromFormat(DateBase::COMMON_DATETIME_FORMAT, $obj->getCreatedDateTime())->format('Ymd'); return '/media/projects/meetings/' . $filePath . '/' . $obj->getMeetingId() . '/' . $obj->getFileName(); break; case $obj instanceof \Company\Model\AnnouncementFile: //return '/media/company/announcement/'.$obj->getOption('companyId').'/'.$obj->getAnnouncementId().'/'.$obj->getFileName(); if (!$obj->getFilePath()) { return '/media/announcement/temp/' . $obj->getAnnouncementId(); } else { return '/media/announcement/' . $obj->getFilePath() . '/' . $obj->getAnnouncementId(); } break; case $obj instanceof \Document\Model\DocumentFile: $filePath = DateBase::createFromFormat(DateBase::COMMON_DATETIME_FORMAT, $obj->getCreatedDateTime())->format('Ymd'); return '/media/document/documents/' . $filePath . '/' . $obj->getDocumentId() . '/' . $obj->getFileName(); break; case $obj instanceof \Idea\Model\File: $filePath = DateBase::createFromFormat(DateBase::COMMON_DATETIME_FORMAT, $obj->getCreatedDateTime())->format('Ymd'); return '/media/idea/' . $obj->getFilePath() . '/' . $obj->getIdeaId() . '/' . $obj->getFileName(); break; case $obj instanceof \User\Model\User: if (!$obj->getCreatedDateTime()) { return '/media/users/default/' . $obj->getId() . '/'; } $datePath = DateBase::toFormat($obj->getCreatedDateTime(), 'Ymd'); return '/media/user/' . $datePath . '/' . $obj->getId() . '/' . $obj->getAvatar(); break; } return ''; }
/** * @author KienNN * @return \Zend\View\Model\ViewModel * chuyển các file của thông báo về đúng thư mục của nó */ public function changeanoucementfilelocationAction() { $dbSql = $this->getServiceLocator()->get('dbSql'); $dbAdapter = $this->getServiceLocator()->get('dbAdapter'); $select = $dbSql->select(['af' => \Company\Model\AnnouncementFileMapper::TABLE_NAME]); $select->join(['a' => \Company\Model\AnnouncementMapper::TABLE_NAME], 'af.announcementId=a.id', ['companyId']); $select->where(['filePath IS NULL']); $select->order(['id asc']); $paginatorAdapter = new \Zend\Paginator\Adapter\DbSelect($select, $dbAdapter); $paginator = new \Zend\Paginator\Paginator($paginatorAdapter); $paginator->setItemCountPerPage(200); $page = $this->getRequest()->getQuery('page', 1); $totalFile = $this->getRequest()->getQuery('totalFile', 0); $paginator->setCurrentPageNumber($page); $fileMapper = $this->getServiceLocator()->get('\\Company\\Model\\AnnouncementFileMapper'); foreach ($paginator as $row) { $row = (array) $row; $fileModel = new \Company\Model\AnnouncementFile(); $fileModel->exchangeArray($row); $filePath = DateBase::toFormat($fileModel->getCreatedDateTime(), 'Ymd'); $fileModel->setFilePath($filePath); $oldSavePath = MEDIA_PATH . '/company/announcement/' . $row['companyId'] . '/' . $fileModel->getAnnouncementId() . '/' . $fileModel->getFileName(); $tempPath = MEDIA_PATH . '/announcement/temp/' . $fileModel->getAnnouncementId() . '/' . $fileModel->getFileName(); if (file_exists($oldSavePath)) { $newSavePath = Uri::getSavePath($fileModel); if (!file_exists($newSavePath)) { $oldmask = umask(0); mkdir($newSavePath, 0777, true); umask($oldmask); } @copy($oldSavePath, $newSavePath . '/' . $fileModel->getFileName()); $fileMapper->save($fileModel); $totalFile++; } elseif (file_exists($tempPath)) { $newSavePath = Uri::getSavePath($fileModel); if (!file_exists($newSavePath)) { $oldmask = umask(0); mkdir($newSavePath, 0777, true); umask($oldmask); } @copy($oldSavePath, $newSavePath . '/' . $fileModel->getFileName()); $fileMapper->save($fileModel); $totalFile++; } } $this->getViewModel()->setTerminal(true); $this->getViewModel()->setVariable('page', $page); $this->getViewModel()->setVariable('totalPages', $paginator->count() + 1); if ($page <= $paginator->count()) { $this->getViewModel()->setVariable('redirectUri', Uri::build('/system/tool/changeanoucementfilelocation', ['page' => $page + 1, 'totalFile' => $totalFile])); } $this->getViewModel()->setVariable('totalFile', $totalFile); return $this->getViewModel(); }
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' => ['']]); }