Files
liche/api/libraries/bobing/Bo.php
T
2021-09-01 09:55:27 +08:00

233 lines
11 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');
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) {
return array('status' => 1, 'title' => '邀请好友', 'content' => '<div>您的博饼次数已用完啦</div><div>立即邀请好友助力博饼,</div><div>冲刺购物卡、苹果手机、汽车大奖</div>');
}
$mc = &load_cache();
$key = 'LiChe_bobing_' . $this->act_key . $this->app_id . $this->uid;
$timeout = $mc->get($key);
if ($timeout && (time() - $timeout) < 2) {
return array('status' => API_CODE_FAIL, 'content' => '您操作太快了,速度越慢越能博到状元,刷新页面再试试');
}
$mc->save($key, time());
$this->ci->load->library('bobing/dice');
$this->ci->dice->init();
$size_result = $this->ci->dice->getResultArr();
$level = $this->ci->dice->getResultLevel();
$data['app_id'] = $this->appConfig['app_id'];
$data['act_key'] = $this->appConfig['act_key'];
$data['uid'] = $this->uid;
$data['dices'] = implode(',', $size_result);
$data['level'] = $level;
$data['credit'] = $this->ci->dice->getcredit($level);
$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();
$content = $title = '';
$re_u = $this->ci->bobing_user_model->get(array('app_id' => $data['app_id'], 'act_key' => $data['act_key'], 'uid' => $this->uid));
if ($re_u['car_gold'] < $this->appConfig['max_car_gold']) {//购车金小于购车金设定值
if ($this->appConfig['ratio_car_gold'] && $this->appConfig['ratio_car_gold'] >= rand(1, 100)) {//购车金概率
$car_gold = $this->carGoldAry[rand(1, 7)];
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 = '您博到购车金' . $car_gold . '元';
$title = '恭喜您';
}
}
$re_l = $this->add_log($data);
if ($re_l['status'] == 1) {
return array('status' => API_CODE_FAIL, 'content' => '博饼日志添加失败');
}
$data['level_name'] = $this->ci->dice->getResultName();
$data['status'] = 0;
$data['lid'] = $re_l['lid'];
$data['title'] = $title;
$data['content'] = $content;
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'];
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']);
return array('status' => 2, 'title' => '立即开桌', 'content' => '<div>您已获得' . $credit . '积分,</div><div>立即开桌获得更多幸运分,</div><div>冲刺购物卡、苹果手机、汽车大奖</div>');
}
$mc = &load_cache();
$key = 'LiChe_bobing_' . $this->act_key . $this->app_id . $this->uid;
$timeout = $mc->get($key);
if ($timeout && (time() - $timeout) < 2) {
return array('status' => API_CODE_FAIL, 'msg' => '您操作太快了,速度越慢越能博到状元,刷新页面再试试');
}
$mc->save($key, time());
$this->ci->load->library('bobing/dice');
$this->ci->dice->init();
$size_result = $this->ci->dice->getResultArr();
$level = $this->ci->dice->getResultLevel();
$data['uid'] = $this->cf_uid;
$data['cf_uid'] = $this->uid;
$data['dices'] = implode(',', $size_result);
$data['level'] = $level;
$data['credit'] = $this->ci->dice->getcredit($level);
$data['bo_date'] = date('Y-m-d');
$data['ip'] = get_client_ip();
$data['ua'] = $_SERVER['HTTP_USER_AGENT'];
$data['type'] = 1;
$content = $title = '';
$re_u = $this->ci->bobing_user_model->get(array('app_id' => $data['app_id'], 'act_key' => $data['act_key'], 'uid' => $data['uid']));
if ($re_u['car_gold'] < $this->appConfig['max_car_gold']) {//购车金小于购车金设定值
if ($this->appConfig['ratio_car_gold'] && $this->appConfig['ratio_car_gold'] >= rand(1, 100)) {//购车金概率
$car_gold = $this->carGoldAry[rand(1, 7)];
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 = '为桌长博到购车金' . $car_gold . '元';
$title = '恭喜您';
}
}
$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']));
if (!$re_l) {//帮博时只能在一个用户上中一次红包
$hong_bao = '0.3'; //'0.' . rand(30, 68);//0.30到0.68红包
$data['hong_bao'] = $hong_bao;
$data['status'] = 1;
$content = '您博到现金红包' . $data['hong_bao'] . '元';
$title = '恭喜您';
$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'] = $this->ci->dice->getResultName();
$data['status'] = 0;
$data['lid'] = $log['lid'];
$data['title'] = $title;
$data['content'] = $content;
return $data;
}
/**
* Notes:添加企业微信加分
* Created on: 2021/8/25 10:04
* Created by: dengbw
*/
public function wxqy_credit()
{
$re_l = $this->ci->bobing_logs_model->get(array('uid' => $this->uid, 'app_id' => $this->appConfig['app_id'], 'type' => 3));
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'] = $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;//加积分
$data['car_gold'] && $up_data["car_gold = car_gold+{$data['car_gold']}"] = null;//加购车金
$data['type'] == 2 && $up_data["wxqy"] = 1;//加企业微信
$this->ci->bobing_user_model->update($up_data, $map);
$map['bo_date'] = $data['bo_date'];
if ($this->ci->bobing_user_credit_model->cache('get', array($map, 'id'))) {
$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'];
if ($this->ci->bobing_user_credit_model->cache('get', array($map_my, 'id'))) {
$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;
}
}