12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace app\api\controller;
- use Throwable;
- use ba\Captcha;
- use ba\ClickCaptcha;
- use think\facade\Config;
- use app\common\facade\Token;
- use app\common\controller\Api;
- use think\facade\Db;
- use app\api\validate\User as UserValidate;
- use app\common\library\xmwechat\miniprogram\MpService;
- class Student extends Api
- {
- protected array $noNeedLogin = ['Register', 'logout'];
- protected array $noNeedPermission = ['index'];
-
- /**
- * 学生手机号获取
- * @return void
- */
- public function Register(Request $request): void
- {
- if ($this->request->isPost()) {
- // code 前端获取,传递给接口
-
- $params = $this->request->post('code');
-
- //获取手机号
- $result['phone'] = MpService::getInstance()->getPhoneNumber($params);
- if (!empty($result)) {
- $this->success('success', $result);
- } else {
- $this->error('error');
- }
-
- }
- }
- //学生信息获取
- public function RegisterEdit(): void
- {
-
- if ($this->request->isPost()) {
- $data = $this->request->post();
- try {
- $user=Db::name('student')->where('student_phone',$data['student_phone'])->find();
- if ($user) {
- // 更新用户
- $result=Db::name('student')->where('student_phone', $data['student_phone'])->update(['student_name' => $data['student_name'],'student_class' => $data['student_class']]);
- $this->success('success', $result);
- } else {
- // 新增用户
- $result=Db::name('student')->save($data);
- $this->success('success', $result);
- }
-
- } catch (Throwable $e) {
- $this->error($e->getMessage());
- }
-
- }
- }
-
- }
|