CustomController.php 28 KB

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