CustomController.php 28 KB

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