CustomController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminRoleClass;
  4. use biz\sj\classes\SjClass;
  5. use bizGhs\custom\classes\CustomClass;
  6. use bizGhs\custom\services\CustomService;
  7. use bizHd\saas\classes\ApplyClass;
  8. use bizHd\saas\services\ApplyService;
  9. use common\components\imgUtil;
  10. use common\components\stringUtil;
  11. use common\components\util;
  12. use Yii;
  13. class CustomController extends BaseController
  14. {
  15. //添加新花店 shish 2021.1.8
  16. public function actionAdd()
  17. {
  18. $post = Yii::$app->request->post();
  19. $post['style'] = SjClass::STYLE_RETAIL;
  20. $post['introSjId'] = $this->sjId;
  21. $post['introStyle'] = SjClass::STYLE_SUPPLIER;
  22. $mobile = $post['mobile'] ?? '';
  23. $confirmMobile = $post['confirmMobile'];
  24. $address = $post['address'] ?? '';
  25. if (stringUtil::isMobile($mobile) == false) {
  26. util::fail(' 请填写正确的手机号');
  27. }
  28. if ($mobile != $confirmMobile) {
  29. util::fail('二次号码填写不一致');
  30. }
  31. $name = $post['name'] ?? '';
  32. if (empty($name)) {
  33. util::fail('名称不能为空');
  34. }
  35. if (stringUtil::getWordNum($name) > 8) {
  36. util::fail('名称不能超过8个汉字');
  37. }
  38. $has = SjClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_RETAIL]);
  39. if (!empty($has)) {
  40. util::fail('名称已经存在');
  41. }
  42. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]);
  43. if (!empty($has)) {
  44. util::fail('手机号已经添加过');
  45. }
  46. if (empty($address)) {
  47. util::fail('请填写地址');
  48. }
  49. $connection = Yii::$app->db;
  50. $transaction = $connection->beginTransaction();
  51. try {
  52. $shop = $this->shop;
  53. $sjId = $this->sjId;
  54. $shopId = $this->shopId;
  55. $sjName = $this->sj->name ?? '';
  56. $city = $shop->city ?? '';
  57. $dist = $shop->dist ?? '';
  58. $applyData = [
  59. 'name' => $name,
  60. 'licenseNo' => $mobile,
  61. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  62. 'mobile' => $mobile,
  63. 'introSjId' => $sjId,
  64. 'introSjName' => $sjName,
  65. 'introShopId' => $shopId,
  66. 'introStyle' => SjClass::STYLE_SUPPLIER,
  67. 'from' => ApplyClass::FROM_GHS,
  68. 'style' => SjClass::STYLE_RETAIL,
  69. 'province' => $shop->province ?? '',
  70. 'city' => $city,
  71. 'dist' => $dist,
  72. 'address' => $address,
  73. 'status' => ApplyClass::STATUS_PASS,
  74. 'replace' => 1,//1表示供应商添加的客户
  75. ];
  76. $apply = ApplyService::replaceRetail($applyData);
  77. $id = $apply['id'] ?? 0;
  78. $respond = ApplyService::pass($id);
  79. $shop = $respond['shop'] ?? [];
  80. $sj = $respond['sj'] ?? [];
  81. $hdSjId = $sj['id'] ?? 0;
  82. $hdShopId = $shop->id ?? 0;
  83. ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
  84. if (empty($hdShopId)) {
  85. util::fail('客户没有添加成功!');
  86. }
  87. $custom = CustomClass::build($this->shopId, $hdShopId);
  88. $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
  89. //客户欠款额度设置
  90. $debt = isset($post['debt']) && $post['debt'] == CustomClass::IS_DEBT_YES ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
  91. $customId = $custom['id'] ?? 0;
  92. $debtLimit = isset($post['debtLimit']) && is_numeric($post['debtLimit']) ? $post['debtLimit'] : 5000;
  93. CustomClass::updateById($customId, ['debtLimit' => $debtLimit, 'debt' => $debt]);
  94. $transaction->commit();
  95. util::success($custom);
  96. } catch (\Exception $exception) {
  97. $transaction->rollBack();
  98. Yii::info("添加客户没有成功:" . $exception->getMessage());
  99. util::fail('添加客户没有成功');
  100. }
  101. }
  102. //客户列表 ssh 2021.7.8
  103. public function actionList()
  104. {
  105. $get = Yii::$app->request->get();
  106. $type = isset($get['type']) ? $get['type'] : 0;
  107. $name = isset($get['name']) ? $get['name'] : '';
  108. $where = ['ownShopId' => $this->shopId];
  109. switch ($type) {
  110. case 1:
  111. //已开店
  112. $where['isOpen'] = 1;
  113. break;
  114. default:
  115. }
  116. if (!empty($name)) {
  117. if (stringUtil::isMobile($name)) {
  118. $where['mobile'] = $name;
  119. } else {
  120. $where['name'] = ['like', $name];
  121. }
  122. }
  123. $list = CustomService::getCustomList($where);
  124. util::success($list);
  125. }
  126. //客户详情 ssh 2021.1.8
  127. public function actionDetail()
  128. {
  129. $get = Yii::$app->request->get();
  130. $customId = $get['id'] ?? 0;
  131. $info = CustomService::getCustomInfo($customId);
  132. CustomClass::valid($info, $this->shopId);
  133. //手动添加的客户经纬度不完善不显示地址,引导完善客户地址
  134. if (isset($info['lat']) && empty($info['lat'])) {
  135. $info['address'] = '';
  136. }
  137. if (isset($info['long']) && empty($info['long'])) {
  138. $info['address'] = '';
  139. }
  140. util::success($info);
  141. }
  142. //允许月结开关 ssh 2021.1.8
  143. public function actionDebt()
  144. {
  145. $get = Yii::$app->request->get();
  146. $debt = isset($get['debt']) ? $get['debt'] : 0;
  147. $customId = isset($get['customId']) ? $get['customId'] : 0;
  148. $custom = CustomClass::getById($customId);
  149. CustomClass::valid($custom, $this->shopId);
  150. CustomClass::debt($custom, $debt);
  151. util::complete();
  152. }
  153. //欠款客户 ssh 2021.2.4
  154. public function actionDebtList()
  155. {
  156. $get = Yii::$app->request->get();
  157. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  158. if (isset($get['name']) && !empty($get['name'])) {
  159. $where['name'] = ['like', $get['name']];
  160. }
  161. $list = CustomService::getDebtList($where);
  162. //共X个客户,合计欠款XXX元
  163. $shop = $this->shop;
  164. $list['customNum'] = $shop->mayGatheringNum ?? 0;
  165. $list['debtAmount'] = $shop->mayGathering ?? 0.00;
  166. util::success($list);
  167. }
  168. //修改欠款额度 shish 20210625
  169. public function actionUpdateDebtLimit()
  170. {
  171. $shopAdmin = $this->shopAdmin;
  172. $roleId = $shopAdmin['roleId'] ?? 0;
  173. $role = AdminRoleClass::getById($roleId);
  174. $roleName = $role['roleName'] ?? '';
  175. if ($roleName == '员工') {
  176. util::fail('您没有权限操作哦');
  177. }
  178. $get = Yii::$app->request->get();
  179. $id = $get['id'] ?? 0;
  180. $debtLimit = $get['debtLimit'] ?? 0;
  181. if (is_numeric($debtLimit) == false || $debtLimit <= 0) {
  182. util::fail('请填写金额');
  183. }
  184. $custom = CustomClass::getById($id, true);
  185. CustomClass::valid($custom, $this->shopId);
  186. $custom->debtLimit = $debtLimit;
  187. $custom->save();
  188. util::complete();
  189. }
  190. }