objMAgents = new MAgents(); } /** * 添加,编辑接收公共字段 * * @return array */ 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'] : '',//启用状态(0禁用 1启用) ]; //判断必传 foreach ($AgentFieldData as $key => $value) { if (empty($value) && $value !== 0) { $this->sendOutput($key . '参数错误', ErrorCode::$paramError); } } $AgentFieldData['contact'] = json_encode($AgentFieldData['contact']);//联系人存json 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); } /** * oem代理商信息设置 */ 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()); } /** * 获取所有企业列表 * @throws \Exception */ 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); } } /** * 根据企业id获取oem企业 */ public function getOemInfo() { $result = $this->objMAgents->getOemInfo(['enterpriseId'=>$this->onlineEnterpriseId]); if ($result->isSuccess()) { parent::sendOutput($result->getData()[0]); } parent::sendOutput($result->getData(), $result->getErrorCode()); } /** * 用户中心添加 / oem用户注册 * @throws \Exception */ 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()); } } /** * oem企业微信模版列表 * @throws \Exception */ 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()); } /** * 查询oem套餐 */ public function getAllMeal() { $result = $this->objMAgents->getAllMeal(); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } parent::sendOutput($result->getData(), ErrorCode::$dberror); } /** * oem续费 */ 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); } } }