CustomController.php 26 KB

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