CustomController.php 27 KB

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