123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- <?php
- /**
- * 代理商
- * Created by PhpStorm.
- * User: user
- * Date: 2021/6/24
- * Time: 12:00
- */
- namespace JinDouYun\Controller\Api;
- 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 System extends BaseController
- {
- public $objMAgents;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->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);
- }
- }
- }
|