CustomController.php 5.8 KB

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