438 lines
20 KiB
PHP
438 lines
20 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
namespace app\api\model;
|
|||
|
|
use think\Model;
|
|||
|
|
use think\Session;
|
|||
|
|
use think\Db;
|
|||
|
|
|
|||
|
|
class DailyTasks extends Model
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
// 开启自动写入时间戳字段
|
|||
|
|
protected $autoWriteTimestamp = 'int';
|
|||
|
|
// 定义时间戳字段名
|
|||
|
|
protected $createTime = 'createtime';
|
|||
|
|
protected $updateTime = 'updatetime';
|
|||
|
|
protected $table;
|
|||
|
|
//每日任务类型枚举
|
|||
|
|
public $processing_type_str = [
|
|||
|
|
1 => '登录',
|
|||
|
|
2 => '去观看',
|
|||
|
|
3 => '去完成',
|
|||
|
|
4 => '去送礼',
|
|||
|
|
5 => '去邀请',
|
|||
|
|
6 => '去充值',
|
|||
|
|
7 => '去发布',
|
|||
|
|
8 => '签到',
|
|||
|
|
9 => '自动完成',
|
|||
|
|
];
|
|||
|
|
public function __construct($data = [])
|
|||
|
|
{
|
|||
|
|
$prefix = config('database.prefix');
|
|||
|
|
$this->table = $prefix . 'vs_daily_tasks';
|
|||
|
|
parent::__construct($data);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
//每日任务列表
|
|||
|
|
public function dailyTasksList($user_id=''){
|
|||
|
|
$reslut = [];
|
|||
|
|
//用户今日充值金币数量
|
|||
|
|
$user_gold = Db::name('vs_user_money_log')->where(['user_id'=>$user_id,'change_type'=>2,'money_type'=>1])
|
|||
|
|
->whereTime('createtime', 'today')
|
|||
|
|
->sum('change_value');
|
|||
|
|
$reslut['user_gold'] = $user_gold ? $user_gold : 0;
|
|||
|
|
//礼盒列表
|
|||
|
|
$gift_box = Db::name('vs_gift_bag')->where('status',1)->where('activities_id',2)->select();
|
|||
|
|
$reslut['gift_box_list'] = [];
|
|||
|
|
foreach ($gift_box as $key => $val) {
|
|||
|
|
$reslut['gift_box_list'][$key]['id'] = $val['id'];
|
|||
|
|
$reslut['gift_box_list'][$key]['name'] = $val['name'];
|
|||
|
|
$reslut['gift_box_list'][$key]['title'] = $val['title'];
|
|||
|
|
$reslut['gift_box_list'][$key]['icon'] = localpath_to_netpath($val['icon']);
|
|||
|
|
$ext = json_decode($val['ext'],true);
|
|||
|
|
$reslut['gift_box_list'][$key]['highest_gain'] = $ext['highest_gain'];
|
|||
|
|
$reslut['gift_box_list'][$key]['meet'] = $ext['meet'] ? $ext['meet'] : 0;
|
|||
|
|
//解锁进度
|
|||
|
|
if($ext['meet']){
|
|||
|
|
if($user_gold > $ext['meet']){
|
|||
|
|
$reslut['gift_box_list'][$key]['unlock_progress'] = 1;
|
|||
|
|
}else{
|
|||
|
|
$reslut['gift_box_list'][$key]['unlock_progress'] = round(( $user_gold / $ext['meet']),2);
|
|||
|
|
}
|
|||
|
|
}else{
|
|||
|
|
$reslut['gift_box_list'][$key]['unlock_progress'] = 0;
|
|||
|
|
}
|
|||
|
|
//今日可抽奖次数
|
|||
|
|
$reslut['gift_box_list'][$key]['all_number'] = $ext['num'] ? $ext['num'] : 0;
|
|||
|
|
//今日已抽奖次数
|
|||
|
|
$reslut['gift_box_list'][$key]['taday_number'] = Db::name('vs_gift_bag_receive_log')->where('user_id',$user_id)->where('gift_bag_id',$val['id'])->whereTime('createtime', 'today')->count();
|
|||
|
|
//今日剩余抽奖次数
|
|||
|
|
$reslut['gift_box_list'][$key]['taday_number_left'] = $ext['num'] - $reslut['gift_box_list'][$key]['taday_number'];
|
|||
|
|
//状态
|
|||
|
|
if ($user_gold < $ext['meet']) {
|
|||
|
|
$reslut['gift_box_list'][$key]['status'] = 0;
|
|||
|
|
$reslut['gift_box_list'][$key]['status_str'] = '未解锁';
|
|||
|
|
} else {
|
|||
|
|
$reslut['gift_box_list'][$key]['status'] = 1;
|
|||
|
|
$reslut['gift_box_list'][$key]['status_str'] = '已解锁('.$reslut['gift_box_list'][$key]['taday_number'].'/'.$ext['num'].')';
|
|||
|
|
}
|
|||
|
|
if ($reslut['gift_box_list'][$key]['taday_number']>=$ext['num']) {
|
|||
|
|
$reslut['gift_box_list'][$key]['status'] = 2;
|
|||
|
|
$reslut['gift_box_list'][$key]['status_str'] = '已用完('.$reslut['gift_box_list'][$key]['taday_number'].'/'.$ext['num'].')';
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//任务列表
|
|||
|
|
$reslut['tasks']['daily_tasks'] = [];//每日任务1
|
|||
|
|
$reslut['tasks']['daily_tasks_special'] = [];//每日特殊任务2
|
|||
|
|
$reslut['tasks']['usual_tasks'] = [];//平台常规任务3
|
|||
|
|
$data = db::name('vs_daily_tasks')
|
|||
|
|
->field('task_id,icon,task_name,gold_reward,target_quantity,task_type')
|
|||
|
|
->where('delete_time',0)
|
|||
|
|
->where('is_active',1)
|
|||
|
|
->order('sort asc')->select();
|
|||
|
|
foreach ($data as $k => $v) {
|
|||
|
|
//完成进度
|
|||
|
|
if(in_array($v['task_type'],[1,2])){
|
|||
|
|
//今日完成进度
|
|||
|
|
$user_daily_tasks = Db::name('vs_user_daily_tasks')
|
|||
|
|
->where('user_id',$user_id)
|
|||
|
|
->where('task_id',$v['task_id'])
|
|||
|
|
->whereTime('createtime', 'today')
|
|||
|
|
->find();
|
|||
|
|
}else{
|
|||
|
|
$user_daily_tasks = Db::name('vs_user_daily_tasks')->where('user_id',$user_id)->where('task_id',$v['task_id'])->find();
|
|||
|
|
}
|
|||
|
|
$progress = isset($user_daily_tasks['current_progress']) ? $user_daily_tasks['current_progress'] : 0;
|
|||
|
|
$quantity_str = "";
|
|||
|
|
if($v['target_quantity']!=1){
|
|||
|
|
$quantity_str= "({$progress}/{$v['target_quantity']})";
|
|||
|
|
}
|
|||
|
|
$v['task_name'] = $v['task_name'].$quantity_str;
|
|||
|
|
//处理状态
|
|||
|
|
$v['task_status'] = 1;
|
|||
|
|
$v['task_type_str'] = "去完成";
|
|||
|
|
if(isset($user_daily_tasks['is_completed']) && $user_daily_tasks['is_completed'] ==1){ //已完成
|
|||
|
|
$v['task_status'] = 2;
|
|||
|
|
$v['task_type_str'] = "领取金币";
|
|||
|
|
}
|
|||
|
|
if(isset($user_daily_tasks['is_claimed']) && $user_daily_tasks['is_claimed'] ==1){ //已完成
|
|||
|
|
$v['task_status'] = 3;
|
|||
|
|
$v['task_type_str'] = "已领取";
|
|||
|
|
}
|
|||
|
|
if($v['task_id']==1){//每日签到处理
|
|||
|
|
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'sign_in_date'=>date('Y-m-d')])->find();
|
|||
|
|
if ($sign_in_info) {
|
|||
|
|
$v['task_status'] =3;
|
|||
|
|
$v['task_type_str'] = "已签到";
|
|||
|
|
}else{
|
|||
|
|
$v['task_status'] = 1;
|
|||
|
|
$v['task_type_str'] = "去签到";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$v['from_id'] = 0;
|
|||
|
|
$v['is_time'] = 0;
|
|||
|
|
if(in_array($v['task_id'],[8,9])){
|
|||
|
|
$v['processing_type'] = 2;
|
|||
|
|
$v['processing_type_str'] = $this->processing_type_str[$v['processing_type']];
|
|||
|
|
//跳转的房间路径
|
|||
|
|
$v['from_id'] = db::name('vs_room')->where(['delete_time'=>0,'room_status'=>1,'type_id'=>['<>',6]])->orderRaw('rand()')->value('id');
|
|||
|
|
$v['target_quantity'] = $v['target_quantity'] * 60;
|
|||
|
|
$v['is_time'] = 1;
|
|||
|
|
}elseif(in_array($v['task_id'],[10])){
|
|||
|
|
$v['processing_type'] = 7;
|
|||
|
|
$v['processing_type_str'] = $this->processing_type_str[$v['processing_type']];
|
|||
|
|
$v['from_id'] = db::name('vs_room')->where(['delete_time'=>0,'room_status'=>1,'type_id'=>['<>',6]])->orderRaw('rand()')->value('id');
|
|||
|
|
} else{
|
|||
|
|
$v['processing_type'] = 9;
|
|||
|
|
$v['processing_type_str'] = $this->processing_type_str[$v['processing_type']];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//分类回显
|
|||
|
|
if ($v['task_type']==1) {
|
|||
|
|
$reslut['tasks']['daily_tasks'][] = $v;
|
|||
|
|
}elseif ($v['task_type']==2) {
|
|||
|
|
$reslut['tasks']['daily_tasks_special'][] = $v;
|
|||
|
|
}else{
|
|||
|
|
$reslut['tasks']['usual_tasks'][] = $v;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
return ['code' => 1, 'msg' => '获取成功', 'data' => $reslut];
|
|||
|
|
}
|
|||
|
|
//完成每日任务
|
|||
|
|
public function tasks_complete($user_id,$task_id){
|
|||
|
|
//查询任务
|
|||
|
|
$task_info = Db::name('vs_daily_tasks')->where('task_id',$task_id)->where('delete_time',0)->where('is_active',1)->find();
|
|||
|
|
if(empty($task_info)){
|
|||
|
|
return ['code' => 0, 'msg' => '任务不存在或已删除','data' => null];
|
|||
|
|
}
|
|||
|
|
//查询用户每日任务进度表
|
|||
|
|
if($task_info['task_type']==3){
|
|||
|
|
$user_daily_tasks = Db::name('vs_user_daily_tasks')->where('user_id',$user_id)->where('task_id',$task_id)->find();
|
|||
|
|
}else{
|
|||
|
|
$user_daily_tasks = Db::name('vs_user_daily_tasks')->where('user_id',$user_id)->where('task_id',$task_id)->whereTime('createtime', 'today')->find();
|
|||
|
|
}
|
|||
|
|
if ($user_daily_tasks && $user_daily_tasks['is_completed'] == 1) {
|
|||
|
|
return ['code' => 0, 'msg' => '您已完成该任务','data' => null];
|
|||
|
|
}
|
|||
|
|
//判断是是否是赠送礼包任务
|
|||
|
|
if($task_info['bag_id'] != 0){
|
|||
|
|
//暂未开发
|
|||
|
|
}
|
|||
|
|
if ($user_daily_tasks) {
|
|||
|
|
$current_progress = $user_daily_tasks['current_progress'] +1;
|
|||
|
|
$is_completed = 0;
|
|||
|
|
if($task_info['target_quantity']==$current_progress){
|
|||
|
|
$is_completed = 1;
|
|||
|
|
}
|
|||
|
|
$reslut = Db::name('vs_user_daily_tasks')->where('id',$user_daily_tasks['id'])->update([
|
|||
|
|
'current_progress' => $current_progress,
|
|||
|
|
'is_completed'=> $is_completed,
|
|||
|
|
]);
|
|||
|
|
}else{
|
|||
|
|
$is_completed = 0;
|
|||
|
|
if($task_info['target_quantity'] == 1){
|
|||
|
|
$is_completed = 1;
|
|||
|
|
}
|
|||
|
|
$reslut = Db::name('vs_user_daily_tasks')->insert([
|
|||
|
|
'user_id' => $user_id,
|
|||
|
|
'task_id' => $task_id,
|
|||
|
|
'current_progress' => 1,
|
|||
|
|
'gold_reward' => $task_info['gold_reward'],
|
|||
|
|
'is_completed' => $is_completed,
|
|||
|
|
'createtime' => time(),
|
|||
|
|
]);
|
|||
|
|
}
|
|||
|
|
if ($reslut) {
|
|||
|
|
if($is_completed==1){
|
|||
|
|
//每日任务直接领取奖励
|
|||
|
|
if($task_id==1){
|
|||
|
|
$this->daily_tasks_receive($user_id,$task_id);
|
|||
|
|
}
|
|||
|
|
return ['code' => 1, 'msg' => '操作成功','data' => ['is_completed'=>1]];
|
|||
|
|
}else{
|
|||
|
|
return ['code' => 1, 'msg' => '操作成功','data' => ['is_completed'=>0]];
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//领取每日任务金币奖励
|
|||
|
|
public function daily_tasks_receive($user_id,$task_id){
|
|||
|
|
$task_info = Db::name('vs_daily_tasks')->where('task_id',$task_id)->find();
|
|||
|
|
if (!$task_info) {
|
|||
|
|
return ['code' => 0, 'msg' => '任务不存在','data' => null];
|
|||
|
|
}
|
|||
|
|
if($task_info['task_type']==3){
|
|||
|
|
$user_daily_tasks = Db::name('vs_user_daily_tasks')->where('user_id',$user_id)->where('task_id',$task_id)->find();
|
|||
|
|
}else{
|
|||
|
|
$user_daily_tasks = Db::name('vs_user_daily_tasks')->where('user_id',$user_id)->where('task_id',$task_id)->whereTime('createtime', 'today')->find();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!$user_daily_tasks) {
|
|||
|
|
return ['code' => 0, 'msg' => '请完成该任务','data' => null];
|
|||
|
|
}
|
|||
|
|
if ($user_daily_tasks['is_completed'] == 0) {
|
|||
|
|
return ['code' => 0, 'msg' => '请完成该任务','data' => null];
|
|||
|
|
}
|
|||
|
|
if ($user_daily_tasks['is_claimed'] == 1) {
|
|||
|
|
return ['code' => 0, 'msg' => '您已领取该奖励','data' => null];
|
|||
|
|
}
|
|||
|
|
Db::startTrans();
|
|||
|
|
try {
|
|||
|
|
$reslut = Db::name('vs_user_daily_tasks')->where('id',$user_daily_tasks['id'])->update([
|
|||
|
|
'is_claimed' => 1,
|
|||
|
|
'updatetime' => time(),
|
|||
|
|
]);
|
|||
|
|
if ($reslut) {
|
|||
|
|
//操作用户金币
|
|||
|
|
$res = model('common/UserWallet')->change_user_money($user_id, $user_daily_tasks['gold_reward'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::DAILY_TASKS_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::DAILY_TASKS_REWARD)."( ".$task_info['task_name'].")");
|
|||
|
|
if ($res['code'] != 1) {
|
|||
|
|
Db::rollback();
|
|||
|
|
return ['code' => 0, 'msg' => $reslut['msg'], 'data' => null];
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
Db::rollback();
|
|||
|
|
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
|||
|
|
}
|
|||
|
|
// 提交事务
|
|||
|
|
Db::commit();
|
|||
|
|
return ['code' => 1, 'msg' => "领取成功", 'data' => null];
|
|||
|
|
}catch (\Exception $e) {
|
|||
|
|
// 回滚事务
|
|||
|
|
Db::rollback();
|
|||
|
|
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
* 开启礼盒
|
|||
|
|
* $user_id 用户id
|
|||
|
|
* $gift_box_id 礼盒id
|
|||
|
|
*/
|
|||
|
|
public function open_gift_box($user_id,$gift_box_id){
|
|||
|
|
$gift_box_info = Db::name('vs_gift_bag')->where('id',$gift_box_id)->find();
|
|||
|
|
if (!$gift_box_info) {
|
|||
|
|
return ['code' => 0, 'msg' => '礼盒不存在','data' => null];
|
|||
|
|
}
|
|||
|
|
$ext = json_decode($gift_box_info['ext'],true);
|
|||
|
|
$gift_bag_receive_num = Db::name('vs_gift_bag_receive_log')->where('user_id',$user_id)->where('gift_bag_id',$gift_box_id)->whereTime('createtime', 'today')->count();
|
|||
|
|
if ($gift_bag_receive_num >= $ext['num']) {
|
|||
|
|
return ['code' => 0, 'msg' => '您已领取该礼盒','data' => null];
|
|||
|
|
}
|
|||
|
|
//查询礼盒详情
|
|||
|
|
$user_gift_box_details = db::name("vs_gift_bag_detail")->where('gift_bag_id',$gift_box_id)->orderRaw('rand()')->find();
|
|||
|
|
if (!$user_gift_box_details) {
|
|||
|
|
return ['code' => 0, 'msg' => '礼盒不存在','data' => null];
|
|||
|
|
}
|
|||
|
|
Db::startTrans();
|
|||
|
|
try {
|
|||
|
|
switch ($user_gift_box_details['type']) {
|
|||
|
|
case 1: //金币 方法1:直接添加到用户钱包
|
|||
|
|
$res = model('common/UserWallet')->change_user_money($user_id, $user_gift_box_details['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::GIFT_BOX_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::GIFT_BOX_REWARD));
|
|||
|
|
$return_data['gift_name']= "恭喜获得".$user_gift_box_details['gold']."金币";
|
|||
|
|
break;
|
|||
|
|
case 2: //礼物 方法2:添加到用户礼物背包
|
|||
|
|
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$user_gift_box_details['foreign_id'],$user_gift_box_details['quantity'],model('UserGiftPack')::GIFT_PACK_GET,$gift_box_info['name']);
|
|||
|
|
$return_data['gift_name']= "恭喜获得".$user_gift_box_details['quantity']."X".$user_gift_box_details['name'];
|
|||
|
|
break;
|
|||
|
|
case 3: //坐骑 方法3:添加到用户装扮
|
|||
|
|
$res = model('Decorate')->pay_decorate($user_id,$user_gift_box_details['foreign_id'],$user_gift_box_details['days'],3);
|
|||
|
|
$return_data['gift_name']= "恭喜获得".$user_gift_box_details['quantity']."天".$user_gift_box_details['name'];
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
if ($res['code'] != 1) {
|
|||
|
|
Db::rollback();
|
|||
|
|
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
|||
|
|
}
|
|||
|
|
//添加礼盒记录
|
|||
|
|
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
|
|||
|
|
'user_id' => $user_id,
|
|||
|
|
'gift_bag_id' => $gift_box_id,
|
|||
|
|
'parent_id' => $user_gift_box_details['id'],
|
|||
|
|
'gift_id' => $user_gift_box_details['foreign_id'],
|
|||
|
|
'num' => $user_gift_box_details['quantity'],
|
|||
|
|
'gift_price' => $user_gift_box_details['gold'],
|
|||
|
|
'bag_price' => $ext['meet'],
|
|||
|
|
'createtime' => time(),
|
|||
|
|
'updatetime' => time()
|
|||
|
|
]);
|
|||
|
|
if ($reslut) {
|
|||
|
|
// 提交事务
|
|||
|
|
Db::commit();
|
|||
|
|
return ['code' => 1, 'msg' => '操作成功','data' => $return_data];
|
|||
|
|
} else {
|
|||
|
|
Db::rollback();
|
|||
|
|
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
|||
|
|
}
|
|||
|
|
}catch (\Exception $e) {
|
|||
|
|
// 回滚事务
|
|||
|
|
Db::rollback();
|
|||
|
|
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
* 礼盒记录
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
public function gift_bag_receive_list($user_id){
|
|||
|
|
//查询每日任务礼盒记录
|
|||
|
|
$gift_bag_receive_list = Db::name('vs_gift_bag_receive_log')
|
|||
|
|
->field('bag.name as gift_bag_name,de.name as gift_name,re.createtime as createtime,de.quantity,de.type,de.foreign_id,de.days,de.gold')
|
|||
|
|
->alias('re')
|
|||
|
|
->join('vs_gift_bag bag', 'bag.id = re.gift_bag_id', 'LEFT')
|
|||
|
|
->join('vs_gift_bag_detail de', 'de.gift_bag_id = re.gift_bag_id','LEFT')
|
|||
|
|
->where(['re.user_id'=>$user_id,'bag.activities_id'=>2,'bag.status'=>1])
|
|||
|
|
->order('re.createtime desc')
|
|||
|
|
->select();
|
|||
|
|
if (!$gift_bag_receive_list) {
|
|||
|
|
return ['code' => 0, 'msg' => '没有礼盒记录','data' => null];
|
|||
|
|
}
|
|||
|
|
$result = [];
|
|||
|
|
foreach ($gift_bag_receive_list as $k=>$v){
|
|||
|
|
$result[$k]['gift_bag_name'] = $v['gift_bag_name'];
|
|||
|
|
if($v['type'] == 1){
|
|||
|
|
$result[$k]['gift_name'] = $v['gold'].'金币';
|
|||
|
|
}elseif ($v['type'] == 2){
|
|||
|
|
$result[$k]['gift_name'] = $v['gift_name'].' x '.$v['quantity'];
|
|||
|
|
}elseif ($v['type'] == 3){
|
|||
|
|
$result[$k]['gift_name'] = $v['gift_name'].' x '.$v['days'].'天';
|
|||
|
|
}
|
|||
|
|
$result[$k]['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
|||
|
|
}
|
|||
|
|
return ['code' => 1, 'msg' => '操作成功','data' => $result];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
* 用户签到
|
|||
|
|
*/
|
|||
|
|
public function sign_in($user_id){
|
|||
|
|
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'sign_in_date'=>date('Y-m-d')])->find();
|
|||
|
|
if ($sign_in_info) {
|
|||
|
|
return ['code' => 0, 'msg' => '今天已经签到过了','data' => null];
|
|||
|
|
}
|
|||
|
|
Db::startTrans();
|
|||
|
|
try {
|
|||
|
|
//每日签到 【完成任务】
|
|||
|
|
$this->tasks_complete($user_id,1);
|
|||
|
|
//判断连续签到
|
|||
|
|
$continuous = 1;
|
|||
|
|
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id])->order('id desc')->find();
|
|||
|
|
if ($sign_in_info) {
|
|||
|
|
if ($sign_in_info['sign_in_date'] == date('Y-m-d',strtotime('-1 day'))) {
|
|||
|
|
$continuous = $sign_in_info['continuous'] + 1;
|
|||
|
|
} else {
|
|||
|
|
$continuous = 1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if($continuous>1){
|
|||
|
|
//连续签到任务送金币
|
|||
|
|
//连续签到7天 【完成任务】
|
|||
|
|
//$this->tasks_complete($user_id,2);
|
|||
|
|
//连续签到任务抽礼包【完成任务】
|
|||
|
|
//连续签到7天 【完成任务】
|
|||
|
|
//$this->tasks_complete($user_id,7);
|
|||
|
|
}
|
|||
|
|
$reslut = Db::name('vs_user_tasks_sign_in')->insert([
|
|||
|
|
'user_id' => $user_id,
|
|||
|
|
'sign_in_date' => date('Y-m-d'),
|
|||
|
|
'continuous' => $continuous,
|
|||
|
|
'createtime' => time(),
|
|||
|
|
'updatetime' => time()
|
|||
|
|
]);
|
|||
|
|
if ($reslut) {
|
|||
|
|
// 提交事务
|
|||
|
|
Db::commit();
|
|||
|
|
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
|||
|
|
} else {
|
|||
|
|
Db::rollback();
|
|||
|
|
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
|||
|
|
}
|
|||
|
|
} catch (\Exception $e) {
|
|||
|
|
// 回滚事务
|
|||
|
|
Db::rollback();
|
|||
|
|
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/*
|
|||
|
|
* 今日签到状态
|
|||
|
|
*/
|
|||
|
|
public function daily_tasks_sign_in_status($user_id){
|
|||
|
|
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'sign_in_date'=>date('Y-m-d')])->find();
|
|||
|
|
$result = [];
|
|||
|
|
if ($sign_in_info) {
|
|||
|
|
$result['status'] = 1;
|
|||
|
|
$result['status_str'] = "已签到";
|
|||
|
|
}else{
|
|||
|
|
$result['status'] = 0;
|
|||
|
|
$result['status_str'] = "未签到";
|
|||
|
|
}
|
|||
|
|
return ['code' => 1, 'msg' => '成功','data' => $result];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|