CustomController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. 'from' => ApplyClass::FROM_GHS,
  63. 'style' => SjClass::STYLE_RETAIL,
  64. 'province' => $shop->province ?? '',
  65. 'city' => $city,
  66. 'dist' => $dist,
  67. 'address' => $address,
  68. 'status' => ApplyClass::STATUS_PASS,
  69. 'replace' => 1,//1表示供货商添加的客户
  70. ];
  71. $apply = ApplyService::replaceRetail($applyData);
  72. $id = $apply['id'] ?? 0;
  73. $respond = ApplyService::pass($id);
  74. $shop = $respond['shop'] ?? [];
  75. $sj = $respond['sj'] ?? [];
  76. $hdSjId = $sj['id'] ?? 0;
  77. $hdShopId = $shop->id ?? 0;
  78. ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
  79. if (empty($hdShopId)) {
  80. util::fail('客户没有添加成功!');
  81. }
  82. $custom = CustomClass::build($this->shopId, $hdShopId);
  83. $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
  84. $transaction->commit();
  85. util::success($custom);
  86. } catch (\Exception $exception) {
  87. $transaction->rollBack();
  88. Yii::info("添加客户没有成功:" . $exception->getMessage());
  89. util::fail('添加客户没有成功');
  90. }
  91. }
  92. //客户列表 ssh 2021.7.8
  93. public function actionList()
  94. {
  95. $get = Yii::$app->request->get();
  96. $type = isset($get['type']) ? $get['type'] : 0;
  97. $name = isset($get['name']) ? $get['name'] : '';
  98. $where = ['ownShopId' => $this->shopId];
  99. switch ($type) {
  100. case 1:
  101. //已开店
  102. $where['isOpen'] = 1;
  103. break;
  104. default:
  105. }
  106. if (!empty($name)) {
  107. if (stringUtil::isMobile($name)) {
  108. $where['mobile'] = $name;
  109. } else {
  110. $where['name'] = ['like', $name];
  111. }
  112. }
  113. $list = CustomService::getCustomList($where);
  114. util::success($list);
  115. }
  116. //客户详情 ssh 2021.1.8
  117. public function actionDetail()
  118. {
  119. $get = Yii::$app->request->get();
  120. $customId = $get['id'] ?? 0;
  121. $info = CustomService::getCustomInfo($customId);
  122. CustomClass::valid($info, $this->shopId);
  123. util::success($info);
  124. }
  125. //允许月结开关 ssh 2021.1.8
  126. public function actionDebt()
  127. {
  128. $get = Yii::$app->request->get();
  129. $debt = isset($get['debt']) ? $get['debt'] : 0;
  130. $customId = isset($get['customId']) ? $get['customId'] : 0;
  131. $custom = CustomClass::getById($customId);
  132. CustomClass::valid($custom, $this->shopId);
  133. CustomClass::debt($custom, $debt);
  134. util::complete();
  135. }
  136. //欠款客户 ssh 2021.2.4
  137. public function actionDebtList()
  138. {
  139. $get = Yii::$app->request->get();
  140. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  141. if (isset($get['name']) && !empty($get['name'])) {
  142. $where['name'] = ['like', $get['name']];
  143. }
  144. $list = CustomService::getDebtList($where);
  145. //共X个客户,合计欠款XXX元
  146. $shop = $this->shop;
  147. $list['customNum'] = $shop->mayGatheringNum ?? 0;
  148. $list['debtAmount'] = $shop->mayGathering ?? 0.00;
  149. util::success($list);
  150. }
  151. }