Student.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\api\controller;
  3. use Throwable;
  4. use ba\Captcha;
  5. use ba\ClickCaptcha;
  6. use think\facade\Config;
  7. use app\common\facade\Token;
  8. use app\common\controller\Api;
  9. use think\facade\Db;
  10. use app\api\validate\User as UserValidate;
  11. use app\common\library\xmwechat\miniprogram\MpService;
  12. class Student extends Api
  13. {
  14. protected array $noNeedLogin = ['Register', 'logout'];
  15. protected array $noNeedPermission = ['index'];
  16. /**
  17. * 学生手机号获取
  18. * @return void
  19. */
  20. public function Register(Request $request): void
  21. {
  22. if ($this->request->isPost()) {
  23. // code 前端获取,传递给接口
  24. $params = $this->request->post('code');
  25. //获取手机号
  26. $result['phone'] = MpService::getInstance()->getPhoneNumber($params);
  27. if (!empty($result)) {
  28. $this->success('success', $result);
  29. } else {
  30. $this->error('error');
  31. }
  32. }
  33. }
  34. //学生信息获取
  35. public function RegisterEdit(): void
  36. {
  37. if ($this->request->isPost()) {
  38. $data = $this->request->post();
  39. try {
  40. $user=Db::name('student')->where('student_phone',$data['student_phone'])->find();
  41. if ($user) {
  42. // 更新用户
  43. $result=Db::name('student')->where('student_phone', $data['student_phone'])->update(['student_name' => $data['student_name'],'student_class' => $data['student_class']]);
  44. $this->success('success', $result);
  45. } else {
  46. // 新增用户
  47. $result=Db::name('student')->save($data);
  48. $this->success('success', $result);
  49. }
  50. } catch (Throwable $e) {
  51. $this->error($e->getMessage());
  52. }
  53. }
  54. }
  55. }