CustomController.php 25 KB

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