UserController.php 12 KB

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