| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721 |
- <?php
- /**
- * 充值记录管理控制器
- *
- */
- namespace app\admin\controller;
- use app\common\library\MakeReportGo;
- use app\common\model\PaySupconModel;
- use app\common\model\CompanyGameBind;
- use think\Db;
- use app\common\library\MakeReport;
- use GuzzleHttp\Client;
- use GuzzleHttp\Exception\GuzzleException;
- use think\Exception;
- class Pay extends Admin
- {
- private $condition = [];
- protected $start;
- protected $end;
- protected $noCheckAuth = ['getChannel'];
- private $gameIds = []; //海外游戏id
- protected function _initialize()
- {
- parent::_initialize();
- $this->gameList = $gameList = model('Common/Game')->getAllByCondition('id,name');
- $tmpSelfGameList = model('Common/Game')->getAllByCondition('id,name', [], '', 'self');
- $selfGameList = array();
- foreach ($tmpSelfGameList as $game) {
- $selfGameList[$game['id']] = $game;
- }
- $this->selfGameList = $selfGameList;
- $this->gameIds = config('haiwai_game_ids_arr');
- }
- /**
- * 前置方法(参数获取)
- */
- protected function _beforeGetParams()
- {
- $start = $this->request->param('start');
- $end = $this->request->param('end');
- $channel_id = $this->request->param('channel_id', 0, 'intval');
- $top_channel_id = $this->request->param('parent_channel_id', 0, 'intval');
- $bplus_channel_id = $this->request->param('bplus_channel_id', 0, 'intval');
- $gameid = $this->request->param('gameid', 0, 'trim');
- $status = $this->request->param('status');
- // $cp_status = $this->request->param('cp_status');
- $orderid = $this->request->param('orderid', '', 'trim');
- $username = $this->request->param('username', '', 'trim');
- // $paytype = $this->request->param('paytype', '', 'trim');
- $servername = $this->request->param('servername', '', 'trim');
- $roleid = $this->request->param('roleid', '', 'trim');
- $rolename = $this->request->param('rolename', '', 'trim');
- $company_id = $this->request->param('company_id', 0, 'intval');
- $client_type = $this->request->param('client_type', 0, 'intval');
- $condition = [];
- // 如果选择了公司,则使用公司绑定的游戏ID列表
- if (!empty($company_id)) {
- $companyGameBind = new CompanyGameBind();
- $companyInfo = $companyGameBind->where(['id' => $company_id])->find();
- if (!empty($companyInfo) && !empty($companyInfo['game_ids'])) {
- $gameIds = explode(',', $companyInfo['game_ids']);
- $gameIds = array_filter($gameIds);
- if (!empty($gameIds)) {
- if (count($gameIds) > 1) {
- $condition['p.gameid'] = ['in', $gameIds];
- } else {
- $condition['p.gameid'] = $gameIds[0];
- }
- } else {
- // 如果公司没有绑定游戏,设置一个不存在的ID,使查询结果为空
- $condition['p.gameid'] = -1;
- }
- } else {
- // 如果公司不存在或没有绑定游戏,设置一个不存在的ID
- $condition['p.gameid'] = -1;
- }
- } elseif (!empty($gameid)) {
- // 如果没有选择公司,则使用原来的游戏ID搜索逻辑
- $gameids = explode(',', $gameid);
- if (count($gameids) > 1) {
- $gameid = ['in', $gameids];
- }
- $condition['p.gameid'] = $gameid;
- }
- if (!empty($orderid)) {
- $condition['p.orderid'] = $orderid;
- }
- // dump($condition);
- // if (!empty($paytype)) {
- // if ($paytype == "wx") {
- // $condition['p.paytype'] = ['IN', ['wxpay-h5', 'ybzf_wxmp_h5', 'coin-wxpay-h5', 'coin-ybzf_wxmp_h5', 'mix-wxpay-h5', 'mix-ybzf_wxmp_h5']];
- // } else if($paytype == "zfb") {
- // $condition['p.paytype'] = ['IN', ['zfb', 'old-zfb-wap', 'coin-zfb', 'old-zfb-wap', 'mix-zfb', 'mix-old-zfb-wap']];
- // } else if($paytype == "coin") {
- // $condition['p.paytype'] = ['IN', ['coinpay', 'coin-zfb', 'coin-old-zfb-wap', 'coin-wxpay-h5', 'coin-ybzf_wxmp_h5']];
- // } else if($paytype == "coupon") {
- // $condition['p.paytype'] = ['IN', ['coupon', 'mix-zfb', 'mix-old-zfb-wap', 'mix-wxpay-h5', 'mix-ybzf_wxmp_h5']];
- // }
- // }
- // if (!empty($paytype)) {
- // $condition['p.paytype'] = $paytype;
- // }
- if (is_numeric($status)) {
- $condition['p.status'] = (int)$status;
- }
- // if (!empty($cp_status)) {
- // $condition['paycpinfo.status'] = $cp_status;
- // }
- if (!empty($username)) {
- // // $condition['p.username'] = ['LIKE', '%' . $username . '%'];
- // $memberId = Db::table('cy_members')->where(['username' => $username])->value('id');
- // //改成精确查询
- // $condition['p.userid'] = $memberId;
- $condition['p.username'] = $username;
- }
- if (!empty($servername)) {
- $condition['p.servername'] = $servername;
- }
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
- if ($business != -1) {
- if ($bplus_channel_id) {
- if (!in_array($bplus_channel_id, $business)) {
- $bplus_channel_id = -1;
- }
- } else {
- if ($business && $business != -2) {
- $bplus_channel_id = implode(',', $business);
- } else {
- $bplus_channel_id = -1;
- }
- }
- }
- //联盟/公会/渠道有选择时判断
- if (!empty($channel_id) || !empty($top_channel_id) || !empty($bplus_channel_id)) {
- if (!empty($channel_id) && !empty($top_channel_id) && !empty($bplus_channel_id)) {
- unset($condition['p.channel_id']);
- $bChannelIds = get_child_channel_arr($top_channel_id);
- array_push($bChannelIds, $top_channel_id);
- $bplusChannelIds = get_child_channel_arr($bplus_channel_id);
- $bplusChannelIds = array_merge($bplusChannelIds, explode(',', $bplus_channel_id));
- $channelIds = array_intersect($bChannelIds, $bplusChannelIds, array($channel_id));
- if ($channelIds) {
- $condition['p.channel_id'] = ['in', $channelIds];
- } else {
- $condition['p.channel_id'] = -1;
- }
- } else if (!empty($top_channel_id) && !empty($bplus_channel_id)) {
- $bChannelIds = get_child_channel_arr($top_channel_id);
- array_push($bChannelIds, $top_channel_id);
- $bplusChannelIds = get_child_channel_arr($bplus_channel_id);
- $bplusChannelIds = array_merge($bplusChannelIds, explode(',', $bplus_channel_id));
- $channelIds = array_intersect($bChannelIds, $bplusChannelIds);
- if ($channelIds) {
- $condition['p.channel_id'] = ['in', $channelIds];
- } else {
- $condition['p.channel_id'] = -1;
- }
- } elseif (!empty($channel_id) && !empty($bplus_channel_id)) {
- $bplusChannelIds = get_child_channel_arr($bplus_channel_id);
- $bplusChannelIds = array_merge($bplusChannelIds, explode(',', $bplus_channel_id));
- $channelIds = array_intersect($bplusChannelIds, array($channel_id));
- if ($channelIds) {
- $condition['p.channel_id'] = ['in', $channelIds];
- } else {
- $condition['p.channel_id'] = -1;
- }
- } elseif (!empty($channel_id) && !empty($top_channel_id)) {
- $bChannelIds = get_child_channel_arr($top_channel_id);
- array_push($bChannelIds, $top_channel_id);
- $channelIds = array_intersect($bChannelIds, array($channel_id));
- if ($channelIds) {
- $condition['p.channel_id'] = ['in', $channelIds];
- } else {
- $condition['p.channel_id'] = -1;
- }
- } elseif (!empty($top_channel_id)) {
- $channelIds = get_child_channel_arr($top_channel_id);
- array_push($channelIds, $top_channel_id);
- $condition['p.channel_id'] = ['in', $channelIds];
- } elseif (!empty($bplus_channel_id)) {
- $channelIds = get_child_channel_arr($bplus_channel_id);
- $channelIds = array_merge($channelIds, explode(',', $bplus_channel_id));
- $condition['p.channel_id'] = ['in', $channelIds];
- } elseif (!empty($channel_id)) {
- $condition['p.channel_id'] = $channel_id;
- }
- }
- $timeName = "p.pay_time";
- if($this->request->action() == 'list'){
- $timeName = "p.create_time";
- }
- //开始时间和结束时间不为空时
- if ($start != '' && $end != '') {
- $condition[$timeName] = [
- ['>=', strtotime($start)],
- ['<=', strtotime($end . ' 23:59:59')],
- ];
- } //开始时间不为空时
- elseif ($start != '') {
- $condition[$timeName] = ['>=', strtotime($start)];
- } //结束时间不为空时
- elseif ($end != '') {
- $condition[$timeName] = ['<=', strtotime($end . ' 23:59:59')];
- } else {
- $start = $end = date('Y-m-d', time());
- $condition[$timeName] = [
- ['>=', strtotime($start)],
- ['<=', strtotime($start . ' 23:59:59')],
- ];
- }
- // if ($username=='' && $orderid==''){
- // if(strtotime($end.' 23:59:59')-strtotime($start)>31*24*3600)
- // {
- // $this->error('单次查询日期的最长跨度为31天');
- // }
- // }
- if (!empty($roleid)) {
- $condition['p.roleid'] = $roleid;
- }
- if (!empty($rolename)) {
- $condition['p.rolename'] = ['like', "%{$rolename}%"];
- }
- $this->start = $start;
- $this->end = $end;
- // 游戏上线状态
- $cooperation_status = $this->request->param('cooperation_status', 0, 'intval'); // 游戏上线状态
- if (!empty($cooperation_status)) {
- $game_cooperation_status = $cooperation_status == 1 ? 1 : 2;
- $gameIds = Model('Game')->getNormalByIds($game_cooperation_status);
- $condition['p.gameid'] = ['in', $gameIds];
- }
- // 数据归属/客户端类型(1=祈盟sdk, 2=巨量, 3=快手磁力包)
- if (!empty($client_type)) {
- $condition['p.client_type'] = $client_type;
- }
- $this->setCondition($condition);
- }
- /**
- * 充值记录管理(抓取) - 弃用
- *
- * @return mixed|string
- */
- public function index()
- {
- $this->_beforeGetParams();
- $condition = $this->getCondition();
- //充值总金额
- $totalAmount = $todayTotalAmount = $lastDayTotalAmount = 0;
- $PayModel = model('Common/Pay');
- $paytype = $this->request->param('paytype', '', 'trim');
- $pageSize = input('page_size', 15);
- if (!empty($paytype)) {
- if ($paytype == "wx") {
- $paytype = [
- "wxpay-h5", "coin-wxpay-h5", "mix-wxpay-h5",
- "ybzf_wxmp_h5", "coin-ybzf_wxmp_h5", "mix-ybzf_wxmp_h5",
- "qzl_wx_h5", "coin-qzl_wx_h5", "mix-qzl_wx_h5",
- 'xty_wx_h5', "coin-xty_wx_h5", "mix-xty_wx_h5",
- 'qmf_wxmp_h5', "coin-qmf_wxmp_h5", "mix-qmf_wxmp_h5",
- 'yyyb_wx_h5', "coin-yyyb_wx_h5", "mix-yyyb_wx_h5",
- "dh_wx"
- ];
- $condition['p.paytype'] = ['IN', $paytype];
- } else if ($paytype == "zfb") {
- $paytype = [
- "zfb", "coin-zfb", "mix-zfb",
- "old-zfb-wap", "coin-old-zfb-wap", "mix-old-zfb-wap",
- 'ldys_zfb_h5', "coin-ldys_zfb_h5", "mix-ldys_zfb_h5",
- "xty_ali_h5", "coin-xty_ali_h5", "mix-xty_ali_h5",
- 'yyyb_ali_h5', "coin-yyyb_ali_h5", "mix-yyyb_ali_h5",
- "dh_zfb"
- ];
- $condition['p.paytype'] = ['IN', $paytype];
- } else if ($paytype == "coin") {
- $paytype = [
- "coinpay",
- "coin-zfb", "coin-old-zfb-wap",
- "coin-ldys_zfb_h5", "coin-xty_ali_h5", "coin-yyyb_ali_h5",
- "coin-qzl_wx_h5", "coin-ldys_wx_h5", "coin-yyyb_wx_h5", "coin-ybzf_wxmp_h5", "coin-xty_wx_h5",
- ];
- $condition['p.paytype'] = ['IN', $paytype];
- } else if ($paytype == "coupon") {
- $paytype = [
- "coupon",
- "mix-zfb", "mix-old-zfb-wap",
- "mix-ldys_zfb_h5", "mix-xty_ali_h5", "mix-yyyb_ali_h5",
- "mix-qzl_wx_h5", "mix-ldys_wx_h5", "mix-yyyb_wx_h5", "mix-ybzf_wxmp_h5", "mix-xty_wx_h5",
- ];
- $condition['p.paytype'] = ['IN', $paytype];
- }
- }
- $cp_status = $this->request->param('cp_status'); // 游戏通知状态:0(通知失败)1(通知成功)
- if (is_numeric($cp_status)) {
- $condition['paycpinfo.status'] = (int)$cp_status;
- }
- $gh_status = input('gh_status', 0); // 是否聚合用户:0=否、1=是
- if ($gh_status <> '') {
- $condition['channel.gh_status'] = $gh_status;
- }
- // http://admin.7dgame.cn/Pay/index.html?start=2024-07-09&end=2024-07-09&gameid=&servername=&status=&cp_status=&paytype=&orderid=&username=&channel_id=&parent_channel_id=&bplus_channel_id=&page=&page_size=100&gh_status=1
- $list = $PayModel->alias('p')
- ->join('nw_channel channel', 'p.channel_id=channel.id')
- ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
- ->field('p.id,p.orderid,p.gameid,p.username,p.userid,p.amount,p.real_amount,p.real_ptb,p.roleid,p.rolelevel,p.rolename,p.serverid,p.servername,p.status,p.paytype,p.create_time,p.channel_id,p.productname,p.recheck_status,p.attach,p.real_coin,p.coupon_member_id,p.coupon_amount,paycpinfo.status as cp_status, p.pay_amount, FROM_UNIXTIME(p.pay_time, "%Y-%m-%d %H:%i:%s") as pay_time, p.serverid, p.servername')
- ->where($condition)
- // ->whereNotIn('gameid',$this->gameIds) // 排除海外游戏
- ->order('p.pay_time desc')
- // ->fetchSql(true)
- // ->select();
- ->paginate($pageSize, false, ['query' => input('get.')]);
- // dump($list);
- $parent_list = model('Common/Channel')->getParentChannel(); // 获取所有父类渠道
- if ($list->total() > 0) {
- $data = $list->toArray()['data'];
- $userIdArr = $paytype = $gameIdArr = $channelIdArr = $ttbhistoryArr = [];
- foreach ($data as $v) {
- $userIdArr[] = $v['userid'];
- $paytype[] = $v['paytype'];
- $gameIdArr[] = $v['gameid'];
- $channelIdArr[] = $v['channel_id'];
- }
- //关联数据查询
- $gameNameArr = model('Common/Game')->whereIn('id', array_unique($gameIdArr))->column('name', 'id');
- $regTimeArr = model('Common/Members')->whereIn('id', array_unique($userIdArr))->column('reg_time', 'id');
- foreach ($list as $key => $item) {
- $default = '--';
- $list[$key]['game_name'] = isset($gameNameArr[$item['gameid']]) ? $gameNameArr[$item['gameid']] : $default;
- $list[$key]['reg_time'] = isset($regTimeArr[$item['userid']]) ? date("Y-m-d H:i:s", $regTimeArr[$item['userid']]) : $default;
- $channel = get_top_second_channel_name($list[$key]['channel_id']);
- $list[$key]['channel_name'] = $channel['channel_name'];
- $list[$key]['second_channel'] = $channel['second_name'];
- $list[$key]['top_channel'] = $channel['top_name'];
- $list[$key]['union_name'] = get_union_channel($list[$key]['channel_id'])['name'];
- }
- //支付成功 或者支付查询条件未选择时
- if (input('status') == 1 || input('status') == '') {
- //充值完成总金额
- $totalAmount = $PayModel->alias('p')
- ->join('nw_channel channel', 'p.channel_id=channel.id')
- ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
- ->field('sum(pay_amount) as total_amount,paycpinfo.status as cp_status')
- ->where($condition)
- // ->whereNotIn('gameid', $this->gameIds)
- ->where('p.status=1')->find()['total_amount'];
- }
- }
- $where['p.create_time'] = [
- ['>=', strtotime(date('Y-m-d'))],
- ['<=', strtotime(date('Y-m-d') . ' 23:59:59')],
- ];
- unset($condition["p.create_time"]);
- $todayTotalAmount = floatval(model('Pay')->alias("p")
- ->join('nw_channel channel', 'p.channel_id=channel.id')
- ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
- ->where($condition)
- // ->whereNotIn('gameid',$this->gameIds)
- ->field('sum(pay_amount) as total_amount,paycpinfo.status as cp_status')->where('p.status=1')->where($where)->find()['total_amount']);
- $where['p.create_time'] = [
- ['>=', strtotime(date("Y-m-d", strtotime("-1 day")))],
- ['<', strtotime(date('Y-m-d'))],
- ];
- $lastDayTotalAmount = floatval(model('Pay')
- ->alias("p")->where($condition)
- ->join('nw_channel channel', 'p.channel_id=channel.id')
- ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
- // ->whereNotIn('gameid',$this->gameIds)
- ->field('sum(pay_amount) as total_amount,paycpinfo.status as cp_status')->where('p.status=1')->where($where)->find()['total_amount']);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- $this->assign('paytype', config('paytype'));
- $this->assign('new_pay_type', config('new_pay_type'));
- $this->assign('game_list', $this->selfGameList);
- $this->assign('channel_id', $this->request->get('channel_id')); //查询条件中的渠道ID
- $this->assign('parent_list', $parent_list); //顶级渠道列表
- $this->assign('start', $this->start);
- $this->assign('end', $this->end);
- $this->assign('totalAmount', $totalAmount);
- $this->assign('todayTotalAmount', $todayTotalAmount);
- $this->assign('lastDayTotalAmount', $lastDayTotalAmount);
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
- $channelWhere = [];
- if ($business != -1) {
- if ($business && $business != -2) {
- $channelWhere['id'] = ['in', $business];
- } else {
- $channelWhere['id'] = -1;
- }
- }
- $uniom = model('Channel')->where(['level' => 0])->where($channelWhere)->field('id,name')->select();
- $this->assign('uniom', $uniom); //顶级渠道列表
- return $this->fetch();
- }
- // 充值记录管理展示
- public function list()
- {
- $this->_beforeGetParams();
- $condition = $this->getCondition();
- $PayModel = model('Common/Pay');
- $paytype = $this->request->param('paytype', '', 'trim');
- $pageSize = input('page_size', 15);
- if (!empty($paytype)) {
- if ($paytype == "wx") {
- $paytype = [
- "wxpay-h5", "coin-wxpay-h5", "mix-wxpay-h5",
- "ybzf_wxmp_h5", "coin-ybzf_wxmp_h5", "mix-ybzf_wxmp_h5",
- "qzl_wx_h5", "coin-qzl_wx_h5", "mix-qzl_wx_h5",
- 'xty_wx_h5', "coin-xty_wx_h5", "mix-xty_wx_h5",
- 'qmf_wxmp_h5', "coin-qmf_wxmp_h5", "mix-qmf_wxmp_h5",
- 'yyyb_wx_h5', "coin-yyyb_wx_h5", "mix-yyyb_wx_h5",
- "dh_wx"
- ];
- $condition['p.paytype'] = ['IN', $paytype];
- } else if ($paytype == "zfb") {
- $paytype = [
- "zfb",
- "coin-zfb",
- "mix-zfb",
- "old-zfb-wap",
- "coin-old-zfb-wap",
- "mix-old-zfb-wap",
- 'ldys_zfb_h5',
- "coin-ldys_zfb_h5",
- "mix-ldys_zfb_h5",
- "xty_ali_h5",
- "coin-xty_ali_h5",
- "mix-xty_ali_h5",
- 'yyyb_ali_h5',
- "coin-yyyb_ali_h5",
- "mix-yyyb_ali_h5",
- "dh_zfb"
- ];
- $condition['p.paytype'] = ['IN', $paytype];
- } else if ($paytype == "coin") {
- $paytype = [
- "coinpay",
- "coin-zfb", "coin-old-zfb-wap",
- "coin-ldys_zfb_h5", "coin-xty_ali_h5", "coin-yyyb_ali_h5",
- "coin-qzl_wx_h5", "coin-ldys_wx_h5", "coin-yyyb_wx_h5", "coin-ybzf_wxmp_h5", "coin-xty_wx_h5",
- ];
- $condition['p.paytype'] = ['IN', $paytype];
- } else if ($paytype == "coupon") {
- $paytype = [
- "coupon",
- "mix-zfb", "mix-old-zfb-wap",
- "mix-ldys_zfb_h5", "mix-xty_ali_h5", "mix-yyyb_ali_h5",
- "mix-qzl_wx_h5", "mix-ldys_wx_h5", "mix-yyyb_wx_h5", "mix-ybzf_wxmp_h5", "mix-xty_wx_h5",
- ];
- $condition['p.paytype'] = ['IN', $paytype];
- }
- }
- $cp_status = $this->request->param('cp_status');
- if (is_numeric($cp_status)) {
- $condition['paycpinfo.status'] = (int)$cp_status;
- }
- $gh_status = input('gh_status', 0); // 是否聚合用户:0=否、1=是
- if ($gh_status <> '') {
- $condition['channel.gh_status'] = $gh_status;
- }
- $test_status = input('test_status', 0); // 是否测试:0=否、1=是
- if($test_status == 1){
- $testMemberIds = Db::table('cy_members')
- ->where('test_status', 1)
- ->column('id');
- // 如果有测试账户,加入查询条件
- if (!empty($testMemberIds)) {
- $condition['p.userid'] = ['not in', $testMemberIds];
- }
- }
- // dump($condition);
- // http://admin.7dgame.cn/Pay/index.html?start=2024-07-09&end=2024-07-09&gameid=&servername=&status=&cp_status=&paytype=&orderid=&username=gao1126&channel_id=&parent_channel_id=&bplus_channel_id=&page=
- $list = $PayModel->alias('p')
- ->join('nw_channel channel', 'p.channel_id=channel.id', 'left')
- ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
- ->field('p.id,p.orderid,p.gameid,p.username,p.userid,p.amount,p.real_amount,p.real_ptb,p.roleid,p.rolelevel,p.rolename,p.serverid,p.servername,p.status,p.paytype,p.create_time,p.channel_id,p.productname,p.recheck_status,p.attach,p.real_coin,p.coupon_member_id,p.coupon_amount,paycpinfo.status as cp_status, p.pay_amount, FROM_UNIXTIME(p.pay_time, "%Y-%m-%d %H:%i:%s") as pay_time, "" as game_name, "" as reg_time, "" as channel_name, "" as second_channel, "" as top_channel, "" as union_name, "" as role_reg_time, p.client_type')
- ->where($condition)
- // ->whereNotIn('gameid', $this->gameIds)
- ->order('p.id desc')
- ->paginate($pageSize, false, ['query' => input('get.')]);
- $parent_list = model('Common/Channel')->getParentChannel();
- if ($list->total() > 0) {
- $data = $list->toArray()['data'];
- $userIdArr = $paytype = $gameIdArr = $channelIdArr = $ttbhistoryArr = $roleIdsArr = [];
- $userIdArr = array_column($data, 'userid');
- // $paytype = array_column($data, 'paytype');
- $gameIdArr = array_column($data, 'gameid');
- // $channelIdArr = array_column($data, 'channel_id');
- $roleIdsArr = array_column($data, 'roleid');
- //关联数据查询
- $gameNameArr = model('Common/Game')->whereIn('id', array_unique($gameIdArr))->column('name', 'id');
- $regTimeArr = model('Common/Members')->whereIn('id', array_unique($userIdArr))->column('reg_time', 'id');
- $roleListByRegtime = model('Common/MemberGameServer')->whereIn('roleid', array_unique($roleIdsArr))->column('create_time', 'roleid');
- foreach ($list as $key => $item) {
- $default = '--';
- $list[$key]['game_name'] = isset($gameNameArr[$item['gameid']]) ? $gameNameArr[$item['gameid']] : $default;
- $list[$key]['reg_time'] = isset($regTimeArr[$item['userid']]) ? date("Y-m-d H:i:s", $regTimeArr[$item['userid']]) : $default;
- $list[$key]['role_reg_time'] = isset($roleListByRegtime[$item['roleid']]) ? date("Y-m-d H:i:s", $roleListByRegtime[$item['roleid']]) : $default;
- // $channel = get_top_second_channel_name($list[$key]['channel_id']);
- $channel = get_top_second_channel_name_v2($list[$key]['channel_id']);
- $list[$key]['channel_name'] = $channel['channel_name'];
- $list[$key]['second_channel'] = $channel['second_name'];
- $list[$key]['top_channel'] = $channel['top_name'];
- $list[$key]['union_name'] = $channel['union_name'];
- }
- }
- // ## 统计数据
- $condition['p.status'] = 1; // 只统计支付成功的订单
- $totalData = model('Common/Pay')->alias('p')
- ->join('nw_channel channel', 'p.channel_id=channel.id', 'left')
- ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
- ->where($condition)
- ->field([
- 'SUM(p.amount) as totalAmount',
- 'SUM(p.coupon_amount) as couponAmount',
- 'SUM(p.pay_amount) as payAmount',
- 'SUM(p.coupon_amount + p.pay_amount) as couponBypayAmount'
- ])
- ->find();
- $statisticsData = [
- 'totalAmount' => $totalData['totalAmount']??0, // 订单金额
- 'couponAmount' => $totalData['couponAmount']??0, // 代金卷抵扣
- 'payAmount' => $totalData['payAmount']??0, // 实付金额
- 'couponBypayAmount' => $totalData['couponBypayAmount']??0, // 代金卷+实付
- ];
- $this->assign('statisticsData', $statisticsData);
- // 获取公司列表
- $companyList = (new CompanyGameBind())->field('id,company_name,company_alias')->order('id desc')->select();
- $companyArr = [];
- foreach ($companyList as $company) {
- $companyArr[] = [
- 'id' => $company['id'],
- 'name' => $company['company_name'] . ' (' . $company['company_alias'] . ')'
- ];
- }
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- $this->assign('paytype', config('paytype'));
- $this->assign('new_pay_type', config('new_pay_type'));
- $this->assign('game_list', $this->selfGameList);
- $this->assign('company_list', $companyArr);
- $this->assign('channel_id', $this->request->get('channel_id')); //查询条件中的渠道ID
- $this->assign('parent_list', $parent_list); //顶级渠道列表
- $this->assign('start', $this->start);
- $this->assign('end', $this->end);
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
- $channelWhere = [];
- if ($business != -1) {
- if ($business && $business != -2) {
- $channelWhere['id'] = ['in', $business];
- } else {
- $channelWhere['id'] = -1;
- }
- }
- $uniom = model('Channel')->where(['level' => 0])->where($channelWhere)->field('id,name')->select();
- $this->assign('uniom', $uniom); //顶级渠道列表
- return $this->fetch();
- }
- /**
- * 前置方法(参数获取)
- */
- protected function _beforeChannelPayGetParams()
- {
- $start = $this->request->param('start');
- $end = $this->request->param('end');
- $b_channel_id = $this->request->param('b_channel_id', 0, 'intval');
- $bplus_channel_id = $this->request->param('bplus_channel_id', 0, 'intval');
- $gameid = $this->request->param('gameid', 0, 'intval');
- $condition = [];
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
- if ($business != -1) {
- if ($bplus_channel_id) {
- if (!in_array($bplus_channel_id, $business)) {
- $bplus_channel_id = [-1];
- }
- } else {
- if ($business && $business != -2) {
- $bplus_channel_id = implode(',', $business);
- } else {
- $bplus_channel_id = [-1];
- }
- }
- }
- if (!empty($gameid)) {
- $condition['gameid'] = $gameid;
- }
- if (!empty($b_channel_id) && !empty($bplus_channel_id)) {
- unset($condition['channel_id']);
- $bChannelIds = get_child_channel_arr($b_channel_id);
- array_push($bChannelIds, $b_channel_id);
- $bplusChannelIds = get_child_channel_arr($bplus_channel_id);
- array_push($bplusChannelIds, $bplus_channel_id);
- $channelIds = array_intersect($bChannelIds, $bplusChannelIds);
- // var_dump($channelIds);
- $condition['channel_id'] = ['in', $channelIds];
- } elseif (!empty($b_channel_id)) {
- unset($condition['channel_id']); // 如果同时输入渠道名称和顶级渠道,出于性能考虑,只查询渠道名称这个条件
- $channelIds = get_child_channel_arr($b_channel_id);
- array_push($channelIds, $b_channel_id);
- $condition['channel_id'] = ['in', $channelIds];
- }
- //顶级渠道存到pay表中 存在渠道改变时候 需要定期刷表的情况后续开发
- elseif (!empty($bplus_channel_id)) {
- unset($condition['channel_id']); // 如果同时输入渠道名称和顶级渠道,出于性能考虑,只查询渠道名称这个条件
- $channelIds = get_child_channel_arr($bplus_channel_id);
- array_push($channelIds, $bplus_channel_id);
- $condition['channel_id'] = ['in', $channelIds];
- }
- //开始时间和结束时间不为空时
- if ($start != '' && $end != '') {
- $condition['create_time'] = [
- ['>=', strtotime($start)],
- ['<=', strtotime($end . ' 23:59:59')],
- ];
- } //开始时间不为空时
- elseif ($start != '') {
- $condition['create_time'] = ['>=', strtotime($start)];
- } //结束时间不为空时
- elseif ($end != '') {
- $condition['create_time'] = ['<=', strtotime($end . ' 23:59:59')];
- } else {
- $start = date('Y-m-d', time());
- $end = date('Y-m-d', time());
- $condition['create_time'] = [
- ['>=', strtotime($start)],
- ['<=', strtotime($end . ' 23:59:59')],
- ];
- }
- /*
- if(strtotime($end.' 23:59:59')-strtotime($start)>31*24*3600){
- $this->error('单次查询日期的最长跨度为31天');
- }
- */
- $this->start = $start;
- $this->end = $end;
- $this->setCondition($condition);
- }
- /**
- * 推广员数据
- * @return mixed|string
- */
- public function channelPay()
- {
- $this->_beforeChannelPayGetParams();
- $condition = $this->getCondition();
- $regCondition = $condition;
- $condition['status'] = 1;
- if (isset($regCondition['gameid'])) {
- $regCondition['game_id'] = $regCondition['gameid'];
- unset($regCondition['gameid']);
- }
- $page_size = input('page_size', 20);
- $PayModel = model('Common/Pay');
- //充值完成总金额
- $totalAmount = 0;
- $totalRegCnt = 0;
- $regSql = model('MemberGameServer')->field('game_id,channel_id,0 as total_pay_amount,count(*) as total_reg_cnt')->where($regCondition)->group('game_id,channel_id')->buildSql();
- $unionSql = model('Pay')->field('gameid as game_id,channel_id as channel_id,sum(pay_amount) as total_pay_amount,0 as total_reg_cnt')->where($condition)->group('gameid,channel_id')->union([$regSql])->buildSql();
- $unionSqlNew = Db::table($unionSql . ' bb')
- ->field('bb.game_id game_id,bb.channel_id channel_id,sum(bb.total_pay_amount) as total_pay_amount,sum(bb.total_reg_cnt) as total_reg_cnt')
- ->group('bb.game_id,bb.channel_id')
- ->buildSql();
- $list = Db::table($unionSqlNew . ' cc')
- ->order('total_pay_amount desc,total_reg_cnt desc,game_id desc,channel_id desc')
- ->paginate($page_size, false, ['query' => input('get.')]);
- // echo Db::table($unionSql . ' bb')->getLastSql() . "----sql-------<br>";
- $listData = array();
- if ($list->total() > 0) {
- //关联数据查询
- foreach ($list as $key => $item) {
- $channel = get_top_second_channel_name($list[$key]['channel_id']);
- $item['game_name'] = get_game_name($list[$key]['game_id']);
- $item['channel_name'] = $channel['channel_name'];
- $item['second_channel'] = $channel['second_name'];
- $item['top_channel'] = $channel['top_name'];
- $item['bplus_channel_name'] = get_union_channel($list[$key]['channel_id'])['name'];
- $listData[] = $item;
- }
- //充值完成总金额
- $totalAmount = $PayModel->field('sum(pay_amount) as total_amount')->where($condition)->find()['total_amount'];
- //玩家新增
- $totalRegCnt = model('MemberGameServer')->field('count(*) as total_reg_cnt')->where($regCondition)->find()['total_reg_cnt'];
- }
- $this->assign('list', $list);
- $this->assign('listData', $listData);
- $this->assign('page', $list->render());
- $this->assign('game_list', $this->selfGameList);
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
- $channelWhere = [];
- if ($business != -1) {
- if ($business && $business != -2) {
- $channelWhere['id'] = ['in', $business];
- } else {
- $channelWhere['id'] = -1;
- }
- }
- $uniom = model('Channel')->where(['level' => 0])->where($channelWhere)->field('id,name')->select();
- $this->assign('uniom', $uniom); //顶级渠道列表
- $this->assign('start', $this->start);
- $this->assign('end', $this->end);
- $this->assign('totalAmount', $totalAmount);
- $this->assign('totalRegCnt', $totalRegCnt);
- return $this->fetch();
- }
- /**
- * 推广员数据报表-下载
- */
- public function channelPayDownload()
- {
- if (request()->isAjax()) {
- $this->_beforeChannelPayGetParams();
- $condition = $this->getCondition();
- $regCondition = $condition;
- $condition['status'] = 1;
- if (isset($regCondition['gameid'])) {
- $regCondition['game_id'] = $regCondition['gameid'];
- unset($regCondition['gameid']);
- }
- $regSql = model('MemberGameServer')->field('game_id,channel_id,0 as total_pay_amount,count(*) as total_reg_cnt')->where($regCondition)->group('game_id,channel_id')->buildSql();
- $unionSql = model('Pay')->field('gameid as game_id,channel_id as channel_id,sum(pay_amount) as total_pay_amount,0 as total_reg_cnt')->where($condition)->group('gameid,channel_id')->union([$regSql])->buildSql();
- $unionSqlNew = Db::table($unionSql . ' bb')
- ->field('bb.game_id game_id,bb.channel_id channel_id,sum(bb.total_pay_amount) as total_pay_amount,sum(bb.total_reg_cnt) as total_reg_cnt')
- ->group('bb.game_id,bb.channel_id')
- ->buildSql();
- $sql = Db::table($unionSqlNew . ' cc')
- ->order('total_pay_amount desc,total_reg_cnt desc,game_id desc,channel_id desc')
- ->fetchSql(true)->select();
- // $PayModel = model('Common/Pay');
- // $regSql = model('MemberGameServer')->field('game_id,channel_id,0 as total_pay_amount,count(*) as total_reg_cnt')->where($regCondition)->group('game_id,channel_id')->buildSql();
- // $unionSql = model('Pay')->field('gameid as game_id,channel_id as channel_id,sum(amount) as total_pay_amount,0 as total_reg_cnt')->where($condition)->group('gameid,channel_id')->union([$regSql])->buildSql();
- // $sql = Db::table($unionSql.' bb')
- // ->field('bb.game_id game_id,bb.channel_id channel_id,sum(bb.total_pay_amount) as total_pay_amount,sum(bb.total_reg_cnt) as total_reg_cnt')
- // ->group('bb.game_id,bb.channel_id')
- // ->order('total_pay_amount desc,total_reg_cnt desc')
- // ->fetchSql(true)->select();
- if ((new MakeReportGo())->addTask('admin.channelPay', $sql, session_id())) {
- $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- } else {
- $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- } else {
- $this->error('非法请求');
- }
- }
- /**
- * 充值记录管理页-查看玩家账号
- */
- public function showUsername()
- {
- $userid = input('userid');
- $game_id = input('game_id');
- if (empty($userid)) {
- $this->error('玩家ID不能为空');
- }
- $username = model('Common/Members')->where(['id' => $userid])->value('username');
- if (!empty($username)) {
- //充值记录管理页
- if (!empty($game_id)) {
- $game_name = model('Common/Game')->where(['id' => $game_id])->value('name');
- $this->insertLog($this->current_node, '查看账号:' . $username . ',关联游戏:' . $game_name, 81);
- } else {
- $this->insertLog($this->current_node, '查看账号:' . $username, 82);
- }
- $this->result($username, 1);
- } else {
- $this->error('玩家信息不存在');
- }
- }
- /**
- * ajax获取非聚合渠道列表
- *
- */
- public function ajaxGetNoComplexChannel()
- {
- $where = ['flag' => ['in', '1,2,3']];
- $level = input('level', '');
- if($level){
- $where['level'] = ['in', $level];
- }
- $channel_list = model('Common/Channel')->getAllByCondition('id,name', $where);
- echo json_encode($channel_list);
- // exit;
- }
- /**
- * ajax获取渠道列表
- */
- public function getChannel()
- {
- $channel_list = model('Common/Channel')->getChannleList();
- echo json_encode($channel_list);
- // exit;
- }
- /**
- * 报表-下载
- */
- public function download()
- {
- if (request()->isAjax()) {
- $makeReportGo = new MakeReportGo();
- $auth = new \app\common\logic\Auth();
- $is_show = input('is_show');
- if ($is_show > (int)$auth->check(session('ADMIN_ID'), 'admin/pay/rechargeDowmExcel')) {
- $this->error('您没有访问权限!');
- }
- $this->_beforeGetParams();
- $condition = $this->getCondition();
- $test_status = input('test_status', 0); // 是否测试:0=否、1=是
- if($test_status == 1){
- $testMemberIds = Db::table('cy_members')
- ->where('test_status', 1)
- ->column('id');
- // 如果有测试账户,加入查询条件(与列表 index 保持一致)
- if (!empty($testMemberIds)) {
- $condition['p.userid'] = ['not in', $testMemberIds];
- }
- }
- $cp_status = $this->request->param('cp_status');
- $paytype = $this->request->param('paytype', '', 'trim');
- if (!empty($paytype)) {
- if ($paytype == "wx") {
- $condition['p.paytype'] = ['IN', [
- 'wxpay-h5', 'coin-wxpay-h5', 'mix-wxpay-h5',
- 'ybzf_wxmp_h5', 'coin-ybzf_wxmp_h5', 'mix-ybzf_wxmp_h5',
- 'qzl_wx_h5', 'coin-qzl_wx_h5', 'mix-qzl_wx_h5',
- 'xty_wx_h5', 'coin-xty_wx_h5', 'mix-xty_wx_h5',
- 'qmf_wxmp_h5', 'coin-qmf_wxmp_h5', 'mix-qmf_wxmp_h5',
- 'yyyb_wx_h5', 'coin-yyyb_wx_h5', 'mix-yyyb_wx_h5',
- ]];
- } else if ($paytype == "zfb") {
- $condition['p.paytype'] = ['IN', [
- 'zfb', 'coin-zfb', 'mix-zfb',
- 'old-zfb-wap', 'coin-old-zfb-wap', 'mix-old-zfb-wap',
- 'xty_ali_h5', 'coin-xty_ali_h5', 'mix-xty_ali_h5',
- 'ldys_zfb', 'coin-ldys_zfb', 'mix-ldys_zfb',
- 'yyyb_ali_h5', 'coin-yyyb_ali_h5', 'mix-yyyb_ali_h5',
- ]];
- } else if ($paytype == "coin") {
- $condition['p.paytype'] = ['IN', [
- 'coinpay',
- "coin-zfb", "coin-old-zfb-wap",
- "coin-ldys_zfb_h5", "coin-xty_ali_h5", "coin-yyyb_ali_h5",
- "coin-qzl_wx_h5", "coin-ldys_wx_h5", "coin-yyyb_wx_h5", "coin-ybzf_wxmp_h5", "coin-xty_wx_h5", "coin-qmf_wxmp_h5",
- ]];
- } else if ($paytype == "coupon") {
- $condition['p.paytype'] = ['IN', [
- 'coupon',
- "mix-zfb", "mix-old-zfb-wap",
- "mix-ldys_zfb_h5", "mix-xty_ali_h5", "mix-yyyb_ali_h5",
- "mix-qzl_wx_h5", "mix-ldys_wx_h5", "mix-yyyb_wx_h5", "mix-ybzf_wxmp_h5", "mix-xty_wx_h5", "mix-qmf_wxmp_h5",
- ]];
- }
- }
- if (is_numeric($cp_status)) {
- $condition['paycpinfo.status'] = (int)$cp_status;
- }
- if (!$condition) {
- $this->error('导出需要至少一个查询条件!');
- }
- if(!empty($condition['p.pay_time']) && input('gh', 0) != 1){
- $condition['p.create_time'] = $condition['p.pay_time'];
- unset($condition['p.pay_time']);
- }
- $sql = Db::table('cy_pay p')
- ->join('nw_channel channel', 'p.channel_id=channel.id', 'left')
- ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
- ->field('p.id,p.orderid,p.gameid,p.username,p.userid,p.amount,p.real_amount,p.real_ptb,p.roleid,p.rolelevel,p.rolename,p.serverid,p.servername,p.status,p.paytype,p.create_time,p.channel_id,p.productname,p.recheck_status,p.attach,p.real_coin,p.coupon_member_id,p.coupon_amount,paycpinfo.status as cp_status, p.pay_amount, p.pay_time, "" as game_name, "" as reg_time, "" as channel_name, "" as second_channel, "" as top_channel, "" as union_name, "" as role_reg_time, p.client_type')
- ->where($condition)
- // ->whereNotIn('gameid', $this->gameIds)
- // 海外游戏
- // ->where(function ($query) use ($is_haiwei) {
- // if ($is_haiwei == 1) {
- // $query->whereIn('p.gameid', $this->gameIds);
- // } else {
- // $query->whereNotIn('p.gameid', $this->gameIds);
- // }
- // })
- ->order('p.id desc')
- ->fetchSql(true)->select();
- // if($makeReport->addTask('payList',$sql,session_id(),['is_show'=>boolval($is_show)])){
- if ($makeReportGo->addTask('payList', $sql, session_id(), ['is_show' => boolval($is_show)])) {
- //高级报表下载
- if ($is_show == 1) {
- $this->insertLog($this->current_node, $this->getDownloadLogContent(), 83);
- }
- $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- } else {
- $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- } else {
- $this->error('非法请求');
- }
- }
- /**
- * 高级报表下载时的,操作日志内容
- */
- private function getDownloadLogContent()
- {
- $start = $this->request->param('start');
- $end = $this->request->param('end');
- $gameid = $this->request->param('gameid', 0, 'intval');
- $username = $this->request->param('username', '', 'trim');
- $content = '';
- //开始时间和结束时间不为空时
- if ($start != '' && $end != '') {
- $content .= '时间:' . $start . '~' . $end;
- } //开始时间不为空时
- elseif ($start != '') {
- $content .= '时间:' . $start . '~';
- } //结束时间不为空时
- elseif ($end != '') {
- $content .= '时间:' . '~' . $end;
- } else {
- $start = date('Y-m-d', time());
- $end = date('Y-m-d', time());
- $content .= '时间:' . $start . '~' . $end;
- }
- if (!empty($gameid)) {
- $content .= ',游戏:' . model('Common/Game')->where(['id' => $gameid])->value('name');
- } else {
- $content .= ',游戏:全部游戏';
- }
- if (!empty($username)) {
- $content .= ',玩家账号:' . $username;
- } else {
- $content .= ',玩家账号:';
- }
- return $content;
- }
- public function setCondition($condition)
- {
- return $this->condition = $condition;
- }
- public function getCondition()
- {
- return $this->condition;
- }
- /**
- * 充值用户列表
- */
- public function user()
- {
- $this->_beforeGetParams();
- $condition = $this->getCondition();
- $PayModel = model('Common/Pay');
- /*
- // 如果没有选择条件,那么默认显示当天的数据
- if (! count($condition)) {
- $start_time = $this->request->get('start', date('Y-m-d'));
- $condition['create_time'] = makeTimeCondition($start_time);
- }
- */
- $order = '';
- $amount_total = input('amount_total', 'desc');
- if ($amount_total) {
- $order = 'amount_total ' . $amount_total;
- }
- $condition['status'] = 1; //只统计充值成功的
- $sql = $PayModel->alias('p')
- ->where($condition)
- ->field('username,userid,sum(pay_amount) as amount_total ,count(1) as pay_total,max(id) as max_id, gameid, p.roleid, p.rolename')
- ->group('username')
- ->order($order);
- if (request()->isAjax() && input('down') == true) {
- $makeReportGo = new MakeReportGo();
- $auth = new \app\common\logic\Auth();
- if (!$auth->check(session('ADMIN_ID'), 'admin/pay/userPayDowmExcel')) {
- $this->error('您没有访问权限!!');
- }
- $downSql = $sql->fetchSql(true)->select();
- if ($makeReportGo->addTask('userPayList', $downSql, session_id())) {
- $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- } else {
- $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- }
- $list = $sql->paginate(20, false, ['query' => input('get.')]);
- $idArr = array_column($list->toArray()['data'], 'max_id');
- $rencentPayArr = $PayModel->where('id', 'in', $idArr)->column('pay_amount', 'id');
- foreach ($list as $key => $value) {
- if (!empty($value['max_id'])) {
- $list[$key]['recent_pay'] = $rencentPayArr[$value['max_id']];
- } else {
- $list[$key]['recent_pay'] = 0;
- }
- }
- $this->assign('game_list_by_ids', $this->selfGameList);
- $this->assign('game_list', $this->gameList);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- $this->assign('start', $this->start);
- $this->assign('end', $this->end);
- return $this->fetch();
- }
- /**
- *充值规则 列表
- */
- public function ruleList()
- {
- $condition = [];
- $gameid = $this->request->param('gameid', 0, 'intval');
- if (!empty($gameid)) {
- $condition['game_id'] = $gameid;
- }
- $list = DB::table('cy_payrule')->where($condition)->order('create_time desc')->paginate(10);
- $gameidArr = [];
- foreach ($list as $v) {
- $gameidArr[] = $v['game_id'];
- }
- $payTypelist = DB::table('cy_paytype')->column('paytype,payname');
- $game_name = model('game')->whereIn('id', array_unique($gameidArr))->column('id,name');
- $this->assign('paytype_list', $payTypelist);
- $this->assign('game_list', $this->selfGameList);
- $this->assign('list', $list);
- $this->assign('game_name', $game_name);
- $this->assign('page', $list->render());
- return $this->fetch('rulelist');
- }
- /**
- *充值规则添加
- */
- public function ruleAdd()
- {
- if ($this->request->isPost()) {
- $data = $this->request->post();
- if (true !== ($res = $this->validate($data, 'payrule'))) {
- $this->error($res);
- }
- $payruleModel = model('Common/Payrule');
- $data['create_time'] = NOW_TIMESTAMP;
- if ($payruleModel->save($data)) {
- $this->success('添加成功', url('ruleList'));
- }
- $this->error($payruleModel->getError() ?: '添加失败');
- }
- $payTypelist = DB::table('cy_paytype')->field('paytype,payname')->select();
- $this->assign('paytype_list', $payTypelist);
- $this->assign('game_list', $this->selfGameList);
- return $this->fetch();
- }
- /**
- *充值规则修改
- */
- public function ruleEdit()
- {
- $id = $this->request->param('id', '', 'intval');
- $payruleModel = model('Common/Payrule');
- if (empty($id)) {
- $this->error('参数错误!');
- }
- if (!$data = $payruleModel->find($id)) {
- $this->error('参数错误,不存在该数据');
- }
- if ($this->request->isPost()) {
- $data = $this->request->post();
- if (true !== ($res = $this->validate($data, 'payrule'))) {
- $this->error($res);
- }
- if ($payruleModel->save($data, ['id' => $id]) !== false) {
- $this->success('修改成功', url('ruleList'));
- }
- $this->error($payruleModel->getError() ?: '修改失败');
- }
- $payTypelist = DB::table('cy_paytype')->field('paytype,payname')->select();
- $this->assign('paytype_list', $payTypelist);
- $this->assign('game_list', $this->selfGameList);
- $this->assign('data', $data);
- return $this->fetch();
- }
- /**
- * 充值规则删除
- */
- public function ruleDelete()
- {
- $id = $this->request->param('id', '', 'intval');
- if (empty($id)) {
- $this->error('参数错误!');
- }
- $payruleModel = model('Common/Payrule');
- if (!$payruleModel->find($id)) {
- $this->error('参数错误,不存在该数据');
- }
- if ($payruleModel->where('id', '=', $id)->delete()) {
- $this->success('删除成功', url('ruleList'));
- }
- $error = $payruleModel->getError();
- $this->error($error ?: '删除失败');
- }
- /**
- * 平台币补单记录
- * @throws \think\exception\DbException
- */
- public function ptblist()
- {
- $where = [];
- $order = 'create_time desc';
- $orderid = $this->request->get('orderid', '', 'trim');
- $username = $this->request->get('username', '', 'trim');
- $cname = $this->request->get('cname', '', 'trim');
- if (isset($orderid) && !empty($orderid)) {
- $where['a.orderid'] = $orderid;
- }
- if (isset($username) && !empty($username)) {
- $where['m.username'] = $username;
- }
- if (isset($cname) && !empty($cname)) {
- $where['c.username'] = $cname;
- }
- $list = Db::name('nw_channel_member_pay')->alias('a')
- ->join('nw_channel_admin c', 'c.id = a.channel_id', 'left')
- ->join('nw_channel cc', 'cc.id = a.qd_id', 'left')
- ->join('cy_members m', 'm.id = a.member_id', 'left')
- ->field('a.*,c.username,m.username as uname,cc.name as ccname')
- ->where($where)
- ->order($order)
- ->paginate();
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- return $this->fetch();
- }
- /**
- * 补单通知CP
- *
- */
- public function ptbreCallback()
- {
- if ($this->request->isPost()) {
- $orderid = input('post.orderid', '', 'trim');
- if (empty($orderid)) {
- $this->error('订单号不能为空');
- }
- $payCpInfoModel = model('Common/PayCpinfo');
- $where['orderid'] = $orderid;
- $paycpInfo = $payCpInfoModel->field('id,fcallbackurl,params,payflag,status')->where($where)->find();
- // if(empty($paycpInfo)){
- // $this->error('订单通知回调记录不存在');
- // }
- // elseif($paycpInfo['status']!=1){
- // $this->error('订单已完成');
- // }
- $guzzle = new Client();
- //将字符串转换成数组
- parse_str($paycpInfo['params'], $param);
- $pay = Db::name('cy_pay')->where(['orderid' => $orderid])->find();
- $userid = $pay['userid']; //用户
- $user_amount = $pay['amount']; //用户金额
- $members = Db::name('cy_members')->where(['id' => $userid])->find(); //用户表
- $chal_id = $members['channel_id']; //用户属于渠道
- $pyb = Db::name('nw_channel_admin')->where(['id' => $chal_id])->find(); //找到渠道 3519
- $pyb_channel_admin = Db::name('nw_channel')->where(['id' => $pyb['channel_id']])->find(); //在找到所属渠道 3544
- $pyb_channel_z = Db::name('nw_channel')->where(['id' => $pyb_channel_admin['parent_id']])->find(); //找到渠道 3543
- $pyb_channel_cz = Db::name('nw_channel_admin')->where(['channel_id' => $pyb_channel_z['id']])->find(); //找到渠道 3543
- if ($pyb_channel_cz['pyb'] < $user_amount) {
- $this->error("订单通知失败,平台币不足: ");
- }
- $data_info['pyb'] = $pyb_channel_cz['pyb'] - $user_amount;
- Db::name('nw_channel_admin')->where(['id' => $pyb_channel_cz['id']])->update($data_info);
- $data_infos['total_pay_amount'] = $members['total_pay_amount'] + $user_amount;
- Db::name('cy_members')->where(['id' => $userid])->update($data_infos);
- $data_pay['status'] = 1;
- $data_pay['payflag'] = 1;
- Db::name('cy_paycpinfo')->where(['orderid' => $orderid])->update($data_pay);
- $ds = [
- 'orderid' => $orderid,
- 'qd_id' => $chal_id,
- 'user_amount' => $user_amount,
- 'channel_id' => $pyb_channel_cz['id'],
- 'member_id' => $userid,
- 'create_time' => time()
- ];
- Db::name('nw_channel_member_pay')->insertGetId($ds);
- try {
- $response = $guzzle->request('post', $paycpInfo['fcallbackurl'], ['form_params' => $param, 'timeout' => 10]);
- //通知成功
- if (0 == strcasecmp($response->getBody(), 'success')) {
- $payCpInfoModel->save(['status' => 1, 'update_time' => NOW_TIMESTAMP], ['id' => $paycpInfo['id']]);
- $this->success('订单通知成功', url('ptblist'));
- } else {
- $this->error('订单通知已发送给对方,但对方未返回[success]信息');
- }
- } catch (GuzzleException $e) {
- $this->error("订单通知失败: " . $e->getMessage());
- }
- }
- return $this->fetch('ptbre_callback');
- }
- public function reCallback()
- {
- if ($this->request->isPost()) {
- $orderid = input('post.orderid', '', 'trim');
- if (empty($orderid)) {
- $this->error('订单号不能为空');
- }
- $payCpInfoModel = model('Common/PayCpinfo');
- $where['orderid'] = $orderid;
- $paycpInfo = $payCpInfoModel->field('id,fcallbackurl,params,payflag')->where($where)->find();
- if (empty($paycpInfo)) {
- $this->error('订单通知回调记录不存在');
- } elseif ($paycpInfo['payflag'] != 1) {
- $this->error('订单未完成支付或支付失败');
- }
- $guzzle = new Client();
- //将字符串转换成数组
- parse_str($paycpInfo['params'], $param);
- try {
- $response = $guzzle->request('post', $paycpInfo['fcallbackurl'], ['form_params' => $param, 'timeout' => 10]);
- log_message("[ADMIN-CP补单-SUCCESS]: " . 'orderid:' . $orderid . " url: " . $paycpInfo['fcallbackurl'] . " - params:" . json_encode($paycpInfo['params']) . " - result:" . $response->getBody()->getContents(), 'log', LOG_PATH . 'callBacklog/');
- //通知成功
- if (0 == strcasecmp($response->getBody(), 'success')) {
- $payCpInfoModel->save(['status' => 1, 'update_time' => NOW_TIMESTAMP], ['id' => $paycpInfo['id']]);
- $this->success('订单通知成功');
- } else {
- $this->error('订单通知已发送给对方,但对方未返回[success]信息');
- }
- } catch (GuzzleException $e) {
- log_message("[ADMIN-CP补单-ERROR]: " . 'orderid:' . $orderid . " url: " . $paycpInfo['fcallbackurl'] . " - params:" . json_encode($paycpInfo['params']), 'log', LOG_PATH . 'callBacklog/');
- $this->error("订单通知失败: " . $e->getMessage());
- }
- }
- return $this->fetch('re_callback');
- }
- /**
- * ajax 获取cp订单号
- */
- public function showAttach()
- {
- $order_id = input('post.orderid', '', 'filterAndTrimInput'); // 订单号
- $this->_showAttach($order_id);
- }
- /**
- * 查看订单的attach信息
- * @param $orderid string 订单号
- */
- private function _showAttach($orderid)
- {
- $runnable = true;
- $msg = '';
- $status = false;
- if (empty($orderid)) {
- $runnable = false;
- $msg = '参数错误';
- }
- if ($runnable) {
- $result = model('Pay')
- ->where(['orderid' => $orderid])
- ->field('attach')
- ->find();
- if (empty($result)) {
- $runnable = false;
- $msg = '订单不存在';
- }
- }
- // 查看attach
- if ($runnable) {
- $status = 1;
- $result['attach'] = 'attach=' . $result['attach'];
- parse_str($result['attach'], $arr);
- $msg = $arr['attach']; // 变量由上一个函数解析出来的
- }
- echo json_encode(['code' => $status, 'msg' => $msg]);
- }
- // 支付中控
- public function paySupcon()
- {
- // ## 支付方式列表
- $paySupconList = (new \app\common\model\PaySupconModel())->select()->toArray();
- $newPaySupconList = [
- 'wx_h5' => [
- "id" => 1,
- "pay_type" => "微信支付-H5",
- "pay_channel" => "",
- "mark" => "wx_h5",
- "type" => 1,
- "probability" => "",
- "description" => "-",
- "parentId" => null,
- "cascade" => "all",
- "children" => [],
- ],
- // 'wx_app' => [],
- 'ali_h5' => [
- "id" => 3,
- "pay_type" => "支付宝-H5",
- "pay_channel" => "",
- "mark" => "ali_h5",
- "type" => 1,
- "probability" => "",
- "description" => "-",
- "parentId" => null,
- "cascade" => "all",
- "children" => [],
- ],
- 'ali_app' => [
- "id" => 4,
- "pay_type" => "支付宝-APP",
- "pay_channel" => "",
- "mark" => "ali_app",
- "type" => 1,
- "probability" => "",
- "description" => "-",
- "parentId" => null,
- "cascade" => "all",
- "children" => [],
- ],
- 'coinpay' => [
- "id" => 5,
- "pay_type" => "平台币",
- "pay_channel" => "",
- "mark" => "coinpay",
- "type" => 1,
- "probability" => "",
- "description" => "-",
- "parentId" => null,
- "cascade" => "all",
- "children" => [],
- ]
- ];
- foreach ($paySupconList as $key => $value) {
- $parentId = 1;
- switch ($value['pay_scene']) {
- case "wx_h5":
- $parentId = 1;
- break;
- case "ali_h5":
- $parentId = 3;
- break;
- case "ali_app":
- $parentId = 4;
- break;
- case "coinpay":
- $parentId = 5;
- break;
- }
- $game_ids = $value['game_ids'];
- if ($value['game_ids'] != 'all') {
- $game_ids = explode(',', substr($value['game_ids'], 1, -1));
- }
- $sdk_versions = $value['sdk_versions'];
- if ($value['sdk_versions'] != 'all') {
- $sdk_versions = explode(',', substr($value['sdk_versions'], 1, -1));
- }
- $children = [
- "id" => $value['id'],
- "pay_type" => "",
- "pay_channel" => $value['paytype_name'],
- "mark" => $value['pay_mark'],
- "type" => 0,
- "probability" => $value['probability'],
- "parentId" => $parentId,
- "description" => "-",
- "isParent" => false,
- "game_ids" => $game_ids,
- "sdk_versions" => $sdk_versions,
- "status" => $value['status'],
- ];
- $newPaySupconList[$value['pay_scene']]['children'][] = $children;
- }
- if ($newPaySupconList) {
- $newPaySupconList = array_values($newPaySupconList);
- }
- $this->assign('paySupconList', json_encode($newPaySupconList));
- // ## 游戏列表
- $gameList = (new \app\common\model\Game())->where(['status' => 1])->order('id desc')->field(['id', 'name', 'type'])->select()->toArray();
- $newGameList = [
- "android" => [
- "id" => "",
- "title" => "Android",
- "field" => "android",
- "checked" => false,
- "spread" => false,
- "children" => []
- ],
- "ios" => [
- "id" => "",
- "title" => "IOS",
- "field" => "ios",
- "checked" => false,
- "spread" => false,
- "children" => []
- ],
- "h5" => [
- "id" => "",
- "title" => "H5",
- "field" => "h5",
- "checked" => false,
- "spread" => false,
- "children" => []
- ],
- ];
- foreach ($gameList as $key => $value) {
- $children = [
- "id" => $value['id'],
- "field" => $value['id'],
- "title" => $value['name'],
- "checked" => false,
- "href" => "",
- ];
- // 游戏类型:1=ios、2=安卓、3=h5
- if ($value['type'] == 2) {
- $newGameList['android']['children'][] = $children;
- } else if ($value['type'] == 3) {
- $newGameList['h5']['children'][] = $children;
- } else if ($value['type'] == 1) {
- $newGameList['ios']['children'][] = $children;
- }
- }
- if ($newGameList) {
- $newGameList = array_values($newGameList);
- }
- $this->assign('gameList', json_encode($newGameList));
- // ## SDK版本
- $versionList = (new \app\common\model\AndroidSdk())->field(['id', 'version', 'num'])->order('id desc')->select()->toArray();
- $newVersionList = [
- "version" => [
- "id" => "",
- "title" => "SDK 版本",
- "field" => "version",
- "checked" => false,
- "spread" => true,
- "children" => []
- ],
- ];
- foreach ($versionList as $key => $value) {
- $children = [
- "id" => $value['id'],
- "field" => $value['num'],
- "title" => $value['version'],
- "checked" => false,
- "href" => "",
- ];
- $newVersionList['version']['children'][] = $children;
- }
- if ($newVersionList) {
- $newVersionList = array_values($newVersionList);
- }
- // dump($newGameList);
- $this->assign('versionList', json_encode($newVersionList));
- return $this->fetch();
- }
- // 处理绑定
- public function saveSupcon()
- {
- try {
- $parame = $this->request->only(['game_ids', 'sdk_versions', 'probability']);
- $id = input('id');
- $result = PaySupconModel::where(['id' => $id])->update($parame);
- if ($result) {
- echo json_encode(['code' => 200, 'msg' => 'success', 'data' => $result]);
- return;
- }
- echo json_encode(['code' => 200, 'msg' => '没有变动!', 'data' => $result]);
- return;
- } catch (\Exception $e) {
- // dump($e->getFile(), $e->getLine());
- echo json_encode(['code' => -110, 'msg' => 'error:' . $e->getMessage(), 'data' => []]);
- return;
- }
- echo json_encode(['code' => -100, 'msg' => 'error', 'data' => []]);
- }
- // 处理状态
- public function saveSupconStatus()
- {
- $parame = $this->request->only(['status']);
- $id = input('id');
- if (empty($id) || empty($id)) {
- echo json_encode(['code' => -100, 'msg' => '参数有误!', 'data' => []]);
- return;
- }
- $supconInfo = PaySupconModel::get($id);
- if (empty($supconInfo)) {
- echo json_encode(['code' => -110, 'msg' => '数据不存在!', 'data' => []]);
- return;
- }
- try {
- $result = (new PaySupconModel())->update($parame, ['id' => $id]);
- if ($result) {
- $this->insertLog($this->current_node, '支付场景:' . $supconInfo['pay_scene'] . ' - 支付渠道:' . $supconInfo['paytype_name'] . ' - 状态:' . ($parame['status'] == 0 ? '关' : '开'), 569);
- echo json_encode(['code' => 200, 'msg' => 'success', 'data' => $result]);
- return;
- }
- } catch (Exception $e) {
- echo json_encode(['code' => -120, 'msg' => 'error:' . $e->getMessage(), 'data' => []]);
- return;
- }
- echo json_encode(['code' => -100, 'msg' => 'error', 'data' => []]);
- }
- // 处理权重
- public function saveProbability()
- {
- try {
- $parame = $this->request->post();
- if (!$parame) {
- echo json_encode(['code' => -100, 'msg' => 'error: 缺少必要参数!', 'data' => []]);
- }
- $result = (new PaySupconModel())->isUpdate()->saveAll($parame['formData']);
- if ($result!== false) {
- echo json_encode(['code' => 200, 'msg' => 'success', 'data' => []]);
- return;
- }
- } catch (Exception $e) {
- echo json_encode(['code' => -110, 'msg' => 'error:' . $e->getMessage(), 'data' => []]);
- return;
- }
- echo json_encode(['code' => -100, 'msg' => 'error', 'data' => []]);
- }
- }
|