CustomController.php 28 KB

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