123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- /**
- * 商户管理(小程序)
- * Created by PhpStorm.
- * User: haoren
- * Date: 2020/12/03
- * Time: 16:00
- */
- namespace JinDouYun\Controller\Merchant;
- use Exception;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Merchant\MMerchant;
- class ApiMerchant extends BaseController
- {
- private $objMMerchant;
- public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin, $checkToken,true);
- $this->objMMerchant = new MMerchant($this->onlineEnterpriseId, $this->onlineUserId);
- }
- /**
- * 获取商户设置
- */
- public function getSetting()
- {
- $where['type'] = StatusCode::$standard;
- $result = $this->objMMerchant->getSetting($where);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 商户申请
- */
- public function addApply()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'name' => isset($params['name']) ? $params['name'] : '',
- 'contactName' => isset($params['contactName']) ? $params['contactName'] : '',
- 'contactMobile' => isset($params['contactMobile']) ? $params['contactMobile'] : '',
- ];
- foreach ($data as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数为空', ErrorCode::$paramError);
- }
- unset($params[$key]);
- }
- $data['desc'] = isset($params['desc']) ? $params['desc'] : '';
- $data['license'] = isset($params['license']) ? $params['license'] : '';
- $data['category'] = isset($params['category']) ? $params['category'] : '';
- $data['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
- $data['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
- $data['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
- $data['address'] = isset($params['address']) ? $params['address'] : '';
- $data['info'] = isset($params['info']) ? $params['info'] : '';
- $data['userCenterId'] = $this->onlineUserId;
- $result = $this->objMMerchant->addApply($data);
- if ($result->isSuccess()) {
- $this->sendOutput($result->getData());
- } else {
- $this->sendOutput($result->getData(), ErrorCode::$contentNotExists);
- }
- }
- /**
- * 获取商户详情
- */
- public function getInfoMerchant()
- {
- $where['userCenterId'] = $this->onlineUserId;
- $result = $this->objMMerchant->getInfoMerchant($where);
- if ($result->isSuccess()) {
- $this->sendOutput($result->getData());
- } else {
- $this->sendOutput($result->getData(), ErrorCode::$contentNotExists);
- }
- }
- /**
- * 取消申请
- */
- public function delApply()
- {
- $id = $this->request->param('request_id');
- $where = [
- 'userCenterId' => $this->onlineUserId,
- 'id' => $id,
- 'deleteStatus' => StatusCode::$standard
- ];
- $update = [
- 'deleteStatus' => StatusCode::$delete
- ];
- $result = $this->objMMerchant->updateMerchant($update, $where);
- if ($result->isSuccess()) {
- $this->sendOutput($result->getData());
- } else {
- $this->sendOutput($result->getData(), ErrorCode::$contentNotExists);
- }
- }
- /**
- * 修改申请
- */
- public function updateApply()
- {
- $id = $this->request->param('request_id');
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'name' => isset($params['name']) ? $params['name'] : '',
- 'contactName' => isset($params['contactName']) ? $params['contactName'] : '',
- 'contactMobile' => isset($params['contactMobile']) ? $params['contactMobile'] : '',
- ];
- foreach ($data as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数为空', ErrorCode::$paramError);
- }
- unset($params[$key]);
- }
- $data['desc'] = isset($params['desc']) ? $params['desc'] : '';
- $data['license'] = isset($params['license']) ? $params['license'] : '';
- $data['category'] = isset($params['category']) ? $params['category'] : '';
- $data['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
- $data['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
- $data['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
- $data['address'] = isset($params['address']) ? $params['address'] : '';
- $data['info'] = isset($params['info']) ? $params['info'] : '';
- $result = $this->objMMerchant->updateApply($data, ['id' => $id]);
- if ($result->isSuccess()) {
- $this->sendOutput($result->getData());
- } else {
- $this->sendOutput($result->getData(), ErrorCode::$contentNotExists);
- }
- }
- /**
- * Doc: (des="")
- * User: XMing
- * Date: 2020/12/29
- * Time: 11:40 上午
- */
- public function getAll()
- {
- $params = (array)$this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $params['page'] = isset($params['page']) ? $params['page'] : 1;
- $params['pageSize'] = isset($params['pageSize']) ? $params['pageSize'] : 10;
- $pageParams = pageToOffset($params['page'], $params['pageSize']);
- $params['limit'] = $pageParams['limit'];
- $params['offset'] = $pageParams['offset'];
- $params['deleteStatus'] = StatusCode::$standard;
- $params['auditStatus'] = StatusCode::$auditStatus['auditPass'];
- $params['enabledStatus'] = StatusCode::$standard;
- $params['latitude'] = getArrayItem($params, 'latitude', '');
- $params['longitude'] = getArrayItem($params, 'longitude', '');
- $params['areaCode'] = $this->areaCode;
- $modelResult = $this->objMMerchant->getAll($params);
- if (!$modelResult->isSuccess()) {
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- $returnData = $modelResult->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- /**
- * Doc: (des="")
- * User: XMing
- * Date: 2021/1/29
- * Time: 11:10 上午
- */
- public function get()
- {
- $shopId = $this->request->param('request_id');
- if (empty($shopId)) {
- parent::sendOutput('id参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMMerchant->get($shopId);
- if ($result->isSuccess()) {
- $this->sendOutput($result->getData());
- }
- $this->sendOutput($result->getData(), ErrorCode::$contentNotExists);
- }
- }
|