Init Repo

This commit is contained in:
root
2019-09-06 23:53:10 +08:00
commit f0ef89dfbb
7905 changed files with 914138 additions and 0 deletions

View File

@ -0,0 +1,81 @@
<?php
namespace wstmart\common\model;
use Think\Db;
/**
* ============================================================================
* 惠宝业务处理器
*/
class UserScores extends Base{
/**
* 获取列表
*/
public function pageQuery($userId){
$type = (int)input('post.type');
$where = ['userId'=>(int)$userId];
if($type!=-1)$where['scoreType'] = $type;
$page = $this->where($where)->order('scoreId desc')->paginate()->toArray();
foreach ($page['Rows'] as $key => $v){
$page['Rows'][$key]['dataSrc'] = WSTLangScore($v['dataSrc']);
}
return $page;
}
/**
* 新增记录
*/
public function add($score,$isAddTotal = false){
$score['createTime'] = date('Y-m-d H:i:s');
$this->create($score);
$user = model('common/users')->get($score['userId']);
if($score['scoreType']==1){//收入
$user->userScore = $user->userScore + $score['score'];
if($isAddTotal)$user->userTotalScore = $user->userTotalScore+$score['score'];
}else{
$user->userScore = $user->userScore - $score['score'];
}
$userinfo = session('WST_USER');
$userinfo['userScore'] = $user->userScore;
session('WST_USER',$userinfo);
$user->save();
}
/**
*签到获得惠宝
*/
public function signScore($userId){
$time = date('Y-m-d');
$frontTime = date("Y-m-d",strtotime("-1 day"));
if(WSTConf('CONF.signScoreSwitch')==0)return WSTReturn("签到失败");
$userscores = $this->where(["userId"=>$userId,"dataSrc"=>5,])->order('createTime desc')->find();
if(!$userscores || date("Y-m-d",strtotime($userscores['createTime']))!=$time){//没签过或最后一次签到不是今天
$rs = Db::name('users')->where(["userId"=>$userId])->field('userScore')->find();
$days = $score = 0;
$days = (date("Y-m-d",strtotime($userscores['createTime']))==$frontTime)?($userscores['dataId']==30)?$userscores['dataId']:$userscores['dataId']+1:1;//是昨天签到的第30天返回天数不然返回天数+1不是昨天签到的返回第一天
$signScore = explode(",",WSTConf('CONF.signScore'));//返回天数每天的惠宝
if($signScore[0]!=0){
$score = $signScore[$days-1];//天数对应的惠宝
}
$data['totalScore'] = $rs['userScore'] + $score;//用户惠宝+签到送的分
$data['score'] = $score;
if($score>0){
//添加
$userinfo = session('WST_USER');
$userinfo['signScoreTime'] = $time;
session('WST_USER',$userinfo);
$uscore = [];
$uscore['userId'] = $userId;
$uscore['score'] = $score;
$uscore['dataSrc'] = 5;
$uscore['dataId'] = $days;
$uscore['dataRemarks'] = "连续".$days."天签到,获得惠宝".$score."";
$uscore['scoreType'] = 1;
$this->add($uscore,true);
return WSTReturn("签到第".$days."天,获得".$score."个惠宝",1,$data);
}else{
return WSTReturn("签到失败");
}
}else{
return WSTReturn("已签到,明天再来");
}
}
}