CustomController.php 26 KB

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