You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

839 lines
32 KiB
PHP

<?php
namespace Admin\Controller;
use Base\Model\PromoteModel;
use Admin\Model\TestResourceModel;
use Base\Service\PromoteService;
use OSS\Core\OssException;
class TestResourceController extends ThinkController
{
public function resources($row = 10, $p = 1)
{
$map = [];
$map['_string'] = " status <> 2 and type=1 and attachment_url = ''";
if (I('server_id')) {
$map['server_id'] = I('server_id');
}
if (I('game_id')) {
$map['game_id'] = I('game_id');
}
$havMap = "1=1";
if (I('resource_num_start')) {
$start = I('resource_num_start');
$havMap .= " and (total_resource_num >= '{$start}' or apply_num >= '{$start}')";
}
if (I('resource_num_end')) {
$end = I('resource_num_end');
$havMap .= " and (total_resource_num <= '{$end}' or apply_num <= '{$end}')";
}
$list = M('work_order_info', 'tab_')
->field("user_account, game_name, server_name, role_name, sum(resource_num) as total_resource_num, sum(if(status=1, resource_num, 0)) as apply_num, tab_user.phone")
->join('tab_user on tab_user.account = tab_work_order_info.user_account')
->where($map)
->page($p, $row)
->group('user_account, game_name, server_name, role_name')
->having($havMap)
->order("created_time desc")
->select();
//echo M('work_order_info', 'tab_')->getLastSql();exit;
$count = M('work_order_info', 'tab_')->where($map)->group('user_account, game_name, server_name, role_name')->count();
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);
}
$this->checkListOrCountAuthRestMap($map,[]);
$show_data_power = (is_administrator()|| session('user_auth')['show_data']);
$this->assign('show_data_power', $show_data_power);
$this->assign('list_data', $list);
$this->display('resources');
}
public function test(){
echo 'test1';
}
public function supportNumberList($p = 1) {
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
$map = [];
if(!empty(I('server_name'))){
$map['tab_test_resource.server_name']=I('server_name');
}
if(!empty(I('game_name'))){
$map['tab_test_resource.game_name']=I('game_name');
}
if(!empty(I('role_name'))){
$map['tab_test_resource.role_name']=['like','%'.I('role_name').'%'];
}
if(!empty(I('user_account'))){
$map['tab_test_resource.user_account']=['like','%'.I('user_account').'%'];
}
if(!empty(I('promote_id')) || I('promote_id')=="0"){
$promote_id = I('promote_id');
$promnote_arr = M("promote","tab_")->field("id")->where("chain like '%/{$promote_id}/%'")->select();
$promnote_arr = array_column($promnote_arr,"id");
array_push($promnote_arr,$promote_id);
$promnote_arr = implode(",",$promnote_arr);
$map['tab_test_resource.promote_id']=['in',$promnote_arr];
if (!I("promote_level")) {
$map['tab_test_resource.promote_id']=I('promote_id');
}
}
//为数据权限添加
setPowerPromoteIds($map, 'tab_test_resource.promote_id');
$data = M('test_resource','tab_')
->field('tab_test_resource.id,tab_test_resource.user_id,tab_test_resource.game_name,tab_test_resource.server_name,tab_test_resource.user_account,tab_test_resource.promote_account,tab_test_resource.role_name,tab_test_resource.create_time,device_number,lock_status as check_status')
->join('left join tab_user as user on tab_test_resource.user_id = user.id')
->where($map)
->page($page,$row)
->order('tab_test_resource.create_time DESC')
->select();
// var_dump($data);die();
foreach ($data as $key => $value) {
$data[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']);
($data[$key]['promote_account']=='官方渠道')?($data[$key]['promote_account']=C('OFFICIEL_CHANNEL')):'';
}
$count = M('test_resource','tab_')
->field('tab_test_resource.game_name,tab_test_resource.server_name,tab_test_resource.user_account,tab_test_resource.promote_account,tab_test_resource.role_name,tab_test_resource.create_time,device_number,lock_status as check_status')
->join('left join tab_user as user on tab_test_resource.user_id = user.id')
->where($map)
->select();
$count = count($count);
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->meta_title = '资源管理';
$this->assign('data',$data);
$show_data_power = (is_administrator()|| session('user_auth')['show_data']);
$this->assign('show_data_power', $show_data_power);
$this->display();
}
public function batchFreeze() {
if (I('id','')) {
$id =I('id','');
} else {
$this->error('请选择资源后再进行操作');
$this->ajaxReturn(['status'=>0, 'msg'=> '请选择资源后再进行操作']);
}
if (!I('status','')&&I('status','')!='0') {
$this->ajaxReturn(['status'=>0, 'msg'=> '请选择状态后在进行操作']);
// $this->error('请选择状态后在进行操作');
}
// $resourceData = M('test_resource','tab_')
// ->field("promote_id")
// ->where(['id'=>['in',$id]])
// ->select();
//
// $resourceData = array_column($resourceData,'promote_id');
// $promoteId = [];
//
// foreach ($resourceData as $key => $value) {
//
// $promoteData = M('promote','tab_')
// ->field('id')
// ->where("chain like '%/{$value}/%' or id = {$value}")
// ->select();
// $promoteId = array_merge($promoteData, $promoteId);
// }
// $promoteId = array_unique($resourceData);
// var_dump($promoteId);die();
$testResource = M('test_resource','tab_')
->field("user_id")
->where(['id'=>['in',$id]])
->group('user_id')
->select();
$data = [
'lock_status' => I('status','')
];
$user_id = implode(',',array_column($testResource,'user_id'));
$isFreeze = M('user','tab_')->where(['id'=>['in',$user_id]])->save($data);
if ($isFreeze) {
// $this->success('操作成功',U('supportNumberList'));
$this->ajaxReturn(['status'=>1, 'msg'=> '操作成功']);
} else {
$this->ajaxReturn(['status'=>0, 'msg'=> '操作失败']);
// $this->error('操作失败',U('supportNumberList'));
}
}
public function freezeSupport() {
$supportId = I('support_id', 0);
if ($supportId == 0) {
$this->ajaxReturn(['status'=>0,'msg'=>"参数错误"]);
}
$data = [
'lock_status' => 0
];
$isFreeze = M('user','tab_')->where("id=".$supportId)->save($data);
if ($isFreeze) {
$userData = M('user','tab_')->where("id=".$supportId)->find();
addOperationLog(['op_type'=>1,'key'=>$userData['account'],'op_name'=>'编辑冻结账号','url'=>U('StatementMangement/lists'),'menu'=>'推广员-测试资源-扶持号管理-冻结账号']);
$this->ajaxReturn(['status'=>1, 'msg'=> '冻结成功']);
} else {
$this->ajaxReturn(['status'=>0, 'msg'=> '冻结失败']);
}
}
public function unfreezeSupport() {
$supportId = I('support_id', 0);
if ($supportId == 0) {
$this->ajaxReturn(['status'=>0,'msg'=>"参数错误"]);
}
$data = [
'lock_status' => 1
];
$isFreeze = M('user','tab_')->where("id=".$supportId)->save($data);
if ($isFreeze) {
$userData = M('user','tab_')->where("id=".$supportId)->find();
addOperationLog(['op_type'=>1,'key'=>$userData['account'],'op_name'=>'编辑解冻账号','url'=>U('StatementMangement/lists'),'menu'=>'推广员-测试资源-扶持号管理-解冻账号']);
$this->ajaxReturn(['status'=>1, 'msg'=> '启用成功']);
} else {
$this->ajaxReturn(['status'=>0, 'msg'=> '启用失败']);
}
}
public function rechangePassward() {
$supportId = I('support_id', 0);
if ($supportId == 0) {
$this->ajaxReturn(['status'=>0,'msg'=>"参数错误"]);
}
$password = $this->getRandomPassword(6);
$data = [
'password' => md5(sha1($password) . UC_AUTH_KEY)
];
$passward = M('user','tab_')->where("id=".$supportId)->save($data);
if ($passward) {
$userData = M('user','tab_')->where("id=".$supportId)->find();
addOperationLog(['op_type'=>1,'key'=>$userData['account'],'op_name'=>'编辑重置密码','url'=>U('StatementMangement/lists'),'menu'=>'推广员-测试资源-扶持号管理-重置密码']);
$this->ajaxReturn(['status'=>1, 'msg'=> '新密码:'.$password]);
} else {
$this->ajaxReturn(['status'=>0, 'msg'=> '重置密码失败']);
}
}
private function getRandomPassword($length, $special = true){
$chars = array(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9'
);
// if($special){
// $chars = array_merge($chars, array(
// '!', '@', '#', '$', '?', '|', '{', '/', ':', ';',
// '%', '^', '&', '*', '(', ')', '-', '_', '[', ']',
// '}', '<', '>', '~', '+', '=', ',', '.'
// ));
// }
$charsLen = count($chars) - 1;
shuffle($chars);
$password = '';
for($i=0; $i<$length; $i++){
$password .= $chars[mt_rand(0, $charsLen)];
}
return $password;
}
public function protectLogList($p = 1) {
$promote_id = get_pid();
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
$map = [];
if(!empty(I('server_name'))){
$map['server_name']=I('server_name');
}
if(!empty(I('game_name'))){
$map['game_name']=I('game_name');
}
if(!empty(I('nickname'))){
$map['nickname']=['like','%'.I('nickname').'%'];
}
if(!empty(I('user_account'))){
$map['user_account']=I('user_account');
}
if(!empty($_REQUEST['start'])&&empty($_REQUEST['end'])){
$map['create_time'] = array('GT',strtotime($_REQUEST['start']));
unset($_REQUEST['start']);
}
if(empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){
$map['create_time'] = array('LT',strtotime($_REQUEST['end'])+24*60*60-1);
unset($_REQUEST['end']);
}
if(!empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){
$map['create_time'] = array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1));
unset($_REQUEST['start']);unset($_REQUEST['end']);
}
if(!empty(I('types'))){
$map['type']=I('types');
}
$field = 'id,game_name,server_name,user_account,nickname,promote_account,detail';
$order = 'id DESC';
$data = D('protect_log')->getProtectLog($field,$map,'',$order,$page,$row);
$count = D('protect_log')->getProtectLog($field,$map,'',$order);
M('protect_log_read', 'tab_')->startTrans(); //事物
try {
$arrUserId = array_column($data,'id');
$logId = implode(',',$arrUserId);
if ($logId) {
$logRead = M('protect_log_read','tab_')
->where("log_id IN({$logId})")
->select();
}
else {
$logRead = [];
}
$upsetData = array_column($logRead,'log_id');
$addData = [];
$k = 0;
foreach($arrUserId as $key => $value) {
if (in_array($value,$upsetData)) {
continue;
} else {
$addData[$k]['log_id'] = $value;
$addData[$k]['promote_id'] = $promote_id;
$addData[$k]['create_time'] = time();
$k++;
}
}
M('protect_log_read','tab_')->addAll($addData);
} catch (OssException $e) {
M('protect_log_read', 'tab_')->rollback();//回滚
}
M('protect_log_read', 'tab_')->commit(); //提交事物
foreach($data as $key => $value) {
($data[$key]['promote_account']=='官方渠道')?($data[$key]['promote_account']=C('OFFICIEL_CHANNEL')):'';
}
$count = count($count);
$page = set_pagination($count,$row);
$this->meta_title = '日志管理';
if($page) {$this->assign('_page', $page);}
$this->assign('data',$data);
$this->display();
}
protected function _initialize()
{
parent::_initialize();
$map['id'] = get_pid();
$pro = M("promote", "tab_")->where($map)->find();
if ($pro['parent_id']!=0) {
$this->error('无权操作!');
}
}
public function index($p=0)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
$map =array();
if(!empty(I('role_name'))){
$map['role_name']=['like','%'.I('role_name').'%'];
}
if(!empty(I('server_name'))){
$map['server_name']=I('server_name');
}
if(!empty(I('game_name'))){
$map['game_name']=I('game_name');
}
if(!empty(I('user_account'))){
$map['user_account']=['like','%'.I('user_account').'%'];
}
if(!empty($_REQUEST['start'])&&empty($_REQUEST['end'])){
$map['create_time'] = array('GT',strtotime($_REQUEST['start']));
unset($_REQUEST['start']);
}
if(empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){
$map['create_time'] = array('LT',strtotime($_REQUEST['end'])+24*60*60-1);
unset($_REQUEST['end']);
}
if(!empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){
$map['create_time'] = array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1));
unset($_REQUEST['start']);unset($_REQUEST['end']);
}
if(!empty($_REQUEST['promote_id'])||$_REQUEST['promote_id']=='0') {
$map['tab_test_resource.promote_id']=I('promote_id');
}
//
$res = D("test_resource")->getResourceCout($map,$page,$row);
foreach ($res['list'] as $key=>&$value) {
($value['promote_account']=='官方渠道')?($value['promote_account']=C('OFFICIEL_CHANNEL')):'';
}
// dump($res);
$parameter =I('get.');
$parameter['p']=I('get.p',1);
$parameter['row']=I('get.row');
$page = set_pagination($res["count"],$row,$parameter);
if($page) {$this->assign('_page', $page);}
// var_dump($res['list']);die();
$this->meta_title = '测试资源';
$this->m_title = '测试资源申请';
$this->assign('data',$res['list']);
$this->assign('count',$res["count"]);
$this->display();
# code...
}
/**
* 获取区服列表
* @param $game_id
*/
public function getServer($game_id="")
{
$map['game_id']=$game_id;
$map['start_time']=['lt',time()];
if (I('status')==2) {
$map['show_status']=1;
}
$data = M('server', 'tab_')
->field('tab_server.id,tab_server.server_name,support_quota')
->where($map)
->join('join tab_game tg ON tg.id=tab_server.game_id')
->select();
$this->AjaxReturn($data);
}
/**
* 系统非常规MD5加密方法
* @param string $str 要加密的字符串
* @return string
*/
public function think_ucenter_md5($str, $key = 'ThinkUCenter'){
return '' === $str ? '' : md5(sha1($str) . $key);
}
//新增扶持
public function add()
{
// dump(I('post.'));
if (IS_POST) {
$count=count(I('user_account'));
session('apply_status', 0);
(empty(I('server_id')) || I('server_id')<1) && $this->error('请选择区服!');;
M()->startTrans(); //事物
$resource = 0;
for ($i=0; $i < $count ; $i++) {
$i_account=I('user_account')[$i];
if (!empty($i_account)) {
$user=M('user', 'tab_')->field('promote_id,promote_account,password,phone')->where(['account'=>$i_account])->find();
if (!$user) {
M('test_resource', 'tab_')->rollback();//回滚
$this->error($i_account.'账号不存在');
}
if (empty(I('user_password')[$i])) {
M('test_resource', 'tab_')->rollback();//回滚
$this->error(I('user_account')[$i].'请输入密码');
}
if ($user['password']!=$this->think_ucenter_md5(I('user_password')[$i], UC_AUTH_KEY)) {
M('test_resource', 'tab_')->rollback();//回滚
$this->error($i_account.'密码不正确');
}
if (empty(I('role_name')[$i])) {
M('test_resource', 'tab_')->rollback();//回滚
$this->error(I('user_account')[$i].'请输入角色名');
}
$supportNum = I('apply_resource')[$i];
if (empty($supportNum)) {
M('test_resource', 'tab_')->rollback();//回滚
$this->error(I('user_account')[$i].'请输入资源数量');
}
if ($supportNum<0 || !preg_match('/^[1-9]\d*$/', $supportNum)) {
M('test_resource', 'tab_')->rollback();//回滚
$this->error(I('user_account')[$i].'请输入资源数量');
}
$map['game_id']=I('game_id');
$map['server_id']=I('server_id');
$map['user_account']=I('user_account')[$i];
// $map['apply_status']=['neq',0];
$map['apply_type']=0;
$list= M('test_resource', 'tab_')->where($map)->find();
// dump($list);die();
if ($list) {
M('test_resource', 'tab_')->rollback();//回滚
$this->error(I('user_account')[$i].'账号已存在');
}
// $support_quota = M('game', 'tab_')->field('support_quota')->find(get_game_id(I('game_name')));
// if ($support_quota['support_quota'] < I('support_num')[$i]) {
// M('test_resource', 'tab_')->rollback();//回滚
// $this->ajaxReturn(['msg'=>'超出申请额度' ,'status'=>0]);
// }
$data['game_id']=I('game_id');
$data['game_name']=I('game_name');
$data['server_id']=I('server_id');
$data['server_name']=I('server_name');
$data['user_account']=I('user_account')[$i];
$data['user_id']=get_user_id(I('user_account')[$i]);
$data['user_password']=base64_encode(I('user_password')[$i]);
$data['phone']=$user['phone'];
$data['role_name']=I('role_name')[$i];
$data['apply_resource']=I('apply_resource')[$i];
$data['apply_remark']=I('apply_remark')[$i];
$data['apply_name']=$user['promote_account'];
$data['apply_id']=$user['promote_id'];
// $data['promote_id']=session("promote_auth.pid");
// $data['promote_account']=session("promote_auth.account");
$data['promote_id']=$user['promote_id'];
$data['promote_account']=$user['promote_account'];
$data['create_time']=time();
$data['apply_type']=0;
$data = $this->checkAutoVerify($data, $resource, 0);
$model = M('test_resource', 'tab_')->add($data);
$resource += $data['apply_resource'];
if ($model) {
session('apply_status', 1);
}
} else {
if (I('user_password')[$i]) {
M('test_resource', 'tab_')->rollback();//回滚
$this->error('请输入账号');
}
}
addOperationLog(['op_type'=>0,'key'=>$i_account.'/'.I('game_name').'/'.I('server_name'),'op_name'=>'新增测试账号','url'=>U('testResource/index'),'menu'=>'推广员-测试资源-测试资源申请-新增测试账号']);
}
if (session('apply_status')==0) {
session('apply_status', null);
$this->error('请输入账号');
}
M('test_resource', 'tab_')->commit(); //提交事物
$this->success('添加成功',U('TestResource/index'));
} else {
$this->meta_title = '新增测试账号';
$this->display();
}
}
/**
*判断申请资源是否自动审核
* @param $data array 新增数据
* @param $resource int 此次已申请资源
* @param $thisCount int 批量申请的第几次
*/
private function checkAutoVerify($data, $resource = 0, $thisCount = 0)
{
$config = M('resource_verify_config', 'tab_')
->where(['game_id' => $data['game_id'], 'status' => 1])
->find();
if ($config) {//已存在该游戏的资源审核配置
// var_dump($config);die();
$count = M('test_resource', 'tab_')
->where(['user_id' => $data['user_id'], 'game_id' => $data['game_id']])
->count();
$count += $thisCount;
if ($count < $config['new_apply_count']) {//新用户
//申请资源数量在最低额度和最高额度之间,自动审核
if ($data['apply_resource'] >= $config['new_low_value'] && $data['apply_resource'] <= $config['new_high_value']) {
$data['verify_remark'] = '自动审核';
$data['verify_resource']= $data['apply_resource'];
$data['verify_time'] = time();
$data['apply_status'] = 2;
$data['is_new'] = 1;
}
} else {//非新用户
$availableBalance = getAvailableBalance($data['promote_id'],$data['game_id'],$data['server_name']);
// var_dump($availableBalance);die();
$promoteAllRecharge = sum_promote_total_money($data['promote_id']);//总充值量
$allVerifyValue = $promoteAllRecharge * $config['old_value_ratio'];//可充值总量
//已用资源(申请通过的)
$used_resource = M('test_resource', 'tab_')
->where([
'promote_id' => $data['promote_id'],
'game_id' => $data['game_id'],
'apply_status' => 2,
'is_new' => 2,
])
->getField('SUM(verify_resource) as used_resource');
$used_resource = $used_resource ?: 0;
$usable_resource = $allVerifyValue - $used_resource;//小于等于这个值自动审核
$usable_resource -= $resource;
if ($data['apply_resource'] <= $usable_resource&&$data['apply_resource']<=$availableBalance) {
$data['verify_remark'] = '自动审核';
$data['verify_resource']= $data['apply_resource'];
$data['verify_time'] = time();
$data['apply_status'] = 2;
$data['is_new'] = 2;
M('promote_game_available_balance','tab_')
->where(['promote_id'=>$data['promote_id'],'game_id'=>$data['game_id'],'server_name'=>$data['server_name']])
->setDec('available_balance',$data['apply_resource']);
}
}
}
return $data;
}
public function edit() {
$id = I('id');
//获取数据
$data = M('test_resource','tab_')->where("id={$id}")->find();
if (!$data) {
$this->error('数据不存在!');
exit();
}
$this->assign('data', $data);
$this->meta_title = '编辑礼包';
$this->m_title = '礼包列表';
$this->display();
}
//修改申请
public function apply_edit(){
$user=M('user','tab_')->field('password')->where(['account'=>I('user_account')])->find();
if($user['password'] !== $this->think_ucenter_md5(I('user_password'), UC_AUTH_KEY)){
$this->error('修改失败,密码不正确!');
}
$data['user_password']=base64_encode(I('user_password'));
$data['role_name']=I('role_name');
$map = I("post.");
unset($map['user_password']);
unset($map['role_name']);
$res=M('test_resource','tab_')->where($map)->save($data);
if($res===false){
$this->error('更新失败');
}else{
$userData = M('test_resource','tab_')->where($map)->find();
addOperationLog(['op_type'=>1,'key'=>$userData['user_account'].'/'.$userData['game_name'].'/'.$userData['server_name'],'op_name'=>'测试资源申请编辑','url'=>U('TestResource/edit',['id'=>$userData['id']]),'menu'=>'推广员-测试资源-测试资源申请-测试资源申请编辑']);
$this->success('更新成功', U('index'));
}
}
//后续申请
public function apply(){
$ids = explode(',', I('id'));
foreach ($ids as $key => $value) {
$map['id']=$value;
$support=M('test_resource','tab_')->field('promote_id')->where($map)->find();
// if($support['promote_id'] !=session("promote_auth.pid") || empty($support) ){
// $this->error('数据错误');
// }
}
$this->m_title = '推广员列表';
$this->meta_title = '申请后续';
$this->display();
}
//申请新增扶持(单个或批量申请)
public function batch_apply(){
$ids = explode(',', I('id'));
M()->startTrans(); //事物
$resource = 0;
foreach ($ids as $key => $value) {
$map['id']=$value;
$support=M('test_resource','tab_')->where($map)->find();
if(I('apply_resource') <0 || !preg_match('/^[1-9]\d*$/', I('apply_resource', 0))){
M('test_resource','tab_')->rollback();//回滚
$this->error('申请资源数量有误');
}
if(empty($support)){
M('test_resource','tab_')->rollback();//回滚
$this->error('数据有误');
}
$data['game_id']=$support['game_id'];
$data['game_name']=$support['game_name'];
$data['server_id']=$support['server_id'];
$data['server_name']=$support['server_name'];
$data['user_account']=$support['user_account'];
$data['user_id']=$support['user_id'];
$data['user_password']=$support['user_password'];
$data['phone']=$support['phone'];
$data['role_name']=$support['role_name'];
$data['apply_resource']=I('apply_resource');
$data['apply_remark']=I('apply_remark');
$data['apply_name']=$support['promote_account'];
$data['apply_id']=$support['promote_id'];
// $data['promote_id']=session("promote_auth.pid");
// $data['promote_account']=session("promote_auth.account");
$data['promote_id']=$support['promote_id'];
$data['promote_account']=$support['promote_account'];
$data['create_time']=time();
$data['apply_type']=1;
$data = $this->checkAutoVerify($data, $resource, $key);
//
$model = M('test_resource','tab_')->add($data);
$resource += $data['apply_resource'];
if($model===false){
M('test_resource','tab_')->rollback();//回滚
$this->error('申请失败');
}else{
//成功
}
addOperationLog(['op_type'=>0,'key'=>$support['user_account'].'/'.$support['game_name'].'/'.$support['server_name'],'op_name'=>'测试资源申请后续','url'=>U('TestResource/apply',['id'=>$value]),'menu'=>'推广员-测试资源-测试资源申请-测试资源申请后续']);
}
M('test_resource','tab_')->commit(); //提交事物
$this->success('申请成功',U('index'));
}
public function lists( $p = 1){
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
if(!empty(I('type'))||I('type')==='0'){
$map['apply_status']=I('type');
}
if(!empty(I('role_name'))){
$map['role_name']=['like','%'.I('role_name').'%'];
}
if(!empty(I('server_name'))){
$map['server_name']=I('server_name');
}
if(!empty(I('game_name'))){
$map['game_name']=I('game_name');
}
if(!empty(I('user_account'))){
$map['user_account']=['like','%'.I('user_account').'%'];
}
if(!empty($_REQUEST['start'])&&empty($_REQUEST['end'])){
$map['create_time'] = array('GT',strtotime($_REQUEST['start']));
unset($_REQUEST['start']);
}
if(empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){
$map['create_time'] = array('LT',strtotime($_REQUEST['end'])+24*60*60-1);
unset($_REQUEST['end']);
}
if(!empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){
$map['create_time'] = array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1));
unset($_REQUEST['start']);unset($_REQUEST['end']);
}
$data=M('test_resource','tab_')->where($map)->order('id desc')->page($page,$row)->select();
$count=M('test_resource','tab_')->field('id')->where($map)->select();
$count = count($count);
$parameter = I("get.");
$parameter['p']=I('get.p',1);
$parameter['row']=I('get.row');
foreach ($data as $key=>&$value) {
($value['promote_account']=='官方渠道')?($value['promote_account']=C('OFFICIEL_CHANNEL')):'';
}
$page = set_pagination($count,$row,$parameter);
if($page) {$this->assign('_page', $page);}
$this->meta_title = '测试资源申请记录';
$this->assign('data',$data);
$this->assign('count',$count);
$this->display();
}
}