123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- <?php
- namespace JinDouYun\Controller\Agent;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Model\Agent\MAgents;
- use JinDouYun\Model\Manage\MEnterprise;
- use JinDouYun\Model\Manage\MWxTemplate;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\UserCenter\MUserCenterRegister;
- class Agents extends BaseController
- {
- public $objMAgents;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMAgents = new MAgents();
- }
-
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $AgentFieldData = [
- 'workName' => isset($params['workName']) ? $params['workName'] : '',
- 'contact' => isset($params['contact']) ? $params['contact'] : '',
- 'address' => isset($params['address']) ? $params['address'] : '',
- 'initiateStatus' => isset($params['initiateStatus']) ? $params['initiateStatus'] : '',
- ];
-
- foreach ($AgentFieldData as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $AgentFieldData['contact'] = json_encode($AgentFieldData['contact']);
- return $AgentFieldData;
- }
-
- public function addAgent()
- {
- $agentData = $this->commonFieldFilter();
- $result = $this->objMAgents->addAgent($agentData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
-
- public function editAgent()
- {
- $id = $this->request->param('id');
- if (empty($id)) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $agentData = $this->commonFieldFilter();
- $agentData['id'] = $id;
- $result = $this->objMAgents->editAgent($agentData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
-
- public function deleteAgent()
- {
- $id = $this->request->param('id');
- if(empty($id)){
- parent::sendOutput('id为空', ErrorCode::$paramError);
- }
- $result = $this->objMAgents->deleteAgent($id);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
-
- public function getAllAgent()
- {
- $page = $this->request->param('page') ?: 1;
- $pageSize = $this->request->param('pageSize') ?: 10;
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- $result = $this->objMAgents->getAllAgent($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
-
- public function oemSystemSet()
- {
- $params = $this->request->getRawJson();
- if( empty($params['setData']) or empty($params['type'])){
- $this->sendOutput('参数为空', ErrorCode::$paramError );
- }
- $result = $this->objMAgents->oemSystemSet($params,$this->onlineEnterpriseId);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
-
- public function getAllEnterprise()
- {
- $page = $this->request->param('page') ?: 1;
- $pageSize = $this->request->param('pageSize') ?: 10;
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'oemId' =>$this->onlineEnterpriseId,
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
-
- $objMEnterprise = new MEnterprise();
- $result = $objMEnterprise->getAllEnterprise($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['enterpriseData'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- }
-
- public function getOemInfo()
- {
- $result = $this->objMAgents->getOemInfo(['enterpriseId'=>$this->onlineEnterpriseId]);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData()[0]);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
-
- public function addOemUserCenter()
- {
-
- $params = $this->request->getRawJson();
-
- $UserCenterData = [
- "mobile" => isset($params['mobile']) ? $params['mobile'] : '',
- "password" => isset($params['password']) ? $params['password'] : '',
- ];
-
- foreach ($UserCenterData as $key => $value) {
- if (empty($value) && $value !== 0) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
-
- $this->checkMobile($UserCenterData['mobile']);
-
- $UserCenterData['password'] = password_hash($UserCenterData['password'], PASSWORD_DEFAULT );
-
- $UserCenterData['source'] = StatusCode::$delete;
- $UserCenterData['createTime'] = time();
- $UserCenterData['updateTime'] = time();
- $objMUserCenterRegister = new MUserCenterRegister();
- $result = $objMUserCenterRegister->addUserCenter($UserCenterData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
-
- public function getOemWxTemplateAll()
- {
- $params = $this->request->getRawJson();
- $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['oemId'] = $this->onlineEnterpriseId;
- $objMWxTemplate = new MWxTemplate();
- $result = $objMWxTemplate->getAll($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
- 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
-
- public function getAllMeal()
- {
- $result = $this->objMAgents->getAllMeal();
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
-
- public function renew()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $details = [
- 'enterpriseId' => getArrayItem($params,'enterpriseId',0),
- 'enterpriseName' => getArrayItem($params,'enterpriseName',''),
- 'mobile' => getArrayItem($params,'mobile',0),
- 'money' => getArrayItem($params,'money',0),
- 'mealId' => getArrayItem($params,'mealId',0),
- ];
- foreach ($details as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMAgents->renew($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
-
- public function getAllRenew()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $params['limit'] = $pageParams['limit'];
- $params['offset'] = $pageParams['offset'];
- $params['enterpriseId'] = getArrayItem($params,'enterpriseId',0);
- $params['mobile'] = getArrayItem($params,'mobile',"");
- $params['mealId'] = getArrayItem($params,'mealId',0);
- $returnData = $this->objMAgents->getAllRenew($params);
- if ($returnData->isSuccess()) {
- $returnData = $returnData->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
- }
- }
- }
|