签到代码
作者:互联网
<?php
namespace app\api\controller;
use jplt\Pinyin;
use jplt\Dates;
use think\Config;
use think\facade\Db;
use app\common\lib\Show;
use app\common\model\mysql\LogicUser;
// 引入七牛鉴权类
use Qiniu\Auth;
// 引入七牛上传类
use Qiniu\Storage\UploadManager;
class Signin extends BaseController
{
/**
* 签到首页
* @return string
*/
public function index()
{
$signin["signin_rules"]=Db::table("jm_signin_rules")
->alias('a')
->Join('logic_admin_gift gift','a.gift_id = gift.id',"left")
->select();
$user = LogicUser::where('id', input('uid'))->find();
if (!$user) {
return json(["msg"=>"失败","code"=>0]);
}
if ($user->anchor !== 1) {
return json(["msg"=>"失败","code"=>0]);
}
$signin["signincount"]=Db::table("jm_signin") ->where("user_id",$user["id"]) ->whereWeek('createtime')->count();
return $this->jsonreturn("成功",$signin,1);
}
/**
* 立即签到
*/
public function dosign()
{
$user = LogicUser::where('id', input('uid'))->find();
if (!$user) {
return json(["msg"=>"失败","code"=>0]);
}
if ($user->anchor !== 1) {
return json(["msg"=>"失败","code"=>0]);
}
//获得当日凌晨的时间戳
$today = strtotime(date("Y-m-d"));
if(Db::table("jm_signin")->where("sign_time",$today)->count()>0){
return $this->jsonreturn("您今天已经签过到了",[],0);
}
$data=[
'user_id'=>$user["id"],
'successions'=>"0",
'createtime'=>time(),
'sign_time'=>$today,
];
$signincount=Db::table("jm_signin") ->where("user_id",$user["id"]) ->whereWeek('createtime')->count();
$signin_rules=Db::table("jm_signin_rules")
->alias('a')
->Join('logic_admin_gift gift','a.gift_id = gift.id',"left")
->where("cumulative",$signincount+1)
->field('gift.*,a.* ')
// ->fetchSql(true)
->find();
// var_dump($signin_rules);die;
if(!empty($signin_rules["gift_id"])&&$signin_rules["gift_id"]!=0){
//添加背包
}
if(!empty($signin_rules["lottery_num"])&&$signin_rules["lottery_num"]!=0){
//抽奖次数
$logic_user_draw= Db::table("logic_user_draw")
->where("uid",$user["id"])
// ->inc("my_experience",$signin_rules["experience"])
// ->fetchSql(true)
->count();
if($logic_user_draw>0){
Db::table("logic_user_draw")
->where("uid",$user["id"])
->inc("draw_num",$signin_rules["lottery_num"])
// ->fetchSql(true)
->update();
}else{
$daea=[
"uid"=>$user["id"],
"create_time"=>time()
];
Db::table("logic_user_draw")
->where("uid",$user["id"])
->insert($daea);
}
}
if(!empty($signin_rules["experience"])&&$signin_rules["experience"]!=0){
//经验
// experience
$logic_user_class= Db::table("logic_user_class")
->where("uid",$user["id"])
->inc("my_experience",$signin_rules["experience"])
// ->fetchSql(true)
->update();
}
$signin_rules=Db::table("jm_signin") ->insert($data);
return $this->jsonreturn("成功",[],1);
}
/**
*
*/
public function jsonreturn($msg="成功",$data=[],$code=1)
{
return json_encode(["code"=>$code,"msg"=>$msg,"data"=>$data,"time"=>time()]);
}
}
标签:gift,签到,代码,signin,rules,user,table,id 来源: https://blog.csdn.net/wangzhae/article/details/116116585