| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262 |
- <?php
- /**
- * 聚合渠道控制器
- *
- */
- namespace app\admin\controller;
- use think\Db;
- use think\Exception;
- use app\common\model\ComplexChannelModel;
- use app\common\model\Game;
- use app\common\model\Polychannel;
- use app\common\model\PolychannelGame;
- use app\common\model\PolyChannelDeposit;
- use app\common\model\PolyChannelDepositRecord;
- use app\common\model\PolyChannelGameFrozen;
- use app\common\logic\Complex;
- use GuzzleHttp\Client;
- use GuzzleHttp\Exception\GuzzleException;
- class ComplexChannel extends Admin
- {
- public function _initialize()
- {
- parent::_initialize();
- $this->complexChannelModel = new ComplexChannelModel;
- $this->_gameModel = new Game;
- $this->_polyChannelDeposit = new PolyChannelDeposit;
- $this->_polyChannelDepositRecord= new polyChannelDepositRecord;
- $this->_polyChannelGameFrozen = new PolyChannelGameFrozen;
- $this->complexLogic = new Complex;
- }
- /**
- * 聚合渠道列表
- * @return mixed|string
- */
- public function index()
- {
- /**搜索条件**/
- $name = input('name');
- $status = input('status');
- $register = input('register');
- $login = input('login');
- $consume = input('consume');
- $where['a.flag'] = 4;
- if ($name) {
- $where['a.name'] = ['like', "%$name%"];
- }
- if ($status!='') {
- $where['a.status'] = $status;
- }
- if ($register!='') {
- if($register==1){
- $where['b.register'] = $register;
- }
- else{
- $where['b.register'] = [['eq',0],['exp',Db::raw('is null')],'or'];
- }
- }
- if ($login!='') {
- if($login==1){
- $where['b.login'] = $login;
- }
- else{
- $where['b.login'] = [['eq',0],['exp',Db::raw('is null')],'or'];
- }
- }
- if ($consume!='') {
- if($consume==1){
- $where['b.consume'] = $consume;
- }
- else{
- $where['b.consume'] = [['eq',0],['exp',Db::raw('is null')],'or'];
- }
- }
- $channles = $this->complexChannelModel
- ->alias('a')
- ->join("nw_polychannel b","a.id=b.channel_id","left")
- ->field('a.id,a.name,a.mark,a.remark,a.create_time,a.status,b.channel_id,b.param_field,b.login,b.register,b.consume')
- ->where($where)
- ->order("a.id DESC")
- ->paginate(30,false, ['query' => input('request.')]);
- // 获取分页显示
- $page = $channles->render();
- $this->assign('total', $channles->total());
- $this->assign("page", $page);
- $this->assign("channles", $channles);
- return $this->fetch();
- }
- /**
- * 添加渠道
- *
- * @return mixed
- */
- public function add()
- {
- return $this->fetch();
- }
- /**
- * 添加渠道
- *
- */
- public function addPost()
- {
- $polychannelModel = new Polychannel;
- $param_field = input('post.param_field','','trim');
- $field_client = input('post.field_client','','trim');
- $register= input('post.register',0,'intval');
- $login= input('post.login',0,'intval');
- $consume= input('post.consume',0,'intval');
- $data = [
- 'name' => input('post.name','','trim'),
- 'remark' => input('post.remark'),
- 'mark' => input('post.mark','','trim'),
- 'status' => input('post.status'),
- 'register' => input('post.register'),
- 'login' => input('post.login'),
- 'consume' => input('post.consume'),
- 'param_field' => $param_field,
- 'field_client' => $field_client,
- ];
- $result = $this->validate($data,
- [
- ['name', 'require', '请填写渠道名称'],
- ['remark', 'max:255', '渠道描述最大不超过255个字符'],
- ['mark', 'require|alphaNum|max:20', '请填写渠道标识|渠道标识必须为英文和数字|渠道标识最大不超过20个字符'],
- ['status', 'require|integer', '渠道状态不能为空|渠道状态必须为整数'],
- ['register', 'require|integer', '渠道新增状态不能为空|渠道新增状态必须为整数'],
- ['login', 'require|integer', '渠道登录状态不能为空|渠道登录状态必须为整数'],
- ['consume', 'require|integer', '渠道消费状态不能为空|渠道消费状态必须为整数'],
- ['param_field', 'max:500', '服务端参数字段名最大不超过500个字符'],
- ['field_client', 'max:500', '客户端参数字段名最大不超过500个字符'],
- ]);
- if (true !== $result) {
- $this->error($result);
- }
- // elseif(!empty($param_field) && count(explode(';',$param_field))!=2){
- // $this->error('参数字段超过两个或不足两个,请联系技术员进行特殊处理');
- // }
- else {
- Db::startTrans();
- try {
- //1. 添加渠道信息
- $channelInfo = $this->complexChannelModel->where(['name' => $data['name']])->find();
- if ($channelInfo) {
- throw new Exception("该渠道信息已存在");
- }
- if ( $this->complexChannelModel->where(['mark' => $data['mark']])->find() ) {
- throw new Exception("渠道标识不能重复");
- }
- unset($data['param_field']);
- unset($data['field_client']);
- unset($data['register']);
- unset($data['login']);
- unset($data['consume']);
- $data['flag'] = 4;
- $data['create_time'] = NOW_TIMESTAMP;
- //添加渠道信息
- $this->complexChannelModel->save($data);
- if ( !$this->complexChannelModel->id ) {
- throw new Exception("添加渠道信息失败");
- }
- //2. 添加聚合渠道参数
- $polyChannelData = array();
- $polyChannelData['channel_id'] = $this->complexChannelModel->id;
- if(!empty($param_field)){
- $polyChannelData['param_field'] = $param_field;
- }
- if(!empty($field_client)){
- $polyChannelData['field_client'] = $field_client;
- }
- $polyChannelData['register'] = $register?1:0;
- $polyChannelData['login'] = $login?1:0;
- $polyChannelData['consume'] = $consume?1:0;
- $polyChannelData['update_time'] = NOW_TIMESTAMP;
- $polychannelModel->save($polyChannelData);
- $status = $data['status'] ? '正常' : '冻结';
- $register = $register ? '冻结' : '正常';
- $login = $login ? '冻结' : '正常';
- $consume = $consume ? '冻结' : '正常';
- //写入日志
- $this->insertLog($this->current_node, "新增聚合渠道:{$data['name']},渠道标识:{$data['mark']},渠道状态:{$status},新增状态:{$register},登录状态:{$login},消费状态:{$consume}", 54);
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- $this->error("添加失败: " . $e->getMessage());
- }
- $this->success("添加成功!", "ComplexChannel/index");
- }
- }
- /**
- * 编辑渠道
- *
- * @return mixed
- */
- public function edit()
- {
- $polychannelModel = new Polychannel;
- $id = input('id', 0, 'intval');
- $channel = $this->complexChannelModel->where(["id" => $id])->find();
- if(empty($channel)){
- $this->error('聚合渠道信息不存在');
- }
- $polychannel = $polychannelModel->where(["channel_id" => $id])->find();
- if(!empty($channel)){
- $param_field = $polychannel['param_field'];
- $field_client = $polychannel['field_client'];
- $register = $polychannel['register'];
- $login = $polychannel['login'];
- $consume = $polychannel['consume'];
- }
- else{
- $param_field = '';
- $field_client = '';
- $register = 0;
- $login = 0;
- $consume = 0;
- }
- $this->assign('channel', $channel);
- $this->assign('param_field', $param_field);
- $this->assign('field_client', $field_client);
- $this->assign('register', $register);
- $this->assign('login', $login);
- $this->assign('consume', $consume);
- return $this->fetch();
- }
- /**
- * 编辑渠道接口
- *
- */
- public function editPost()
- {
- $id = input('post.id',0,'intval');
- $param_field= input('post.param_field','','trim');
- $field_client= input('post.field_client','','trim');
- $register= input('post.register',0,'intval');
- $login= input('post.login',0,'intval');
- $consume= input('post.consume',0,'intval');
- $polychannelModel = new Polychannel;
- $data = ['name' => input('post.name','','trim'),
- 'remark' => input('post.remark'),
- 'status' => input('post.status'),
- 'register' => input('post.register'),
- 'login' => input('post.login'),
- 'consume' => input('post.consume'),
- 'param_field' => $param_field,
- 'field_client' => $field_client
- ];
- $result = $this->validate($data,
- [
- ['name', 'require', '请填写渠道名称'],
- ['remark', 'max:255', '渠道描述最大不超过255个字符'],
- ['status', 'require|integer', '渠道状态不能为空|渠道状态必须为整数'],
- ['register', 'require|integer', '渠道新增状态不能为空|渠道新增状态必须为整数'],
- ['login', 'require|integer', '渠道登录状态不能为空|渠道登录状态必须为整数'],
- ['consume', 'require|integer', '渠道消费状态不能为空|渠道消费状态必须为整数'],
- ['param_field', 'max:500', '服务端参数字段名最大不超过500个字符'],
- ['field_client', 'max:500', '客户端参数字段名最大不超过500个字符'],
- ]);
- if (true !== $result) {
- $this->error($result);
- } elseif (empty($this->complexChannelModel->where(['id' => $id])->find())) {
- $this->error('聚合渠道不存在');
- }
- // elseif(!empty($param_field) && count(explode(';',$param_field))!=2){
- // $this->error('参数字段超过两个或不足两个,请联系技术员进行特殊处理');
- // }
- else {
- Db::startTrans();
- try {
- //1. 添加渠道信息
- $channelInfo = $this->complexChannelModel->where(['name' => $data['name'], 'id' => ['<>', $id]])->find();
- if ($channelInfo) {
- throw new Exception("渠道名称不能重复");
- }
- unset($data['param_field']);
- unset($data['field_client']);
- unset($data['register']);
- unset($data['login']);
- unset($data['consume']);
- //添加渠道信息
- $this->complexChannelModel->save($data, ['id' => $id]);
- //2. 添加聚合渠道参数
- $polyChannelData = array();
- if (!empty($param_field)) {
- $polyChannelData['param_field'] = $param_field;
- }
- if (!empty($field_client)) {
- $polyChannelData['field_client'] = $field_client;
- }
- $polyChannelData['register'] = $register ? 1 : 0;
- $polyChannelData['login'] = $login ? 1 : 0;
- $polyChannelData['consume'] = $consume ? 1 : 0;
- $polyChannelData['update_time'] = NOW_TIMESTAMP;
- //更新
- if($polychannelModel->where(['channel_id'=>$id])->find())
- {
- $result = $polychannelModel->save($polyChannelData,['channel_id'=>$id]);
- }
- //新增
- else{
- $polyChannelData['channel_id'] = $id;
- $result = $polychannelModel->save($polyChannelData);
- }
- $status = $data['status'] ? '正常' : '冻结';
- $mark = $this->complexChannelModel->where(['id' => $id])->value('mark');
- $register = $register ? '冻结' : '正常';
- $login = $login ? '冻结' : '正常';
- $consume = $consume ? '冻结' : '正常';
- //写入日志
- $this->insertLog($this->current_node, "修改聚合渠道:{$data['name']},渠道标识:{$mark},渠道状态:{$status},新增状态:{$register},登录状态:{$login},消费状态:{$consume}", 55);
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- $this->error("编辑失败: " . $e->getMessage());
- }
- $this->success("编辑成功!", "ComplexChannel/index");
- }
- }
- //变更渠道状态
- public function updateStatus()
- {
- $polychannelModel = new Polychannel;
- //渠道ID
- $id = input('id', 0, 'intval');
- $status = input('status', 0, 'intval');
- if (!empty($id)) {
- $result = $this->complexChannelModel->where(["id" => $id,'flag'=>4])->setField('status', $status);
- if ($result !== false) {
- //添加日志
- $frozenInfo = $polychannelModel->where(['id' => $id])->find();
- $channelInfo = $this->complexChannelModel->where(['id' => $id])->find();
- $channel_name = $channelInfo['name'];
- $mark = $channelInfo['mark'];
- $register = $frozenInfo['register'] ? '冻结' : '正常';
- $login = $frozenInfo['login'] ? '冻结' : '正常';
- $consume = $frozenInfo['consume'] ? '冻结' : '正常';
- $statusStr = $status ? '正常' : '冻结';
- $this->insertLog($this->current_node, "修改聚合渠道:{$channel_name},渠道标识:{$mark},渠道状态:{$statusStr},新增状态:{$register},登录状态:{$login},消费状态:{$consume}", 55);
- $this->success("更改渠道状态成功!", url("ComplexChannel/index"));
- } else {
- $this->error('更改渠道状态失败!');
- }
- } else {
- $this->error('数据传入失败!');
- }
- }
- // +----------------------------------------------------------------------
- // | 聚合游戏
- // +----------------------------------------------------------------------
- /**
- * 聚合游戏列表
- */
- public function gameList()
- {
- $is_down = input('request.download', '0', 'intval');
- $channel_id = input('request.channel_id', '0', 'intval');
- $gameid = $this->request->param('gameid', 0, 'intval');
- $type = input('request.type', '');
- $condition = [];
- if (!empty($channel_id)) {
- $condition['cg.channel_id'] = $channel_id;
- }
- if (!empty($gameid)) {
- $condition['cg.game_id'] = $gameid;
- }
- if (!empty($type)) {
- $condition['g.type'] = $type;
- }
- $polychannelGameModel = new PolychannelGame;
- if ($is_down) {
- $list = $polychannelGameModel->alias('cg')
- ->join('nw_complex_channel c', 'cg.channel_id=c.id', 'left')
- ->join('cy_game g', 'g.id=cg.game_id', 'left')
- ->join('cy_game_pay_discount cgpd', 'cgpd.game_id=cg.game_id', 'left')
- ->field('cg.game_id,cg.id,cg.create_time,cg.remark,cg.param,g.name game_name,g.origin_name,c.name channel_name,c.mark, cg.discount_status, cgpd.proportion')
- ->where($condition)
- ->order("cg.id DESC")
- ->select();
- } else {
- $list = $polychannelGameModel->alias('cg')
- ->join('nw_complex_channel c', 'cg.channel_id=c.id', 'left')
- ->join('cy_game g', 'g.id=cg.game_id', 'left')
- ->join('cy_game_pay_discount cgpd', 'cgpd.game_id=cg.game_id', 'left')
- ->field('cg.game_id,cg.id,cg.create_time,cg.remark,cg.param,g.name game_name,g.origin_name,c.name channel_name,c.mark, cg.discount_status, cgpd.proportion')
- ->where($condition)
- ->order("cg.id DESC")
- ->paginate(30, false, ['query' => input('get.')]);
- }
- if($is_down>0){
- $title = "聚合游戏列表-".date('YmdHis');
- if(!$list){
- $this->error('暂无数据');
- }
- $this->downloadexls($list, $title,'listGame');
- exit();
- }
- // 获取分页显示
- $page = $list->render();
- $channelList = $this->_getChannelList();
- $selfChannelList = array();
- foreach ($channelList as $channel) {
- $selfChannelList[ $channel['id']] = $channel;
- }
- $this->assign('channel_list', $selfChannelList);
- $this->assign('total', $list->total());
- $this->assign("page", $page);
- $this->assign('list',$list);
- $SelfGameList = model('Common/Game')->getAllByCondition('id,name', [],'','self');
- $GameList = array();
- foreach ($SelfGameList as $game) {
- $GameList[ $game['id']] = $game;
- }
- $this->assign('game_list', $GameList);
- return $this->fetch('game_list');
- }
- /**
- * 获得聚合渠道的参数
- */
- public function ajaxGetChannelGameParam()
- {
- if(request()->isAjax())
- {
- $polychannelGameModel = new PolychannelGame;
- $polychannelModel = new Polychannel;
- $id = input('post.id'); //渠道游戏ID
- $info = $polychannelGameModel->field('channel_id,game_id,param,param_client')
- ->where(['id'=>$id])
- ->find();
- if(empty($info)){
- $this->error('聚合渠道游戏信息不存在');
- }
- $return_html = '服务端参数<br>';
- $return_html_client = '客户端参数<br>';
- $return_html .= $info['param_client'].'<br>';
- $return_html_client .= $info['param'].'<br>';
- $this->result(['return_html'=>$return_html_client.'<br>'.$return_html],1);
- }
- else{
- $this->error('非法请求');
- }
- }
- /**
- * 聚合渠道游戏新增
- */
- public function gameAdd()
- {
- $complexChannelModel = new ComplexChannelModel;
- $gameModel = new Game;
- //表单提交
- if (request()->isPost()) {
- $polychannelGameModel = new PolychannelGame;
- $polychannelModel = new Polychannel;
- $input = input();
- // $param = input('post.param'); //参数
- $param = $input['param']; //参数
- $param_client = $input['param_client']??""; //参数
- $data = [
- 'game_id' => input('post.game_id', 0, 'intval'),
- 'channel_id' => input('post.channel_id', 0, 'intval'),
- 'remark' => input('post.remark'),
- 'discount_status' => input('post.discount_status', 2, 'intval'), // 折扣状态(1=开启、2=关闭)
- ];
- $result = $this->validate($data,
- [
- ['game_id', 'require|positiveInteger', '请选择游戏|游戏ID必须为整型'],
- ['channel_id', 'require|positiveInteger', '请选择渠道|渠道ID必须为整型'],
- ['remark', 'max:500', '备注最大不超过500个字符'],
- ]);
- if (true !== $result) {
- $this->error($result);
- } elseif ($polychannelGameModel->where(['game_id' => $data['game_id'], 'channel_id' => $data['channel_id']])->find()) {
- $this->error('渠道游戏信息已经存在');
- } else {
- $data['create_time'] = NOW_TIMESTAMP;
- $paramArr = $polychannelModel->field('param_field,field_client')->where(['channel_id' => $data['channel_id']])->find();
- if ($param && !empty($paramArr['param_field'])) {
- // if(count($param)!=2){
- // $this->error('参数字段超过两个或不足两个,请联系技术员进行特殊处理');
- // }
- $paramHandle = explode(';', $paramArr['param_field']);
- $newParam = [];
- for ($i = 0; $i < count($paramHandle); $i++) {
- $newParam[$paramHandle[$i]] = '';
- if (!empty($param[$i])) {
- $newParam[$paramHandle[$i]] = $param[$i];
- }
- }
- if ($newParam) {
- $newParam = json_encode($newParam);
- }
- $data['param'] = $newParam;
- }
- if ($param_client) {
- $data['param_client'] = $param_client;
- }
- // 判断当前游戏是否有折扣配置,没有则不能开启折扣
- $proportion = Db::table('cy_game_pay_discount')->where(['game_id' => $data['game_id']])->value('proportion')??0;
- if($data['discount_status'] == 1 && $proportion == 0){
- $this->error('当前游戏未配置折扣,不能开启使用');
- }
- Db::startTrans();
- try {
- $polychannelGameModel->insert($data);
- //如果聚合渠道预付款配置表没有记录时,新增
- if(!$this->_polyChannelDeposit->where(['channel_id'=>$data['channel_id']])->find())
- {
- //聚合渠道预付款配置
- $this->_polyChannelDeposit->insert(['channel_id'=>$data['channel_id'],'mobile'=>'','create_time'=>NOW_TIMESTAMP]);
- }
- //聚合渠道游戏冻结配置
- $this->_polyChannelGameFrozen->insert([
- 'game_id'=>$data['game_id'],
- 'channel_id'=>$data['channel_id'],
- 'create_time'=>NOW_TIMESTAMP
- ]);
- Db::commit();
- }
- catch (\Exception $e) {
- Db::rollback();
- $this->error("渠道游戏添加失败!".$e->getMessage());
- }
- $this->success('渠道游戏添加成功','ComplexChannel/gameList');
- }
- }
- $channelList= $complexChannelModel->field('id,name')->where(['status'=>1,'flag'=>4])->order('name asc')->select();
- $selfChannelList = array();
- foreach ($channelList as $channel) {
- $selfChannelList[ $channel['id']] = $channel;
- }
- $gameList = $gameModel->getAllByCondition('id,name',['isdelete'=>0],'name asc','self');
- $selfGameList = array();
- foreach ($gameList as $game) {
- $selfGameList[ $game['id']] = $game;
- }
- $this->assign('game_list',$selfGameList);
- $this->assign('channel_list',$selfChannelList);
- return $this->fetch('game_add');
- }
- /**
- * 获得聚合渠道的参数字段
- */
- public function ajaxGetChannelParamField()
- {
- if(request()->isAjax())
- {
- $channel_id = input('post.channel_id');
- $polychannelModel = new Polychannel;
- $param_field = $polychannelModel->field('param_field,field_client')->where(['channel_id'=>$channel_id])->find();
- $this->result(['param_field'=>$param_field['param_field'],'field_client'=>$param_field['field_client']],1);
- }
- else{
- $this->error('非法请求');
- }
- }
- /**
- * 聚合渠道游戏编辑
- */
- public function gameEdit()
- {
- $polychannelGameModel = new PolychannelGame;
- $polychannelModel = new Polychannel;
- $id = input('id',0,'intval');
- $info = $polychannelGameModel->table('cy_polychannel_game cg,nw_complex_channel c,cy_game g')
- ->field('cg.*,g.name game_name,c.name channel_name')
- ->where('cg.channel_id=c.id and g.id=cg.game_id')
- ->where(['cg.id'=>$id])
- ->find();
- if(empty($info)){
- $this->error('聚合渠道游戏信息不存在');
- }
- // 参数字段
- $param_field_arr = $polychannelModel->field('field_client,param_field')->where(['channel_id'=>$info['channel_id']])->find();
- $param_field = $param_field_arr['param_field'];
- $field_client = $param_field_arr['field_client'];
- // 折扣信息
- $proportion = Db::table('cy_game_pay_discount')->where(['game_id' => $info['game_id']])->value('proportion');
- //表单提交
- if(request()->isPost())
- {
- $param = input('post.param');
- $param_client = input('post.param_client'); // 参数
- $discount_status = input('post.discount_status'); // 折扣状态(1=开启、2=关闭)
- $data = [
- 'remark' => input('post.remark'),
- ];
- $result = $this->validate($data,
- [
- ['remark', 'max:500', '备注最大不超过500个字符'],
- ]);
- if (true !== $result) {
- $this->error($result);
- }
- else{
- if($param){
- // if(count($param)!=2){
- // $this->error('参数字段超过两个或不足两个,请联系技术员进行特殊处理');
- // }
- if(!is_json($param)){
- $this->error('json异常');
- }
- $data['param'] = $param;
- }
- if($param_client){
- $data['param_client'] = $param_client;
- }
- // 折扣状态
- if($discount_status){
- $data['discount_status'] = $discount_status;
- }
- $polychannelGameModel->save($data,['id'=>$id]);
- $this->success('渠道游戏编辑成功','ComplexChannel/gameList');
- }
- }
- $discountInfo = [
- 'status' => 2,
- 'proportion' => 0
- ];
- if($proportion > 0 && $proportion < 1){
- $discountInfo = [
- 'status' => 1,
- 'proportion' => $proportion
- ];
- }
- $this->assign('discountInfo',$discountInfo);
- $this->assign('info',$info);
- $this->assign('param_field',$param_field);
- $this->assign('arrParam',$info['param']);
- $this->assign('field_client',$field_client);
- $this->assign('arrParamClient',$info['param_client']);
- return $this->fetch('game_edit');
- }
- /**
- * 聚合游戏记录删除
- */
- public function gameDelete()
- {
- $id = $this->request->param('id', 0, 'intval');
- $polychannelGameModel = new PolychannelGame;
- Db::startTrans();
- try {
- // 获取游戏id和渠道id
- $info = $polychannelGameModel->where(['id'=>$id])->field('game_id,channel_id')->find();
- $polychannelGameModel->where(['id'=>$id])->delete();
- $this->_polyChannelGameFrozen->where(['game_id'=>$info['game_id'],'channel_id'=>$info['channel_id']])->delete();
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- $this->error("删除失败!".$e->getMessage());
- }
- $this->success("删除成功!");
- }
- // 聚合游戏冻结配置
- public function listGameFrozen(){
- $is_down = input('request.download', '0', 'intval');
- $channel_id = $this->request->param('channel_id', 0, 'intval');
- $condition = [];
- $condition['channel_id'] = $channel_id;
- $list = [];
- $count_total_amount = $count_real_amount = $total_advance = $balance = $last_advance = 0;
- $param = input();
- $whereTime = [];
- if(!empty($param['start_time'])){
- // $whereTime['start_time'] = strtotime($param['start_time'] . " 00:00:00");
- $whereTime['start_time'] = strtotime($param['start_time']);
- }
- if(!empty($param['end_time'])){
- // $whereTime['end_time'] = strtotime($param['end_time'] . " +1 day");
- $whereTime['end_time'] = strtotime($param['end_time']);
- }
- if (!empty($condition)) {
- if($is_down>0){
- $list = $this->_polyChannelGameFrozen->where($condition)->order('id desc')->select();
- // 安全写法
- if (is_object($list) && method_exists($list, 'toArray')) {
- $list = $list->toArray();
- } else {
- $list = collection($list)->toArray(); // TP5 自带 helper 函数
- }
- $gameIds = array_column($list, 'game_id');
- } else {
- $list = $this->_polyChannelGameFrozen->where($condition)->order('status desc, total_amount desc')->paginate(50, false, array('query' => $param));
- $gameIds = array_column($list->toArray()['data'], 'game_id');
- }
- // dump($whereTime);
- // ## 游戏配置信息 : divide_point=祈盟分成, proportion=折扣
- $gamePayConfig = Db::table('cy_polychannel_game_frozen')->alias('cpgf')
- ->join('cy_game_pay_discount cgpd', 'cpgf.game_id = cgpd.game_id', 'LEFT')
- ->where(['cpgf.game_id' => ['in', $gameIds], 'cpgf.channel_id' => $channel_id])
- ->column('cpgf.divide_point, cgpd.proportion', 'cpgf.game_id');
- // $gameByProportion = Db::table('cy_game_pay_discount')->where(['game_id' => ['in', $gameIds]])->column('game_id,proportion');
- $openGameIds = [];
- foreach ( $list as &$item ) {
- // 当前流水
- $item['total_amount'] = Db::table('nw_complex_pay')
- ->where(['gameid' => $item['game_id'], 'channel_id' => $channel_id, 'status' => 1])
- ->where(function($q) use ($whereTime) {
- if (!empty($whereTime['start_time'])) {
- $q->where('create_time', '>=', $whereTime['start_time']);
- }
- if (!empty($whereTime['end_time'])) {
- $q->where('create_time', '<', $whereTime['end_time']);
- }
- })
- ->sum('amount');
- $item['discount'] = 0;
- if(!empty($gamePayConfig[$item['game_id']]['proportion'])){
- $item['discount'] = $gamePayConfig[$item['game_id']]['proportion'];
- }
- $item['game_name'] = $this->_getGameName($item['game_id']);
- $item['origin_name'] = $this->_getGameOriginName($item['game_id']);
- $item['divide_point'] = (0 != $item['divide_point']) ? $item['divide_point']: 0;
- // 折扣后流水
- $discount_amount = cleanAmount($item['total_amount']);
- if($item['discount']){
- $discount_amount = cleanAmount(number_format($item['total_amount']*$item['discount'], 2));
- }
- $item['discount_amount'] = $discount_amount;
- // 扣除预付款
- $item['actual_amount'] = round($discount_amount*$item['divide_point'], 2);
- if($item['status'] == 1){
- $openGameIds[] = $item['game_id'];
- }
- }
- // ## 当前流水
- // $count_total_amount = $this->_polyChannelGameFrozen->where(['channel_id' => $channel_id, 'status' => 1, 'game_id' => ['in', $gameIds]])->sum('total_amount');
- $count_total_amount = Db::table('nw_complex_pay')
- ->where(['gameid' => ['in', $openGameIds], 'channel_id' => $channel_id, 'status' => 1])
- ->where(function($q) use ($whereTime) {
- if (!empty($whereTime['start_time'])) {
- $q->where('create_time', '>=', $whereTime['start_time']);
- }
- if (!empty($whereTime['end_time'])) {
- $q->where('create_time', '<', $whereTime['end_time']);
- }
- })
- ->sum('amount');
- $count_total_amount = floatval($count_total_amount);
- // ## 折扣后流水
- // $count_real_amount = $this->complexLogic->getChannelGameTotalAmount($channel_id);
- $count_real_amount = Db::table('nw_complex_pay')->alias('ncp')
- ->join('cy_game_pay_discount cgpd', 'ncp.gameid = cgpd.game_id', 'LEFT')
- ->where(['ncp.gameid' => ['in', $openGameIds], 'ncp.channel_id' => $channel_id, 'ncp.status' => 1])
- ->where(function($q) use ($whereTime) {
- if (!empty($whereTime['start_time'])) {
- $q->where('ncp.create_time', '>=', $whereTime['start_time']);
- }
- if (!empty($whereTime['end_time'])) {
- $q->where('ncp.create_time', '<', $whereTime['end_time']);
- }
- })
- ->value("ROUND(SUM(ncp.amount * COALESCE(cgpd.proportion, 1.000)), 2)");
- $count_real_amount = floatval($count_real_amount);
- // ## 扣除预付款累计
- $count_deduct_amount = 0;
- // $count_deduct_amount = Db::table('nw_complex_pay')->alias('ncp')
- // ->join('cy_polychannel_game_frozen cpgf', 'ncp.gameid = cpgf.game_id', 'LEFT')
- // ->where(['ncp.gameid' => ['in', $gameIds], 'ncp.channel_id' => $channel_id, 'ncp.create_time' => ['between', [$param['start_time'], $param['end_time']]], 'ncp.status' => 1])
- // ->value("ROUND(SUM(ncp.amount * cpgf.divide_point), 2)");
- $count_deduct_list = Db::table('nw_complex_pay')
- ->where(['gameid' => ['in', $openGameIds], 'channel_id' => $channel_id, 'status' => 1])
- ->where(function($q) use ($whereTime) {
- if (!empty($whereTime['start_time'])) {
- $q->where('create_time', '>=', $whereTime['start_time']);
- }
- if (!empty($whereTime['end_time'])) {
- $q->where('create_time', '<', $whereTime['end_time']);
- }
- })
- ->field("gameid, SUM(amount) as amount")
- ->group("gameid")
- ->select();
- foreach ($count_deduct_list as &$item) {
- $amount = $item['amount'];
- // 折扣
- if(!empty($gamePayConfig[$item['gameid']]) && $gamePayConfig[$item['gameid']]['proportion'] > 0){
- $amount = $amount * $gamePayConfig[$item['gameid']]['proportion'];
- }
- // 分成
- if(!empty($gamePayConfig[$item['gameid']]) && $gamePayConfig[$item['gameid']]['divide_point'] > 0){
- $amount = $amount * $gamePayConfig[$item['gameid']]['divide_point'];
- }
- $count_deduct_amount += $amount;
- }
- $count_deduct_amount = round($count_deduct_amount, 2);
- // ## 已交预付款
- $ChannelDepositInfo = $this->_polyChannelDeposit->where(['channel_id' => $channel_id])->find();
- if($ChannelDepositInfo){
- $total_advance = floatval($ChannelDepositInfo->total_advance);
- $last_advance = floatval($ChannelDepositInfo->last_advance);
- }
- // 查询时间内清空后交的预付款
- // $total_advance = Db::table('cy_polychannel_deposit_record')->where(['channel_id' => $channel_id])
- // ->where(function($q) use ($whereTime) {
- // if (!empty($whereTime['start_time'])) {
- // $q->where('create_time', '>=', $whereTime['start_time']);
- // }
- // if (!empty($whereTime['end_time'])) {
- // $q->where('create_time', '<', $whereTime['end_time']);
- // }
- // })->sum('amount');
- // dump($total_advance, $count_real_amount);
- // ## 剩余预付款 = 累计预付款 - 扣除预付款
- $balance = floatval(bcsub($total_advance, $count_deduct_amount, 2));
- if($is_down>0){
- $title = "聚合游戏冻结配置-".date('YmdHis');
- if(!$list){
- $this->error('暂无数据');
- }
- $list_more = array();
- $list_more['count_total_amount'] = $count_total_amount;
- $list_more['count_real_amount'] = $count_real_amount;
- $list_more['total_advance'] = $total_advance;
- $list_more['last_advance'] = $last_advance;
- $list_more['balance'] = $balance;
- $this->downloadexls($list, $title, 'listGameFrozen', $list_more);
- exit();
- }
- }
- $this->assign('list', $list);
- $this->assign('total', $list->total());
- $this->assign('page', $list->render());
- $this->assign('count', [
- $count_total_amount, // 当前流水
- $count_real_amount, // 折扣后流水
- $count_deduct_amount, // 扣除预付款
- $total_advance, // 累计预付款
- $balance, // 剩余预付款
- $last_advance, // 最近一次充值预付款
- ]);
- $channelList = $this->_getChannelList();
- $selfChannelList = array();
- foreach ($channelList as $channel) {
- $selfChannelList[ $channel['id']] = $channel;
- }
- $this->assign('channel_list', $selfChannelList);
- $this->assign('select_channel',$channel_id);
- return $this->fetch("listGameFrozen");
- }
- public function editGameFrozen() {
- if (request()->isPost()) {
- $divide_point = $this->request->param('divide_point', 0, 'floatval');
- $status = $this->request->param('status', 0, 'intval');
- $depf_register = $this->request->param('depf_register', 0, 'intval');
- $depf_login = $this->request->param('depf_login', 0, 'intval');
- $depf_consume = $this->request->param('depf_consume', 0, 'intval');
- if (0 >= $divide_point || 1 < $divide_point) {
- $this->error('‘祈盟所得分成’配置,只能在0-1之间!');
- }
- $switch = [0,1];
- if ( ! in_array($status, $switch) || ! in_array($depf_register, $switch) || ! in_array($depf_login, $switch) || ! in_array($depf_consume, $switch) ) {
- $this->error('预付状态|禁止新增|禁止登录|禁止充值等参数只能设定为1或0');
- }
- $id = $this->request->param('id', 0, 'intval');
- $data = [
- 'divide_point' => $divide_point,
- 'depf_register' => $depf_register,
- 'depf_login' => $depf_login,
- 'depf_consume' => $depf_consume,
- 'status' => $status,
- 'update_time' => time()
- ];
- $update = $this->_polyChannelGameFrozen->where(['id' => $id])->update($data);
- if ( false === $update ) {
- $this->error('更新失败');
- } else {
- $info = $this->_polyChannelGameFrozen->where(['id' => $id])->column('id,channel_id,game_id');
- $content = '编辑了渠道:'.$this->_getChannelName($info[$id]['channel_id']).",游戏:".$this->_getGameName($info[$id]['game_id']);
- $content .= ",分成配置:".$divide_point;
- $content .= ",预付状态:".($status ? '开启' : '关闭');
- $content .= ",禁止新增:".($depf_register ? '开启' : '关闭');
- $content .= ",禁止登录:".($depf_login ? '开启' : '关闭');
- $content .= ",禁止充值:".($depf_consume ? '开启' : '关闭');
- $this->insertLog($this->current_node, $content, 51);
- $this->success('更新成功', url('ComplexChannel/listGameFrozen', ['channel_id' => $info[$id]['channel_id'] ] ) );
- }
- } else {
- $id = $this->request->param('id', 0, 'intval');
- if ( empty($id) ) {
- $this->error('参数出错');
- }
- $info = $this->_polyChannelGameFrozen->field(['id', 'game_id', 'channel_id', 'divide_point', 'depf_register', 'depf_login', 'depf_consume', 'status'])->find($id);
- if ( empty($info) ) {
- $this->error('数据不存在');
- }
- $info['game_name'] = $this->_getGameName($info['game_id']);
- $info['divide_point'] = (0 != $info['divide_point']) ? $info['divide_point']: '';
- $this->assign('vo', $info);
- return $this->fetch("editGameFrozen");
- }
- }
- // 聚合渠道预付款配置
- public function listDeposit() {
- $channel_id = $this->request->param('channel_id', 0, 'intval');
- $condition = [];
- if (!empty($channel_id) ) {
- $condition['channel_id'] = $channel_id;
- }
- //查询参数
- $param = input('get.');
- $list = $this->_polyChannelDeposit->where($condition)->order('id desc')->paginate(20, false, array('query' => $param));
-
- // 批量获取渠道总流水
- $channel_ids = array_column($list->toArray()['data'], 'channel_id');
- // 批量获取渠道名称和描述
- $channelInfoMap = [];
- if (!empty($channel_ids)) {
- $channelInfoMap = $this->complexChannelModel
- ->where('id', 'in', $channel_ids)
- ->column('name,remark', 'id');
- }
-
- foreach ( $list as &$channel ) {
- $channelId = $channel['channel_id'];
- $channel['channel_name'] = $channelInfoMap[$channelId]['name'] ?? '';
- $channel['channel_desc'] = $channelInfoMap[$channelId]['remark'] ?? '';
- $channel['total_amount'] = $this->complexLogic->getChannelGameTotalAmount($channelId);
- }
- $this->assign('total', $list->total());
- $this->assign('page', $list->render());
- $this->assign('list', $list);
- $channelList = $this->_getChannelList();
- $selfChannelList = array();
- foreach ($channelList as $channel) {
- $selfChannelList[ $channel['id']] = $channel;
- }
- $this->assign('channel_list', $selfChannelList);
- return $this->fetch("listDeposit");
- }
- public function editDeposit() {
- if (request()->isPost()) {
- $last_advance = $this->request->param('add2advance', 0);
- $mobile = $this->request->param('mobile', '', 'trim');
- $warn_amount = $this->request->param('warn_amount', 0, 'floatval');
- $over_limit_amount = $this->request->param('over_limit_amount', 0, 'floatval');
- $remark = $this->request->param('remark', '', 'filterAndTrimInput');
- if ( 0 > $warn_amount || 0 > $over_limit_amount ) {
- $this->error('预警额度和可超额度都不能小于零');
- }
- /*
- if ($last_advance < 0) {
- $this->error('新增预付款必须为正整数,不追加请留空');
- }
- */
- $mobile = str_replace(PHP_EOL, ',', $mobile);
- $mobileArray = explode(",",$mobile);
- while(list($key,$val)=@each($mobileArray)){
- if (trim($val)) {
- if(! preg_match("/^1\d{10}$/", trim($val))){
- $this->error('存在手机号码不正确,请确认');
- }
- else{
- $mobileArray[$key] = trim($val);
- }
- }
- else{
- unset($mobileArray[$key]);
- }
- }
- $mobileArray = array_unique($mobileArray);
- $mobile = implode(",",$mobileArray);
- $id = $this->request->param('id', 0, 'intval');
- $data = [
- 'mobile' => $mobile,
- 'warn_amount' => $warn_amount,
- 'over_limit_amount' => $over_limit_amount,
- 'remark' => $remark,
- 'update_time' => time()
- ];
- // 启动事务
- $result = true;
- // Db::startTrans();
- try {
- if ( 0 <> $last_advance ) {
- $data['last_advance'] = $last_advance;
- $data['total_advance'] = Db::raw("total_advance+{$last_advance}");
- // $channel_id = $this->_polyChannelDeposit->where(['id' => $id])->value('channel_id');
- $depositInfo = $this->_polyChannelDeposit->where(['id' => $id])->field('channel_id,total_advance')->find();
- $total_amount = $this->complexLogic->getChannelGameTotalAmount($depositInfo['channel_id']);
- $remaining_amount = bcsub($depositInfo['total_advance'], $total_amount, 2);
- $recordData = [
- 'channel_id' => $depositInfo['channel_id'],
- 'amount' => $last_advance,
- 'remaining_amount' => $remaining_amount,
- 'admin_id' => session('ADMIN_ID') ?: 1,
- 'admin_name' => session('USERNAME') ?: '',
- 'remark' => $remark,
- 'create_time' => time(),
- ];
- // dump($recordData);
- $result = $this->_polyChannelDepositRecord->insert($recordData);
- }
- $update = $this->_polyChannelDeposit->where(['id' => $id])->update($data);
- if ( false === $update || false === $result) {
- throw new \Exception('更新失败');
- } else {
- $channel_id = $this->_polyChannelDeposit->where(['id' => $id])->value('channel_id');
- $content = '编辑了渠道:'.$this->_getChannelName($channel_id);
- ( 0 <> $last_advance ) && $content .= ",增加预付款:".$last_advance;
- $content .= ",手机号码:".$mobile;
- $content .= ",预警额度:{$warn_amount}元";
- $content .= ",可超额度:{$over_limit_amount}元";
- $content .= ",备注:".$remark;
- $this->insertLog($this->current_node, $content, 52);
- }
- Db::commit();
- $this->success('更新成功', url('ComplexChannel/listDeposit') );
- } catch (\Exception $e){
- Db::rollback();
- if ($e instanceof \think\exception\HttpResponseException) {
- throw $e;
- }
- $this->error('操作失败:' . $e->getMessage());
- }
- } else {
- $id = $this->request->param('id', 0, 'intval');
- if ( empty($id) ) {
- $this->error('参数出错');
- }
- $info = $this->_polyChannelDeposit->field(['id', 'channel_id', 'total_advance', 'mobile', 'warn_amount', 'over_limit_amount', 'remark'])->find($id);
- if ( empty($info) ) {
- $this->error('数据不存在');
- }
- $info['channel_name'] = $this->_getChannelName($info['channel_id']);
- $info['channel_desc'] = $this->_getChannelDesc($info['channel_id']);
- $info['total_amount'] = $this->complexLogic->getChannelGameTotalAmount($info['channel_id']);
- $info['mobile'] = str_replace(',',PHP_EOL, $info['mobile']); //多个手机号用逗号分隔
- $this->assign('vo', $info);
- return $this->fetch("editDeposit");
- }
- }
- // 聚合渠道预付款记录
- public function listDepositRecord() {
- $channel_id = $this->request->param('channel_id', 0, 'intval');
- $condition = [];
- if ( ! empty($channel_id) ) {
- $condition['channel_id'] = $channel_id;
- }
- $list = $this->_polyChannelDepositRecord->where($condition)->order('id desc')->select();
- $this->assign('list', $list);
- return $this->fetch("listDepositRecord");
- }
- /**
- * 获取聚合渠道列表
- *
- * @return array
- */
- protected function _getChannelList() {
- $list = $this->complexChannelModel->field(['id', 'name'])->where(['flag' => 4])->order('id desc')->select();
- return $list ?: [];
- }
- /**
- * 获取游戏名称
- *
- * @param int $game_id
- * @return string
- */
- protected function _getGameName($game_id) {
- $nickname = $this->_gameModel->getName($game_id);
- return $nickname ?: '';
- }
- /**
- * 获取游戏原名
- *
- * @param int $game_id
- * @return string
- */
- protected function _getGameOriginName($game_id) {
- $nickname = $this->_gameModel->getOriginName($game_id);
- return $nickname ?: '';
- }
- /**
- * 获取渠道名称
- *
- * @param int $channel_id
- * @return string
- */
- protected function _getChannelName($channel_id) {
- $name = $this->complexChannelModel->where(['id' => $channel_id] )->value('name');
- return $name ?: '';
- }
- protected function _getChannelDesc($channel_id) {
- $desc = $this->complexChannelModel->where(['id' => $channel_id] )->value('remark');
- return $desc ?: '';
- }
- }
|