CustomController.php 24 KB

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