Browse Source

签到

master
林一峰 7 years ago
parent
commit
600afb3adf
  1. 59
      app/Http/Controllers/Api/UserController.php
  2. 56
      app/Http/Model/User.php

59
app/Http/Controllers/Api/UserController.php

@ -13,6 +13,65 @@ class UserController extends CommonController
{
parent::__construct();
}
//签到
public function signin(Request $request)
{
$user = MallDataManager::userFirst(['id'=>Token::$uid]);
if($user){}else{return ReturnCode::create(ReturnCode::PARAMS_ERROR);}
$signin_time='';
if(!empty($user->signin_time)){$signin_time = date('Ymd',strtotime($user->signin_time));} //签到时间
$today = date('Ymd',time()); //今日日期
if($signin_time==$today){return ReturnCode::create(101,'已经签到啦,请明天再来!');}
$signin_point = (int)DB::table('system')->where(['keyword'=>'signin_point'])->value('value'); //签到积分
DB::table('user')->where(['id'=>Token::$uid])->update(['point'=>($user->point+$signin_point),'signin_time'=>date('Y-m-d H:i:s')]); //更新用户积分,及签到时间
DB::table('user_point_log')->insert(['type'=>1,'point'=>$signin_point,'des'=>'签到','user_id'=>Token::$uid]); //添加签到积分记录
return ReturnCode::create(ReturnCode::SUCCESS,'恭喜您今日签到成功!+'.$signin_point.'积分');
}
//验证码校验
public function verifyCodeCheck(Request $request)
{
$mobile = $request->input('mobile', null); //手机号码
$verificationCode = $request->input('verificationCode', null); //手机验证码
$type = $request->input('type', null); //验证码类型
if ($mobile==null || $verificationCode==null || $type==null)
{
return ReturnCode::create(ReturnCode::PARAMS_ERROR);
}
if (!Helper::isValidMobile($mobile))
{
return ReturnCode::create(ReturnCode::MOBILE_FORMAT_FAIL);
}
$verifyCode = VerifyCode::isVerify($mobile, $verificationCode, $type);
if(!$verifyCode)
{
return ReturnCode::create(ReturnCode::INVALID_VERIFY_CODE);
}
return ReturnCode::create(ReturnCode::SUCCESS);
}
//积分记录
public function getCommunityNoticeList(Request $request)
{
$where = '';
$page = $request->input('page',1);
$size = $request->input('size',10);
$skip = ($page-1)*$size;
$select = ['id','title','des','litpic','type','created_at as time'];
$orderBy = ['id','desc'];
return ReturnCode::create(ReturnCode::SUCCESS,MallDataManager::getCommunityNoticeList($where,$select,$orderBy,$skip,$size));
}
//用户收货地址列表
public function userAddressList(Request $request)

56
app/Http/Model/User.php

@ -1,7 +1,6 @@
<?php
namespace App\Http\Model;
use Illuminate\Database\Eloquent\Model;
use App\Common\Token;
class User extends BaseModel
@ -25,4 +24,59 @@ class User extends BaseModel
{
return $this->belongsTo(UserRole::class, 'role_id', 'id');
}
//签到
public static function signin(array $param)
{
extract($param); //参数:limit,offset
$user = self::where(['id'=>Token::$uid])->first();
if($user){}else{return false;}
$signin_time='';
if(!empty($user->signin_time)){$signin_time = date('Ymd',strtotime($user->signin_time));} //签到时间
$today = date('Ymd',time()); //今日日期
if($signin_time==$today){return ReturnCode::create(101,'已经签到啦,请明天再来!');}
$signin_point = (int)DB::table('system')->where(['keyword'=>'signin_point'])->value('value'); //签到积分
DB::table('user')->where(['id'=>Token::$uid])->update(['point'=>($user->point+$signin_point),'signin_time'=>date('Y-m-d H:i:s')]); //更新用户积分,及签到时间
DB::table('user_point_log')->insert(['type'=>1,'point'=>$signin_point,'des'=>'签到','user_id'=>Token::$uid]); //添加签到积分记录
return ReturnCode::create(ReturnCode::SUCCESS,'恭喜您今日签到成功!+'.$signin_point.'积分');
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$model = self::where('user_id', Token::$uid);
$res['count'] = $model->count();
$res['list'] = array();
if($res['count']>0)
{
$res['list'] = $model->skip($offset)->take($limit)->get()->toArray();
if($res['list'])
{
foreach($res['list'] as $k=>$v)
{
$res['list'][$k]['country_name'] = Region::getRegionName($v['country']);
$res['list'][$k]['province_name'] = Region::getRegionName($v['province']);
$res['list'][$k]['city_name'] = Region::getRegionName($v['city']);
$res['list'][$k]['district_name'] = Region::getRegionName($v['district']);
}
}
}
else
{
return false;
}
return $res;
}
}
Loading…
Cancel
Save