250 lines
12 KiB
PHP
250 lines
12 KiB
PHP
<?php
|
|
/**
|
|
* Notes:博
|
|
* Created on: 2021/8/10 17:41
|
|
* Created by: dengbw
|
|
*/
|
|
require_once APPPATH . 'libraries/bobing/Base.class.php';
|
|
|
|
class Bo extends Base
|
|
{
|
|
private $appConfig = array();
|
|
private $carGoldAry = array(1 => '100', 2 => '100', 3 => '150', 4 => '100', 5 => '150', 6 => '100', 7 => '150');
|
|
private $dicesAry = array(1 => array(1, 3, 6, 1, 1, 5), 2 => array(6, 5, 3, 1, 2, 5), 3 => array(3, 3, 3, 6, 5, 5)
|
|
, 4 => array(6, 3, 1, 2, 2, 3), 5 => array(5, 5, 6, 3, 6, 6), 6 => array(5, 2, 3, 5, 6, 3));//罚黑随机数组
|
|
|
|
public function __construct()
|
|
{
|
|
$this->ci->load->model('bobing/bobing_user_model');
|
|
$this->ci->load->model('bobing/bobing_user_credit_model');
|
|
$this->ci->load->model('bobing/bobing_logs_model');
|
|
$this->appConfig = $this->ci->bobing_user_model->appConfig();
|
|
}
|
|
|
|
/**
|
|
* Notes:开桌博饼
|
|
* Created on: 2021/8/10 17:41
|
|
* Created by: dengbw
|
|
* @return mixed
|
|
*/
|
|
public function kz_bo()
|
|
{
|
|
if ($this->valid_nums <= 0) {
|
|
$content = '<div>您的博饼次数已经用完啦~</div><div>立即邀请好友助力博饼,</div><div>获得更多购车金,</div><div>冲击汽车大奖!!!</div>';
|
|
$popup = array('title' => '邀请好友', 'content' => $content, 'btn' => array('title' => '立即邀请', 'url' => '/bobing/pages/game/invite/index'));
|
|
return array('status' => 1, 'popup' => $popup);
|
|
}
|
|
$data['app_id'] = $this->appConfig['app_id'];
|
|
$data['act_key'] = $this->appConfig['act_key'];
|
|
$data['uid'] = $this->uid;
|
|
$this->ci->load->library('bobing/dice');
|
|
$this->ci->dice->init();
|
|
$dices = $this->ci->dice->getResultArr();
|
|
$level = $this->ci->dice->getResultLevel();
|
|
$credit = $this->ci->dice->getcredit($level);
|
|
$level_name = $this->ci->dice->getResultName();
|
|
$re_u = $this->ci->bobing_user_model->get(array('app_id' => $data['app_id'], 'act_key' => $data['act_key'], 'uid' => $this->uid));
|
|
if ($this->car_id == 15 && $level >= 6) {//ex1用户博到状元时设为罚黑
|
|
$dices = $this->dicesAry[rand(1, 6)];
|
|
$level = $credit = 0;
|
|
$level_name = '罚黑';
|
|
}
|
|
$data['dices'] = implode(',', $dices);
|
|
$data['level'] = $level;
|
|
$data['credit'] = $credit;
|
|
$data['bo_date'] = date('Y-m-d');
|
|
$data['ip'] = get_client_ip();
|
|
$data['ua'] = $_SERVER['HTTP_USER_AGENT'];
|
|
$data['type'] = 0;
|
|
$data['c_time'] = time();
|
|
$popup = '';
|
|
if ($re_u['car_gold'] < $this->appConfig['max_car_gold']) {//购车金小于购车金设定值
|
|
if ($this->appConfig['ratio_car_gold_kz'] && $this->appConfig['ratio_car_gold_kz'] <= rand(1, 5)) {//购车金概率
|
|
//$car_gold = $this->carGoldAry[rand(1, 7)];
|
|
$car_gold = rand(25, 35);
|
|
if (($car_gold + $re_u['car_gold']) > $this->appConfig['max_car_gold']) {//如果购车金大于设定值,那么本次增加到最大值
|
|
$car_gold = $this->appConfig['max_car_gold'] - $re_u['car_gold'];
|
|
}
|
|
$data['car_gold'] = $car_gold;
|
|
$all_car_gold = $car_gold + $re_u['car_gold'] + $re_u['buy_car_gold'] + $re_u['lotter_gold'];
|
|
$content = '<div>博到 ' . $car_gold . ' 元购车金!</div><div><br></div><div>您已累计博得</div><div> ' . $all_car_gold . ' 元购车金</div>';
|
|
$popup = array('title' => '恭喜您', 'content' => $content, 'btn' => array('title' => '立即使用购车金', 'url' => '/bobing/pages/game/signUp/index'));
|
|
}
|
|
}
|
|
$re_l = $this->add_log($data);
|
|
if ($re_l['status'] == 1) {
|
|
return array('status' => API_CODE_FAIL, 'content' => '博饼日志添加失败');
|
|
}
|
|
$data['level_name'] = $level_name;
|
|
$data['status'] = 0;
|
|
$data['lid'] = $re_l['lid'];
|
|
$data['popup'] = $popup;
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Notes:助力博饼
|
|
* Created on: 2021/8/12 17:13
|
|
* Created by: dengbw
|
|
* @return mixed
|
|
*/
|
|
public function zl_bo()
|
|
{
|
|
$data['app_id'] = $this->appConfig['app_id'];
|
|
$data['act_key'] = $this->appConfig['act_key'];
|
|
$data['uid'] = $this->cf_uid;
|
|
$data['cf_uid'] = $this->uid;
|
|
if ($this->valid_nums <= 0) {
|
|
$re_u = $this->ci->bobing_user_model->get(array('app_id' => $data['app_id'], 'act_key' => $data['act_key'], 'uid' => $this->uid));
|
|
$credit = intval($re_u['credit']);
|
|
$content = '<div>您已获得' . $credit . '积分,</div><div>立即开桌获得更多幸运分,</div><div>冲刺购物卡、苹果手机、汽车大奖</div>';
|
|
$popup = array('title' => '开桌', 'content' => $content, 'btn' => array('title' => '立即开桌', 'url' => '/bobing/pages/index/index'));
|
|
return array('status' => 2, 'popup' => $popup);
|
|
}
|
|
$this->ci->load->library('bobing/dice');
|
|
$this->ci->dice->init();
|
|
$dices = $this->ci->dice->getResultArr();
|
|
$level = $this->ci->dice->getResultLevel();
|
|
$credit = $this->ci->dice->getcredit($level);
|
|
$level_name = $this->ci->dice->getResultName();
|
|
$re_u = $this->ci->bobing_user_model->get(array('app_id' => $data['app_id'], 'act_key' => $data['act_key'], 'uid' => $data['uid']));
|
|
if ($this->car_id == 15 && $level >= 6) {//ex1用户博到状元时设为罚黑
|
|
$dices = $this->dicesAry[rand(1, 6)];
|
|
$level = $credit = 0;
|
|
$level_name = '罚黑';
|
|
}
|
|
$data['dices'] = implode(',', $dices);
|
|
$data['level'] = $level;
|
|
$data['credit'] = $credit;
|
|
$data['bo_date'] = date('Y-m-d');
|
|
$data['ip'] = get_client_ip();
|
|
$data['ua'] = $_SERVER['HTTP_USER_AGENT'];
|
|
$data['type'] = 1;
|
|
$popup = '';
|
|
if ($re_u['car_gold'] < $this->appConfig['max_car_gold']) {//购车金小于购车金设定值
|
|
if ($this->appConfig['ratio_car_gold_zl'] && $this->appConfig['ratio_car_gold_zl'] == rand(1, 3)) {//购车金概率
|
|
//$car_gold = $this->carGoldAry[rand(1, 7)];
|
|
$car_gold = rand(40, 60);
|
|
if (($car_gold + $re_u['car_gold']) > $this->appConfig['max_car_gold']) {//如果购车金大于设定值,那么本次增加到最大值
|
|
$car_gold = $this->appConfig['max_car_gold'] - $re_u['car_gold'];
|
|
}
|
|
$data['car_gold'] = $car_gold;
|
|
$content = '<div>帮助好友博到' . $car_gold . '元购车金和' . $data['credit'] . '幸运分,</div><div>您的好友离汽车大奖更进一步了!</div>';
|
|
$popup = array('title' => '恭喜您', 'content' => $content, 'btn' => array('title' => '我也要开桌博取汽车大奖'
|
|
, 'url' => '/bobing/pages/index/index'));
|
|
}
|
|
}
|
|
$hong_bao_day = $this->ci->bobing_user_model->hongBaoDay($data['act_key']);
|
|
if (!$data['car_gold'] && ($hong_bao_day < $this->appConfig['hong_bao_day'])) {//无购车金时抽红包与红包小于每日设定值
|
|
if ($this->appConfig['ratio_hong_bao'] && $this->appConfig['ratio_hong_bao'] >= rand(1, 100)) {//红包概率
|
|
$re_l = $this->ci->bobing_logs_model->get(array('app_id' => $data['app_id'], 'act_key' => $data['act_key'], 'uid' => $data['uid']
|
|
, 'cf_uid' => $data['cf_uid'], 'hong_bao >' => 0));
|
|
if (!$re_l) {//帮博时只能在一个用户上中一次红包
|
|
$hong_bao = '0.3'; //'0.' . rand(30, 68);//0.30到0.68红包
|
|
$data['hong_bao'] = $hong_bao;
|
|
$data['status'] = 1;
|
|
$this->ci->bobing_user_model->hongBaoDay($data['act_key'], $hong_bao);
|
|
}
|
|
}
|
|
}
|
|
$log = $this->add_log($data);
|
|
if ($log['status'] == 1) {
|
|
return array('status' => API_CODE_FAIL, 'content' => '博饼日志添加失败');
|
|
}
|
|
$data['level_name'] = $level_name;
|
|
$data['status'] = 0;
|
|
$data['lid'] = $log['lid'];
|
|
$data['popup'] = $popup;
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Notes:添加企业微信加购车金
|
|
* Created on: 2021/8/25 10:04
|
|
* Created by: dengbw
|
|
*/
|
|
public function wxqy_car_gold()
|
|
{
|
|
$where = array('app_id' => $this->appConfig['app_id'], 'act_key' => $this->appConfig['act_key'], 'uid' => $this->uid);
|
|
$re_u = $this->ci->bobing_user_model->get($where);
|
|
if (!$re_u) {
|
|
return array('status' => -1, 'content' => '未参加博饼');
|
|
}
|
|
$re_l = $this->ci->bobing_logs_model->get(array_merge($where, array('type' => 2)));
|
|
if ($re_l) {
|
|
return array('status' => -1, 'content' => '已添过企业微信加购车金了');
|
|
}
|
|
$data['app_id'] = $this->appConfig['app_id'];
|
|
$data['act_key'] = $this->appConfig['act_key'];
|
|
$data['uid'] = $this->uid;
|
|
$data['credit'] = 0;
|
|
$data['car_gold'] = $this->appConfig['wxqy_nums'];
|
|
$data['bo_date'] = date('Y-m-d');
|
|
$data['ip'] = get_client_ip();
|
|
$data['ua'] = $_SERVER['HTTP_USER_AGENT'];
|
|
$data['type'] = 2;
|
|
$data['c_time'] = time();
|
|
$log = $this->add_log($data);
|
|
if ($log['status'] == 1) {
|
|
return array('status' => -1, 'content' => '博饼日志添加失败');
|
|
}
|
|
return array('status' => $log['lid'], 'content' => '企业微信加购车金成功');
|
|
}
|
|
|
|
//博饼结果保存到数据库
|
|
private function add_log($data)
|
|
{
|
|
$_data['status'] = 0;
|
|
$this->ci->bobing_logs_model->db->trans_begin();
|
|
try {
|
|
$lid = $this->ci->bobing_logs_model->add($data);
|
|
if ($lid) {
|
|
$map = array('act_key' => $data['act_key'], 'app_id' => $data['app_id'], 'uid' => $data['uid']);
|
|
$up_data["credit = credit+{$data['credit']}"] = null;//加积分
|
|
if ($data['type'] == 2) {//加企业微信
|
|
$up_data["wxqy"] = 1;
|
|
$up_data["buy_car_gold"] = $data['car_gold'];
|
|
} else {
|
|
$data['car_gold'] && $up_data["car_gold = car_gold+{$data['car_gold']}"] = null;//加购车金
|
|
}
|
|
$this->ci->bobing_user_model->update($up_data, $map);
|
|
$map['bo_date'] = $data['bo_date'];
|
|
$re_c = $this->ci->bobing_user_credit_model->get($map);
|
|
if ($re_c) {
|
|
$this->ci->bobing_user_credit_model->update(array("credit = credit+{$data['credit']}" => null), $map);
|
|
} else {
|
|
$map['credit'] = $data['credit'];
|
|
$map['c_time'] = time();
|
|
$this->ci->bobing_user_credit_model->add($map);
|
|
}
|
|
//助力加分
|
|
if ($data['type'] == 1) {
|
|
$map_my = array('act_key' => $data['act_key'], 'app_id' => $data['app_id'], 'uid' => $data['cf_uid']);
|
|
$this->ci->bobing_user_model->update(array("credit = credit+{$data['credit']}" => null), $map_my);
|
|
$map_my['bo_date'] = $data['bo_date'];
|
|
$re_c = $this->ci->bobing_user_credit_model->get($map_my);
|
|
if ($re_c) {
|
|
$this->ci->bobing_user_credit_model->update(array("credit = credit+{$data['credit']}" => null), $map_my);
|
|
} else {
|
|
$map_my['credit'] = $data['credit'];
|
|
$map_my['c_time'] = time();
|
|
$this->ci->bobing_user_credit_model->add($map_my);
|
|
}
|
|
}
|
|
$this->ci->bobing_user_model->boNums($data['act_key'], 1);
|
|
}
|
|
$_data['lid'] = $lid;
|
|
} catch (Exception $e) {
|
|
$this->ci->bobing_logs_model->db->trans_rollback();
|
|
$_data['status'] = 1;
|
|
return $_data;
|
|
}
|
|
if ($this->ci->bobing_logs_model->db->trans_status() === FALSE) {
|
|
$this->ci->bobing_logs_model->db->trans_rollback();
|
|
$_data['status'] = 1;
|
|
return $_data;
|
|
}
|
|
$this->ci->bobing_logs_model->db->trans_commit();
|
|
return $_data;
|
|
}
|
|
} |