|
@@ -2,6 +2,27 @@
|
|
|
|
|
|
class SvenModel extends CI_Model
|
|
class SvenModel extends CI_Model
|
|
{
|
|
{
|
|
|
|
+ public $wheelRewards = [
|
|
|
|
+ 0 => [ 'propsId' => 18, 'num' => 1, 'pro' => 10, 'cnt' => 10, 'skin' => 0 ],
|
|
|
|
+ 1 => [ 'propsId' => 19, 'num' => 1, 'pro' => 100, 'cnt' => 0, 'skin' => 342 ],
|
|
|
|
+ 2 => [ 'propsId' => 15, 'num' => 500, 'pro' => 120, 'cnt' => 0 , 'skin' => 0 ],
|
|
|
|
+ 3 => [ 'propsId' => 61, 'num' => 1, 'pro' => 40, 'cnt' => 6, 'skin' => 0 ],
|
|
|
|
+ 4 => [ 'propsId' => 19, 'num' => 1, 'pro' => 40, 'cnt' => 8, 'skin' => 338 ],
|
|
|
|
+ 5 => [ 'propsId' => 9, 'num' => 1, 'pro' => 150, 'cnt' => 0, 'skin' => 0 ],
|
|
|
|
+ 6 => [ 'propsId' => 15, 'num' => 1500, 'pro' => 60, 'cnt' => 4, 'skin' => 0 ],
|
|
|
|
+ 7 => [ 'propsId' => 19, 'num' => 1, 'pro' => 80, 'cnt' => 3, 'skin' => 336 ],
|
|
|
|
+ 8 => [ 'propsId' => 15, 'num' => 1000, 'pro' => 80, 'cnt' => 2, 'skin' => 0 ],
|
|
|
|
+ 9 => [ 'propsId' => 23, 'num' => 1, 'pro' => 70, 'cnt' => 4, 'skin' => 60 ],
|
|
|
|
+ 10 => [ 'propsId' => 19, 'num' => 1, 'pro' => 100, 'cnt' => 0, 'skin' => 339 ],
|
|
|
|
+ 11 => [ 'propsId' => 8, 'num' => 100000, 'pro' => 150, 'cnt' => 0, 'skin' => 0 ],
|
|
|
|
+ ];
|
|
|
|
+ public $taskRewards = [
|
|
|
|
+ 1 => [ 'propsId' => 15, 'num' => 10, 'finishedCnt' => 10,], // 分享
|
|
|
|
+ 2 => [ 'propsId' => 15, 'num' => 50, 'finishedCnt' => 1,], // 登录
|
|
|
|
+ 3 => [ 'propsId' => 15, 'num' => 500, 'finishedCnt' => 5,], // 邀请注册
|
|
|
|
+ 4 => [ 'propsId' => 15, 'num' => 500, 'finishedCnt' => 5,], // 完成支付
|
|
|
|
+ ];
|
|
|
|
+
|
|
static function sendRewardToEmail($msgId, $uid, array $rewards, $days = 7){
|
|
static function sendRewardToEmail($msgId, $uid, array $rewards, $days = 7){
|
|
$tb = otable::userSysMail($uid);
|
|
$tb = otable::userSysMail($uid);
|
|
$key = okeys::sysMsgGet($uid);
|
|
$key = okeys::sysMsgGet($uid);
|
|
@@ -479,4 +500,169 @@ class SvenModel extends CI_Model
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 用户每日体力消耗
|
|
|
|
+ public function getUserDailySpinsUsed($uid){
|
|
|
|
+ $date = date('Ymd',CURRENT_TIMESTAMP);
|
|
|
|
+ $rkey = okeys::userDayData($date, $uid);
|
|
|
|
+ $hkey = 'cost_spin';
|
|
|
|
+ return oo::commonOprRedis('statistics')->hGet($rkey, $hkey);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 用户支付数据[cnt => 0, money=>0] 订单数,总金额
|
|
|
|
+ public function getUserPayments($uid, $begin, $end){
|
|
|
|
+ $begin = date('Y-m-d', $begin);
|
|
|
|
+ $end = date('Y-m-d', $end);
|
|
|
|
+ $orderTable = otable::gameOrder();
|
|
|
|
+ $sql = "select * from {$orderTable} where uid={$uid} and created_at >= '{$begin}' and created_at < '{$end}' and status = 4";
|
|
|
|
+ $payments = oo::commonOprDb('slavedb')->getAll($sql);
|
|
|
|
+ $paymentMoneys = array_map(function($v){return $v['price'];}, $payments);
|
|
|
|
+ return [
|
|
|
|
+ 'cnt' => count($payments),
|
|
|
|
+ 'money' => array_sum($paymentMoneys)
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 用户邀请数
|
|
|
|
+ public function getUserInvite($uid, $begin, $end){
|
|
|
|
+ $inviteTable = otable::AdJustData();
|
|
|
|
+ $label = base64_encode($uid);
|
|
|
|
+ $sql = "select count(1) as cnt from {$inviteTable} where label={$label} and created_at >= {$begin} and created_at < {$end}";
|
|
|
|
+ $inviteTotal = oo::commonOprDb('slavedb')->getOne($sql);
|
|
|
|
+ return intval($inviteTotal['cnt']);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 转盘数据
|
|
|
|
+ public function initWheelData($params){
|
|
|
|
+ $uid = intval($params['uid']);
|
|
|
|
+ if(!$uid)throw new Exception('Wrong operation!',__LINE__);
|
|
|
|
+ $wheelMax = 2;
|
|
|
|
+ $maxShareTimes = 10;
|
|
|
|
+ $preWheelSpins = 10000;
|
|
|
|
+ $date = date('Ymd',CURRENT_TIMESTAMP);
|
|
|
|
+
|
|
|
|
+ // 最后登陆时间
|
|
|
|
+ $todayBegin = strtotime($date);
|
|
|
|
+ $lastLoginTime = oo::commonOprRedis('games')->get(okeys::lastLoginTime($uid));
|
|
|
|
+ $todayLogin = $lastLoginTime >= $todayBegin;
|
|
|
|
+
|
|
|
|
+ // 查询邀请注册人数
|
|
|
|
+ $inviteNum = $this->getUserInvite($uid, $todayBegin, $todayBegin + 86400);
|
|
|
|
+
|
|
|
|
+ // 支付次数
|
|
|
|
+ $paymentTotal = $this->getUserPayments($uid, $todayBegin, $todayBegin + 86400);
|
|
|
|
+
|
|
|
|
+ // 每日体力消耗
|
|
|
|
+ $spinsUsed = $this->getUserDailySpinsUsed($uid);
|
|
|
|
+
|
|
|
|
+ // 组装返回数据
|
|
|
|
+ $userDataKey = okeys::fansActKey("USER_DATA:{$uid}:{$date}"); // 每日数据
|
|
|
|
+ $userRecordsKey = okeys::fansActKey("USER_RECORDS:{$uid}"); // 已转到的奖励
|
|
|
|
+ $userData = oo::commonOprRedis('games')->hGetAll($userDataKey);
|
|
|
|
+ $userData['wheelRewards'] = oo::commonOprRedis('games')->get($userRecordsKey);
|
|
|
|
+ $userData['shareTimes'] = $userData['shareTimes'] ?? 0;
|
|
|
|
+ $userData['wheelTimes'] = $userData['wheelTimes'] ?? 0;
|
|
|
|
+ $userData['wheelRewards'] = $userData['wheelRewards'] ? explode(',', $userData['wheelRewards']) : [] ?? 0;
|
|
|
|
+ foreach ($this->taskRewards as $idx => $reward){
|
|
|
|
+ $userData["taskRewarded{$idx}"] = $userData["taskRewarded{$idx}"] ?? 0 ; // 任务领奖次数
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $userData["taskFinished1"] = min($userData['shareTimes'], $maxShareTimes) ; // 分享完成次数
|
|
|
|
+ $userData["taskFinished2"] = $todayLogin ? 1 : 0 ; // 登录完成
|
|
|
|
+ $userData["taskFinished3"] = $inviteNum ; // 邀请注册完成
|
|
|
|
+ $userData["taskFinished4"] = intval($paymentTotal['cnt']) ; // 支付完成
|
|
|
|
+ $userData["spinsUsed"] = intval($spinsUsed) ; // 每日体力消耗
|
|
|
|
+ $userData["wheelTotal"] = min($wheelMax, intval(floor($spinsUsed/$preWheelSpins))) ; // 转盘总次数
|
|
|
|
+ $userData["wheelLeft"] = max($userData["wheelTotal"]-$userData["wheelTimes"], 0) ; // 转盘剩余次数
|
|
|
|
+ $userData["dataKey"] = $userDataKey ; // 转盘剩余次数
|
|
|
|
+
|
|
|
|
+ return $userData;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 转动转盘
|
|
|
|
+ public function doWheel($params){
|
|
|
|
+ $uid = intval($params['uid']);
|
|
|
|
+ if(!$uid)throw new Exception('Wrong operation!',__LINE__);
|
|
|
|
+ $date = date('Ymd',CURRENT_TIMESTAMP);
|
|
|
|
+ $preWheelSpins = 10000;
|
|
|
|
+ $spinsUsed = $this->getUserDailySpinsUsed($uid);
|
|
|
|
+ $userDataKey = okeys::fansActKey("USER_DATA:{$uid}:{$date}");
|
|
|
|
+ $userData = oo::commonOprRedis('games')->hGetAll($userDataKey);
|
|
|
|
+ $wheelTimes = intval($userData['wheelTimes']);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $userRecordsKey = okeys::fansActKey("USER_RECORDS:{$uid}");
|
|
|
|
+ $wheelRewards = oo::commonOprRedis('games')->get($userRecordsKey);
|
|
|
|
+ $wheelRewards = $wheelRewards ? explode(',', $wheelRewards) : []; // 已转到的奖励
|
|
|
|
+ $wheelTotal = floor($spinsUsed/$preWheelSpins);
|
|
|
|
+ if($wheelTotal <= $wheelTimes)throw new Exception('Wrong operation!',__LINE__);
|
|
|
|
+ oo::commonOprRedis('games')->hIncrBy($userDataKey, 'wheelTimes', 1);// 旋转次数+1
|
|
|
|
+ $rewards = [];
|
|
|
|
+ $totalProb = 0;
|
|
|
|
+ foreach ($this->wheelRewards as $idx => $reward){
|
|
|
|
+ if ($reward['cnt'] <= $wheelTimes && !in_array($idx, $wheelRewards)){ // 达到旋转次数且未转到过
|
|
|
|
+ $reward['idx'] = $idx;
|
|
|
|
+ $rewards[] = $reward;
|
|
|
|
+ $totalProb += $reward['pro'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $rand = rand(0, $totalProb);
|
|
|
|
+ $prizeIdx = -1;
|
|
|
|
+ foreach ($rewards as $reward){
|
|
|
|
+ $prizeIdx = $reward['idx'];
|
|
|
|
+ $pro = $reward['pro'];
|
|
|
|
+ if($rand <= $pro){
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ $rand-=$pro;
|
|
|
|
+ }
|
|
|
|
+ if(empty($this->wheelRewards[$prizeIdx]))throw new Exception('Wrong operation!'.$prizeIdx,__LINE__);
|
|
|
|
+ $wheelRewards[] = $prizeIdx;
|
|
|
|
+
|
|
|
|
+ oo::commonOprRedis('games')->set($userRecordsKey, implode(',', $wheelRewards));
|
|
|
|
+ oo::commonOprRedis('games')->expire($userDataKey, 86400 * 15);
|
|
|
|
+ oo::commonOprRedis('games')->expire($userRecordsKey, 86400 * 15);
|
|
|
|
+ $rewards = [
|
|
|
|
+ [
|
|
|
|
+ 'propsId' => $this->wheelRewards[$prizeIdx]['propsId'],
|
|
|
|
+ 'num' => $this->wheelRewards[$prizeIdx]['num'],
|
|
|
|
+ 'skin' => $this->wheelRewards[$prizeIdx]['skin'],
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+ self::sendRewardToEmail(691, $uid, $rewards, 7);
|
|
|
|
+ return ['idx' => $prizeIdx];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 日常任务领奖
|
|
|
|
+ public function getDailyTaskReward($params){
|
|
|
|
+ $uid = intval($params['uid']);
|
|
|
|
+ $taskId = intval($params['taskId']);
|
|
|
|
+ if(!$uid)throw new Exception('Wrong operation!',__LINE__);
|
|
|
|
+ if(empty($this->taskRewards[$taskId]))throw new Exception('Wrong operation!',__LINE__);
|
|
|
|
+
|
|
|
|
+ $date = date('Ymd',CURRENT_TIMESTAMP);
|
|
|
|
+ $userDataKey = okeys::fansActKey("USER_DATA:{$uid}:{$date}");
|
|
|
|
+ $userData = $this->initWheelData($params);
|
|
|
|
+ if($userData["taskFinished{$taskId}"] <= $userData["taskRewarded{$taskId}"])throw new Exception('Wrong operation!',__LINE__);
|
|
|
|
+ oo::commonOprRedis('games')->hIncrBy($userDataKey, "taskRewarded{$taskId}", 1); // 领奖数+1
|
|
|
|
+ $rewards = [
|
|
|
|
+ [
|
|
|
|
+ 'propsId' => $this->taskRewards[$taskId]['propsId'],
|
|
|
|
+ 'num' => $this->taskRewards[$taskId]['num'],
|
|
|
|
+ ]
|
|
|
|
+ ];
|
|
|
|
+ self::sendRewardToEmail(690, $uid, $rewards, 7);
|
|
|
|
+ return [];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 分享页面
|
|
|
|
+ public function shareWheel($params){
|
|
|
|
+ $uid = intval($params['uid']);
|
|
|
|
+ if(!$uid)throw new Exception('Wrong operation!',__LINE__);
|
|
|
|
+
|
|
|
|
+ $date = date('Ymd',CURRENT_TIMESTAMP);
|
|
|
|
+ $userDataKey = okeys::fansActKey("USER_DATA:{$uid}:{$date}");
|
|
|
|
+ oo::commonOprRedis('games')->hIncrBy($userDataKey, "shareTimes", 1); // 分享数+1
|
|
|
|
+ return [];
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|