Files
liche/api/controllers/plan/Bobing.php
T
2021-09-14 16:30:15 +08:00

195 lines
8.2 KiB
PHP

<?php
/**
* Notes:博饼任务
* Created on: 2021/8/20 17:15
* Created by: dengbw
*/
class Bobing extends HD_Controller
{
private $log_file;
private $appConfig;
public function __construct()
{
parent::__construct();
$this->log_file = 'bobing.log';
$this->load->model('bobing/bobing_user_model', 'mdBobingUser');
$this->load->model('bobing/bobing_user_credit_model', 'mdBobingUserCredit');
$this->load->model('bobing/bobing_logs_model', 'mdBobingLogs');
$this->appConfig = $this->mdBobingUser->appConfig();
}
public function index()
{
}
/**
* Notes:设置每日中奖
* Created on: 2021/8/27 17:20
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/bobing/lottery
* https://api.liche.cn/plan/bobing/lottery
*/
public function lottery()
{
$params = $this->input->get();
$hour = date('H');
if ($hour != '00' && !$params['sd']) {
echo '[0]点过后才会开奖昨天的中奖用户[' . $hour . ']';
return;
}
if ($this->appConfig['game_start_date'] > date('Y-m-d H:i')) {
echo '博饼未开始';
return;
}
$game_end_date = date('Y-m-d H:i', strtotime('-1 day'));
if ($this->appConfig['game_end_date'] < $game_end_date) {
echo '博饼已结束';
return;
}
$date = date('Y-m-d', strtotime('-1 day'));//中奖用户
$where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'bo_date' => $date, 'lottery' => 1);
$re = $this->mdBobingUserCredit->get($where);
if ($re) {
echo '[' . $date . ']已执行过中奖了';
return;
}
$where['lottery'] = 0;
$where['credit >'] = 0;
$where['uid not in(select uid from lc_bobing_user_credit where app_id = ' . $this->appConfig['app_id']
. ' and act_key = ' . $this->appConfig['act_key'] . ' and lottery= 1)'] = null;
$res_c = $this->mdBobingUserCredit->select($where, 'credit desc,u_time asc', 1, $this->appConfig['lottery_nums'], 'id,uid,credit');
if ($res_c) {//设置中奖用户
foreach ($res_c as $key => $value) {
//设中奖
$this->mdBobingUserCredit->update(array('lottery' => 1), array('id' => $value['id']));
//加中奖购车金
$this->mdBobingUser->update(array('lotter_gold' => $this->appConfig['lotter_gold'])
, array('uid' => $value['uid'], 'app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key']));
}
$lottery = json_encode($res_c, JSON_UNESCAPED_UNICODE);
debug_log('lottery:' . $lottery, $this->log_file);
echo json_encode($lottery, JSON_UNESCAPED_UNICODE);
return;
}
}
/**
* Notes:马甲总积分跑分数
* Created on: 2021/9/8 11:59
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/bobing/mj
* https://api.liche.cn/plan/bobing/mj
*/
public function mj()
{
$params = $this->input->get();
if ($params['sd']) {
$date = $params['date'] ? $params['date'] : date('Y-m-d');
$hong_bao_day = $this->mdBobingLogs->sum('hong_bao', array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key']
, 'bo_date' => $date, 'status' => 2));
echo $date . '_发放红包' . $hong_bao_day['hong_bao'] . '元';
return;
}
$hour = date('H');
if ($hour < 9 || $hour > 22) {
echo '9点到22点博';
return;
}
if ($this->appConfig['game_start_date'] > date('Y-m-d H:i')) {
echo '博饼未开始';
return;
}
if ($this->appConfig['game_end_date'] < date('Y-m-d H:i')) {
echo '博饼已结束';
return;
}
$uid = 1;
$credits = array(1 => 30, 2 => 50, 3 => 60, 4 => 70, 5 => 50, 6 => 30, 7 => 60, 8 => 30);
$credit = $credits[rand(1, 8)];
$where = array('uid' => $uid, 'app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key']);
$ret = $this->mdBobingUser->update(array("credit = credit+{$credit}" => null), $where);
if ($ret) {
$where['bo_date'] = date('Y-m-d');
$re_u = $this->mdBobingUserCredit->get($where);
if ($re_u) {
$this->mdBobingUserCredit->update(array("credit = credit+{$credit}" => null), $where);
} else {
$where['credit'] = $credit;
$where['c_time'] = time();
$this->mdBobingUserCredit->add($where);
}
echo 'uid(' . $uid . ')本次加了' . $credit;
} else {
echo 'uid(' . $uid . ')本次加分失败了';
}
}
/**
* Notes:马甲每日积分跑分数
* Created on: 2021/9/14 11:59
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/bobing/mj_day
* https://api.liche.cn/plan/bobing/mj_day
*/
public function mj_day()
{
$hour = date('H');
if ($hour < 9 || $hour > 22) {
echo '9点到22点博';
return;
}
if ($this->appConfig['game_start_date'] > date('Y-m-d H:i')) {
echo '博饼未开始';
return;
}
if ($this->appConfig['game_end_date'] < date('Y-m-d H:i')) {
echo '博饼已结束';
return;
}
$uids = array(
'2021-09-14' => [3007, 3008, 3009, 3010, 3011], '2021-09-15' => [3012, 3013, 3014, 3015, 3016],
'2021-09-16' => [3017, 3018, 3019, 3020, 3021], '2021-09-17' => [3022, 3023, 3024, 3025, 3026],
'2021-09-18' => [3027, 3028, 3029, 3030, 3031], '2021-09-19' => [3032, 3033, 3034, 3035, 3036],
'2021-09-20' => [3037, 3038, 3039, 3040, 3041], '2021-09-21' => [3042, 3043, 3044, 3045, 3046],
'2021-09-22' => [3047, 3048, 3049, 3050, 3051], '2021-09-23' => [3052, 3053, 3054, 3055, 3056],
'2021-09-24' => [3057, 3058, 3059, 3060, 3061], '2021-09-25' => [3062, 3063, 3064, 3065, 3066],
'2021-09-26' => [3067, 3068, 3069, 3070, 3071], '2021-09-27' => [3072, 3073, 3074, 3075, 3076],
'2021-09-28' => [3077, 3078, 3079, 3080, 3081], '2021-09-29' => [3082, 3083, 3084, 3085, 3086],
'2021-09-30' => [3087, 3088, 3089, 3090, 3091], '2021-10-01' => [3092, 3093, 3094, 3095, 3096],
'2021-10-02' => [3097, 3098, 3099, 3100, 3101], '2021-10-03' => [3102, 3103, 3104, 3105, 3106],
'2021-10-04' => [3107, 3108, 3109, 3110, 3111], '2021-10-05' => [3112, 3113, 3114, 3115, 3116],
'2021-10-06' => [3117, 3118, 3119, 3120, 3121], '2021-10-07' => [3122, 3123, 3124, 3125, 3126],
'2021-10-08' => [3127, 3128, 3129, 3130, 3131]);
$credits = array(1 => 30, 2 => 50, 3 => 60, 4 => 70, 5 => 50, 6 => 30, 7 => 20, 8 => 15);
$date = date('Y-m-d');
$uids_day = $uids[$date];
foreach ($uids_day as $key => $value) {
$where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key']);
$uid = $value;
$credit = $credits[rand(1, 8)];
$where['uid'] = $uid;
$re_bu = $this->mdBobingUser->get($where);
if ($re_bu) {
$this->mdBobingUser->update(array("credit = credit+{$credit}" => null), $where);
} else {
$addUser = array_merge($where, array('c_time' => time(), 'credit' => $credit));
$this->mdBobingUser->add($addUser);
}
$where['bo_date'] = date('Y-m-d');
$re_u = $this->mdBobingUserCredit->get($where);
if ($re_u) {
$this->mdBobingUserCredit->update(array("credit = credit+{$credit}" => null), $where);
} else {
$where['credit'] = $credit;
$where['c_time'] = time();
$this->mdBobingUserCredit->add($where);
}
echo 'uid(' . $uid . ')本次加了:' . $credit . ',今天总分:' . ($re_u['credit'] + $credit) . '<br>';
}
}
}