CustomController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminRoleClass;
  4. use biz\ghs\classes\GhsClass;
  5. use biz\shop\classes\ShopAdminClass;
  6. use biz\sj\classes\SjClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\custom\services\CustomService;
  9. use bizHd\saas\classes\ApplyClass;
  10. use bizHd\saas\services\ApplyService;
  11. use common\components\imgUtil;
  12. use common\components\stringUtil;
  13. use common\components\util;
  14. use Yii;
  15. class CustomController extends BaseController
  16. {
  17. //添加新花店 shish 2021.1.8
  18. public function actionAdd()
  19. {
  20. $post = Yii::$app->request->post();
  21. $post['style'] = SjClass::STYLE_RETAIL;
  22. $post['introSjId'] = $this->sjId;
  23. $post['introStyle'] = SjClass::STYLE_SUPPLIER;
  24. $mobile = $post['mobile'] ?? '';
  25. $confirmMobile = $post['confirmMobile'];
  26. $address = $post['address'] ?? '';
  27. util::fail('功能已停用');
  28. if (stringUtil::isMobile($mobile) == false) {
  29. util::fail(' 请填写正确的手机号');
  30. }
  31. if ($mobile != $confirmMobile) {
  32. util::fail('二次号码填写不一致');
  33. }
  34. $name = $post['name'] ?? '';
  35. if (empty($name)) {
  36. util::fail('名称不能为空');
  37. }
  38. if (stringUtil::getWordNum($name) > 8) {
  39. util::fail('名称不能超过8个汉字');
  40. }
  41. $has = SjClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_RETAIL]);
  42. if (!empty($has)) {
  43. util::fail('名称已经存在');
  44. }
  45. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]);
  46. if (!empty($has)) {
  47. util::fail('手机号已经添加过');
  48. }
  49. if (empty($address)) {
  50. util::fail('请填写地址');
  51. }
  52. $connection = Yii::$app->db;
  53. $transaction = $connection->beginTransaction();
  54. try {
  55. $shop = $this->shop;
  56. $sjId = $this->sjId;
  57. $shopId = $this->shopId;
  58. $sjName = $this->sj->name ?? '';
  59. $city = $shop->city ?? '';
  60. $dist = $shop->dist ?? '';
  61. $applyData = [
  62. 'name' => $name,
  63. 'licenseNo' => $mobile,
  64. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  65. 'mobile' => $mobile,
  66. 'introSjId' => $sjId,
  67. 'introSjName' => $sjName,
  68. 'introShopId' => $shopId,
  69. 'introStyle' => SjClass::STYLE_SUPPLIER,
  70. 'from' => ApplyClass::FROM_GHS,
  71. 'style' => SjClass::STYLE_RETAIL,
  72. 'province' => $shop->province ?? '',
  73. 'city' => $city,
  74. 'dist' => $dist,
  75. 'address' => $address,
  76. 'status' => ApplyClass::STATUS_PASS,
  77. 'replace' => 1,//1表示供应商添加的客户
  78. ];
  79. $apply = ApplyService::replaceRetail($applyData);
  80. $id = $apply['id'] ?? 0;
  81. $respond = ApplyService::pass($id);
  82. $shop = $respond['shop'] ?? [];
  83. $sj = $respond['sj'] ?? [];
  84. $hdSjId = $sj['id'] ?? 0;
  85. $hdShopId = $shop->id ?? 0;
  86. ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
  87. if (empty($hdShopId)) {
  88. util::fail('客户没有添加成功!');
  89. }
  90. $custom = CustomClass::build($this->shopId, $hdShopId);
  91. $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
  92. //客户欠款额度设置
  93. $debt = isset($post['debt']) && $post['debt'] == CustomClass::IS_DEBT_YES ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
  94. $customId = $custom['id'] ?? 0;
  95. $debtLimit = isset($post['debtLimit']) && is_numeric($post['debtLimit']) ? $post['debtLimit'] : 5000;
  96. CustomClass::updateById($customId, ['debtLimit' => $debtLimit, 'debt' => $debt]);
  97. $transaction->commit();
  98. util::success($custom);
  99. } catch (\Exception $exception) {
  100. $transaction->rollBack();
  101. Yii::info("添加客户没有成功:" . $exception->getMessage());
  102. util::fail('添加客户没有成功');
  103. }
  104. }
  105. //客户列表 ssh 2021.7.8
  106. public function actionList()
  107. {
  108. $get = Yii::$app->request->get();
  109. $type = isset($get['type']) ? $get['type'] : 0;
  110. $name = isset($get['name']) ? $get['name'] : '';
  111. $where = ['ownShopId' => $this->shopId];
  112. if ($type == 1) {
  113. //欠款客户
  114. $where['isDebt'] = 1;
  115. $sort = 'debtAmount DESC';
  116. } else if ($type == 2) {
  117. //消费排行
  118. $sort = 'buyAmount DESC';
  119. } else {
  120. //其它
  121. $sort = 'addTime DESC';
  122. }
  123. if (!empty($name)) {
  124. if (stringUtil::isLetter($name)) {
  125. $where['py'] = ['like', $name];
  126. } else {
  127. $where['name'] = ['like', $name];
  128. }
  129. }
  130. $list = CustomService::getCustomSortList($where, $sort);
  131. $shop = $this->shop;
  132. $list['totalUser'] = $shop->totalUser ?? 0;
  133. $list['mayGatheringNum'] = $shop->mayGatheringNum ?? 0;
  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. //手动添加的客户经纬度不完善不显示地址,引导完善客户地址
  144. if (isset($info['lat']) && empty($info['lat'])) {
  145. $info['address'] = '';
  146. }
  147. if (isset($info['long']) && empty($info['long'])) {
  148. $info['address'] = '';
  149. }
  150. $shopId = $info['shopId'] ?? 0;
  151. //超管的信息
  152. $superInfo = ShopAdminClass::getSuper($shopId);
  153. $superName = $superInfo['name'] ?? '';
  154. $currentSuper = ['name' => $superName];
  155. $info['superInfo'] = $currentSuper;
  156. util::success($info);
  157. }
  158. //允许月结开关 ssh 2021.1.8
  159. public function actionDebt()
  160. {
  161. $get = Yii::$app->request->get();
  162. $debt = isset($get['debt']) ? $get['debt'] : 0;
  163. $customId = isset($get['customId']) ? $get['customId'] : 0;
  164. $custom = CustomClass::getById($customId);
  165. CustomClass::valid($custom, $this->shopId);
  166. CustomClass::debt($custom, $debt);
  167. util::complete();
  168. }
  169. //采购查看权限的黑白名单开关 shizhongqi 2021.08.08
  170. public function actionSetBlack()
  171. {
  172. $black = Yii::$app->request->get('black', 2);
  173. $customId = Yii::$app->request->get('customId', 0);
  174. $custom = CustomClass::getById($customId);
  175. CustomClass::valid($custom, $this->shopId);
  176. CustomClass::black($custom, $black);
  177. util::complete();
  178. }
  179. //欠款客户 ssh 2021.2.4
  180. public function actionDebtList()
  181. {
  182. $get = Yii::$app->request->get();
  183. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  184. if (isset($get['name']) && !empty($get['name'])) {
  185. $where['name'] = ['like', $get['name']];
  186. }
  187. $list = CustomService::getDebtList($where);
  188. //共X个客户,合计欠款XXX元
  189. $shop = $this->shop;
  190. $list['customNum'] = $shop->mayGatheringNum ?? 0;
  191. $list['debtAmount'] = $shop->mayGathering ?? 0.00;
  192. util::success($list);
  193. }
  194. //修改欠款额度 shish 20210625
  195. public function actionUpdateDebtLimit()
  196. {
  197. $shopAdmin = $this->shopAdmin;
  198. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  199. util::fail('管理员才能操作');
  200. }
  201. $get = Yii::$app->request->get();
  202. $id = $get['id'] ?? 0;
  203. $debtLimit = $get['debtLimit'] ?? 0;
  204. if (is_numeric($debtLimit) == false || $debtLimit <= 0) {
  205. util::fail('请填写金额');
  206. }
  207. $custom = CustomClass::getById($id, true);
  208. CustomClass::valid($custom, $this->shopId);
  209. $custom->debtLimit = $debtLimit;
  210. $custom->save();
  211. util::complete();
  212. }
  213. //修改折扣 shish 20210913
  214. public function actionChangeDiscount()
  215. {
  216. $shopAdmin = $this->shopAdmin;
  217. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  218. util::fail('管理员才能操作');
  219. }
  220. $get = Yii::$app->request->get();
  221. $id = $get['id'] ?? 0;
  222. $discount = $get['discount'] ?? 0;
  223. if (is_numeric($discount) == false || $discount > 1 || $discount == 0) {
  224. util::fail('请填写小数值');
  225. }
  226. $custom = CustomClass::getById($id, true);
  227. CustomClass::valid($custom, $this->shopId);
  228. $custom->discount = $discount;
  229. $custom->save();
  230. $ghsId = $custom->ghsId ?? 0;
  231. $ghs = GhsClass::getById($ghsId, true);
  232. $ghs->giveDiscount = $discount;
  233. $ghs->save();
  234. util::complete();
  235. }
  236. }