user_info; if (!$data->head_img) { $data->head_img = 'https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/defaulthead.png'; } $data['is_vip'] = 0; $data['vip_days'] = 0; $data['phone'] = $this->phone; $year_record = YearOrderService::getRecord($this->uid); if ($year_record) { $data['is_vip'] = 1; $time = strtotime($year_record['end_time']) - time(); if ($time >= 86400) { $data['vip_days'] = floor($time / 86400) . '天'; } elseif ($time > 3600) { $data['vip_days'] = floor($time / 3600) . '小时'; } elseif ($time > 60) { $data['vip_days'] = floor($time / 60) . '分钟'; } else { $data['vip_days'] = $time . '秒'; } } return response()->success($data); } /** * @apiVersion 1.0.0 * @apiDescription 用户签到 * @api {GET} sign 用户签到 * @apiHeader {String} [Authorization] token * @apiGroup User * @apiName sign * @apiSuccess {Double} fee 签到奖励 * @apiSuccess {Number} days 签到天数 * @apiSuccessExample {json} Success-Response: * * { * "code": 0, * "msg": "", * "data": { * "fee": 30, * "days": 1 * } * } */ public function sign() { $result = UserSignService::signV2($this->uid, date('Y-m-d')); if ($result) { return response()->success($result); } return response()->error('QAPP_SYS_ERROR'); } /** * @apiVersion 1.0.0 * @apiDescription 发送验证码 * @api {POST} user/sendCode 发送验证码 * @apiHeader {String} [Authorization] token * @apiGroup User * @apiName sendCode * @apiParam {String} phone 手机号 * @apiSuccessExample {json} Success-Response: * * { * "code": 0, * "msg": "", * "data": {} * } */ public function sendCode(Request $request) { $phone = $request->post('phone'); $code = random_int(1000, 9999); Redis::setex('quser_code:' . $phone, 120, $code); AliSMS::send($phone, 'quickapp_user_bind_phone', ['code' => $code]); return response()->success(); } /** * @apiVersion 1.0.0 * @apiDescription 绑定手机号 * @api {POST} user/bindPhone 绑定手机号 * @apiHeader {String} [Authorization] token * @apiGroup User * @apiName bindPhone * @apiParam {String} phone 手机号 * @apiParam {String} code 验证码 * @apiSuccessExample {json} Success-Response: * * { * "code": 0, * "msg": "", * "data": {} * } */ public function bindPhone(Request $request) { $code = $request->post('code'); $phone = $request->post('phone'); $old = Redis::get('quser_code:' . $phone); if ($old && $old == $code) { try { Redis::del('quser_code:' . $phone); $result = QappUserService::bindPhoneStatic($this->uid, $phone); if (!$result) { return response()->error('WAP_BIND_PHONE_EXIST'); } else { return response()->success(); } } catch (\Exception $e) { return response()->error(); } } else { return response()->error('WAP_SEND_CODE_ERROR'); } } }