ServiceController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\api\logic\UserGoodsLogic;
  16. use app\common\server\JsonServer;
  17. use app\api\validate\{ServiceValidate,
  18. LoginAccountValidate,
  19. RegisterValidate,
  20. UserGoodsValidate,
  21. WebScanLoginValidate,
  22. WechatLoginValidate};
  23. use app\api\logic\LoginLogic;
  24. use app\api\logic\ServiceLogic;
  25. /**
  26. * 服务商管理
  27. * Class LoginController
  28. * @package app\api\controller
  29. */
  30. class ServiceController extends BaseApiController
  31. {
  32. public array $notNeedLogin = ['register', 'account', 'logout', 'codeUrl', 'oaLogin', 'mnpLogin', 'getScanCode', 'scanLogin'];
  33. /**
  34. * @notes 服务商入住
  35. * @return \think\response\Json
  36. * @author 段誉
  37. * @date 2022/9/7 15:38
  38. */
  39. public function serviceProviderSettled()
  40. {
  41. if($this->request->isPost()) {
  42. $params = (new ServiceValidate())->post()->goCheck('agricultural_machinery_operator');
  43. $userId = $this->userId;
  44. $params['user_id'] = $userId;
  45. $result = ServiceLogic::Settled($params);
  46. if (true === $result) {
  47. switch ($params['type']){
  48. case 1 :
  49. $type_name = '农机手';
  50. break;
  51. case 2 :
  52. $type_name = '烘干服务';
  53. break ;
  54. case 3 :
  55. $type_name = '飞防服务';
  56. break;
  57. default :
  58. $type_name = '';
  59. break;
  60. }
  61. return $this->success($type_name.'入驻成功', [], 1, 1);
  62. }
  63. }else{
  64. return $this->fail('请求方式错误'); return JsonServer::error('请求方式错误');
  65. }
  66. }
  67. /**
  68. * @notes 注册账号
  69. * @return \think\response\Json
  70. * @author 段誉
  71. * @date 2022/9/7 15:38
  72. */
  73. public function register()
  74. {
  75. $params = (new RegisterValidate())->post()->goCheck('register');
  76. $result = LoginLogic::register($params);
  77. if (true === $result) {
  78. return $this->success('注册成功', [], 1, 1);
  79. }
  80. return $this->fail(LoginLogic::getError());
  81. }
  82. /**
  83. * @notes 账号密码/手机号密码/手机号验证码登录
  84. * @return \think\response\Json
  85. * @author 段誉
  86. * @date 2022/9/16 10:42
  87. */
  88. public function account()
  89. {
  90. $params = (new LoginAccountValidate())->post()->goCheck();
  91. $result = LoginLogic::login($params);
  92. if (false === $result) {
  93. return $this->fail(LoginLogic::getError());
  94. }
  95. return $this->data($result);
  96. }
  97. /**
  98. * @notes 退出登录
  99. * @return \think\response\Json
  100. * @throws \think\db\exception\DataNotFoundException
  101. * @throws \think\db\exception\DbException
  102. * @throws \think\db\exception\ModelNotFoundException
  103. * @author 段誉
  104. * @date 2022/9/16 10:42
  105. */
  106. public function logout()
  107. {
  108. LoginLogic::logout($this->userInfo);
  109. return $this->success();
  110. }
  111. /**
  112. * @notes 获取微信请求code的链接
  113. * @return \think\response\Json
  114. * @author 段誉
  115. * @date 2022/9/15 18:27
  116. */
  117. public function codeUrl()
  118. {
  119. $url = $this->request->get('url');
  120. $result = ['url' => LoginLogic::codeUrl($url)];
  121. return $this->success('获取成功', $result);
  122. }
  123. /**
  124. * @notes 公众号登录
  125. * @return \think\response\Json
  126. * @throws \GuzzleHttp\Exception\GuzzleException
  127. * @author 段誉
  128. * @date 2022/9/20 19:48
  129. */
  130. public function oaLogin()
  131. {
  132. $params = (new WechatLoginValidate())->post()->goCheck('oa');
  133. $res = LoginLogic::oaLogin($params);
  134. if (false === $res) {
  135. return $this->fail(LoginLogic::getError());
  136. }
  137. return $this->success('', $res);
  138. }
  139. /**
  140. * @notes 小程序-登录接口
  141. * @return \think\response\Json
  142. * @author 段誉
  143. * @date 2022/9/20 19:48
  144. */
  145. public function mnpLogin()
  146. {
  147. $params = (new WechatLoginValidate())->post()->goCheck('mnpLogin');
  148. $res = LoginLogic::mnpLogin($params);
  149. if (false === $res) {
  150. return $this->fail(LoginLogic::getError());
  151. }
  152. return $this->success('', $res);
  153. }
  154. /**
  155. * @notes 小程序绑定微信
  156. * @return \think\response\Json
  157. * @author 段誉
  158. * @date 2022/9/20 19:48
  159. */
  160. public function mnpAuthBind()
  161. {
  162. $params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
  163. $params['user_id'] = $this->userId;
  164. $result = LoginLogic::mnpAuthLogin($params);
  165. if ($result === false) {
  166. return $this->fail(LoginLogic::getError());
  167. }
  168. return $this->success('绑定成功', [], 1, 1);
  169. }
  170. /**
  171. * @notes 公众号绑定微信
  172. * @return \think\response\Json
  173. * @throws \GuzzleHttp\Exception\GuzzleException
  174. * @author 段誉
  175. * @date 2022/9/20 19:48
  176. */
  177. public function oaAuthBind()
  178. {
  179. $params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
  180. $params['user_id'] = $this->userId;
  181. $result = LoginLogic::oaAuthLogin($params);
  182. if ($result === false) {
  183. return $this->fail(LoginLogic::getError());
  184. }
  185. return $this->success('绑定成功', [], 1, 1);
  186. }
  187. /**
  188. * @notes 获取扫码地址
  189. * @return \think\response\Json
  190. * @author 段誉
  191. * @date 2022/10/20 18:25
  192. */
  193. public function getScanCode()
  194. {
  195. $redirectUri = $this->request->get('url/s');
  196. $result = LoginLogic::getScanCode($redirectUri);
  197. if (false === $result) {
  198. return $this->fail(LoginLogic::getError() ?? '未知错误');
  199. }
  200. return $this->success('', $result);
  201. }
  202. /**
  203. * @notes 网站扫码登录
  204. * @return \think\response\Json
  205. * @author 段誉
  206. * @date 2022/10/21 10:28
  207. */
  208. public function scanLogin()
  209. {
  210. $params = (new WebScanLoginValidate())->post()->goCheck();
  211. $result = LoginLogic::scanLogin($params);
  212. if (false === $result) {
  213. return $this->fail(LoginLogic::getError() ?? '登录失败');
  214. }
  215. return $this->success('', $result);
  216. }
  217. /**
  218. * @notes 更新用户头像昵称
  219. * @return \think\response\Json
  220. * @author 段誉
  221. * @date 2023/2/22 11:15
  222. */
  223. public function updateUser()
  224. {
  225. $params = (new WechatLoginValidate())->post()->goCheck("updateUser");
  226. LoginLogic::updateUser($params, $this->userId);
  227. return $this->success('操作成功', [], 1, 1);
  228. }
  229. }