CustomController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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. class CustomController extends BaseController
  27. {
  28. public $guestAccess = ['list'];
  29. //修改生日 ssh 20250814
  30. public function actionModifyBirthday()
  31. {
  32. $get = Yii::$app->request->get();
  33. $customId = $get['customId'];
  34. list(, $updateResult) = CustomClass::modifyBirthday($customId, $this->shopId, $get);
  35. if ($updateResult) {
  36. util::complete('生日修改成功');
  37. } else {
  38. util::complete('客户本人设置了,您不需要修改它');
  39. }
  40. }
  41. public function actionChangeLevel()
  42. {
  43. $get = Yii::$app->request->get();
  44. $customId = $get['customId'];
  45. $level = $get['level'] ?? 0;
  46. if ($level < 0) {
  47. util::fail('等级选择错误');
  48. }
  49. $custom = CustomClass::getById($customId, true);
  50. if (empty($custom)) {
  51. util::fail('没有找到客户');
  52. }
  53. $shopId = $this->shopId;
  54. if ($custom->shopId != $shopId) {
  55. util::fail('不是你的客户');
  56. }
  57. $hdId = $custom->hdId;
  58. $hd = HdClass::getById($hdId, true);
  59. if (empty($hd)) {
  60. util::fail('客户信息缺失,编号3445');
  61. }
  62. $staff = $this->shopAdmin;
  63. $staffId = $staff->id;
  64. $staffName = $staff->name;
  65. $params = [
  66. 'style' => 1,//手动修改
  67. 'staffId' => $staffId,
  68. 'adminId' => $this->adminId,
  69. 'staffName' => $staffName,
  70. ];
  71. $shop = $this->shop;
  72. $connection = Yii::$app->db;
  73. $transaction = $connection->beginTransaction();
  74. try {
  75. $beforeLevel = $custom->member ?? 0;
  76. CustomClass::levelChange($beforeLevel, $level, $shop, $custom, $hd, $params);
  77. $transaction->commit();
  78. util::complete('修改成功');
  79. } catch (\Exception $exception) {
  80. $transaction->rollBack();
  81. Yii::info("修改失败:" . $exception->getMessage());
  82. util::fail('修改失败');
  83. }
  84. }
  85. //修改客户地址 ssh 20231109
  86. public function actionModifyAddress()
  87. {
  88. $post = Yii::$app->request->post();
  89. $id = $post['id'] ?? 0;
  90. unset($post['id']);
  91. $custom = CustomClass::getById($id, true);
  92. if (empty($custom)) {
  93. util::fail('没有找到客户信息');
  94. }
  95. $userId = $custom->userId ?? 0;
  96. $city = $post['city'] ?? '';
  97. $dist = $post['dist'] ?? '';
  98. $address = $post['address'] ?? '';
  99. $floor = $post['floor'] ?? '';
  100. $post['fullAddress'] = $city . $dist . $address . $floor;
  101. UserClass::updateByCondition(['id' => $userId], $post);
  102. CustomClass::updateByCondition(['id' => $id], $post);
  103. util::complete('修改成功');
  104. }
  105. //会员权限开关
  106. public function actionChangeVip()
  107. {
  108. $post = Yii::$app->request->post();
  109. $vip = $post['vip'];
  110. $id = $post['customId'];
  111. unset($post['id']);
  112. $custom = CustomClass::getById($id, true, 'id, shopId, vip');
  113. if (empty($custom)) {
  114. util::fail('没有找到客户信息');
  115. }
  116. if ($custom->shopId != $this->shopId) {
  117. util::fial('你不能操作');
  118. }
  119. if (!isset($this->shopAdmin->founder) || $this->shopAdmin->founder != 2) {
  120. util::fail('超管才能操作哦');
  121. }
  122. $custom->vip = $vip;
  123. $custom->save();
  124. $hint = $vip == 1 ? '已开启' : '已关闭';
  125. util::complete($hint);
  126. }
  127. //修改名称 ssh 2022096
  128. public function actionChangeName()
  129. {
  130. $get = Yii::$app->request->get();
  131. $name = $get['name'] ?? '';
  132. $id = $get['id'] ?? 0;
  133. if (empty($name)) {
  134. util::fail('请填写名称');
  135. }
  136. $py = stringUtil::py($name);
  137. $custom = CustomClass::getById($id, true);
  138. CustomClass::valid($custom, $this->shopId);
  139. $custom->name = $name;
  140. $custom->py = $py;
  141. $custom->save();
  142. OrderClass::updateByCondition(['customId' => $id], ['customName' => $name, 'customNamePy' => $py]);
  143. util::complete();
  144. }
  145. //批量添加客户 ssh 20220919
  146. public function actionBatchAddCustom()
  147. {
  148. $post = Yii::$app->request->post();
  149. $connection = Yii::$app->db;
  150. $transaction = $connection->beginTransaction();
  151. try {
  152. for ($i = 1; $i <= 5; $i++) {
  153. $name = $post['name' . $i] ?? '';
  154. $mobile = $post['mobile' . $i] ?? '';
  155. $confirmMobile = $post['confirmMobile' . $i] ?? '';
  156. if (empty($name) && empty($mobile) && empty($confirmMobile)) {
  157. continue;
  158. }
  159. if (empty($name)) {
  160. util::fail('客户名称不能为空');
  161. }
  162. if (stringUtil::getWordNum($name) > 15) {
  163. util::fail('名称不能超过15个汉字');
  164. }
  165. if (empty($mobile)) {
  166. util::fail($name . " 手机号不能为空");
  167. }
  168. if (stringUtil::isMobile($mobile) == false) {
  169. util::fail($name . " 手机号格式不正确");
  170. }
  171. if ($mobile != $confirmMobile) {
  172. util::fail($name . " 二次手机号不一致");
  173. }
  174. $user = \bizMall\user\classes\UserClass::replaceUser(['name' => $name, 'mobile' => $mobile]);
  175. if (isset($this->shop) && !empty($this->shop)) {
  176. //花店增加客户,散客增加门店
  177. CustomClass::buildRelation($this->shop, $user);
  178. }
  179. }
  180. $transaction->commit();
  181. util::complete();
  182. } catch (\Exception $e) {
  183. $transaction->rollBack();
  184. util::fail('添加失败');
  185. }
  186. }
  187. //客户列表 ssh 2019.11.30
  188. public function actionList()
  189. {
  190. $get = Yii::$app->request->get();
  191. $type = $get['type'] ?? 0;
  192. $where = ['shopId' => $this->shopId];
  193. $all = CustomClass::getCount($where);
  194. if ($type == 1) {
  195. //消费排行
  196. $sort = 'buyAmount DESC';
  197. } else if ($type == 2) {
  198. //余额客户
  199. $sort = 'balance DESC';
  200. } else if ($type == 3) {
  201. //生日
  202. $sort = 'birthdayTime ASC';
  203. $where['birthdayTime>'] = 0;
  204. } else if ($type == 4) {
  205. //已经删除的客户
  206. $sort = 'id ASC';
  207. $where['delStatus'] = 1;
  208. } else if ($type == 5) {
  209. //只显示VIP用户
  210. $sort = 'id ASC';
  211. $where['vip'] = 1;
  212. } else {
  213. $sort = 'visitTime DESC';
  214. }
  215. $where = array_merge($where, $this->getListSearchWhere($get));
  216. $list = CustomService::getCustomList($where, $sort);
  217. $list['all'] = $all; //全部的总人数
  218. $list['balance'] = $all; //余额排行的总人数
  219. $list['buyAmount'] = $all; //消费排行的总人数
  220. $list['birth'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['birthdayTime>' => 0])); //有设置生日的总人数
  221. $list['deleted'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['delStatus' => 1])); //被删除的总人数
  222. $list['vip'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['vip' => 1])); //是vip的总人数
  223. util::success($list);
  224. }
  225. //客户余额统计 ssh 20260708
  226. public function actionBalanceStat()
  227. {
  228. $get = Yii::$app->request->get();
  229. $where = array_merge(['shopId' => $this->shopId], $this->getListSearchWhere($get));
  230. $respond = CustomClass::getBalanceStat($where);
  231. util::success($respond);
  232. }
  233. private function getListSearchWhere($get)
  234. {
  235. $where = [];
  236. $searchStyle = $get['searchStyle'] ?? 0;
  237. $name = $get['name'] ?? '';
  238. if (empty($name)) {
  239. $name = $get['keyword'] ?? '';
  240. }
  241. if (empty($name)) {
  242. $name = $get['searchText'] ?? '';
  243. }
  244. if (!empty($name)) {
  245. if ($searchStyle == 0) {
  246. $where['mobile'] = ['like', $name];
  247. } else {
  248. if (stringUtil::isLetter($name)) {
  249. $where['py'] = ['like', $name];
  250. } else {
  251. $where['name'] = ['like', $name];
  252. }
  253. }
  254. }
  255. return $where;
  256. }
  257. //获取客户信息 ssh 20250510
  258. public function actionInfo()
  259. {
  260. $get = Yii::$app->request->get();
  261. $id = $get['id'] ?? 0;
  262. $custom = CustomClass::getById($id, true);
  263. if (empty($custom)) {
  264. util::fail('没有找到客户信息');
  265. }
  266. if ($custom->shopId != $this->shopId) {
  267. util::fail('不是你的客户');
  268. }
  269. util::success(['custom' => $custom]);
  270. }
  271. //获取客户基本和资产信息 ssh 2019.11.30
  272. public function actionDetail()
  273. {
  274. $userId = Yii::$app->request->get('userId');
  275. if (empty($userId)) {
  276. $userId = Yii::$app->request->get('id');
  277. }
  278. $info = CustomClass::getCustomInfo($userId);
  279. CustomClass::valid($info, $this->shopId);
  280. util::success($info);
  281. }
  282. //获取客户详情,包括基本信息、资产、订单和备注 2019.11.30
  283. public function actionUserDetail()
  284. {
  285. $userId = Yii::$app->request->get('userId');
  286. if (empty($userId)) {
  287. $userId = Yii::$app->request->get('id');
  288. }
  289. $info = UserService::getFullUserInfo($userId);
  290. UserService::valid($info, $this->sjId);
  291. $list = MerchantRemarkService::getRemarkList($userId);
  292. $info['remarkList'] = $list;
  293. util::success($info);
  294. }
  295. //添加客户,申请会员时会自动同步资产 ssh 2019.11.30
  296. public function actionAdd()
  297. {
  298. $post = Yii::$app->request->post();
  299. if (isset($post['mobile']) == false || stringUtil::isMobile($post['mobile']) == false) {
  300. util::fail('请输入手机号');
  301. }
  302. if ($post['mobile'] != $post['confirmMobile']) {
  303. util::fail('二次输入手机号不一样');
  304. }
  305. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : '';
  306. AdminService::verifyPayPassword($this->adminId, $payPassword);
  307. $mobile = $post['mobile'];
  308. $user = UserService::getByMobile($mobile, $this->sjId);
  309. if (!empty($user)) {
  310. util::fail('手机号已使用');
  311. }
  312. $post['sjId'] = $this->sjId;
  313. $post['member'] = $post['memberLevel'];
  314. UserService::addUser($post);
  315. util::complete();
  316. }
  317. //充值 ssh 2019.12.1
  318. public function actionRecharge()
  319. {
  320. $post = Yii::$app->request->post();
  321. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : '';
  322. AdminService::verifyPayPassword($this->adminId, $payPassword);
  323. $userId = isset($post['userId']) ? $post['userId'] : 0;
  324. $rechargeAmount = isset($post['rechargeAmount']) ? $post['rechargeAmount'] : 1;
  325. $user = UserService::getById($userId);
  326. if (empty($user)) {
  327. util::fail('找不到客户');
  328. }
  329. if ($user['sjId'] != $this->sjId) {
  330. util::fail('您无法操作');
  331. }
  332. $userAsset = UserAssetService::getByUserId($userId);
  333. $totalBalance = $userAsset['balance'] + $rechargeAmount;
  334. $totalRecharge = $userAsset['totalRecharge'] + $rechargeAmount;
  335. $upData['balance'] = $totalBalance;
  336. $upData['totalRecharge'] = $totalRecharge;
  337. $merchantAsset = MerchantAssetService::getBySjId($this->sjId);
  338. $return = xhRechargeService::recharge($rechargeAmount, $user, $this->adminId, $this->sj->attributes, $this->sjExtend->attributes, $merchantAsset);
  339. if ($return['code'] == 'A0001') {
  340. util::complete();
  341. }
  342. util::fail();
  343. }
  344. //升级 ssh 2019.12.1
  345. public function actionUpgrade()
  346. {
  347. $post = Yii::$app->request->post();
  348. $userId = isset($post['userId']) ? $post['userId'] : 0;
  349. $member = isset($post['member']) ? $post['member'] : 0;
  350. $user = UserService::getById($userId);
  351. if (empty($user)) {
  352. util::fail('客户不存在');
  353. }
  354. //验证是否商家客户
  355. UserService::valid($user, $this->sjId);
  356. //验证确认密码
  357. $payPassword = $post['payPassword'];
  358. AdminService::verifyPayPassword($this->adminId, $payPassword);
  359. $grade = xhMerchantExtendService::getGradeList($this->sjExtend->attributes, 'desc');
  360. //升级后的成长值
  361. $newLevelGrowth = $grade[$member]['growth'];
  362. $newDiscount = $grade[$member]['discount'];
  363. $userAsset = UserAssetService::getByUserId($userId);
  364. if ($userAsset['member'] >= $member) {
  365. util::fail('客户已经达到此级别了');
  366. }
  367. $now = time();
  368. $date = date("Y-m-d H:i", $now);
  369. $connection = Yii::$app->db;
  370. $transaction = $connection->beginTransaction();
  371. try {
  372. $addGrowth = $newLevelGrowth - $userAsset['growth'];
  373. $upData['growth'] = $newLevelGrowth;
  374. $upData['member'] = $member;
  375. $upData['discount'] = $newDiscount;
  376. UserAssetService::updateByUserId($userId, $upData);
  377. UserService::updateById($userId, ['member' => $member]);
  378. $upgradeData = [
  379. 'member' => $member,
  380. 'prevMember' => $userAsset['member'],
  381. 'sjId' => $this->sjId,
  382. 'gainType' => 0,
  383. 'addTime' => $now,
  384. 'userId' => $userId,
  385. ];
  386. $upgradeRespond = UserUpgradeService::add($upgradeData);
  387. $growthData = [
  388. 'userId' => $userId,
  389. 'userName' => $user['userName'],
  390. 'sjId' => $this->sjId,
  391. 'relateId' => $upgradeRespond['id'],
  392. 'growth' => $newLevelGrowth,
  393. 'num' => $addGrowth,
  394. 'io' => 1,
  395. 'payWay' => 4,
  396. 'alipayId' => '',
  397. 'event' => '管理员操作升到' . $member . '级增加成长值',
  398. 'operatorId' => $userId,
  399. 'createTime' => $date,
  400. 'gainType' => 0,
  401. 'addTime' => $now,
  402. ];
  403. UserGrowthService::add($growthData);
  404. $transaction->commit();
  405. } catch (\Exception $e) {
  406. $transaction->rollBack();
  407. util::fail();
  408. }
  409. $allTM = xhTMessageService::getList($this->sjId);
  410. $openId = isset($user['openId']) ? $user['openId'] : '';
  411. if (empty($openId)) {
  412. util::complete();
  413. }
  414. $shortTempId = 'OPENTM205211943';//升级通知
  415. if (isset($allTM[$shortTempId]) == false) {
  416. util::complete();
  417. }
  418. $tempId = $allTM[$shortTempId];
  419. $data = [
  420. "touser" => $openId, "template_id" => $tempId, "url" => '',
  421. "data" => [
  422. "first" => ["value" => "恭喜,您已经升为{$member}级会员。", "color" => "#173177"],
  423. "keyword1" => ["value" => $user['userName'], "color" => "#173177"],
  424. "keyword2" => ["value" => $date, "color" => "#173177"],
  425. "remark" => ["value" => "点击查看会员权益", "color" => "#173177"],
  426. ]];
  427. wxUtil::sendTaskInform($data, $this->sj);
  428. util::complete();
  429. }
  430. //重置客户密码
  431. public function actionResetPayPassword()
  432. {
  433. $post = Yii::$app->request->post();
  434. $userId = isset($post['userId']) ? $post['userId'] : 0;
  435. $password = isset($post['password']) ? $post['password'] : 0;
  436. $info = UserService::getById($userId);
  437. UserService::valid($info, $this->sjId);
  438. UserService::updateById($userId, ['payPassword' => password_hash($password, PASSWORD_BCRYPT)]);
  439. util::complete();
  440. }
  441. //获取登陆客户的资产 ssh 2019.11.22
  442. public function actionAsset()
  443. {
  444. $asset = UserAssetService::getByUserId($this->adminId);
  445. util::success($asset);
  446. }
  447. //获取登陆客户的优惠情况 ssh 2019.12.3
  448. public function actionDiscount()
  449. {
  450. $discount = UserAssetService::getDiscount($this->adminId);
  451. util::success($discount);
  452. }
  453. //小程序用户完整信息 ssh 2019.12.12
  454. public function actionMiniFullInfo()
  455. {
  456. $post = Yii::$app->request->post();
  457. $iv = isset($post['iv']) ? $post['iv'] : '';
  458. $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
  459. $appId = $this->sj['miniAppId'];
  460. $sjId = $this->sjId;
  461. $miniOpenId = $this->user['miniOpenId'];
  462. if (empty($miniOpenId)) {
  463. util::fail('mini_open_id empty');
  464. }
  465. $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
  466. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  467. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  468. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  469. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  470. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  471. if ($errCode != 0) {
  472. Yii::info($result . ' ' . $errCode);
  473. util::fail('获取用户信息失败');
  474. }
  475. Yii::info('小程序获取用户信息:' . $result);
  476. $originalInfo = Json::decode($result);
  477. $source = UserClass::$userSourceId['mini']['name'];
  478. $user = UserService::replaceUser($originalInfo, $source, $sjId);
  479. $userId = $user['id'];
  480. $userInfo = UserService::getUserInfo($userId);
  481. util::success($userInfo);
  482. }
  483. //小程序用户手机号
  484. public function actionMiniMobile()
  485. {
  486. $post = Yii::$app->request->post();
  487. $iv = $post['iv'];
  488. $encryptedData = $post['encryptedData'];
  489. $sjId = $this->sjId;
  490. $merchant = $this->sj->attributes;
  491. $appId = $merchant['miniAppId'];
  492. $miniOpenId = $this->user['miniOpenId'];
  493. $user = $this->user;
  494. if (!empty($user) && !empty($user['mobile'])) {
  495. $userId = $user['id'];
  496. util::success(['mobile' => $user['mobile']]);
  497. }
  498. $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
  499. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  500. if (empty($sessionKey)) {
  501. util::fail('系统错误,sesstion empty');
  502. }
  503. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  504. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  505. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  506. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  507. if ($errCode != 0) {
  508. util::fail('解密失败');
  509. }
  510. $arr = Json::decode($result);
  511. $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  512. if (empty($mobile)) {
  513. util::fail('没有获取手机号,请重试');
  514. }
  515. $userId = $user['id'];
  516. UserService::becomeMember($user, $merchant, ['mobile' => $mobile]);
  517. util::success(['mobile' => $mobile]);
  518. }
  519. //密码修改
  520. public function actionPassword()
  521. {
  522. $post = Yii::$app->request->post();
  523. $old = isset($post['old']) ? $post['old'] : '';
  524. $new = isset($post['new']) ? $post['new'] : '';
  525. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  526. if (empty($new)) {
  527. util::fail('请输入新密码');
  528. }
  529. if ($new != $confirm) {
  530. util::fail('二次密码不一致');
  531. }
  532. $userId = $this->adminId;
  533. $user = UserService::getUserInfo($userId);
  534. if (isset($user['hasPayPwd']) && $user['hasPayPwd'] == 1) {
  535. if (empty($old)) {
  536. util::fail('请填写旧密码');
  537. }
  538. if (password_verify($old, $user['payPassword']) == false) {
  539. util::fail('旧密码错误');
  540. }
  541. }
  542. UserService::updateById($userId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT), 'hasPayPwd' => 1]);
  543. util::complete('修改成功');
  544. }
  545. //申请会员 ssh 2019.12.18
  546. public function actionApplyMember()
  547. {
  548. $post = Yii::$app->request->post();
  549. $mobile = isset($post['mobile']) ? $post['mobile'] : 0;
  550. if (stringUtil::isMobile($mobile) == false) {
  551. util::fail('请输入手机号');
  552. }
  553. $userId = $this->adminId;
  554. $asset = UserAssetService::getByUserId($userId);
  555. if (isset($asset['member']) && $asset['member'] != -1) {
  556. util::fail('已经是会员了');
  557. }
  558. $code = isset($post['code']) ? $post['code'] : '';
  559. $cacheCode = SmsService::getApplyMemberCode($userId, $mobile);
  560. if (empty($cacheCode) || $cacheCode != $code) {
  561. util::fail('验证码错误');
  562. }
  563. $update = [];
  564. if (isset($post['realName']) && !empty($post['realName'])) {
  565. $update['realName'] = $post['realName'];
  566. }
  567. if (isset($post['birthday']) && !empty($post['birthday'])) {
  568. $update['birthday'] = $post['birthday'];
  569. }
  570. $user = UserService::getByCondition(['sjId' => $this->sjId, 'mobile' => $mobile]);
  571. if ($userId == $user['id']) {
  572. util::fail('手机号已验证');
  573. }
  574. if (!empty($user)) {
  575. util::fail('手机号已经注册过了');
  576. }
  577. $update['mobile'] = $mobile;
  578. UserService::becomeMember($this->user, $this->sj->attributes, $update);
  579. util::complete('注册成功');
  580. }
  581. //用户基本信息和资产 ssh 2019.12.19
  582. public function actionMyProfile()
  583. {
  584. $custom = $this->custom;
  585. $user = UserService::getUserInfo($this->adminId);
  586. $growth = $custom['growth'] ?? 0;
  587. $extend = $this->sjExtend->attributes;
  588. $grade = MerchantExtendService::getGradeList($extend, 'asc');
  589. //下个等级的积分
  590. $nextLevelGrowth = 0;
  591. foreach ($grade as $val) {
  592. $currentGrowth = $val['growth'];
  593. if ($currentGrowth > $growth) {
  594. $nextLevelGrowth = $currentGrowth;
  595. break;
  596. }
  597. }
  598. $user['userAsset']['nextLevelGrowth'] = $nextLevelGrowth;
  599. util::success($user);
  600. }
  601. //登陆客户的信息 ssh 2020.3.12
  602. public function actionLoginDetail()
  603. {
  604. $user = $this->user;
  605. util::success($user);
  606. }
  607. //总挂账和总余额汇总 ssh 20250620
  608. public function actionShowTotalBalance()
  609. {
  610. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  611. if ($lookMoney == 0) {
  612. util::fail('无法查看哦');
  613. }
  614. $lsShop = $this->shop;
  615. $pfShopId = $lsShop->pfShopId;
  616. $lsShopId = $this->shopId;
  617. $respond = \bizGhs\custom\classes\CustomClass::showTotalBalance($pfShopId, $lsShopId);
  618. $respond['pfShopId'] = $pfShopId;
  619. $respond['lsShopId'] = $lsShopId;
  620. util::success($respond);
  621. }
  622. /**
  623. * 客户余额页小程序码(隔天/无原单返余额海报用)
  624. * GET: id=customId
  625. */
  626. public function actionGetGatheringMiniCode()
  627. {
  628. $get = Yii::$app->request->get();
  629. $id = intval($get['id'] ?? 0);
  630. $custom = CustomClass::getById($id, true);
  631. if (empty($custom)) {
  632. util::fail('没有找到客户');
  633. }
  634. if (intval($custom->shopId ?? 0) !== intval($this->shopId)) {
  635. util::fail('不是你的客户');
  636. }
  637. $merchant = \bizHd\wx\classes\WxOpenClass::getMallWxInfo();
  638. $page = 'pages/home/user';
  639. $ptStyle = \common\components\dict::getDict('ptStyle', 'mall');
  640. $scene = 's=' . $this->shopId;
  641. $envVersion = \common\components\miniUtil::normalizeMiniEnvVersion($get['env_version'] ?? 'release');
  642. $miniCode = \common\components\miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle, $envVersion);
  643. $imageUrl = \common\components\imgUtil::groupImg($miniCode);
  644. util::success([
  645. 'imgUrl' => $imageUrl,
  646. 'shopId' => $this->shopId,
  647. 'balance' => bcadd((string)($custom->balance ?? '0'), '0', 2),
  648. ]);
  649. }
  650. //今日访客
  651. public function actionGetVisit()
  652. {
  653. $userIds = StatVisitClass::getVisitCustomIds($this->shopId);
  654. if (empty($userIds)) {
  655. util::success(['list' => []]);
  656. }
  657. $sort = 'visitTime DESC';
  658. $where = [
  659. 'shopId' => $this->shopId,
  660. 'userId' => ['in', $userIds]
  661. ];
  662. $list = CustomService::getCustomList($where, $sort);
  663. util::success($list);
  664. }
  665. //删除客户 ssh 20250923
  666. public function actionDelCustom()
  667. {
  668. $get = Yii::$app->request->get();
  669. $id = $get['id'] ?? 0;
  670. $custom = CustomClass::getById($id, true);
  671. if (empty($custom)) {
  672. util::fail('没有找到客户');
  673. }
  674. if ($custom->shopId != $this->shopId) {
  675. util::fail('不是你的客户');
  676. }
  677. $hdId = $custom->hdId ?? 0;
  678. $hd = HdClass::getById($hdId, true);
  679. if (empty($hd)) {
  680. util::fail('客户信息缺失');
  681. }
  682. $custom->delStatus = 1;
  683. $custom->save();
  684. $hd->delStatus = 1;
  685. $hd->save();
  686. util::complete('删除成功');
  687. }
  688. //重新统计客户的消费总额
  689. public function actionUpdateBuyAmount()
  690. {
  691. $post = Yii::$app->request->post();
  692. $customId = $post['customId'];
  693. $c = CustomClass::getLockById($customId);
  694. // 1.重新统计客户的消费总额
  695. $orderList = OrderClass::getAllByCondition(['customId' => $customId], null, 'id, actPrice');
  696. $buyAmount = 0;
  697. if (!empty($orderList)) {
  698. foreach ($orderList as $order) {
  699. $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
  700. }
  701. }
  702. $c->buyAmount = $buyAmount;
  703. $c->listend = false;
  704. $c->save();
  705. // 2.更新此客户所对应花店的消费金额 expendAmount ---- xhHd -> expendAmount
  706. HdClass::updateById($c->hdId, ['expendAmount' => $buyAmount]);
  707. util::success(['customId' => $customId, 'buyAmount' => $buyAmount]);
  708. }
  709. /**
  710. * 切换客户是否启用送货上门(同步 xhCustom 与 xhHd)
  711. */
  712. public function actionChangeHome()
  713. {
  714. $get = Yii::$app->request->get();
  715. $home = isset($get['home']) ? (int)$get['home'] : 0;
  716. $customId = !empty($get['customId']) ? (int)$get['customId'] : 0;
  717. $custom = CustomClass::getById($customId, true);
  718. if (empty($custom)) {
  719. util::fail('没有找到客户');
  720. }
  721. if ($custom->shopId != $this->shopId) {
  722. util::fail('不是你的客户');
  723. }
  724. $hdId = $custom->hdId ?? 0;
  725. $hd = HdClass::getById($hdId, true);
  726. if (empty($hd)) {
  727. util::fail('客户信息缺失');
  728. }
  729. $custom->home = $home;
  730. $custom->save();
  731. $hd->home = $home;
  732. $hd->save();
  733. util::complete('修改成功');
  734. }
  735. /**
  736. * 客户送货上门单独规则(homeRule=1 时覆盖 xhPsMethod style=0 总设置)
  737. */
  738. public function actionModifyHomeAmount()
  739. {
  740. $get = Yii::$app->request->get();
  741. $id = $get['id'] ?? 0;
  742. $homeAmount = $get['homeAmount'] ?? 0;
  743. $homeNum = $get['homeNum'] ?? 0;
  744. $homeUnMeet = $get['homeUnMeet'] ?? 0;
  745. $homeUnFee = $get['homeUnFee'] ?? 0;
  746. $homeRule = $get['homeRule'] ?? 0;
  747. $custom = CustomClass::getById($id, true);
  748. if (empty($custom)) {
  749. util::fail('没有找到客户');
  750. }
  751. if ($custom->shopId != $this->shopId) {
  752. util::fail('不是你的客户');
  753. }
  754. $hdId = $custom->hdId ?? 0;
  755. $hd = HdClass::getById($hdId, true);
  756. if (empty($hd)) {
  757. util::fail('客户信息缺失');
  758. }
  759. $custom->homeAmount = $homeAmount;
  760. $custom->homeNum = $homeNum;
  761. $custom->homeUnMeet = $homeUnMeet;
  762. $custom->homeUnFee = $homeUnFee;
  763. $custom->homeRule = $homeRule;
  764. $custom->save();
  765. $hd->homeAmount = $homeAmount;
  766. $hd->homeNum = $homeNum;
  767. $hd->homeUnMeet = $homeUnMeet;
  768. $hd->homeUnFee = $homeUnFee;
  769. $hd->homeRule = $homeRule;
  770. $hd->save();
  771. util::complete('修改成功');
  772. }
  773. }