CustomController.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. //欠款客户
  113. if (!empty($type) && $type == 1) {
  114. $where['isDebt'] = 1;
  115. }
  116. if (!empty($name)) {
  117. if (stringUtil::isLetter($name)) {
  118. $where['py'] = ['like', $name];
  119. } else {
  120. $where['name'] = ['like', $name];
  121. }
  122. }
  123. if ($type == 2) {
  124. $list = CustomService::getCustomOrderList($where, 'buyAmount DESC');
  125. } else {
  126. $list = CustomService::getCustomList($where);
  127. }
  128. $shop = $this->shop;
  129. $list['totalUser'] = $shop->totalUser ?? 0;
  130. $list['mayGatheringNum'] = $shop->mayGatheringNum ?? 0;
  131. util::success($list);
  132. }
  133. //客户详情 ssh 2021.1.8
  134. public function actionDetail()
  135. {
  136. $get = Yii::$app->request->get();
  137. $customId = $get['id'] ?? 0;
  138. $info = CustomService::getCustomInfo($customId);
  139. CustomClass::valid($info, $this->shopId);
  140. //手动添加的客户经纬度不完善不显示地址,引导完善客户地址
  141. if (isset($info['lat']) && empty($info['lat'])) {
  142. $info['address'] = '';
  143. }
  144. if (isset($info['long']) && empty($info['long'])) {
  145. $info['address'] = '';
  146. }
  147. $shopId = $info['shopId'] ?? 0;
  148. //超管的信息
  149. $superInfo = ShopAdminClass::getSuper($shopId);
  150. $superName = $superInfo['name'] ?? '';
  151. $currentSuper = ['name' => $superName];
  152. $info['superInfo'] = $currentSuper;
  153. util::success($info);
  154. }
  155. //允许月结开关 ssh 2021.1.8
  156. public function actionDebt()
  157. {
  158. $get = Yii::$app->request->get();
  159. $debt = isset($get['debt']) ? $get['debt'] : 0;
  160. $customId = isset($get['customId']) ? $get['customId'] : 0;
  161. $custom = CustomClass::getById($customId);
  162. CustomClass::valid($custom, $this->shopId);
  163. CustomClass::debt($custom, $debt);
  164. util::complete();
  165. }
  166. //采购查看权限的黑白名单开关 shizhongqi 2021.08.08
  167. public function actionSetBlack()
  168. {
  169. $black = Yii::$app->request->get('black', 2);
  170. $customId = Yii::$app->request->get('customId', 0);
  171. $custom = CustomClass::getById($customId);
  172. CustomClass::valid($custom, $this->shopId);
  173. CustomClass::black($custom, $black);
  174. util::complete();
  175. }
  176. //欠款客户 ssh 2021.2.4
  177. public function actionDebtList()
  178. {
  179. $get = Yii::$app->request->get();
  180. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  181. if (isset($get['name']) && !empty($get['name'])) {
  182. $where['name'] = ['like', $get['name']];
  183. }
  184. $list = CustomService::getDebtList($where);
  185. //共X个客户,合计欠款XXX元
  186. $shop = $this->shop;
  187. $list['customNum'] = $shop->mayGatheringNum ?? 0;
  188. $list['debtAmount'] = $shop->mayGathering ?? 0.00;
  189. util::success($list);
  190. }
  191. //修改欠款额度 shish 20210625
  192. public function actionUpdateDebtLimit()
  193. {
  194. $shopAdmin = $this->shopAdmin;
  195. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  196. util::fail('管理员才能操作');
  197. }
  198. $get = Yii::$app->request->get();
  199. $id = $get['id'] ?? 0;
  200. $debtLimit = $get['debtLimit'] ?? 0;
  201. if (is_numeric($debtLimit) == false || $debtLimit <= 0) {
  202. util::fail('请填写金额');
  203. }
  204. $custom = CustomClass::getById($id, true);
  205. CustomClass::valid($custom, $this->shopId);
  206. $custom->debtLimit = $debtLimit;
  207. $custom->save();
  208. util::complete();
  209. }
  210. //修改折扣 shish 20210913
  211. public function actionChangeDiscount()
  212. {
  213. $shopAdmin = $this->shopAdmin;
  214. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  215. util::fail('管理员才能操作');
  216. }
  217. $get = Yii::$app->request->get();
  218. $id = $get['id'] ?? 0;
  219. $discount = $get['discount'] ?? 0;
  220. if (is_numeric($discount) == false || $discount > 1 || $discount == 0) {
  221. util::fail('请填写小数值');
  222. }
  223. $custom = CustomClass::getById($id, true);
  224. CustomClass::valid($custom, $this->shopId);
  225. $custom->discount = $discount;
  226. $custom->save();
  227. $ghsId = $custom->ghsId ?? 0;
  228. $ghs = GhsClass::getById($ghsId, true);
  229. $ghs->giveDiscount = $discount;
  230. $ghs->save();
  231. util::complete();
  232. }
  233. }