ApiMerchant.Class.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /**
  3. * 商户管理(小程序)
  4. * Created by PhpStorm.
  5. * User: haoren
  6. * Date: 2020/12/03
  7. * Time: 16:00
  8. */
  9. namespace JinDouYun\Controller\Merchant;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use Mall\Framework\Core\StatusCode;
  14. use JinDouYun\Controller\BaseController;
  15. use JinDouYun\Model\Merchant\MMerchant;
  16. class ApiMerchant extends BaseController
  17. {
  18. private $objMMerchant;
  19. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true)
  20. {
  21. parent::__construct($isCheckAcl, $isMustLogin, $checkToken,true);
  22. $this->objMMerchant = new MMerchant($this->onlineEnterpriseId, $this->onlineUserId);
  23. }
  24. /**
  25. * 获取商户设置
  26. */
  27. public function getSetting()
  28. {
  29. $where['type'] = StatusCode::$standard;
  30. $result = $this->objMMerchant->getSetting($where);
  31. if ($result->isSuccess()) {
  32. parent::sendOutput($result->getData());
  33. } else {
  34. parent::sendOutput($result->getData(), $result->getErrorCode());
  35. }
  36. }
  37. /**
  38. * 商户申请
  39. */
  40. public function addApply()
  41. {
  42. $params = $this->request->getRawJson();
  43. if (empty($params)) {
  44. parent::sendOutput('参数为空', ErrorCode::$paramError);
  45. }
  46. $data = [
  47. 'name' => isset($params['name']) ? $params['name'] : '',
  48. 'contactName' => isset($params['contactName']) ? $params['contactName'] : '',
  49. 'contactMobile' => isset($params['contactMobile']) ? $params['contactMobile'] : '',
  50. ];
  51. foreach ($data as $key => $value) {
  52. if (empty($value)) {
  53. parent::sendOutput($key . '参数为空', ErrorCode::$paramError);
  54. }
  55. unset($params[$key]);
  56. }
  57. $data['desc'] = isset($params['desc']) ? $params['desc'] : '';
  58. $data['license'] = isset($params['license']) ? $params['license'] : '';
  59. $data['category'] = isset($params['category']) ? $params['category'] : '';
  60. $data['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
  61. $data['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
  62. $data['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
  63. $data['address'] = isset($params['address']) ? $params['address'] : '';
  64. $data['info'] = isset($params['info']) ? $params['info'] : '';
  65. $data['userCenterId'] = $this->onlineUserId;
  66. $result = $this->objMMerchant->addApply($data);
  67. if ($result->isSuccess()) {
  68. $this->sendOutput($result->getData());
  69. } else {
  70. $this->sendOutput($result->getData(), ErrorCode::$contentNotExists);
  71. }
  72. }
  73. /**
  74. * 获取商户详情
  75. */
  76. public function getInfoMerchant()
  77. {
  78. $where['userCenterId'] = $this->onlineUserId;
  79. $result = $this->objMMerchant->getInfoMerchant($where);
  80. if ($result->isSuccess()) {
  81. $this->sendOutput($result->getData());
  82. } else {
  83. $this->sendOutput($result->getData(), ErrorCode::$contentNotExists);
  84. }
  85. }
  86. /**
  87. * 取消申请
  88. */
  89. public function delApply()
  90. {
  91. $id = $this->request->param('request_id');
  92. $where = [
  93. 'userCenterId' => $this->onlineUserId,
  94. 'id' => $id,
  95. 'deleteStatus' => StatusCode::$standard
  96. ];
  97. $update = [
  98. 'deleteStatus' => StatusCode::$delete
  99. ];
  100. $result = $this->objMMerchant->updateMerchant($update, $where);
  101. if ($result->isSuccess()) {
  102. $this->sendOutput($result->getData());
  103. } else {
  104. $this->sendOutput($result->getData(), ErrorCode::$contentNotExists);
  105. }
  106. }
  107. /**
  108. * 修改申请
  109. */
  110. public function updateApply()
  111. {
  112. $id = $this->request->param('request_id');
  113. $params = $this->request->getRawJson();
  114. if (empty($params)) {
  115. parent::sendOutput('参数为空', ErrorCode::$paramError);
  116. }
  117. $data = [
  118. 'name' => isset($params['name']) ? $params['name'] : '',
  119. 'contactName' => isset($params['contactName']) ? $params['contactName'] : '',
  120. 'contactMobile' => isset($params['contactMobile']) ? $params['contactMobile'] : '',
  121. ];
  122. foreach ($data as $key => $value) {
  123. if (empty($value)) {
  124. parent::sendOutput($key . '参数为空', ErrorCode::$paramError);
  125. }
  126. unset($params[$key]);
  127. }
  128. $data['desc'] = isset($params['desc']) ? $params['desc'] : '';
  129. $data['license'] = isset($params['license']) ? $params['license'] : '';
  130. $data['category'] = isset($params['category']) ? $params['category'] : '';
  131. $data['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
  132. $data['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
  133. $data['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
  134. $data['address'] = isset($params['address']) ? $params['address'] : '';
  135. $data['info'] = isset($params['info']) ? $params['info'] : '';
  136. $result = $this->objMMerchant->updateApply($data, ['id' => $id]);
  137. if ($result->isSuccess()) {
  138. $this->sendOutput($result->getData());
  139. } else {
  140. $this->sendOutput($result->getData(), ErrorCode::$contentNotExists);
  141. }
  142. }
  143. /**
  144. * Doc: (des="")
  145. * User: XMing
  146. * Date: 2020/12/29
  147. * Time: 11:40 上午
  148. */
  149. public function getAll()
  150. {
  151. $params = (array)$this->request->getRawJson();
  152. if (empty($params)) {
  153. parent::sendOutput('参数为空', ErrorCode::$paramError);
  154. }
  155. $params['page'] = isset($params['page']) ? $params['page'] : 1;
  156. $params['pageSize'] = isset($params['pageSize']) ? $params['pageSize'] : 10;
  157. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  158. $params['limit'] = $pageParams['limit'];
  159. $params['offset'] = $pageParams['offset'];
  160. $params['deleteStatus'] = StatusCode::$standard;
  161. $params['auditStatus'] = StatusCode::$auditStatus['auditPass'];
  162. $params['enabledStatus'] = StatusCode::$standard;
  163. $params['latitude'] = getArrayItem($params, 'latitude', '');
  164. $params['longitude'] = getArrayItem($params, 'longitude', '');
  165. $params['areaCode'] = $this->areaCode;
  166. $modelResult = $this->objMMerchant->getAll($params);
  167. if (!$modelResult->isSuccess()) {
  168. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  169. }
  170. $returnData = $modelResult->getData();
  171. $pageData = [
  172. 'pageIndex' => $params['page'],
  173. 'pageSize' => $params['pageSize'],
  174. 'pageTotal' => $returnData['total'],
  175. ];
  176. parent::sendOutput($returnData['data'], 0, $pageData);
  177. }
  178. /**
  179. * Doc: (des="")
  180. * User: XMing
  181. * Date: 2021/1/29
  182. * Time: 11:10 上午
  183. */
  184. public function get()
  185. {
  186. $shopId = $this->request->param('request_id');
  187. if (empty($shopId)) {
  188. parent::sendOutput('id参数错误', ErrorCode::$paramError);
  189. }
  190. $result = $this->objMMerchant->get($shopId);
  191. if ($result->isSuccess()) {
  192. $this->sendOutput($result->getData());
  193. }
  194. $this->sendOutput($result->getData(), ErrorCode::$contentNotExists);
  195. }
  196. }