diff --git a/app/api/controller/food/User.php b/app/api/controller/food/User.php index a154c4e..6a045a4 100644 --- a/app/api/controller/food/User.php +++ b/app/api/controller/food/User.php @@ -1,4 +1,5 @@ where('user_id',10042)->find(); - Cache::set('food_token_10042',$detail,3600*24*7);//登录状态存储7天 + $detail = (new UserModel)->where('user_id', 10042)->find(); + Cache::set('food_token_10042', $detail, 3600 * 24 * 7);//登录状态存储7天 $detail['is_login'] = true; return $this->renderSuccess(compact('detail')); } - + /** * 获取当前用户信息 */ @@ -40,15 +42,15 @@ class User extends Controller $error = $detail->getError() ?: '更新失败'; return $this->renderError($error); } - + /** * 自动登录/注册 */ public function autoLogin() { $model = new UserModel; - if($detail = $model->autoLogin($this->request->post())){ - return $this->renderSuccess(compact('detail'),'登录成功'); + if ($detail = $model->autoLogin($this->request->post())) { + return $this->renderSuccess(compact('detail'), '登录成功'); } $error = $model->getError() ?: '登录失败'; return $this->renderError($error); @@ -61,13 +63,13 @@ class User extends Controller { $userInfo = $this->getUserDetail(); $model = new UserModel; - if ($detail = $model->getPhoneNumber($this->request->post(),$userInfo)) { - return $this->renderSuccess(compact('detail'),'登录成功'); + if ($detail = $model->getPhoneNumber($this->request->post(), $userInfo)) { + return $this->renderSuccess(compact('detail'), '登录成功'); } $error = $model->getError() ?: '手机号获取失败'; return $this->renderError($error); } - + /** * 安全退出 */ @@ -80,45 +82,93 @@ class User extends Controller $error = $model->getError() ?: '退出失败'; return $this->renderError($error); } - + /** - * 发动短信验证码 - */ - public function sendsms() + * 发动短信验证码 + */ + public function sendsms() { $data = $this->request->post(); $values = Setting::getItem('sms'); - if($values['gateway'] == ''){ + if ($values['gateway'] == '') { return $this->renderError('未配置短信平台'); } - if($values['scene']['captcha'] == 0){ + if ($values['scene']['captcha'] == 0) { return $this->renderError('未开启短信验证码'); } - if($error = get_addons_status('sms'.$values['gateway'])){ + if ($error = get_addons_status('sms' . $values['gateway'])) { return $this->renderError($error); } $sms = new Sms($values['gateway']); $code = get_captcha(); - if($sms->sendSms($data['phone'], ['code' => $code])){ - Cache::set($data['phone'] . '_' . $code,'sms_captcha',300); - return $this->renderSuccess('发送成功'); + if ($sms->sendSms($data['phone'], ['code' => $code])) { + Cache::set($data['phone'] . '_' . $code, 'sms_captcha', 300); + return $this->renderSuccess('发送成功'); } $error = $sms->getError() ?: '短信验证码发送失败'; return $this->renderError($error); - } - - /** + } + + /** * 手机验证码登录 */ public function h5CodeLogin() { $model = new UserModel; - if($detail = $model->h5CodeLogin($this->request->post())){ - return $this->renderSuccess(compact('detail'),'登录成功'); + if ($detail = $model->h5CodeLogin($this->request->post())) { + return $this->renderSuccess(compact('detail'), '登录成功'); } $error = $model->getError() ?: '登录失败'; return $this->renderError($error); } + + /** + * 公众号 优惠券列表 + * @return \think\response\Json + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getWxUserCoupon() + { + $post = $this->request->post(); + $where = [ + 'openid' => $post['openid'], + ]; + if (isset($post['id'])) { + $where['coupon_user_id'] = $post['id']; + } + $data = Db::name('food_coupon_user_wx')->where($where)->select(); + return $this->renderSuccess($data, '成功'); + } + + + /** + * 公众号 优惠券核销 + * @return \think\response\Json + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function write() + { + $post = $this->request->post(); + + $user = Db::name('user_wx')->where(['wx_openid' => $post['openid']])->value('is_role'); + if (empty($user) || $user == 0) { + return $this->renderError('你没核销权限'); + } + + $where = [ +// 'openid' => $post['openid'], + 'coupon_user_id' => $post['id'], + ]; + + $data = Db::name('food_coupon_user_wx')->where($where)->update(['status' => 2]); + return $this->renderSuccess($data, '成功'); + } + + }