1 line
2.2 KiB
PHP
1 line
2.2 KiB
PHP
<?php
|
|
namespace app\api\controller\food\market;
|
|
|
|
use app\api\controller\food\Controller;
|
|
use app\api\model\food\SignLog as SignLogModel;
|
|
use app\api\model\food\Setting as SettingModel;
|
|
use think\facade\Cache;
|
|
|
|
|
|
/**
|
|
* 签到管理
|
|
*/
|
|
class Sign extends Controller
|
|
{
|
|
private $user;
|
|
|
|
/**
|
|
* 构造方法
|
|
*/
|
|
public function initialize()
|
|
{
|
|
parent::initialize();
|
|
$this->user = $this->getUserDetail(); // 用户信息
|
|
}
|
|
|
|
/**
|
|
* 是否签到
|
|
*/
|
|
public function isSign()
|
|
{
|
|
$model = new SignLogModel;
|
|
$isSign = $model->getIsSign((int)$this->user['user_id']);
|
|
$setting = SettingModel::getItem('sign',$this->applet_id);
|
|
$sign_in=0;
|
|
//如果有签到套餐
|
|
if(sizeof($setting['plan']) > 0){
|
|
$setting['plan'] = array_sort($setting['plan'], 'days');//按照天数从小到大排序
|
|
$sign_in = Cache::get('food_sign_' . $this->user['user_id'] . '_' . $this->applet_id,0);//获取连续签到天数
|
|
foreach($setting['plan'] as $item){
|
|
if($sign_in < $item['days']){
|
|
$plan = [];
|
|
for($n=0;$n<$item['days'];$n++){
|
|
$plan[] = $n+1;
|
|
}
|
|
$setting['plan'] = $plan;
|
|
if($item['type'] == 'score'){
|
|
$title = '个积分';
|
|
}else{
|
|
$title = '元余额';
|
|
}
|
|
$setting['plan_title'] = '连续签到' . $item['days'] . '天,赠送' . $item['number'] . $title;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return $this->renderSuccess(compact('isSign','setting','sign_in'));
|
|
|
|
}
|
|
|
|
/**
|
|
* 签到
|
|
*/
|
|
public function sign()
|
|
{
|
|
$model = new SignLogModel;
|
|
if($model->add(['user_id' => $this->user['user_id']])){
|
|
return $this->renderMsg('签到成功');
|
|
}
|
|
return $this->renderError('签到失败');
|
|
}
|
|
|
|
/**
|
|
* 签到记录
|
|
*/
|
|
public function logs()
|
|
{
|
|
$model = new SignLogModel;
|
|
$list = $model->getList($this->user['user_id']);
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
}
|
|
|