CustomController.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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. $searchStyle = $get['searchStyle'] ?? 0;
  193. $where = ['shopId' => $this->shopId];
  194. $all = CustomClass::getCount($where);
  195. if ($type == 1) {
  196. //消费排行
  197. $sort = 'buyAmount DESC';
  198. } else if ($type == 2) {
  199. //余额客户
  200. $sort = 'balance DESC';
  201. } else if ($type == 3) {
  202. //生日
  203. $sort = 'birthdayTime ASC';
  204. $where['birthdayTime>'] = 0;
  205. } else if ($type == 4) {
  206. //已经删除的客户
  207. $sort = 'id ASC';
  208. $where['delStatus'] = 1;
  209. } else if ($type == 5) {
  210. //只显示VIP用户
  211. $sort = 'id ASC';
  212. $where['vip'] = 1;
  213. } else {
  214. $sort = 'visitTime DESC';
  215. }
  216. $name = $get['name'] ?? '';
  217. if (empty($name)) {
  218. $name = $get['keyword'] ?? '';
  219. }
  220. if (empty($name)) {
  221. $name = $get['searchText'] ?? '';
  222. }
  223. if (!empty($name)) {
  224. if ($searchStyle == 0) {
  225. $where['mobile'] = ['like', $name];
  226. } else {
  227. if (stringUtil::isLetter($name)) {
  228. $where['py'] = ['like', $name];
  229. } else {
  230. $where['name'] = ['like', $name];
  231. }
  232. }
  233. }
  234. $list = CustomService::getCustomList($where, $sort);
  235. $list['all'] = $all; //全部的总人数
  236. $list['balance'] = $all; //余额排行的总人数
  237. $list['buyAmount'] = $all; //消费排行的总人数
  238. $list['birth'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['birthdayTime>' => 0])); //有设置生日的总人数
  239. $list['deleted'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['delStatus' => 1])); //被删除的总人数
  240. $list['vip'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['vip' => 1])); //是vip的总人数
  241. util::success($list);
  242. }
  243. //获取客户信息 ssh 20250510
  244. public function actionInfo()
  245. {
  246. $get = Yii::$app->request->get();
  247. $id = $get['id'] ?? 0;
  248. $custom = CustomClass::getById($id, true);
  249. if (empty($custom)) {
  250. util::fail('没有找到客户信息');
  251. }
  252. if ($custom->shopId != $this->shopId) {
  253. util::fail('不是你的客户');
  254. }
  255. util::success(['custom' => $custom]);
  256. }
  257. //获取客户基本和资产信息 ssh 2019.11.30
  258. public function actionDetail()
  259. {
  260. $userId = Yii::$app->request->get('userId');
  261. $info = CustomClass::getCustomInfo($userId);
  262. CustomClass::valid($info, $this->shopId);
  263. util::success($info);
  264. }
  265. //获取客户详情,包括基本信息、资产、订单和备注 2019.11.30
  266. public function actionUserDetail()
  267. {
  268. $userId = Yii::$app->request->get('userId');
  269. $info = UserService::getFullUserInfo($userId);
  270. UserService::valid($info, $this->sjId);
  271. $list = MerchantRemarkService::getRemarkList($userId);
  272. $info['remarkList'] = $list;
  273. util::success($info);
  274. }
  275. //添加客户,申请会员时会自动同步资产 ssh 2019.11.30
  276. public function actionAdd()
  277. {
  278. $post = Yii::$app->request->post();
  279. if (isset($post['mobile']) == false || stringUtil::isMobile($post['mobile']) == false) {
  280. util::fail('请输入手机号');
  281. }
  282. if ($post['mobile'] != $post['confirmMobile']) {
  283. util::fail('二次输入手机号不一样');
  284. }
  285. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : '';
  286. AdminService::verifyPayPassword($this->adminId, $payPassword);
  287. $mobile = $post['mobile'];
  288. $user = UserService::getByMobile($mobile, $this->sjId);
  289. if (!empty($user)) {
  290. util::fail('手机号已使用');
  291. }
  292. $post['sjId'] = $this->sjId;
  293. $post['member'] = $post['memberLevel'];
  294. UserService::addUser($post);
  295. util::complete();
  296. }
  297. //充值 ssh 2019.12.1
  298. public function actionRecharge()
  299. {
  300. $post = Yii::$app->request->post();
  301. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : '';
  302. AdminService::verifyPayPassword($this->adminId, $payPassword);
  303. $userId = isset($post['userId']) ? $post['userId'] : 0;
  304. $rechargeAmount = isset($post['rechargeAmount']) ? $post['rechargeAmount'] : 1;
  305. $user = UserService::getById($userId);
  306. if (empty($user)) {
  307. util::fail('找不到客户');
  308. }
  309. if ($user['sjId'] != $this->sjId) {
  310. util::fail('您无法操作');
  311. }
  312. $userAsset = UserAssetService::getByUserId($userId);
  313. $totalBalance = $userAsset['balance'] + $rechargeAmount;
  314. $totalRecharge = $userAsset['totalRecharge'] + $rechargeAmount;
  315. $upData['balance'] = $totalBalance;
  316. $upData['totalRecharge'] = $totalRecharge;
  317. $merchantAsset = MerchantAssetService::getBySjId($this->sjId);
  318. $return = xhRechargeService::recharge($rechargeAmount, $user, $this->adminId, $this->sj->attributes, $this->sjExtend->attributes, $merchantAsset);
  319. if ($return['code'] == 'A0001') {
  320. util::complete();
  321. }
  322. util::fail();
  323. }
  324. //升级 ssh 2019.12.1
  325. public function actionUpgrade()
  326. {
  327. $post = Yii::$app->request->post();
  328. $userId = isset($post['userId']) ? $post['userId'] : 0;
  329. $member = isset($post['member']) ? $post['member'] : 0;
  330. $user = UserService::getById($userId);
  331. if (empty($user)) {
  332. util::fail('客户不存在');
  333. }
  334. //验证是否商家客户
  335. UserService::valid($user, $this->sjId);
  336. //验证确认密码
  337. $payPassword = $post['payPassword'];
  338. AdminService::verifyPayPassword($this->adminId, $payPassword);
  339. $grade = xhMerchantExtendService::getGradeList($this->sjExtend->attributes, 'desc');
  340. //升级后的成长值
  341. $newLevelGrowth = $grade[$member]['growth'];
  342. $newDiscount = $grade[$member]['discount'];
  343. $userAsset = UserAssetService::getByUserId($userId);
  344. if ($userAsset['member'] >= $member) {
  345. util::fail('客户已经达到此级别了');
  346. }
  347. $now = time();
  348. $date = date("Y-m-d H:i", $now);
  349. $connection = Yii::$app->db;
  350. $transaction = $connection->beginTransaction();
  351. try {
  352. $addGrowth = $newLevelGrowth - $userAsset['growth'];
  353. $upData['growth'] = $newLevelGrowth;
  354. $upData['member'] = $member;
  355. $upData['discount'] = $newDiscount;
  356. UserAssetService::updateByUserId($userId, $upData);
  357. UserService::updateById($userId, ['member' => $member]);
  358. $upgradeData = [
  359. 'member' => $member,
  360. 'prevMember' => $userAsset['member'],
  361. 'sjId' => $this->sjId,
  362. 'gainType' => 0,
  363. 'addTime' => $now,
  364. 'userId' => $userId,
  365. ];
  366. $upgradeRespond = UserUpgradeService::add($upgradeData);
  367. $growthData = [
  368. 'userId' => $userId,
  369. 'userName' => $user['userName'],
  370. 'sjId' => $this->sjId,
  371. 'relateId' => $upgradeRespond['id'],
  372. 'growth' => $newLevelGrowth,
  373. 'num' => $addGrowth,
  374. 'io' => 1,
  375. 'payWay' => 4,
  376. 'alipayId' => '',
  377. 'event' => '管理员操作升到' . $member . '级增加成长值',
  378. 'operatorId' => $userId,
  379. 'createTime' => $date,
  380. 'gainType' => 0,
  381. 'addTime' => $now,
  382. ];
  383. UserGrowthService::add($growthData);
  384. $transaction->commit();
  385. } catch (\Exception $e) {
  386. $transaction->rollBack();
  387. util::fail();
  388. }
  389. $allTM = xhTMessageService::getList($this->sjId);
  390. $openId = isset($user['openId']) ? $user['openId'] : '';
  391. if (empty($openId)) {
  392. util::complete();
  393. }
  394. $shortTempId = 'OPENTM205211943';//升级通知
  395. if (isset($allTM[$shortTempId]) == false) {
  396. util::complete();
  397. }
  398. $tempId = $allTM[$shortTempId];
  399. $data = [
  400. "touser" => $openId, "template_id" => $tempId, "url" => '',
  401. "data" => [
  402. "first" => ["value" => "恭喜,您已经升为{$member}级会员。", "color" => "#173177"],
  403. "keyword1" => ["value" => $user['userName'], "color" => "#173177"],
  404. "keyword2" => ["value" => $date, "color" => "#173177"],
  405. "remark" => ["value" => "点击查看会员权益", "color" => "#173177"],
  406. ]];
  407. wxUtil::sendTaskInform($data, $this->sj);
  408. util::complete();
  409. }
  410. //重置客户密码
  411. public function actionResetPayPassword()
  412. {
  413. $post = Yii::$app->request->post();
  414. $userId = isset($post['userId']) ? $post['userId'] : 0;
  415. $password = isset($post['password']) ? $post['password'] : 0;
  416. $info = UserService::getById($userId);
  417. UserService::valid($info, $this->sjId);
  418. UserService::updateById($userId, ['payPassword' => password_hash($password, PASSWORD_BCRYPT)]);
  419. util::complete();
  420. }
  421. //获取登陆客户的资产 ssh 2019.11.22
  422. public function actionAsset()
  423. {
  424. $asset = UserAssetService::getByUserId($this->adminId);
  425. util::success($asset);
  426. }
  427. //获取登陆客户的优惠情况 ssh 2019.12.3
  428. public function actionDiscount()
  429. {
  430. $discount = UserAssetService::getDiscount($this->adminId);
  431. util::success($discount);
  432. }
  433. //小程序用户完整信息 ssh 2019.12.12
  434. public function actionMiniFullInfo()
  435. {
  436. $post = Yii::$app->request->post();
  437. $iv = isset($post['iv']) ? $post['iv'] : '';
  438. $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
  439. $appId = $this->sj['miniAppId'];
  440. $sjId = $this->sjId;
  441. $miniOpenId = $this->user['miniOpenId'];
  442. if (empty($miniOpenId)) {
  443. util::fail('mini_open_id empty');
  444. }
  445. $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
  446. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  447. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  448. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  449. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  450. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  451. if ($errCode != 0) {
  452. Yii::info($result . ' ' . $errCode);
  453. util::fail('获取用户信息失败');
  454. }
  455. Yii::info('小程序获取用户信息:' . $result);
  456. $originalInfo = Json::decode($result);
  457. $source = UserClass::$userSourceId['mini']['name'];
  458. $user = UserService::replaceUser($originalInfo, $source, $sjId);
  459. $userId = $user['id'];
  460. $userInfo = UserService::getUserInfo($userId);
  461. util::success($userInfo);
  462. }
  463. //小程序用户手机号
  464. public function actionMiniMobile()
  465. {
  466. $post = Yii::$app->request->post();
  467. $iv = $post['iv'];
  468. $encryptedData = $post['encryptedData'];
  469. $sjId = $this->sjId;
  470. $merchant = $this->sj->attributes;
  471. $appId = $merchant['miniAppId'];
  472. $miniOpenId = $this->user['miniOpenId'];
  473. $user = $this->user;
  474. if (!empty($user) && !empty($user['mobile'])) {
  475. $userId = $user['id'];
  476. util::success(['mobile' => $user['mobile']]);
  477. }
  478. $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
  479. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  480. if (empty($sessionKey)) {
  481. util::fail('系统错误,sesstion empty');
  482. }
  483. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  484. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  485. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  486. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  487. if ($errCode != 0) {
  488. util::fail('解密失败');
  489. }
  490. $arr = Json::decode($result);
  491. $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  492. if (empty($mobile)) {
  493. util::fail('没有获取手机号,请重试');
  494. }
  495. $userId = $user['id'];
  496. UserService::becomeMember($user, $merchant, ['mobile' => $mobile]);
  497. util::success(['mobile' => $mobile]);
  498. }
  499. //密码修改
  500. public function actionPassword()
  501. {
  502. $post = Yii::$app->request->post();
  503. $old = isset($post['old']) ? $post['old'] : '';
  504. $new = isset($post['new']) ? $post['new'] : '';
  505. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  506. if (empty($new)) {
  507. util::fail('请输入新密码');
  508. }
  509. if ($new != $confirm) {
  510. util::fail('二次密码不一致');
  511. }
  512. $userId = $this->adminId;
  513. $user = UserService::getUserInfo($userId);
  514. if (isset($user['hasPayPwd']) && $user['hasPayPwd'] == 1) {
  515. if (empty($old)) {
  516. util::fail('请填写旧密码');
  517. }
  518. if (password_verify($old, $user['payPassword']) == false) {
  519. util::fail('旧密码错误');
  520. }
  521. }
  522. UserService::updateById($userId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT), 'hasPayPwd' => 1]);
  523. util::complete('修改成功');
  524. }
  525. //申请会员 ssh 2019.12.18
  526. public function actionApplyMember()
  527. {
  528. $post = Yii::$app->request->post();
  529. $mobile = isset($post['mobile']) ? $post['mobile'] : 0;
  530. if (stringUtil::isMobile($mobile) == false) {
  531. util::fail('请输入手机号');
  532. }
  533. $userId = $this->adminId;
  534. $asset = UserAssetService::getByUserId($userId);
  535. if (isset($asset['member']) && $asset['member'] != -1) {
  536. util::fail('已经是会员了');
  537. }
  538. $code = isset($post['code']) ? $post['code'] : '';
  539. $cacheCode = SmsService::getApplyMemberCode($userId, $mobile);
  540. if (empty($cacheCode) || $cacheCode != $code) {
  541. util::fail('验证码错误');
  542. }
  543. $update = [];
  544. if (isset($post['realName']) && !empty($post['realName'])) {
  545. $update['realName'] = $post['realName'];
  546. }
  547. if (isset($post['birthday']) && !empty($post['birthday'])) {
  548. $update['birthday'] = $post['birthday'];
  549. }
  550. $user = UserService::getByCondition(['sjId' => $this->sjId, 'mobile' => $mobile]);
  551. if ($userId == $user['id']) {
  552. util::fail('手机号已验证');
  553. }
  554. if (!empty($user)) {
  555. util::fail('手机号已经注册过了');
  556. }
  557. $update['mobile'] = $mobile;
  558. UserService::becomeMember($this->user, $this->sj->attributes, $update);
  559. util::complete('注册成功');
  560. }
  561. //用户基本信息和资产 ssh 2019.12.19
  562. public function actionMyProfile()
  563. {
  564. $custom = $this->custom;
  565. $user = UserService::getUserInfo($this->adminId);
  566. $growth = $custom['growth'] ?? 0;
  567. $extend = $this->sjExtend->attributes;
  568. $grade = MerchantExtendService::getGradeList($extend, 'asc');
  569. //下个等级的积分
  570. $nextLevelGrowth = 0;
  571. foreach ($grade as $val) {
  572. $currentGrowth = $val['growth'];
  573. if ($currentGrowth > $growth) {
  574. $nextLevelGrowth = $currentGrowth;
  575. break;
  576. }
  577. }
  578. $user['userAsset']['nextLevelGrowth'] = $nextLevelGrowth;
  579. util::success($user);
  580. }
  581. //登陆客户的信息 ssh 2020.3.12
  582. public function actionLoginDetail()
  583. {
  584. $user = $this->user;
  585. util::success($user);
  586. }
  587. //总挂账和总余额汇总 ssh 20250620
  588. public function actionShowTotalBalance()
  589. {
  590. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  591. if ($lookMoney == 0) {
  592. util::fail('无法查看哦');
  593. }
  594. $lsShop = $this->shop;
  595. $pfShopId = $lsShop->pfShopId;
  596. $lsShopId = $this->shopId;
  597. $respond = \bizGhs\custom\classes\CustomClass::showTotalBalance($pfShopId, $lsShopId);
  598. $respond['pfShopId'] = $pfShopId;
  599. $respond['lsShopId'] = $lsShopId;
  600. util::success($respond);
  601. }
  602. //今日访客
  603. public function actionGetVisit()
  604. {
  605. $userIds = StatVisitClass::getVisitCustomIds($this->shopId);
  606. if (empty($userIds)) {
  607. util::success(['list' => []]);
  608. }
  609. $sort = 'visitTime DESC';
  610. $where = [
  611. 'shopId' => $this->shopId,
  612. 'userId' => ['in', $userIds]
  613. ];
  614. $list = CustomService::getCustomList($where, $sort);
  615. util::success($list);
  616. }
  617. //删除客户 ssh 20250923
  618. public function actionDelCustom()
  619. {
  620. $get = Yii::$app->request->get();
  621. $id = $get['id'] ?? 0;
  622. $custom = CustomClass::getById($id, true);
  623. if (empty($custom)) {
  624. util::fail('没有找到客户');
  625. }
  626. if ($custom->shopId != $this->shopId) {
  627. util::fail('不是你的客户');
  628. }
  629. $hdId = $custom->hdId ?? 0;
  630. $hd = HdClass::getById($hdId, true);
  631. if (empty($hd)) {
  632. util::fail('客户信息缺失');
  633. }
  634. $custom->delStatus = 1;
  635. $custom->save();
  636. $hd->delStatus = 1;
  637. $hd->save();
  638. util::complete('删除成功');
  639. }
  640. //重新统计客户的消费总额
  641. public function actionUpdateBuyAmount()
  642. {
  643. $post = Yii::$app->request->post();
  644. $customId = $post['customId'];
  645. $c = CustomClass::getLockById($customId);
  646. // 1.重新统计客户的消费总额
  647. $orderList = OrderClass::getAllByCondition(['customId' => $customId], null, 'id, forward, actPrice');
  648. $buyAmount = 0;
  649. if (!empty($orderList)) {
  650. foreach ($orderList as $order) {
  651. if ($order['forward'] == 0) { //0 常规订单
  652. $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
  653. } elseif ($order['forward'] == 1) { //1 售后付款单(红冲)
  654. $buyAmount = bcsub($buyAmount, $order['actPrice'], 2);
  655. } else {
  656. Yii::info('订单类型不存在');
  657. continue;
  658. }
  659. }
  660. }
  661. $c->buyAmount = $buyAmount;
  662. $c->listend = false;
  663. $c->save();
  664. // 2.更新此客户所对应花店的消费金额 expendAmount ---- xhHd -> expendAmount
  665. HdClass::updateById($c->hdId, ['expendAmount' => $buyAmount]);
  666. util::success(['customId' => $customId, 'buyAmount' => $buyAmount]);
  667. }
  668. }