CustomController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\admin\services\AdminService;
  4. use bizHd\custom\classes\CustomClass;
  5. use bizHd\custom\classes\HdClass;
  6. use bizHd\custom\services\CustomService;
  7. use biz\sj\services\MerchantAssetService;
  8. use biz\sj\services\MerchantRemarkService;
  9. use bizHd\order\classes\OrderClass;
  10. use bizHd\stat\classes\StatVisitClass;
  11. use bizHd\user\services\UserAssetService;
  12. use bizHd\user\services\UserGrowthService;
  13. use bizHd\user\services\UserService;
  14. use bizHd\user\services\UserUpgradeService;
  15. use common\components\wxUtil;
  16. use common\services\xhMerchantExtendService;
  17. use common\services\xhRechargeService;
  18. use common\services\xhTMessageService;
  19. use Yii;
  20. use common\components\stringUtil;
  21. use common\components\util;
  22. use biz\sj\services\MerchantExtendService;
  23. use bizHd\message\services\SmsService;
  24. use bizHd\user\classes\UserClass;
  25. use yii\helpers\Json;
  26. class CustomController extends BaseController
  27. {
  28. public $guestAccess = ['list'];
  29. //修改生日 ssh 20250814
  30. public function actionModifyBirthday()
  31. {
  32. $get = Yii::$app->request->get();
  33. $customId = $get['customId'];
  34. CustomClass::modifyBirthday($customId, $this->shopId, $get);
  35. util::complete('修改成功');
  36. }
  37. public function actionChangeLevel()
  38. {
  39. $get = Yii::$app->request->get();
  40. $customId = $get['customId'];
  41. $level = $get['level'] ?? 0;
  42. if ($level < 0) {
  43. util::fail('等级选择错误');
  44. }
  45. $custom = CustomClass::getById($customId, true);
  46. if (empty($custom)) {
  47. util::fail('没有找到客户');
  48. }
  49. $shopId = $this->shopId;
  50. if ($custom->shopId != $shopId) {
  51. util::fail('不是你的客户');
  52. }
  53. $hdId = $custom->hdId;
  54. $hd = HdClass::getById($hdId, true);
  55. if (empty($hd)) {
  56. util::fail('客户信息缺失,编号3445');
  57. }
  58. $staff = $this->shopAdmin;
  59. $staffId = $staff->id;
  60. $staffName = $staff->name;
  61. $params = [
  62. 'style' => 1,//手动修改
  63. 'staffId' => $staffId,
  64. 'adminId' => $this->adminId,
  65. 'staffName' => $staffName,
  66. ];
  67. $shop = $this->shop;
  68. $connection = Yii::$app->db;
  69. $transaction = $connection->beginTransaction();
  70. try {
  71. $beforeLevel = $custom->member ?? 0;
  72. CustomClass::levelChange($beforeLevel, $level, $shop, $custom, $hd, $params);
  73. $transaction->commit();
  74. util::complete('修改成功');
  75. } catch (\Exception $exception) {
  76. $transaction->rollBack();
  77. Yii::info("修改失败:" . $exception->getMessage());
  78. util::fail('修改失败');
  79. }
  80. }
  81. //修改客户地址 ssh 20231109
  82. public function actionModifyAddress()
  83. {
  84. $post = Yii::$app->request->post();
  85. $id = $post['id'] ?? 0;
  86. unset($post['id']);
  87. $custom = CustomClass::getById($id, true);
  88. if (empty($custom)) {
  89. util::fail('没有找到客户信息');
  90. }
  91. $userId = $custom->userId ?? 0;
  92. $city = $post['city'] ?? '';
  93. $dist = $post['dist'] ?? '';
  94. $address = $post['address'] ?? '';
  95. $floor = $post['floor'] ?? '';
  96. $post['fullAddress'] = $city . $dist . $address . $floor;
  97. UserClass::updateByCondition(['id' => $userId], $post);
  98. CustomClass::updateByCondition(['id' => $id], $post);
  99. util::complete('修改成功');
  100. }
  101. //会员权限开关
  102. public function actionChangeVip()
  103. {
  104. $post = Yii::$app->request->post();
  105. $vip = $post['vip'];
  106. $id = $post['customId'];
  107. unset($post['id']);
  108. $custom = CustomClass::getById($id, true, 'id, shopId, vip');
  109. if (empty($custom)) {
  110. util::fail('没有找到客户信息');
  111. }
  112. if ($custom->shopId != $this->shopId) {
  113. util::fial('你不能操作');
  114. }
  115. if (!isset($this->shopAdmin->founder) || $this->shopAdmin->founder != 2) {
  116. util::fail('超管才能操作哦');
  117. }
  118. $custom->vip = $vip;
  119. $custom->save();
  120. $hint = $vip == 1 ? '已开启' : '已关闭';
  121. util::complete($hint);
  122. }
  123. //修改名称 ssh 2022096
  124. public function actionChangeName()
  125. {
  126. $get = Yii::$app->request->get();
  127. $name = $get['name'] ?? '';
  128. $id = $get['id'] ?? 0;
  129. if (empty($name)) {
  130. util::fail('请填写名称');
  131. }
  132. $py = stringUtil::py($name);
  133. $custom = CustomClass::getById($id, true);
  134. CustomClass::valid($custom, $this->shopId);
  135. $custom->name = $name;
  136. $custom->py = $py;
  137. $custom->save();
  138. OrderClass::updateByCondition(['customId' => $id], ['customName' => $name, 'customNamePy' => $py]);
  139. util::complete();
  140. }
  141. //批量添加客户 ssh 20220919
  142. public function actionBatchAddCustom()
  143. {
  144. $post = Yii::$app->request->post();
  145. $connection = Yii::$app->db;
  146. $transaction = $connection->beginTransaction();
  147. try {
  148. for ($i = 1; $i <= 5; $i++) {
  149. $name = $post['name' . $i] ?? '';
  150. $mobile = $post['mobile' . $i] ?? '';
  151. $confirmMobile = $post['confirmMobile' . $i] ?? '';
  152. if (empty($name) && empty($mobile) && empty($confirmMobile)) {
  153. continue;
  154. }
  155. if (empty($name)) {
  156. util::fail('客户名称不能为空');
  157. }
  158. if (stringUtil::getWordNum($name) > 15) {
  159. util::fail('名称不能超过15个汉字');
  160. }
  161. if (empty($mobile)) {
  162. util::fail($name . " 手机号不能为空");
  163. }
  164. if (stringUtil::isMobile($mobile) == false) {
  165. util::fail($name . " 手机号格式不正确");
  166. }
  167. if ($mobile != $confirmMobile) {
  168. util::fail($name . " 二次手机号不一致");
  169. }
  170. $user = \bizMall\user\classes\UserClass::replaceUser(['name' => $name, 'mobile' => $mobile]);
  171. if (isset($this->shop) && !empty($this->shop)) {
  172. //花店增加客户,散客增加门店
  173. CustomClass::buildRelation($this->shop, $user);
  174. }
  175. }
  176. $transaction->commit();
  177. util::complete();
  178. } catch (\Exception $e) {
  179. $transaction->rollBack();
  180. util::fail('添加失败');
  181. }
  182. }
  183. //客户列表 ssh 2019.11.30
  184. public function actionList()
  185. {
  186. $get = Yii::$app->request->get();
  187. $type = $get['type'] ?? 0;
  188. $searchStyle = $get['searchStyle'] ?? 0;
  189. $where = ['shopId' => $this->shopId];
  190. $all = CustomClass::getCount($where);
  191. if ($type == 1) {
  192. //消费排行
  193. $sort = 'buyAmount DESC';
  194. } else if ($type == 2) {
  195. //余额客户
  196. $sort = 'balance DESC';
  197. } else if ($type == 3) {
  198. //生日
  199. $sort = 'birthdayTime ASC';
  200. $where['birthdayTime>'] = 0;
  201. } else if ($type == 4) {
  202. //已经删除的客户
  203. $sort = 'id ASC';
  204. $where['delStatus'] = 1;
  205. } else if ($type == 5) {
  206. //只显示VIP用户
  207. $sort = 'id ASC';
  208. $where['vip'] = 1;
  209. } else {
  210. $sort = 'visitTime DESC';
  211. }
  212. $name = $get['name'] ?? '';
  213. if (empty($name)) {
  214. $name = $get['keyword'] ?? '';
  215. }
  216. if (empty($name)) {
  217. $name = $get['searchText'] ?? '';
  218. }
  219. if (!empty($name)) {
  220. if ($searchStyle == 0) {
  221. $where['mobile'] = ['like', $name];
  222. } else {
  223. if (stringUtil::isLetter($name)) {
  224. $where['py'] = ['like', $name];
  225. } else {
  226. $where['name'] = ['like', $name];
  227. }
  228. }
  229. }
  230. $list = CustomService::getCustomList($where, $sort);
  231. $list['all'] = $all; //全部的总人数
  232. $list['balance'] = $all; //余额排行的总人数
  233. $list['buyAmount'] = $all; //消费排行的总人数
  234. $list['birth'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['birthdayTime>' => 0])); //有设置生日的总人数
  235. $list['deleted'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['delStatus' => 1])); //被删除的总人数
  236. $list['vip'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['vip' => 1])); //是vip的总人数
  237. util::success($list);
  238. }
  239. //获取客户信息 ssh 20250510
  240. public function actionInfo()
  241. {
  242. $get = Yii::$app->request->get();
  243. $id = $get['id'] ?? 0;
  244. $custom = CustomClass::getById($id, true);
  245. if (empty($custom)) {
  246. util::fail('没有找到客户信息');
  247. }
  248. if ($custom->shopId != $this->shopId) {
  249. util::fail('不是你的客户');
  250. }
  251. util::success(['custom' => $custom]);
  252. }
  253. //获取客户基本和资产信息 ssh 2019.11.30
  254. public function actionDetail()
  255. {
  256. $userId = Yii::$app->request->get('userId');
  257. $info = CustomClass::getCustomInfo($userId);
  258. CustomClass::valid($info, $this->shopId);
  259. util::success($info);
  260. }
  261. //获取客户详情,包括基本信息、资产、订单和备注 2019.11.30
  262. public function actionUserDetail()
  263. {
  264. $userId = Yii::$app->request->get('userId');
  265. $info = UserService::getFullUserInfo($userId);
  266. UserService::valid($info, $this->sjId);
  267. $list = MerchantRemarkService::getRemarkList($userId);
  268. $info['remarkList'] = $list;
  269. util::success($info);
  270. }
  271. //添加客户,申请会员时会自动同步资产 ssh 2019.11.30
  272. public function actionAdd()
  273. {
  274. $post = Yii::$app->request->post();
  275. if (isset($post['mobile']) == false || stringUtil::isMobile($post['mobile']) == false) {
  276. util::fail('请输入手机号');
  277. }
  278. if ($post['mobile'] != $post['confirmMobile']) {
  279. util::fail('二次输入手机号不一样');
  280. }
  281. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : '';
  282. AdminService::verifyPayPassword($this->adminId, $payPassword);
  283. $mobile = $post['mobile'];
  284. $user = UserService::getByMobile($mobile, $this->sjId);
  285. if (!empty($user)) {
  286. util::fail('手机号已使用');
  287. }
  288. $post['sjId'] = $this->sjId;
  289. $post['member'] = $post['memberLevel'];
  290. UserService::addUser($post);
  291. util::complete();
  292. }
  293. //充值 ssh 2019.12.1
  294. public function actionRecharge()
  295. {
  296. $post = Yii::$app->request->post();
  297. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : '';
  298. AdminService::verifyPayPassword($this->adminId, $payPassword);
  299. $userId = isset($post['userId']) ? $post['userId'] : 0;
  300. $rechargeAmount = isset($post['rechargeAmount']) ? $post['rechargeAmount'] : 1;
  301. $user = UserService::getById($userId);
  302. if (empty($user)) {
  303. util::fail('找不到客户');
  304. }
  305. if ($user['sjId'] != $this->sjId) {
  306. util::fail('您无法操作');
  307. }
  308. $userAsset = UserAssetService::getByUserId($userId);
  309. $totalBalance = $userAsset['balance'] + $rechargeAmount;
  310. $totalRecharge = $userAsset['totalRecharge'] + $rechargeAmount;
  311. $upData['balance'] = $totalBalance;
  312. $upData['totalRecharge'] = $totalRecharge;
  313. $merchantAsset = MerchantAssetService::getBySjId($this->sjId);
  314. $return = xhRechargeService::recharge($rechargeAmount, $user, $this->adminId, $this->sj->attributes, $this->sjExtend->attributes, $merchantAsset);
  315. if ($return['code'] == 'A0001') {
  316. util::complete();
  317. }
  318. util::fail();
  319. }
  320. //升级 ssh 2019.12.1
  321. public function actionUpgrade()
  322. {
  323. $post = Yii::$app->request->post();
  324. $userId = isset($post['userId']) ? $post['userId'] : 0;
  325. $member = isset($post['member']) ? $post['member'] : 0;
  326. $user = UserService::getById($userId);
  327. if (empty($user)) {
  328. util::fail('客户不存在');
  329. }
  330. //验证是否商家客户
  331. UserService::valid($user, $this->sjId);
  332. //验证确认密码
  333. $payPassword = $post['payPassword'];
  334. AdminService::verifyPayPassword($this->adminId, $payPassword);
  335. $grade = xhMerchantExtendService::getGradeList($this->sjExtend->attributes, 'desc');
  336. //升级后的成长值
  337. $newLevelGrowth = $grade[$member]['growth'];
  338. $newDiscount = $grade[$member]['discount'];
  339. $userAsset = UserAssetService::getByUserId($userId);
  340. if ($userAsset['member'] >= $member) {
  341. util::fail('客户已经达到此级别了');
  342. }
  343. $now = time();
  344. $date = date("Y-m-d H:i", $now);
  345. $connection = Yii::$app->db;
  346. $transaction = $connection->beginTransaction();
  347. try {
  348. $addGrowth = $newLevelGrowth - $userAsset['growth'];
  349. $upData['growth'] = $newLevelGrowth;
  350. $upData['member'] = $member;
  351. $upData['discount'] = $newDiscount;
  352. UserAssetService::updateByUserId($userId, $upData);
  353. UserService::updateById($userId, ['member' => $member]);
  354. $upgradeData = [
  355. 'member' => $member,
  356. 'prevMember' => $userAsset['member'],
  357. 'sjId' => $this->sjId,
  358. 'gainType' => 0,
  359. 'addTime' => $now,
  360. 'userId' => $userId,
  361. ];
  362. $upgradeRespond = UserUpgradeService::add($upgradeData);
  363. $growthData = [
  364. 'userId' => $userId,
  365. 'userName' => $user['userName'],
  366. 'sjId' => $this->sjId,
  367. 'relateId' => $upgradeRespond['id'],
  368. 'growth' => $newLevelGrowth,
  369. 'num' => $addGrowth,
  370. 'io' => 1,
  371. 'payWay' => 4,
  372. 'alipayId' => '',
  373. 'event' => '管理员操作升到' . $member . '级增加成长值',
  374. 'operatorId' => $userId,
  375. 'createTime' => $date,
  376. 'gainType' => 0,
  377. 'addTime' => $now,
  378. ];
  379. UserGrowthService::add($growthData);
  380. $transaction->commit();
  381. } catch (\Exception $e) {
  382. $transaction->rollBack();
  383. util::fail();
  384. }
  385. $allTM = xhTMessageService::getList($this->sjId);
  386. $openId = isset($user['openId']) ? $user['openId'] : '';
  387. if (empty($openId)) {
  388. util::complete();
  389. }
  390. $shortTempId = 'OPENTM205211943';//升级通知
  391. if (isset($allTM[$shortTempId]) == false) {
  392. util::complete();
  393. }
  394. $tempId = $allTM[$shortTempId];
  395. $data = [
  396. "touser" => $openId, "template_id" => $tempId, "url" => '',
  397. "data" => [
  398. "first" => ["value" => "恭喜,您已经升为{$member}级会员。", "color" => "#173177"],
  399. "keyword1" => ["value" => $user['userName'], "color" => "#173177"],
  400. "keyword2" => ["value" => $date, "color" => "#173177"],
  401. "remark" => ["value" => "点击查看会员权益", "color" => "#173177"],
  402. ]];
  403. wxUtil::sendTaskInform($data, $this->sj);
  404. util::complete();
  405. }
  406. //重置客户密码
  407. public function actionResetPayPassword()
  408. {
  409. $post = Yii::$app->request->post();
  410. $userId = isset($post['userId']) ? $post['userId'] : 0;
  411. $password = isset($post['password']) ? $post['password'] : 0;
  412. $info = UserService::getById($userId);
  413. UserService::valid($info, $this->sjId);
  414. UserService::updateById($userId, ['payPassword' => password_hash($password, PASSWORD_BCRYPT)]);
  415. util::complete();
  416. }
  417. //获取登陆客户的资产 ssh 2019.11.22
  418. public function actionAsset()
  419. {
  420. $asset = UserAssetService::getByUserId($this->adminId);
  421. util::success($asset);
  422. }
  423. //获取登陆客户的优惠情况 ssh 2019.12.3
  424. public function actionDiscount()
  425. {
  426. $discount = UserAssetService::getDiscount($this->adminId);
  427. util::success($discount);
  428. }
  429. //小程序用户完整信息 ssh 2019.12.12
  430. public function actionMiniFullInfo()
  431. {
  432. $post = Yii::$app->request->post();
  433. $iv = isset($post['iv']) ? $post['iv'] : '';
  434. $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
  435. $appId = $this->sj['miniAppId'];
  436. $sjId = $this->sjId;
  437. $miniOpenId = $this->user['miniOpenId'];
  438. if (empty($miniOpenId)) {
  439. util::fail('mini_open_id empty');
  440. }
  441. $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
  442. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  443. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  444. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  445. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  446. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  447. if ($errCode != 0) {
  448. Yii::info($result . ' ' . $errCode);
  449. util::fail('获取用户信息失败');
  450. }
  451. Yii::info('小程序获取用户信息:' . $result);
  452. $originalInfo = Json::decode($result);
  453. $source = UserClass::$userSourceId['mini']['name'];
  454. $user = UserService::replaceUser($originalInfo, $source, $sjId);
  455. $userId = $user['id'];
  456. $userInfo = UserService::getUserInfo($userId);
  457. util::success($userInfo);
  458. }
  459. //小程序用户手机号
  460. public function actionMiniMobile()
  461. {
  462. $post = Yii::$app->request->post();
  463. $iv = $post['iv'];
  464. $encryptedData = $post['encryptedData'];
  465. $sjId = $this->sjId;
  466. $merchant = $this->sj->attributes;
  467. $appId = $merchant['miniAppId'];
  468. $miniOpenId = $this->user['miniOpenId'];
  469. $user = $this->user;
  470. if (!empty($user) && !empty($user['mobile'])) {
  471. $userId = $user['id'];
  472. util::success(['mobile' => $user['mobile']]);
  473. }
  474. $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
  475. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  476. if (empty($sessionKey)) {
  477. util::fail('系统错误,sesstion empty');
  478. }
  479. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  480. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  481. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  482. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  483. if ($errCode != 0) {
  484. util::fail('解密失败');
  485. }
  486. $arr = Json::decode($result);
  487. $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  488. if (empty($mobile)) {
  489. util::fail('没有获取手机号,请重试');
  490. }
  491. $userId = $user['id'];
  492. UserService::becomeMember($user, $merchant, ['mobile' => $mobile]);
  493. util::success(['mobile' => $mobile]);
  494. }
  495. //密码修改
  496. public function actionPassword()
  497. {
  498. $post = Yii::$app->request->post();
  499. $old = isset($post['old']) ? $post['old'] : '';
  500. $new = isset($post['new']) ? $post['new'] : '';
  501. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  502. if (empty($new)) {
  503. util::fail('请输入新密码');
  504. }
  505. if ($new != $confirm) {
  506. util::fail('二次密码不一致');
  507. }
  508. $userId = $this->adminId;
  509. $user = UserService::getUserInfo($userId);
  510. if (isset($user['hasPayPwd']) && $user['hasPayPwd'] == 1) {
  511. if (empty($old)) {
  512. util::fail('请填写旧密码');
  513. }
  514. if (password_verify($old, $user['payPassword']) == false) {
  515. util::fail('旧密码错误');
  516. }
  517. }
  518. UserService::updateById($userId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT), 'hasPayPwd' => 1]);
  519. util::complete('修改成功');
  520. }
  521. //申请会员 ssh 2019.12.18
  522. public function actionApplyMember()
  523. {
  524. $post = Yii::$app->request->post();
  525. $mobile = isset($post['mobile']) ? $post['mobile'] : 0;
  526. if (stringUtil::isMobile($mobile) == false) {
  527. util::fail('请输入手机号');
  528. }
  529. $userId = $this->adminId;
  530. $asset = UserAssetService::getByUserId($userId);
  531. if (isset($asset['member']) && $asset['member'] != -1) {
  532. util::fail('已经是会员了');
  533. }
  534. $code = isset($post['code']) ? $post['code'] : '';
  535. $cacheCode = SmsService::getApplyMemberCode($userId, $mobile);
  536. if (empty($cacheCode) || $cacheCode != $code) {
  537. util::fail('验证码错误');
  538. }
  539. $update = [];
  540. if (isset($post['realName']) && !empty($post['realName'])) {
  541. $update['realName'] = $post['realName'];
  542. }
  543. if (isset($post['birthday']) && !empty($post['birthday'])) {
  544. $update['birthday'] = $post['birthday'];
  545. }
  546. $user = UserService::getByCondition(['sjId' => $this->sjId, 'mobile' => $mobile]);
  547. if ($userId == $user['id']) {
  548. util::fail('手机号已验证');
  549. }
  550. if (!empty($user)) {
  551. util::fail('手机号已经注册过了');
  552. }
  553. $update['mobile'] = $mobile;
  554. UserService::becomeMember($this->user, $this->sj->attributes, $update);
  555. util::complete('注册成功');
  556. }
  557. //用户基本信息和资产 ssh 2019.12.19
  558. public function actionMyProfile()
  559. {
  560. $custom = $this->custom;
  561. $user = UserService::getUserInfo($this->adminId);
  562. $growth = $custom['growth'] ?? 0;
  563. $extend = $this->sjExtend->attributes;
  564. $grade = MerchantExtendService::getGradeList($extend, 'asc');
  565. //下个等级的积分
  566. $nextLevelGrowth = 0;
  567. foreach ($grade as $val) {
  568. $currentGrowth = $val['growth'];
  569. if ($currentGrowth > $growth) {
  570. $nextLevelGrowth = $currentGrowth;
  571. break;
  572. }
  573. }
  574. $user['userAsset']['nextLevelGrowth'] = $nextLevelGrowth;
  575. util::success($user);
  576. }
  577. //登陆客户的信息 ssh 2020.3.12
  578. public function actionLoginDetail()
  579. {
  580. $user = $this->user;
  581. util::success($user);
  582. }
  583. //总挂账和总余额汇总 ssh 20250620
  584. public function actionShowTotalBalance()
  585. {
  586. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  587. if ($lookMoney == 0) {
  588. util::fail('无法查看哦');
  589. }
  590. $lsShop = $this->shop;
  591. $pfShopId = $lsShop->pfShopId;
  592. $lsShopId = $this->shopId;
  593. $respond = \bizGhs\custom\classes\CustomClass::showTotalBalance($pfShopId, $lsShopId);
  594. $respond['pfShopId'] = $pfShopId;
  595. $respond['lsShopId'] = $lsShopId;
  596. util::success($respond);
  597. }
  598. //今日访客
  599. public function actionGetVisit()
  600. {
  601. $userIds = StatVisitClass::getVisitCustomIds($this->shopId);
  602. if (empty($userIds)) {
  603. util::success(['list' => []]);
  604. }
  605. $sort = 'visitTime DESC';
  606. $where = [
  607. 'shopId' => $this->shopId,
  608. 'userId' => ['in', $userIds]
  609. ];
  610. $list = CustomService::getCustomList($where, $sort);
  611. util::success($list);
  612. }
  613. //删除客户 ssh 20250923
  614. public function actionDelCustom()
  615. {
  616. $get = Yii::$app->request->get();
  617. $id = $get['id'] ?? 0;
  618. $custom = CustomClass::getById($id, true);
  619. if (empty($custom)) {
  620. util::fail('没有找到客户');
  621. }
  622. if ($custom->shopId != $this->shopId) {
  623. util::fail('不是你的客户');
  624. }
  625. $hdId = $custom->hdId ?? 0;
  626. $hd = HdClass::getById($hdId, true);
  627. if (empty($hd)) {
  628. util::fail('客户信息缺失');
  629. }
  630. $custom->delStatus = 1;
  631. $custom->save();
  632. $hd->delStatus = 1;
  633. $hd->save();
  634. util::complete('删除成功');
  635. }
  636. //重新统计客户的消费总额
  637. public function actionUpdateBuyAmount()
  638. {
  639. $post = Yii::$app->request->post();
  640. $customId = $post['customId'];
  641. $c = CustomClass::getLockById($customId);
  642. // 1.重新统计客户的消费总额
  643. $orderList = OrderClass::getAllByCondition(['customId' => $customId], null, 'id, forward, actPrice');
  644. $buyAmount = 0;
  645. if (!empty($orderList)) {
  646. foreach ($orderList as $order) {
  647. if ($order['forward'] == 0) { //0 常规订单
  648. $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
  649. } elseif ($order['forward'] == 1) { //1 售后付款单(红冲)
  650. $buyAmount = bcsub($buyAmount, $order['actPrice'], 2);
  651. } else {
  652. Yii::info('订单类型不存在');
  653. continue;
  654. }
  655. }
  656. }
  657. $c->buyAmount = $buyAmount;
  658. $c->listend = false;
  659. $c->save();
  660. // 2.更新此客户所对应花店的消费金额 expendAmount ---- xhHd -> expendAmount
  661. HdClass::updateById($c->hdId, ['expendAmount' => $buyAmount]);
  662. util::success(['customId' => $customId, 'buyAmount' => $buyAmount]);
  663. }
  664. }