Files
liche/api/controllers/plan/Bobing.php
T
2021-09-09 17:57:43 +08:00

130 lines
4.8 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 = 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 => 80, 6 => 90, 7 => 100, 8 => 120);
$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) {
$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 . ')本次加分失败了';
}
}
}