CustomController.php 7.2 KB

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