CustomController.php 26 KB

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