UserController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\controller;
  20. use app\common\enum\NoticeEnum;
  21. use app\shopapi\{
  22. logic\UserLogic,
  23. lists\TransferLists,
  24. validate\UserValidate,
  25. validate\SetUserInfoValidate
  26. };
  27. /**
  28. * 用户控制器
  29. * Class UserController
  30. * @package app\shopapi\controller
  31. */
  32. class UserController extends BaseShopController
  33. {
  34. public array $notNeedLogin = ['resetPasswordCaptcha', 'resetPassword'];
  35. /**
  36. * @notes 个人中心
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @author cjhao
  41. * @date 2021/8/6 19:16
  42. */
  43. public function centre()
  44. {
  45. $data = (new UserLogic)->centre($this->userInfo);
  46. return $this->success('', $data);
  47. }
  48. /**
  49. * @notes 设置用户信息
  50. * @return \think\response\Json
  51. * @author cjhao
  52. * @date 2021/8/6 20:34
  53. */
  54. public function setInfo()
  55. {
  56. $params = (new SetUserInfoValidate())->post()->goCheck(null, ['id' => $this->userId]);
  57. (new UserLogic)->setInfo($this->userId, $params);
  58. return $this->success('操作成功', [],1,1);
  59. }
  60. /**
  61. * @notes 发送验证码 - 绑定手机号
  62. * @author Tab
  63. * @date 2021/8/25 17:35
  64. */
  65. public function bindMobileCaptcha()
  66. {
  67. $params = (new UserValidate())->post()->goCheck('bindMobileCaptcha');
  68. $code = mt_rand(1000, 9999);
  69. $result = event('Notice', [
  70. 'scene_id' => NoticeEnum::BIND_MOBILE_CAPTCHA,
  71. 'params' => [
  72. 'user_id' => $this->userId,
  73. 'code' => $code,
  74. 'mobile' => $params['mobile']
  75. ]
  76. ]);
  77. if ($result[0] === true) {
  78. return $this->success('发送成功');
  79. }
  80. return $this->fail($result[0], [], 0, 1);
  81. }
  82. /**
  83. * @notes 发送验证码 - 变更手机号
  84. * @author Tab
  85. * @date 2021/8/25 17:35
  86. */
  87. public function changeMobileCaptcha()
  88. {
  89. $params = (new UserValidate())->post()->goCheck('changeMobileCaptcha');
  90. $code = mt_rand(1000, 9999);
  91. $result = event('Notice', [
  92. 'scene_id' => NoticeEnum::CHANGE_MOBILE_CAPTCHA,
  93. 'params' => [
  94. 'user_id' => $this->userId,
  95. 'code' => $code,
  96. 'mobile' => $params['mobile']
  97. ]
  98. ]);
  99. if ($result[0] === true) {
  100. return $this->success('发送成功');
  101. }
  102. return $this->fail($result[0], [], 0, 1);
  103. }
  104. /**
  105. * @notes 绑定手机号
  106. * @return \think\response\Json
  107. * @author Tab
  108. * @date 2021/8/25 17:46
  109. */
  110. public function bindMobile()
  111. {
  112. $params = (new UserValidate())->post()->goCheck('bindMobile');
  113. $params['id'] = $this->userId;
  114. $result = UserLogic::bindMobile($params);
  115. if($result) {
  116. return $this->success('绑定成功', [], 1, 1);
  117. }
  118. return $this->fail(UserLogic::getError());
  119. }
  120. /**
  121. * @notes 绑定推荐码
  122. * @return \think\response\Json
  123. * @author Tab
  124. * @date 2021/8/25 17:46
  125. */
  126. public function bindInviterCode()
  127. {
  128. $params = (new UserValidate())->post()->goCheck('bindInviterCode');
  129. $params['id'] = $this->userId;
  130. $result = UserLogic::bindInviterId($params);
  131. if($result) {
  132. return $this->success('绑定成功', [], 1, 1);
  133. }
  134. return $this->fail(UserLogic::getError());
  135. }
  136. /**
  137. * @notes 用户等级
  138. * @return \think\response\Json
  139. * @author cjhao
  140. * @date 2021/8/9 10:18
  141. */
  142. public function userLevel()
  143. {
  144. $userLevel = (new UserLogic)->userLevel($this->userId);
  145. return $this->success('', $userLevel);
  146. }
  147. /**
  148. * @notes 余额转账
  149. * @author Tab
  150. * @date 2021/8/11 20:20
  151. */
  152. public function transfer()
  153. {
  154. $params = (new UserValidate())->post()->goCheck('transfer', ['user_id' => $this->userId]);
  155. $result = UserLogic::transfer($params);
  156. if($result) {
  157. return $this->success('转账成功', [], 1, 1);
  158. }
  159. return $this->fail(UserLogic::getError());
  160. }
  161. /**
  162. * @notes 最近转账记录(3条)
  163. * @return \think\response\Json
  164. * @author Tab
  165. * @date 2021/8/12 10:17
  166. */
  167. public function transferRecent()
  168. {
  169. $result = UserLogic::transferRecent($this->userId);
  170. return $this->data($result);
  171. }
  172. /**
  173. * @notes 收款用户信息
  174. * @return \think\response\Json
  175. * @author Tab
  176. * @date 2021/8/12 10:53
  177. */
  178. public function transferIn()
  179. {
  180. $params = (new UserValidate())->goCheck('transferIn');
  181. $result = UserLogic::transferIn($params);
  182. if($result !== false) {
  183. return $this->data($result);
  184. }
  185. return $this->fail(UserLogic::getError());
  186. }
  187. /**
  188. * @notes 判断用户是否已设置支付密码
  189. * @return \think\response\Json
  190. * @author Tab
  191. * @date 2021/8/17 10:29
  192. */
  193. public function hasPayPassword()
  194. {
  195. $result = UserLogic::hasPayPassword($this->userId);
  196. return $this->data($result);
  197. }
  198. /**
  199. * @notes 设置/修改交易密码
  200. * @return \think\response\Json
  201. * @author Tab
  202. * @date 2021/8/12 11:10
  203. */
  204. public function setPayPassword()
  205. {
  206. $params = (new UserValidate())->post()->goCheck('setPayPassword');
  207. $params['user_id'] = $this->userId;
  208. $result = UserLogic::setPayPassword($params);
  209. if($result) {
  210. return $this->success('修改成功',[], 1, 1);
  211. }
  212. return $this->fail(UserLogic::getError());
  213. }
  214. /**
  215. * @notes 发送验证码 - 重置支付密码
  216. * @author Tab
  217. * @date 2021/8/24 15:49
  218. */
  219. public function resetPayPasswordCaptcha()
  220. {
  221. $params = (new UserValidate())->post()->goCheck('resetPayPasswordCaptcha');
  222. $code = mt_rand(1000, 9999);
  223. $result = event('Notice', [
  224. 'scene_id' => NoticeEnum::FIND_PAY_PASSWORD_CAPTCHA,
  225. 'params' => [
  226. 'user_id' => $this->userId,
  227. 'code' => $code,
  228. 'mobile' => $params['mobile']
  229. ]
  230. ]);
  231. if ($result[0] === true) {
  232. return $this->success('发送成功');
  233. }
  234. return $this->fail($result[0], [], 0, 1);
  235. }
  236. /**
  237. * @notes 重置支付密码
  238. * @return \think\response\Json
  239. * @author Tab
  240. * @date 2021/8/24 16:18
  241. */
  242. public function resetPayPassword()
  243. {
  244. $params = (new UserValidate())->post()->goCheck('resetPayPassword', ['id' => $this->userId]);
  245. $result = UserLogic:: resetPayPassword($params);
  246. if($result) {
  247. return $this->success('重置支付密码成功', [], 1, 1);
  248. }
  249. return $this->fail(UserLogic::getError());
  250. }
  251. /**
  252. * @notes 发送验证码 - 重置登录密码
  253. * @author Tab
  254. * @date 2021/8/25 16:33
  255. */
  256. public function resetPasswordCaptcha()
  257. {
  258. $params = (new UserValidate())->post()->goCheck('resetPasswordCaptcha');
  259. $code = mt_rand(1000, 9999);
  260. $result = event('Notice', [
  261. 'scene_id' => NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA,
  262. 'params' => [
  263. 'user_id' => $this->userId,
  264. 'code' => $code,
  265. 'mobile' => $params['mobile']
  266. ]
  267. ]);
  268. if ($result[0] === true) {
  269. return $this->success('发送成功');
  270. }
  271. return $this->fail($result[0], [], 0, 1);
  272. }
  273. /**
  274. * @notes 重置登录密码
  275. * @return \think\response\Json
  276. * @author Tab
  277. * @date 2021/8/25 16:35
  278. */
  279. public function resetPassword()
  280. {
  281. $params = (new UserValidate())->post()->goCheck('resetPassword');
  282. $result = UserLogic:: resetPassword($params);
  283. if($result) {
  284. return $this->success('重置登录密码成功', [], 1, 1);
  285. }
  286. return $this->fail(UserLogic::getError());
  287. }
  288. /**
  289. * @notes 查看转账记录列表
  290. * @return \think\response\Json
  291. * @author Tab
  292. * @date 2021/8/12 11:40
  293. */
  294. public function transferLists()
  295. {
  296. return $this->dataLists(new TransferLists());
  297. }
  298. /**
  299. * @notes 钱包
  300. * @return \think\response\Json
  301. * @author Tab
  302. * @date 2021/8/12 14:55
  303. */
  304. public function wallet()
  305. {
  306. $result = UserLogic::wallet($this->userId);
  307. return $this->data($result);
  308. }
  309. /**
  310. * @notes 用户信息
  311. * @return \think\response\Json
  312. * @author Tab
  313. * @date 2021/8/25 17:18
  314. */
  315. public function info()
  316. {
  317. $result = UserLogic::info($this->userId);
  318. return $this->data($result);
  319. }
  320. /**
  321. * @notes 获取微信手机号并绑定
  322. * @return mixed
  323. * @author Tab
  324. * @date 2021/8/24 15:09
  325. */
  326. public function getMobileByMnp()
  327. {
  328. $params = (new UserValidate())->post()->goCheck('getMobileByMnp');
  329. $params['user_id'] = $this->userId;
  330. $result = UserLogic::getNewMobileByMnp($params);
  331. if($result === false) {
  332. return $this->fail(UserLogic::getError());
  333. }
  334. return $this->success('绑定成功', [], 1, 1);
  335. }
  336. /**
  337. * @notes 获取服务协议
  338. * @return \think\response\Json
  339. * @author Tab
  340. * @date 2021/8/24 16:44
  341. */
  342. public function getServiceAgreement()
  343. {
  344. $result = UserLogic::getServiceAgreement();
  345. return $this->data($result);
  346. }
  347. /**
  348. * @notes 获取隐私政策
  349. * @return \think\response\Json
  350. * @author Tab
  351. * @date 2021/8/24 16:44
  352. */
  353. public function getPrivacyPolicy()
  354. {
  355. $result = UserLogic::getPrivacyPolicy();
  356. return $this->data($result);
  357. }
  358. /**
  359. * @notes 获取版本号
  360. * @return \think\response\Json
  361. * @author Tab
  362. * @date 2021/8/24 16:47
  363. */
  364. public function getVersion()
  365. {
  366. return $this->data(['version' => $this->request->header('version')]);
  367. }
  368. /**
  369. * @notes 设置登录密码
  370. * @return \think\response\Json
  371. * @author Tab
  372. * @date 2021/10/22 18:09
  373. */
  374. public function setPassword()
  375. {
  376. $params = (new UserValidate())->post()->goCheck('setPassword');
  377. $params['user_id'] = $this->userId;
  378. $result = UserLogic::setPassword($params);
  379. if($result) {
  380. return $this->success('设置成功',[], 1, 1);
  381. }
  382. return $this->fail(UserLogic::getError());
  383. }
  384. /**
  385. * @notes 修改登录密码
  386. * @return \think\response\Json
  387. * @author Tab
  388. * @date 2021/10/22 18:09
  389. */
  390. public function changePassword()
  391. {
  392. $params = (new UserValidate())->post()->goCheck('changePassword');
  393. $params['user_id'] = $this->userId;
  394. $result = UserLogic::changePassword($params);
  395. if($result) {
  396. return $this->success('修改成功',[], 1, 1);
  397. }
  398. return $this->fail(UserLogic::getError());
  399. }
  400. /**
  401. * @notes 判断用户是否设置登录密码
  402. * @return mixed
  403. * @author Tab
  404. * @date 2021/10/22 18:24
  405. */
  406. public function hasPassword()
  407. {
  408. $result = UserLogic::hasPassword($this->userId);
  409. return $this->data([
  410. 'has_password' => $result
  411. ]);
  412. }
  413. /**
  414. * @notes 设置 注册奖励已弹窗
  415. * @return \think\response\Json
  416. * @author lbzy
  417. * @datetime 2024-06-21 14:22:53
  418. */
  419. function updateRegisterAward()
  420. {
  421. UserLogic::updateRegisterAward($this->userId);
  422. return $this->success('成功');
  423. }
  424. }