CustomController.php 5.9 KB

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