CustomController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\classes\SjClass;
  5. use biz\sj\services\MerchantService;
  6. use bizGhs\custom\classes\CustomClass;
  7. use bizGhs\custom\services\CustomService;
  8. use bizHd\saas\classes\ApplyClass;
  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. $data = [
  45. 'id' => 2,
  46. 'name' => '小石头',
  47. 'avatar' => 'https://img.huaml.com/ghs/home/deserve.png',
  48. ];
  49. util::success($data);
  50. $connection = Yii::$app->db;
  51. $transaction = $connection->beginTransaction();
  52. try {
  53. $date = date("Y-m-d H:i:s");
  54. $shop = $this->shop;
  55. $city = $shop->city ?? '';
  56. $dist = $shop->dist ?? '';
  57. $address = $post['address'] ?? '';
  58. $fullAddress = $city . $dist . $address;
  59. $apply = [
  60. 'logo' => '',
  61. 'name' => '',
  62. 'hasLicense' => '',
  63. 'licenseNo' => '',
  64. 'certType' => '',
  65. 'adminId' => '',
  66. 'adminName' => '未命名',
  67. 'mobile' => $mobile,
  68. 'introSjId' => 0,
  69. 'introSjName' => '',
  70. 'introShopId' => 0,
  71. 'customId' => '',
  72. 'shopAdminId' => '',
  73. 'from' => '',
  74. 'fee' => '',
  75. 'income' => '',
  76. 'sjId' => '',
  77. 'style' => SjClass::STYLE_RETAIL,
  78. 'main' => '',
  79. 'long' => '',
  80. 'lat' => '',
  81. 'province' => $shop->province ?? '',
  82. 'city' => $city,
  83. 'dist' => $dist,
  84. 'address' => $address,
  85. 'floor' => '',
  86. 'fullAddress' => $fullAddress,
  87. 'showAddress' => '',
  88. 'remark' => '',
  89. 'status' => 2,
  90. 'addTime' => $date,
  91. 'updateTime' => $date,
  92. ];
  93. $sj = MerchantService::initSjInfo($apply);
  94. $sjId = $sj['id'] ?? 0;
  95. if (empty($sjId)) {
  96. util::fail('添加客户没有成功');
  97. }
  98. $hdShop = ShopClass::getByCondition(['sjId' => $sjId], true);
  99. $hdShopId = $hdShop->id ?? 0;
  100. if (empty($hdShopId)) {
  101. util::fail('添加客户没有成功!');
  102. }
  103. $custom = CustomClass::build($this->shopId, $hdShopId);
  104. $transaction->commit();
  105. util::success($custom);
  106. } catch (\Exception $exception) {
  107. $transaction->rollBack();
  108. Yii::info("添加客户没有成功:" . $exception->getMessage());
  109. util::fail('添加客户没有成功');
  110. }
  111. }
  112. //客户列表 ssh 2021.7.8
  113. public function actionList()
  114. {
  115. $get = Yii::$app->request->get();
  116. $type = isset($get['type']) ? $get['type'] : 0;
  117. $name = isset($get['name']) ? $get['name'] : '';
  118. $where = ['ownShopId' => $this->shopId];
  119. switch ($type) {
  120. case 1:
  121. //已开店
  122. $where['isOpen'] = 1;
  123. break;
  124. default:
  125. }
  126. if (!empty($name)) {
  127. if (stringUtil::isMobile($name)) {
  128. $where['mobile'] = $name;
  129. } else {
  130. $where['name'] = ['like', $name];
  131. }
  132. }
  133. $list = CustomService::getCustomList($where);
  134. util::success($list);
  135. }
  136. //客户详情 ssh 2021.1.8
  137. public function actionDetail()
  138. {
  139. $get = Yii::$app->request->get();
  140. $customId = $get['id'] ?? 0;
  141. $info = CustomService::getCustomInfo($customId);
  142. CustomClass::valid($info, $this->shopId);
  143. util::success($info);
  144. }
  145. //允许月结开关 ssh 2021.1.8
  146. public function actionDebt()
  147. {
  148. $get = Yii::$app->request->get();
  149. $debt = isset($get['debt']) ? $get['debt'] : 0;
  150. $customId = isset($get['customId']) ? $get['customId'] : 0;
  151. $custom = CustomClass::getById($customId);
  152. CustomClass::valid($custom, $this->shopId);
  153. CustomClass::debt($custom, $debt);
  154. util::complete();
  155. }
  156. //欠款客户 ssh 2021.2.4
  157. public function actionDebtList()
  158. {
  159. $get = Yii::$app->request->get();
  160. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  161. if (isset($get['name']) && !empty($get['name'])) {
  162. $where['name'] = ['like', $get['name']];
  163. }
  164. $list = CustomService::getDebtList($where);
  165. //共X个客户,合计欠款XXX元
  166. $shop = $this->shop;
  167. $list['customNum'] = $shop->mayGatheringNum ?? 0;
  168. $list['debtAmount'] = $shop->mayGathering ?? 0.00;
  169. util::success($list);
  170. }
  171. }