作者 潘浩文
1 个管道 的构建 通过 耗费 4 秒

接口

... ... @@ -133,6 +133,16 @@ class SignController extends RestBaseController
* @return sleep:睡前打卡记录(null为未进行睡前打卡)
*/
public function daySign(){
$param=$this->request->param();
if ($param['status']==1){
$type='morning';
}elseif ($param['status']==2){
$type='noon';
}elseif ($param['status']==3){
$type='night';
}elseif ($param['status']==4){
$type='sleep';
}
//用户信息
$user=Db::name('user')->where('id',$this->getUserId())->find();
//当天签到记录
... ... @@ -168,13 +178,10 @@ class SignController extends RestBaseController
public function daySignPost(){
$param=$this->request->param();
$user=Db::name('user')->where('id',$this->getUserId())->find();
//是否需要进入每日一签页面
$day_sign=0;
//根据签到种类判断增加积分数
$score=Db::name('config')->where('id',1)->find();
if ($param['status']==1){
//根据星期判断music,image(只有早签到)
//早签到积分
$score=$score['morning_sign_score'];
$type='morning';
... ... @@ -188,6 +195,11 @@ class SignController extends RestBaseController
$score=$score['sleep_sign_score'];
$type='sleep';
}
if(Db::name('user_sign')->where(['user_id'=>$user['id'],$type=>['neq',null]])->find()){
$this->error('当前时间段已签到');
}
//将签到写入记录
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
... ... @@ -195,6 +207,8 @@ class SignController extends RestBaseController
//已有记录
$re=Db::name('user_sign')->where(['user_id'=>$user['id'],'create_time'=>[ 'between time', [$beginToday,$endToday]]])->find();
if ($re){
//是否需要进入每日一签页面
$day_sign=0;
//更新打卡
Db::name('user_sign')->where('id',$re['id'])->update(["$type"=>time()]);
//判断是否打满了4次
... ... @@ -219,6 +233,7 @@ class SignController extends RestBaseController
}
//无记录
else{
//是否需要进入每日一签页面
$day_sign=1;
Db::name('user_sign')->insert(['user_id'=>$this->getUserId(),'create_time'=>time(),"$type"=>time()]);
}
... ...