UserController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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 cjhao
  124. * @date 2021/8/9 10:18
  125. */
  126. public function userLevel()
  127. {
  128. $userLevel = (new UserLogic)->userLevel($this->userId);
  129. return $this->success('', $userLevel);
  130. }
  131. /**
  132. * @notes 余额转账
  133. * @author Tab
  134. * @date 2021/8/11 20:20
  135. */
  136. public function transfer()
  137. {
  138. $params = (new UserValidate())->post()->goCheck('transfer', ['user_id' => $this->userId]);
  139. $result = UserLogic::transfer($params);
  140. if($result) {
  141. return $this->success('转账成功', [], 1, 1);
  142. }
  143. return $this->fail(UserLogic::getError());
  144. }
  145. /**
  146. * @notes 最近转账记录(3条)
  147. * @return \think\response\Json
  148. * @author Tab
  149. * @date 2021/8/12 10:17
  150. */
  151. public function transferRecent()
  152. {
  153. $result = UserLogic::transferRecent($this->userId);
  154. return $this->data($result);
  155. }
  156. /**
  157. * @notes 收款用户信息
  158. * @return \think\response\Json
  159. * @author Tab
  160. * @date 2021/8/12 10:53
  161. */
  162. public function transferIn()
  163. {
  164. $params = (new UserValidate())->goCheck('transferIn');
  165. $result = UserLogic::transferIn($params);
  166. if($result !== false) {
  167. return $this->data($result);
  168. }
  169. return $this->fail(UserLogic::getError());
  170. }
  171. /**
  172. * @notes 判断用户是否已设置支付密码
  173. * @return \think\response\Json
  174. * @author Tab
  175. * @date 2021/8/17 10:29
  176. */
  177. public function hasPayPassword()
  178. {
  179. $result = UserLogic::hasPayPassword($this->userId);
  180. return $this->data($result);
  181. }
  182. /**
  183. * @notes 设置/修改交易密码
  184. * @return \think\response\Json
  185. * @author Tab
  186. * @date 2021/8/12 11:10
  187. */
  188. public function setPayPassword()
  189. {
  190. $params = (new UserValidate())->post()->goCheck('setPayPassword');
  191. $params['user_id'] = $this->userId;
  192. $result = UserLogic::setPayPassword($params);
  193. if($result) {
  194. return $this->success('修改成功',[], 1, 1);
  195. }
  196. return $this->fail(UserLogic::getError());
  197. }
  198. /**
  199. * @notes 发送验证码 - 重置支付密码
  200. * @author Tab
  201. * @date 2021/8/24 15:49
  202. */
  203. public function resetPayPasswordCaptcha()
  204. {
  205. $params = (new UserValidate())->post()->goCheck('resetPayPasswordCaptcha');
  206. $code = mt_rand(1000, 9999);
  207. $result = event('Notice', [
  208. 'scene_id' => NoticeEnum::FIND_PAY_PASSWORD_CAPTCHA,
  209. 'params' => [
  210. 'user_id' => $this->userId,
  211. 'code' => $code,
  212. 'mobile' => $params['mobile']
  213. ]
  214. ]);
  215. if ($result[0] === true) {
  216. return $this->success('发送成功');
  217. }
  218. return $this->fail($result[0], [], 0, 1);
  219. }
  220. /**
  221. * @notes 重置支付密码
  222. * @return \think\response\Json
  223. * @author Tab
  224. * @date 2021/8/24 16:18
  225. */
  226. public function resetPayPassword()
  227. {
  228. $params = (new UserValidate())->post()->goCheck('resetPayPassword', ['id' => $this->userId]);
  229. $result = UserLogic:: resetPayPassword($params);
  230. if($result) {
  231. return $this->success('重置支付密码成功', [], 1, 1);
  232. }
  233. return $this->fail(UserLogic::getError());
  234. }
  235. /**
  236. * @notes 发送验证码 - 重置登录密码
  237. * @author Tab
  238. * @date 2021/8/25 16:33
  239. */
  240. public function resetPasswordCaptcha()
  241. {
  242. $params = (new UserValidate())->post()->goCheck('resetPasswordCaptcha');
  243. $code = mt_rand(1000, 9999);
  244. $result = event('Notice', [
  245. 'scene_id' => NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA,
  246. 'params' => [
  247. 'user_id' => $this->userId,
  248. 'code' => $code,
  249. 'mobile' => $params['mobile']
  250. ]
  251. ]);
  252. if ($result[0] === true) {
  253. return $this->success('发送成功');
  254. }
  255. return $this->fail($result[0], [], 0, 1);
  256. }
  257. /**
  258. * @notes 重置登录密码
  259. * @return \think\response\Json
  260. * @author Tab
  261. * @date 2021/8/25 16:35
  262. */
  263. public function resetPassword()
  264. {
  265. $params = (new UserValidate())->post()->goCheck('resetPassword');
  266. $result = UserLogic:: resetPassword($params);
  267. if($result) {
  268. return $this->success('重置登录密码成功', [], 1, 1);
  269. }
  270. return $this->fail(UserLogic::getError());
  271. }
  272. /**
  273. * @notes 查看转账记录列表
  274. * @return \think\response\Json
  275. * @author Tab
  276. * @date 2021/8/12 11:40
  277. */
  278. public function transferLists()
  279. {
  280. return $this->dataLists(new TransferLists());
  281. }
  282. /**
  283. * @notes 钱包
  284. * @return \think\response\Json
  285. * @author Tab
  286. * @date 2021/8/12 14:55
  287. */
  288. public function wallet()
  289. {
  290. $result = UserLogic::wallet($this->userId);
  291. return $this->data($result);
  292. }
  293. /**
  294. * @notes 用户信息
  295. * @return \think\response\Json
  296. * @author Tab
  297. * @date 2021/8/25 17:18
  298. */
  299. public function info()
  300. {
  301. $result = UserLogic::info($this->userId);
  302. return $this->data($result);
  303. }
  304. /**
  305. * @notes 获取微信手机号并绑定
  306. * @return mixed
  307. * @author Tab
  308. * @date 2021/8/24 15:09
  309. */
  310. public function getMobileByMnp()
  311. {
  312. $params = (new UserValidate())->post()->goCheck('getMobileByMnp');
  313. $params['user_id'] = $this->userId;
  314. $result = UserLogic::getNewMobileByMnp($params);
  315. if($result === false) {
  316. return $this->fail(UserLogic::getError());
  317. }
  318. return $this->success('绑定成功', [], 1, 1);
  319. }
  320. /**
  321. * @notes 获取服务协议
  322. * @return \think\response\Json
  323. * @author Tab
  324. * @date 2021/8/24 16:44
  325. */
  326. public function getServiceAgreement()
  327. {
  328. $result = UserLogic::getServiceAgreement();
  329. return $this->data($result);
  330. }
  331. /**
  332. * @notes 获取隐私政策
  333. * @return \think\response\Json
  334. * @author Tab
  335. * @date 2021/8/24 16:44
  336. */
  337. public function getPrivacyPolicy()
  338. {
  339. $result = UserLogic::getPrivacyPolicy();
  340. return $this->data($result);
  341. }
  342. /**
  343. * @notes 获取版本号
  344. * @return \think\response\Json
  345. * @author Tab
  346. * @date 2021/8/24 16:47
  347. */
  348. public function getVersion()
  349. {
  350. return $this->data(['version' => $this->request->header('version')]);
  351. }
  352. /**
  353. * @notes 设置登录密码
  354. * @return \think\response\Json
  355. * @author Tab
  356. * @date 2021/10/22 18:09
  357. */
  358. public function setPassword()
  359. {
  360. $params = (new UserValidate())->post()->goCheck('setPassword');
  361. $params['user_id'] = $this->userId;
  362. $result = UserLogic::setPassword($params);
  363. if($result) {
  364. return $this->success('设置成功',[], 1, 1);
  365. }
  366. return $this->fail(UserLogic::getError());
  367. }
  368. /**
  369. * @notes 修改登录密码
  370. * @return \think\response\Json
  371. * @author Tab
  372. * @date 2021/10/22 18:09
  373. */
  374. public function changePassword()
  375. {
  376. $params = (new UserValidate())->post()->goCheck('changePassword');
  377. $params['user_id'] = $this->userId;
  378. $result = UserLogic::changePassword($params);
  379. if($result) {
  380. return $this->success('修改成功',[], 1, 1);
  381. }
  382. return $this->fail(UserLogic::getError());
  383. }
  384. /**
  385. * @notes 判断用户是否设置登录密码
  386. * @return mixed
  387. * @author Tab
  388. * @date 2021/10/22 18:24
  389. */
  390. public function hasPassword()
  391. {
  392. $result = UserLogic::hasPassword($this->userId);
  393. return $this->data([
  394. 'has_password' => $result
  395. ]);
  396. }
  397. /**
  398. * @notes 设置 注册奖励已弹窗
  399. * @return \think\response\Json
  400. * @author lbzy
  401. * @datetime 2024-06-21 14:22:53
  402. */
  403. function updateRegisterAward()
  404. {
  405. UserLogic::updateRegisterAward($this->userId);
  406. return $this->success('成功');
  407. }
  408. }