CustomController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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 bizGhs\merchant\classes\WlClass;
  10. use bizGhs\order\classes\OrderClass;
  11. use bizHd\saas\classes\ApplyClass;
  12. use bizHd\saas\services\ApplyService;
  13. use bizHd\shop\classes\ShopClass;
  14. use bizHd\stat\classes\StatVisitClass;
  15. use common\components\dict;
  16. use common\components\imgUtil;
  17. use common\components\orderSn;
  18. use common\components\stringUtil;
  19. use common\components\util;
  20. use Yii;
  21. class CustomController extends BaseController
  22. {
  23. //供货商给客户充值和结账 ssh 20240309
  24. public function actionRecharge()
  25. {
  26. ini_set('memory_limit', '2045M');
  27. set_time_limit(0);
  28. $staff = $this->shopAdmin;
  29. if (isset($staff->finance) == false || $staff->finance == 0) {
  30. util::fail('无法充值销单。。。');
  31. }
  32. //多个地方需要同步修改clear_order_power
  33. if (getenv('YII_ENV') == 'production') {
  34. //小向花卉
  35. if (in_array($this->shopId, [23580, 24713])) {
  36. if ($this->adminId != 24043) {
  37. util::fail('不能销单!');
  38. }
  39. }
  40. //花样年华只有总控才能结账
  41. if (in_array($this->shopId, [1585, 1596])) {
  42. if ($this->adminId != 2876) {
  43. util::fail('不能充值销单哦');
  44. }
  45. }
  46. //花大苪 洋桔梗,只有叶荷姐才能销账
  47. if (in_array($this->shopId, [16070])) {
  48. if (!in_array($this->adminId, [9303, 4])) {
  49. util::fail('不能充值销单哈');
  50. }
  51. }
  52. //天天鲜花 陈江店
  53. if (in_array($this->shopId, [763, 1405, 795])) {
  54. if (!in_array($this->adminId, [2094, 5959])) {
  55. util::fail('不能操作充值销单!');
  56. }
  57. }
  58. //花儿好仙
  59. if (in_array($this->shopId, [22666])) {
  60. if (!in_array($this->adminId, [12869, 23174])) {
  61. util::fail('不能充值销单哈');
  62. }
  63. }
  64. //小丽鲜花
  65. if (in_array($this->shopId, [11094])) {
  66. if (!in_array($this->adminId, [12073, 12296])) {
  67. util::fail('您不能充值销单哦');
  68. }
  69. }
  70. } else {
  71. if (in_array($this->shopId, [36523])) {
  72. if ($this->adminId != 919) {
  73. util::fail('暂不能操作充值销单哈');
  74. }
  75. }
  76. }
  77. $get = Yii::$app->request->get();
  78. $amount = $get['amount'] ?? 0;
  79. $customId = $get['customId'] ?? 0;
  80. $payWay = $get['payWay'] ?? -1;
  81. $remark = $get['remark'] ?? '';
  82. if ($payWay < 0) {
  83. util::fail('请选择付款方式');
  84. }
  85. if ($amount <= 0) {
  86. //util::fail('充值金额需要大于0');
  87. }
  88. $custom = CustomClass::getLockById($customId);
  89. if (empty($custom)) {
  90. util::fail('没有找到客户');
  91. }
  92. if ($custom->ownMainId != $this->mainId) {
  93. util::fail('不是你的客户,无法充值');
  94. }
  95. $customShopId = $custom->shopId ?? 0;
  96. $shop = $this->shop;
  97. if ($customShopId == $shop->lsShopId) {
  98. util::fail('不能给自己充值');
  99. }
  100. $connection = Yii::$app->db;
  101. $transaction = $connection->beginTransaction();
  102. try {
  103. $staff = $this->shopAdmin;
  104. $params = ['remark' => $remark];
  105. CustomService::rechargeClear($custom, $amount, $this->shop, $staff, $payWay, $params);
  106. $transaction->commit();
  107. util::complete('充值成功');
  108. } catch (\Exception $e) {
  109. Yii::info("充值失败原因:" . $e->getMessage());
  110. $transaction->rollBack();
  111. util::fail('充值失败');
  112. }
  113. }
  114. //生成货位号 ssh 20231215
  115. public function actionCreateSeatSn()
  116. {
  117. $get = Yii::$app->request->get();
  118. $id = $get['id'] ?? 0;
  119. $custom = CustomClass::getById($id, true);
  120. if ($custom->ownMainId != $this->mainId) {
  121. util::fail('不是您的客户');
  122. }
  123. $seatSn = $custom->seatSn ?? '';
  124. if (!empty($seatSn)) {
  125. util::fail('已经有货位号了');
  126. }
  127. $new = CustomClass::createSeatSn($this->mainId);
  128. $custom->seatSn = $new;
  129. $custom->save();
  130. util::complete('已生成');
  131. }
  132. //修改货位号 ssh 20231215
  133. public function actionModifySeatSn()
  134. {
  135. $get = Yii::$app->request->get();
  136. $id = $get['id'] ?? 0;
  137. $new = $get['seatSn'] ?? 0;
  138. $custom = CustomClass::getById($id, true);
  139. if ($custom->ownMainId != $this->mainId) {
  140. util::fail('不是您的客户');
  141. }
  142. if (is_numeric($new) == false) {
  143. util::fail('请填写数字');
  144. }
  145. $custom->seatSn = $new;
  146. $custom->save();
  147. util::complete('修改成功');
  148. }
  149. //修改客户地址 ssh 20230929
  150. public function actionModifyAddress()
  151. {
  152. $post = Yii::$app->request->post();
  153. $id = $post['id'] ?? 0;
  154. unset($post['id']);
  155. $custom = CustomClass::getById($id, true);
  156. if ($custom->ownMainId != $this->mainId) {
  157. util::fail('不是您的客户哦');
  158. }
  159. $city = $post['city'] ?? '';
  160. $dist = $post['dist'] ?? '';
  161. $address = $post['address'] ?? '';
  162. $floor = $post['floor'] ?? '';
  163. $post['fullAddress'] = $city . $dist . $address . $floor;
  164. $shopId = $custom->shopId ?? 0;
  165. ShopClass::updateById($shopId, $post);
  166. CustomClass::updateByCondition(['shopId' => $shopId], $post);
  167. util::complete('修改成功');
  168. }
  169. //修改花店散客身份 ssh 20230216
  170. public function actionChangeIsHd()
  171. {
  172. $get = Yii::$app->request->get();
  173. $id = $get['customId'] ?? 0;
  174. $isHd = $get['isHd'] ?? 1;
  175. $custom = CustomClass::getById($id, true);
  176. if (empty($custom)) {
  177. util::fail('没有找到客户');
  178. }
  179. if ($custom->ownMainId != $this->mainId) {
  180. util::fail('没有权限');
  181. }
  182. $ghsId = $custom->ghsId ?? 0;
  183. $ghs = GhsClass::getById($ghsId, true);
  184. if (empty($ghs)) {
  185. util::fail('修改失败了');
  186. }
  187. $ghs->isHd = $isHd;
  188. $ghs->save();
  189. $custom->isHd = $isHd;
  190. $custom->save();
  191. util::complete('修改成功');
  192. }
  193. //修改物流名称 ssh 20230112
  194. public function actionChangeWlName()
  195. {
  196. $get = Yii::$app->request->get();
  197. $id = $get['id'] ?? 0;
  198. $wlName = $get['wlName'] ?? 0;
  199. $custom = CustomClass::getById($id, true);
  200. if (empty($custom) || $custom->ownMainId != $this->mainId) {
  201. util::fail('修改失败');
  202. }
  203. $ghsId = $custom->ghsId ?? 0;
  204. $ghs = GhsClass::getById($ghsId, true);
  205. if (empty($ghs)) {
  206. util::fail('修改失败');
  207. }
  208. $ghs->customWlName = $wlName;
  209. $ghs->save();
  210. $custom->wlName = $wlName;
  211. $custom->save();
  212. util::complete('已修改');
  213. }
  214. //修改物流信息 ssh 20230105
  215. public function actionChangeWl()
  216. {
  217. util::fail('修改失败');
  218. }
  219. //修改名称 ssh 2022096
  220. public function actionChangeName()
  221. {
  222. $get = Yii::$app->request->get();
  223. $name = $get['name'] ?? '';
  224. $id = $get['id'] ?? 0;
  225. if (empty($name)) {
  226. util::fail('请填写名称');
  227. }
  228. $py = stringUtil::py($name);
  229. $custom = CustomClass::getById($id, true);
  230. CustomClass::valid($custom, $this->shopId);
  231. $custom->name = $name;
  232. $custom->py = $py;
  233. $custom->save();
  234. OrderClass::updateByCondition(['customId' => $id], ['customName' => $name, 'customNamePy' => $py]);
  235. $customShopId = $custom->shopId ?? 0;
  236. //在首店修改客户名称,直营店自动同步
  237. $masterShop = $this->shop;
  238. if (isset($masterShop->default) && $masterShop->default == 1) {
  239. $sjId = $masterShop->sjId ?? 0;
  240. $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  241. foreach ($shopList as $shop) {
  242. $shopId = $shop->id ?? 0;
  243. if (isset($shop->join) && $shop->join == 1) {
  244. //加盟店不同步修改
  245. continue;
  246. }
  247. if ($shopId == $masterShop->id) {
  248. //前面已经同步修改过了
  249. continue;
  250. }
  251. $custom = CustomClass::getByCondition(['ownShopId' => $shopId, 'shopId' => $customShopId], true);
  252. if (empty($custom)) {
  253. continue;
  254. }
  255. $custom->name = $name;
  256. $custom->py = $py;
  257. $custom->save();
  258. }
  259. }
  260. util::complete('修改成功');
  261. }
  262. //帮客户添加员工 ssh 20220613
  263. public function actionAddStaff()
  264. {
  265. $post = Yii::$app->request->post();
  266. $customId = $post['id'] ?? 0;
  267. $mobile = $post['mobile'] ?? 0;
  268. if (stringUtil::isMobile($mobile) == false) {
  269. util::fail('手机号填写错误');
  270. }
  271. $info = CustomService::getById($customId, true);
  272. CustomClass::valid($info, $this->shopId);
  273. $connection = Yii::$app->db;
  274. $transaction = $connection->beginTransaction();
  275. try {
  276. $shopId = $info->shopId ?? 0;
  277. $customShop = ShopClass::getById($shopId, true);
  278. if (empty($customShop)) {
  279. util::fail('没有找到客户的门店');
  280. }
  281. $mainId = $customShop->mainId ?? 0;
  282. $ptStyle = dict::getDict('ptStyle', 'hd');
  283. $adminInfo = ['name' => $mobile, 'mobile' => $mobile, 'style' => $ptStyle, 'currentShopId' => $shopId];
  284. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  285. $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
  286. $roleList = AdminRoleClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  287. if (empty($roleList)) {
  288. util::fail('客户门店没有员工角色');
  289. }
  290. $currentRoleId = 0;
  291. foreach ($roleList as $role) {
  292. $roleId = $role->id ?? 0;
  293. $currentRoleId = $roleId;
  294. if ($role->roleName == '员工') {
  295. break;
  296. }
  297. }
  298. $params = [
  299. 'shopId' => $shopId,
  300. 'mobile' => $mobile,
  301. 'roleId' => $currentRoleId,
  302. ];
  303. \bizHd\staff\classes\StaffClass::appGenerateStaff($params, $admin);
  304. $transaction->commit();
  305. util::complete('添加成功');
  306. } catch (\Exception $e) {
  307. $transaction->rollBack();
  308. util::fail('添加失败');
  309. }
  310. }
  311. //添加新花店 ssh 2021.1.8
  312. public function actionAdd()
  313. {
  314. $post = Yii::$app->request->post();
  315. $post['style'] = SjClass::STYLE_RETAIL;
  316. $post['introSjId'] = $this->sjId;
  317. $post['introStyle'] = SjClass::STYLE_SUPPLIER;
  318. $mobile = $post['mobile'] ?? '';
  319. $confirmMobile = $post['confirmMobile'];
  320. $address = $post['address'] ?? '';
  321. util::fail('功能已停用');
  322. if (stringUtil::isMobile($mobile) == false) {
  323. util::fail(' 请填写正确的手机号');
  324. }
  325. if ($mobile != $confirmMobile) {
  326. util::fail('二次号码填写不一致');
  327. }
  328. $name = $post['name'] ?? '';
  329. if (empty($name)) {
  330. util::fail('名称不能为空');
  331. }
  332. if (stringUtil::getWordNum($name) > 15) {
  333. util::fail('名称不能超过15个汉字');
  334. }
  335. $has = SjClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_RETAIL]);
  336. if (!empty($has)) {
  337. util::fail('名称已经存在');
  338. }
  339. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]);
  340. if (!empty($has)) {
  341. util::fail('手机号已经添加过');
  342. }
  343. if (empty($address)) {
  344. util::fail('请填写地址');
  345. }
  346. $connection = Yii::$app->db;
  347. $transaction = $connection->beginTransaction();
  348. try {
  349. $shop = $this->shop;
  350. $sjId = $this->sjId;
  351. $shopId = $this->shopId;
  352. $sjName = $this->sj->name ?? '';
  353. $city = $shop->city ?? '';
  354. $dist = $shop->dist ?? '';
  355. $applyData = [
  356. 'name' => $name,
  357. 'licenseNo' => $mobile,
  358. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  359. 'mobile' => $mobile,
  360. 'introSjId' => $sjId,
  361. 'introSjName' => $sjName,
  362. 'introShopId' => $shopId,
  363. 'introStyle' => SjClass::STYLE_SUPPLIER,
  364. 'from' => ApplyClass::FROM_GHS,
  365. 'style' => SjClass::STYLE_RETAIL,
  366. 'province' => $shop->province ?? '',
  367. 'city' => $city,
  368. 'dist' => $dist,
  369. 'address' => $address,
  370. 'status' => ApplyClass::STATUS_PASS,
  371. 'replace' => 1,//1表示供货商添加的客户
  372. ];
  373. $apply = ApplyService::replaceRetail($applyData);
  374. $id = $apply['id'] ?? 0;
  375. $respond = ApplyService::pass($id);
  376. $shop = $respond['shop'] ?? [];
  377. $sj = $respond['sj'] ?? [];
  378. $hdSjId = $sj['id'] ?? 0;
  379. $hdShopId = $shop->id ?? 0;
  380. ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
  381. if (empty($hdShopId)) {
  382. util::fail('客户没有添加成功!');
  383. }
  384. $custom = CustomClass::build($this->shopId, $hdShopId);
  385. $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
  386. //客户欠款额度设置
  387. $debt = isset($post['debt']) && $post['debt'] == CustomClass::IS_DEBT_YES ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
  388. $customId = $custom['id'] ?? 0;
  389. $debtLimit = isset($post['debtLimit']) && is_numeric($post['debtLimit']) ? $post['debtLimit'] : 5000;
  390. CustomClass::updateById($customId, ['debtLimit' => $debtLimit, 'debt' => $debt]);
  391. $transaction->commit();
  392. util::success($custom);
  393. } catch (\Exception $exception) {
  394. $transaction->rollBack();
  395. Yii::info("添加客户没有成功:" . $exception->getMessage());
  396. util::fail('添加客户没有成功');
  397. }
  398. }
  399. //向队列写入新花店数据 shizhongqi 2022.6.8
  400. public function actionCreateCustomers()
  401. {
  402. $post = Yii::$app->request->post();
  403. $virtual = $post['virtual'] ?? 0;
  404. $arr = [];
  405. for ($i = 1; $i <= 5; $i++) {
  406. $name = $post['name' . $i] ?? '';
  407. $mobile = $post['mobile' . $i] ?? '';
  408. $confirmMobile = $post['confirmMobile' . $i] ?? '';
  409. if (empty($name) && empty($mobile) && empty($confirmMobile)) {
  410. continue;
  411. }
  412. if (empty($name)) {
  413. util::fail('花店名称不能为空');
  414. }
  415. if (stringUtil::getWordNum($name) > 15) {
  416. util::fail('名称不能超过15个汉字');
  417. }
  418. if (empty($mobile)) {
  419. //添加虚拟客户
  420. if ($virtual == 1) {
  421. $mobile = orderSn::getMobileSn();
  422. $confirmMobile = $mobile;
  423. } else {
  424. util::fail($name . " 手机号不能为空");
  425. }
  426. }
  427. if (stringUtil::isMobile($mobile) == false) {
  428. util::fail($name . " 手机号格式不正确");
  429. }
  430. if ($mobile != $confirmMobile) {
  431. util::fail($name . " 二次手机号不一致");
  432. }
  433. $hasShop = ShopClass::getByCondition(['mobile' => $mobile], true);
  434. if (!empty($hasShop)) {
  435. $shop = ShopClass::getByCondition(['mobile' => $mobile, 'ptStyle' => 1], true);
  436. if (!empty($shop)) {
  437. $ghsShopId = $this->shopId;
  438. $hdShopId = $shop->id;
  439. $custom = CustomClass::build($ghsShopId, $hdShopId);
  440. $customId = $custom['id'] ?? 0;
  441. $custom = CustomClass::getById($customId, true);
  442. if (!empty($custom)) {
  443. $custom->name = $name;
  444. $py = stringUtil::py($name);
  445. $custom->py = $py;
  446. $custom->save();
  447. }
  448. util::complete($shop->merchantName . ' 添加成功');
  449. }
  450. util::fail($mobile . "手机号已经添加过了");
  451. }
  452. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  453. if (!empty($has)) {
  454. util::fail($mobile . "手机号已经申请添加过了");
  455. }
  456. $arr[] = ['name' => $name, 'mobile' => $mobile];
  457. }
  458. if (empty($arr)) {
  459. util::fail('请填写客户');
  460. }
  461. foreach ($arr as $item) {
  462. $name = $item['name'] ?? '';
  463. $mobile = $item['mobile'] ?? '';
  464. //队列方式去处理
  465. $customerCachedKey = 'batch_create_customer_list';
  466. $value = $name . '_' . $mobile . '_' . $this->sjId . '_' . $this->shop->id . '_' . $this->sj->name . '_' . $this->shopAdminId;
  467. Yii::$app->redis->executeCommand('LPUSH', [$customerCachedKey, $value]);
  468. Yii::info("供货商添加客户:name - " . $name . ' == mobile - ' . $mobile);
  469. Yii::info("shopAdminId: " . $this->shopAdminId);
  470. }
  471. util::complete('已提交,15秒后生效');
  472. }
  473. //从其它店同步客户 shizhongqi 2022.6.9
  474. public function actionCopyCustomers()
  475. {
  476. $get = Yii::$app->request->get();
  477. $fromShopId = $get['fromShopId'] ?? 0;
  478. $fromShop = ShopClass::getById($fromShopId, true);
  479. if (empty($fromShop)) {
  480. util::fail('门店不存在');
  481. }
  482. $toShopId = $this->shopId;
  483. if ($fromShopId == $toShopId) {
  484. util::fail('本店无需同步');
  485. }
  486. $fromShopName = $fromShop->shopName ?? '';
  487. if ($fromShop->syncCustom == 0) {
  488. util::fail('不允许从' . $fromShopName . '同步客户');
  489. }
  490. $toShop = $this->shop;
  491. $toShopName = $toShop->shopName ?? '';
  492. if ($toShop->syncCustom == 0) {
  493. util::fail($toShopName . '已关闭同步功能');
  494. }
  495. $toSjId = $toShop->sjId ?? 0;
  496. $fromSjId = $fromShop->sjId ?? 0;
  497. if ($toSjId != $fromSjId) {
  498. util::fail('不是您的门店');
  499. }
  500. $cachedKey = 'copy_other_shop_customers';
  501. Yii::$app->redis->executeCommand('LPUSH', [$cachedKey, $toShopId . '_' . $fromShopId]);
  502. Yii::info("从其他门店同步客户:目标门店id = " . $toShopId . ' 来源门店id = ' . $fromShopId);
  503. util::complete('已提交,1分钟后生效');
  504. }
  505. //客户列表 ssh 2021.7.8
  506. public function actionList()
  507. {
  508. $get = Yii::$app->request->get();
  509. $type = isset($get['type']) ? $get['type'] : 0;
  510. $name = isset($get['name']) ? $get['name'] : '';
  511. $mainId = $this->mainId;
  512. $isCashier = $get['isCashier'] ?? 0;
  513. if ($isCashier == 1) {
  514. //去掉收银台提示价格更新
  515. $staffId = $this->shopAdminId;
  516. Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  517. }
  518. $where = ['ownMainId' => $this->mainId];
  519. $sort = 'visitTime DESC';
  520. if ($type == 1) {
  521. //消费排行
  522. $sort = 'buyAmount DESC';
  523. } else if ($type == 2) {
  524. //欠款客户
  525. $where['isDebt'] = 1;
  526. $sort = '(debtAmount-balance) DESC';
  527. } else if ($type == 3) {
  528. $where['level'] = 0;
  529. }
  530. $name = trim($name);
  531. if (!empty($name)) {
  532. if (is_numeric($name) && strlen($name) > 4) {
  533. if (stringUtil::isMobile($name)) {
  534. $where['mobile'] = $name;
  535. } else {
  536. $where['mobile'] = ['like', $name];
  537. }
  538. } else if (stringUtil::isLetter($name)) {
  539. $where['py'] = ['like', $name];
  540. } else {
  541. $where['name'] = ['like', $name];
  542. }
  543. }
  544. $list = CustomService::getCustomSortList($where, $sort);
  545. $main = $this->main;
  546. $list['totalUser'] = $main->totalUser ?? 0;
  547. $list['mayGatheringNum'] = $main->mayGatheringNum ?? 0;
  548. util::success($list);
  549. }
  550. //今日访客 ssh 20211022
  551. public function actionGetVisit()
  552. {
  553. $ids = StatVisitClass::getVisitCustomIds($this->shop);
  554. if (empty($ids)) {
  555. util::success(['list' => []]);
  556. }
  557. $sort = 'visitTime DESC';
  558. $where = ['id' => ['in', $ids]];
  559. $respond = CustomService::getCustomSortList($where, $sort);
  560. util::success($respond);
  561. }
  562. //客户详情 ssh 2021.1.8
  563. public function actionDetail()
  564. {
  565. $get = Yii::$app->request->get();
  566. $customId = $get['id'] ?? 0;
  567. $info = CustomService::getCustomInfo($customId);
  568. CustomClass::valid($info, $this->shopId);
  569. $mainId = $info['mainId'] ?? 0;
  570. //超管的信息
  571. $superInfo = ShopAdminClass::getManager($mainId);
  572. $superName = $superInfo['name'] ?? '';
  573. $currentSuper = ['name' => $superName];
  574. $info['superInfo'] = $currentSuper;
  575. util::success($info);
  576. }
  577. //修改是否显示库存 ssh 20221022
  578. public function actionChangeShowStock()
  579. {
  580. $get = Yii::$app->request->get();
  581. $showStock = isset($get['showStock']) ? $get['showStock'] : 0;
  582. $customId = isset($get['customId']) ? $get['customId'] : 0;
  583. $custom = CustomClass::getById($customId, true);
  584. CustomClass::valid($custom, $this->shopId);
  585. $ghsId = $custom->ghsId ?? 0;
  586. $ghs = GhsClass::getById($ghsId, true);
  587. if (empty($ghs)) {
  588. util::fail('没有找到供货商');
  589. }
  590. $ghs->showStock = $showStock;
  591. $ghs->save();
  592. $custom->showStock = $showStock;
  593. $custom->save();
  594. util::complete();
  595. }
  596. //允许月结开关 ssh 2021.1.8
  597. public function actionDebt()
  598. {
  599. if (getenv('YII_ENV') == 'production') {
  600. if ($this->mainId == 4884) {
  601. if ($this->shopAdminId != 130738) {
  602. util::fail('只有倩姐才能修改');
  603. }
  604. }
  605. }
  606. $get = Yii::$app->request->get();
  607. $debt = isset($get['debt']) ? $get['debt'] : 0;
  608. $customId = isset($get['customId']) ? $get['customId'] : 0;
  609. $custom = CustomClass::getById($customId);
  610. CustomClass::valid($custom, $this->shopId);
  611. CustomClass::debt($custom, $debt);
  612. util::complete();
  613. }
  614. //采购查看权限的黑白名单开关 shizhongqi 2021.08.08
  615. public function actionSetBlack()
  616. {
  617. $black = Yii::$app->request->get('black', 2);
  618. $customId = Yii::$app->request->get('customId', 0);
  619. $custom = CustomClass::getById($customId, true);
  620. CustomClass::valid($custom, $this->shopId);
  621. $custom->black = $black;
  622. $custom->save();
  623. $ghsId = $custom->ghsId ?? 0;
  624. $ghs = GhsClass::getById($ghsId, true);
  625. if (empty($ghs)) {
  626. util::fail('出错了');
  627. }
  628. $ghs->black = $black;
  629. $ghs->save();
  630. util::complete();
  631. }
  632. //欠款客户 ssh 2021.2.4
  633. public function actionDebtList()
  634. {
  635. $get = Yii::$app->request->get();
  636. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  637. if (isset($get['name']) && !empty($get['name'])) {
  638. $where['name'] = ['like', $get['name']];
  639. }
  640. $list = CustomService::getDebtList($where);
  641. //共X个客户,合计欠款XXX元
  642. $main = $this->main;
  643. $list['customNum'] = $main->mayGatheringNum ?? 0;
  644. $list['debtAmount'] = $main->mayGathering ?? 0.00;
  645. util::success($list);
  646. }
  647. //修改欠款额度 ssh 20210625
  648. public function actionUpdateDebtLimit()
  649. {
  650. $shopAdmin = $this->shopAdmin;
  651. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  652. util::fail('管理员才能操作');
  653. }
  654. if (getenv('YII_ENV') == 'production') {
  655. if ($this->mainId == 4884) {
  656. if ($this->shopAdminId != 130738) {
  657. util::fail('只有倩姐才能修改');
  658. }
  659. }
  660. }
  661. $get = Yii::$app->request->get();
  662. $id = $get['id'] ?? 0;
  663. $debtLimit = $get['debtLimit'] ?? 0;
  664. if (is_numeric($debtLimit) == false || $debtLimit <= 0) {
  665. util::fail('请填写金额');
  666. }
  667. $custom = CustomClass::getById($id, true);
  668. CustomClass::valid($custom, $this->shopId);
  669. $custom->debtLimit = $debtLimit;
  670. $custom->save();
  671. util::complete();
  672. }
  673. //修改折扣 ssh 20210913
  674. public function actionChangeDiscount()
  675. {
  676. $shopAdmin = $this->shopAdmin;
  677. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  678. util::fail('管理员才能操作');
  679. }
  680. $get = Yii::$app->request->get();
  681. $id = $get['id'] ?? 0;
  682. $discount = $get['discount'] ?? 0;
  683. if (is_numeric($discount) == false || $discount > 1 || $discount == 0) {
  684. util::fail('请填写小数值');
  685. }
  686. $custom = CustomClass::getById($id, true);
  687. CustomClass::valid($custom, $this->shopId);
  688. $custom->discount = $discount;
  689. $custom->save();
  690. $ghsId = $custom->ghsId ?? 0;
  691. $ghs = GhsClass::getById($ghsId, true);
  692. $ghs->giveDiscount = $discount;
  693. $ghs->save();
  694. util::complete();
  695. }
  696. //修改客户等级 ssh 20211007
  697. public function actionChangeLevel()
  698. {
  699. $shopAdmin = $this->shopAdmin;
  700. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  701. util::fail('超管才能修改');
  702. }
  703. //泉城的只有苏小娟才能修改
  704. if (getenv('YII_ENV') == 'production') {
  705. if ($this->mainId == 60) {
  706. if (in_array($this->adminId, [2499, 4]) == false) {
  707. util::fail('请小娟修改');
  708. }
  709. }
  710. }
  711. $get = Yii::$app->request->get();
  712. $customId = $get['customId'] ?? 0;
  713. $level = $get['level'] ?? 1;
  714. $custom = CustomClass::getById($customId, true);
  715. CustomClass::valid($custom, $this->shopId);
  716. $custom->level = $level;
  717. $custom->save();
  718. $ghsId = $custom->ghsId ?? 0;
  719. $ghs = GhsClass::getById($ghsId, true);
  720. if (empty($ghs)) {
  721. util::fail('出错了');
  722. }
  723. $ghs->giveLevel = $level;
  724. $ghs->save();
  725. $map = CustomClass::$levelMap;
  726. $name = $map[$level] ?? '';
  727. util::success(['levelName' => $name]);
  728. }
  729. }