CustomController.php 28 KB

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