CustomController.php 8.8 KB

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