123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <?php
- /**
- * 商铺合作管理Controller
- * Created by PhpStorm.
- * User: 小威
- * Date: 2019/11/01
- * Time: 10:00
- */
- namespace JinDouYun\Controller\ShopPartner;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\ShopPartner\MShopPartner;
- class ShopPartner extends BaseController
- {
- private $objMShopPartner;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMShopPartner = new MShopPartner($this->onlineEnterpriseId, $this->onlineUserId);
- }
- /**
- * 获取参数
- *
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $ShopPartnerData = [
- "logo" => isset($params['logo']) ? $params['logo'] : '', //varchar(50) DEFAULT NULL COMMENT '企业logo',
- "name" => isset($params['name']) ? $params['name'] : '', //varchar(30) DEFAULT NULL COMMENT '合伙人姓名/合伙企业名称',
- "model" => isset($params['model']) ? $params['model'] : '', //tinyint(3) DEFAULT NULL COMMENT '经营模式 1:直营 2:加盟',
- "provinceCode" => isset($params['provinceCode']) ? $params['provinceCode'] : '',
- "cityCode" => isset($params['cityCode']) ? $params['cityCode'] : '',
- "districtCode" => isset($params['districtCode']) ? $params['districtCode'] : '',
- "address" => isset($params['address']) ? $params['address'] : '', //varchar(255) DEFAULT NULL COMMENT '地址',
- "mobile" => isset($params['mobile']) ? $params['mobile'] : '', //char(11) DEFAULT NULL COMMENT '负责人联系电话',
- "userCenterId" => isset($params['userCenterId']) ? $params['userCenterId'] : '',
- "enterpriseId" => $this->onlineEnterpriseId
- ];
- //必填项
- foreach ($ShopPartnerData as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $ShopPartnerData['shopId'] = isset($params['shopId']) && !empty($params['shopId']) ? $params['shopId'] : null;
- //选填项
- $ShopPartnerData['updateTime'] = time();
- return $ShopPartnerData;
- }
- /**
- * 增
- */
- /**
- * 商铺合作添加
- * @throws \Exception
- */
- public function addShopPartner()
- {
- $ShopPartnerData = $this->commonFieldFilter();
- $result = $this->objMShopPartner->addShopPartner($ShopPartnerData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 获取企业下的管理员列表
- * @throws \Exception
- */
- public function getManagerList()
- {
- $result = $this->objMShopPartner->getManagerList();
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 删
- */
- /**
- * 商铺合作删除
- */
- public function deleteShopPartner()
- {
- $params['id'] = $this->request->param('request_id');
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMShopPartner->deleteShopPartner($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 改
- */
- /**
- * 商铺合作修改
- */
- public function updateShopPartner()
- {
- $params['id'] = $this->request->param('request_id');
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $ShopPartnerData = $this->commonFieldFilter();
- $result = $this->objMShopPartner->updateShopPartner($ShopPartnerData, $params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 商铺合作启用/禁用
- */
- public function enableShopPartner()
- {
- $paramsData = $this->request->getRawJson();
- if (empty($paramsData)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $params = [
- 'enableStatus' => isset($paramsData['enableStatus']) ? $paramsData['enableStatus'] : '',
- 'partnerId' => isset($paramsData['partnerId']) ? $paramsData['partnerId'] : '',
- ];
- foreach ($params as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- if ($params['enableStatus'] == StatusCode::$standard) {
- $params['enableStatus'] = StatusCode::$standard;
- } elseif ($params['enableStatus'] == StatusCode::$delete) {
- $params['enableStatus'] = StatusCode::$delete;
- } else {
- $this->sendOutput('enableStatus参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMShopPartner->enableShopPartner($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 查
- */
- /**
- * 商铺合作列表
- */
- public function getAllShopPartner()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $result = $this->objMShopPartner->getAllShopPartner($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- }
- /**
- * 商铺合作详情
- */
- public function getShopPartnerInfo()
- {
- $params['id'] = $this->request->param('request_id');
- if (empty($params['id'])) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMShopPartner->getShopPartnerInfo($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 搜索
- */
- public function search()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [
- 'name' => isset($params['name']) ? $params['name'] : '',
- 'mobile' => isset($params['mobile']) ? $params['mobile'] : ''
- ];
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $result = $this->objMShopPartner->search($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- }
- }
|