Pay.php 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721
  1. <?php
  2. /**
  3. * 充值记录管理控制器
  4. *
  5. */
  6. namespace app\admin\controller;
  7. use app\common\library\MakeReportGo;
  8. use app\common\model\PaySupconModel;
  9. use app\common\model\CompanyGameBind;
  10. use think\Db;
  11. use app\common\library\MakeReport;
  12. use GuzzleHttp\Client;
  13. use GuzzleHttp\Exception\GuzzleException;
  14. use think\Exception;
  15. class Pay extends Admin
  16. {
  17. private $condition = [];
  18. protected $start;
  19. protected $end;
  20. protected $noCheckAuth = ['getChannel'];
  21. private $gameIds = []; //海外游戏id
  22. protected function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->gameList = $gameList = model('Common/Game')->getAllByCondition('id,name');
  26. $tmpSelfGameList = model('Common/Game')->getAllByCondition('id,name', [], '', 'self');
  27. $selfGameList = array();
  28. foreach ($tmpSelfGameList as $game) {
  29. $selfGameList[$game['id']] = $game;
  30. }
  31. $this->selfGameList = $selfGameList;
  32. $this->gameIds = config('haiwai_game_ids_arr');
  33. }
  34. /**
  35. * 前置方法(参数获取)
  36. */
  37. protected function _beforeGetParams()
  38. {
  39. $start = $this->request->param('start');
  40. $end = $this->request->param('end');
  41. $channel_id = $this->request->param('channel_id', 0, 'intval');
  42. $top_channel_id = $this->request->param('parent_channel_id', 0, 'intval');
  43. $bplus_channel_id = $this->request->param('bplus_channel_id', 0, 'intval');
  44. $gameid = $this->request->param('gameid', 0, 'trim');
  45. $status = $this->request->param('status');
  46. // $cp_status = $this->request->param('cp_status');
  47. $orderid = $this->request->param('orderid', '', 'trim');
  48. $username = $this->request->param('username', '', 'trim');
  49. // $paytype = $this->request->param('paytype', '', 'trim');
  50. $servername = $this->request->param('servername', '', 'trim');
  51. $roleid = $this->request->param('roleid', '', 'trim');
  52. $rolename = $this->request->param('rolename', '', 'trim');
  53. $company_id = $this->request->param('company_id', 0, 'intval');
  54. $client_type = $this->request->param('client_type', 0, 'intval');
  55. $condition = [];
  56. // 如果选择了公司,则使用公司绑定的游戏ID列表
  57. if (!empty($company_id)) {
  58. $companyGameBind = new CompanyGameBind();
  59. $companyInfo = $companyGameBind->where(['id' => $company_id])->find();
  60. if (!empty($companyInfo) && !empty($companyInfo['game_ids'])) {
  61. $gameIds = explode(',', $companyInfo['game_ids']);
  62. $gameIds = array_filter($gameIds);
  63. if (!empty($gameIds)) {
  64. if (count($gameIds) > 1) {
  65. $condition['p.gameid'] = ['in', $gameIds];
  66. } else {
  67. $condition['p.gameid'] = $gameIds[0];
  68. }
  69. } else {
  70. // 如果公司没有绑定游戏,设置一个不存在的ID,使查询结果为空
  71. $condition['p.gameid'] = -1;
  72. }
  73. } else {
  74. // 如果公司不存在或没有绑定游戏,设置一个不存在的ID
  75. $condition['p.gameid'] = -1;
  76. }
  77. } elseif (!empty($gameid)) {
  78. // 如果没有选择公司,则使用原来的游戏ID搜索逻辑
  79. $gameids = explode(',', $gameid);
  80. if (count($gameids) > 1) {
  81. $gameid = ['in', $gameids];
  82. }
  83. $condition['p.gameid'] = $gameid;
  84. }
  85. if (!empty($orderid)) {
  86. $condition['p.orderid'] = $orderid;
  87. }
  88. // dump($condition);
  89. // if (!empty($paytype)) {
  90. // if ($paytype == "wx") {
  91. // $condition['p.paytype'] = ['IN', ['wxpay-h5', 'ybzf_wxmp_h5', 'coin-wxpay-h5', 'coin-ybzf_wxmp_h5', 'mix-wxpay-h5', 'mix-ybzf_wxmp_h5']];
  92. // } else if($paytype == "zfb") {
  93. // $condition['p.paytype'] = ['IN', ['zfb', 'old-zfb-wap', 'coin-zfb', 'old-zfb-wap', 'mix-zfb', 'mix-old-zfb-wap']];
  94. // } else if($paytype == "coin") {
  95. // $condition['p.paytype'] = ['IN', ['coinpay', 'coin-zfb', 'coin-old-zfb-wap', 'coin-wxpay-h5', 'coin-ybzf_wxmp_h5']];
  96. // } else if($paytype == "coupon") {
  97. // $condition['p.paytype'] = ['IN', ['coupon', 'mix-zfb', 'mix-old-zfb-wap', 'mix-wxpay-h5', 'mix-ybzf_wxmp_h5']];
  98. // }
  99. // }
  100. // if (!empty($paytype)) {
  101. // $condition['p.paytype'] = $paytype;
  102. // }
  103. if (is_numeric($status)) {
  104. $condition['p.status'] = (int)$status;
  105. }
  106. // if (!empty($cp_status)) {
  107. // $condition['paycpinfo.status'] = $cp_status;
  108. // }
  109. if (!empty($username)) {
  110. // // $condition['p.username'] = ['LIKE', '%' . $username . '%'];
  111. // $memberId = Db::table('cy_members')->where(['username' => $username])->value('id');
  112. // //改成精确查询
  113. // $condition['p.userid'] = $memberId;
  114. $condition['p.username'] = $username;
  115. }
  116. if (!empty($servername)) {
  117. $condition['p.servername'] = $servername;
  118. }
  119. $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
  120. if ($business != -1) {
  121. if ($bplus_channel_id) {
  122. if (!in_array($bplus_channel_id, $business)) {
  123. $bplus_channel_id = -1;
  124. }
  125. } else {
  126. if ($business && $business != -2) {
  127. $bplus_channel_id = implode(',', $business);
  128. } else {
  129. $bplus_channel_id = -1;
  130. }
  131. }
  132. }
  133. //联盟/公会/渠道有选择时判断
  134. if (!empty($channel_id) || !empty($top_channel_id) || !empty($bplus_channel_id)) {
  135. if (!empty($channel_id) && !empty($top_channel_id) && !empty($bplus_channel_id)) {
  136. unset($condition['p.channel_id']);
  137. $bChannelIds = get_child_channel_arr($top_channel_id);
  138. array_push($bChannelIds, $top_channel_id);
  139. $bplusChannelIds = get_child_channel_arr($bplus_channel_id);
  140. $bplusChannelIds = array_merge($bplusChannelIds, explode(',', $bplus_channel_id));
  141. $channelIds = array_intersect($bChannelIds, $bplusChannelIds, array($channel_id));
  142. if ($channelIds) {
  143. $condition['p.channel_id'] = ['in', $channelIds];
  144. } else {
  145. $condition['p.channel_id'] = -1;
  146. }
  147. } else if (!empty($top_channel_id) && !empty($bplus_channel_id)) {
  148. $bChannelIds = get_child_channel_arr($top_channel_id);
  149. array_push($bChannelIds, $top_channel_id);
  150. $bplusChannelIds = get_child_channel_arr($bplus_channel_id);
  151. $bplusChannelIds = array_merge($bplusChannelIds, explode(',', $bplus_channel_id));
  152. $channelIds = array_intersect($bChannelIds, $bplusChannelIds);
  153. if ($channelIds) {
  154. $condition['p.channel_id'] = ['in', $channelIds];
  155. } else {
  156. $condition['p.channel_id'] = -1;
  157. }
  158. } elseif (!empty($channel_id) && !empty($bplus_channel_id)) {
  159. $bplusChannelIds = get_child_channel_arr($bplus_channel_id);
  160. $bplusChannelIds = array_merge($bplusChannelIds, explode(',', $bplus_channel_id));
  161. $channelIds = array_intersect($bplusChannelIds, array($channel_id));
  162. if ($channelIds) {
  163. $condition['p.channel_id'] = ['in', $channelIds];
  164. } else {
  165. $condition['p.channel_id'] = -1;
  166. }
  167. } elseif (!empty($channel_id) && !empty($top_channel_id)) {
  168. $bChannelIds = get_child_channel_arr($top_channel_id);
  169. array_push($bChannelIds, $top_channel_id);
  170. $channelIds = array_intersect($bChannelIds, array($channel_id));
  171. if ($channelIds) {
  172. $condition['p.channel_id'] = ['in', $channelIds];
  173. } else {
  174. $condition['p.channel_id'] = -1;
  175. }
  176. } elseif (!empty($top_channel_id)) {
  177. $channelIds = get_child_channel_arr($top_channel_id);
  178. array_push($channelIds, $top_channel_id);
  179. $condition['p.channel_id'] = ['in', $channelIds];
  180. } elseif (!empty($bplus_channel_id)) {
  181. $channelIds = get_child_channel_arr($bplus_channel_id);
  182. $channelIds = array_merge($channelIds, explode(',', $bplus_channel_id));
  183. $condition['p.channel_id'] = ['in', $channelIds];
  184. } elseif (!empty($channel_id)) {
  185. $condition['p.channel_id'] = $channel_id;
  186. }
  187. }
  188. $timeName = "p.pay_time";
  189. if($this->request->action() == 'list'){
  190. $timeName = "p.create_time";
  191. }
  192. //开始时间和结束时间不为空时
  193. if ($start != '' && $end != '') {
  194. $condition[$timeName] = [
  195. ['>=', strtotime($start)],
  196. ['<=', strtotime($end . ' 23:59:59')],
  197. ];
  198. } //开始时间不为空时
  199. elseif ($start != '') {
  200. $condition[$timeName] = ['>=', strtotime($start)];
  201. } //结束时间不为空时
  202. elseif ($end != '') {
  203. $condition[$timeName] = ['<=', strtotime($end . ' 23:59:59')];
  204. } else {
  205. $start = $end = date('Y-m-d', time());
  206. $condition[$timeName] = [
  207. ['>=', strtotime($start)],
  208. ['<=', strtotime($start . ' 23:59:59')],
  209. ];
  210. }
  211. // if ($username=='' && $orderid==''){
  212. // if(strtotime($end.' 23:59:59')-strtotime($start)>31*24*3600)
  213. // {
  214. // $this->error('单次查询日期的最长跨度为31天');
  215. // }
  216. // }
  217. if (!empty($roleid)) {
  218. $condition['p.roleid'] = $roleid;
  219. }
  220. if (!empty($rolename)) {
  221. $condition['p.rolename'] = ['like', "%{$rolename}%"];
  222. }
  223. $this->start = $start;
  224. $this->end = $end;
  225. // 游戏上线状态
  226. $cooperation_status = $this->request->param('cooperation_status', 0, 'intval'); // 游戏上线状态
  227. if (!empty($cooperation_status)) {
  228. $game_cooperation_status = $cooperation_status == 1 ? 1 : 2;
  229. $gameIds = Model('Game')->getNormalByIds($game_cooperation_status);
  230. $condition['p.gameid'] = ['in', $gameIds];
  231. }
  232. // 数据归属/客户端类型(1=祈盟sdk, 2=巨量, 3=快手磁力包)
  233. if (!empty($client_type)) {
  234. $condition['p.client_type'] = $client_type;
  235. }
  236. $this->setCondition($condition);
  237. }
  238. /**
  239. * 充值记录管理(抓取) - 弃用
  240. *
  241. * @return mixed|string
  242. */
  243. public function index()
  244. {
  245. $this->_beforeGetParams();
  246. $condition = $this->getCondition();
  247. //充值总金额
  248. $totalAmount = $todayTotalAmount = $lastDayTotalAmount = 0;
  249. $PayModel = model('Common/Pay');
  250. $paytype = $this->request->param('paytype', '', 'trim');
  251. $pageSize = input('page_size', 15);
  252. if (!empty($paytype)) {
  253. if ($paytype == "wx") {
  254. $paytype = [
  255. "wxpay-h5", "coin-wxpay-h5", "mix-wxpay-h5",
  256. "ybzf_wxmp_h5", "coin-ybzf_wxmp_h5", "mix-ybzf_wxmp_h5",
  257. "qzl_wx_h5", "coin-qzl_wx_h5", "mix-qzl_wx_h5",
  258. 'xty_wx_h5', "coin-xty_wx_h5", "mix-xty_wx_h5",
  259. 'qmf_wxmp_h5', "coin-qmf_wxmp_h5", "mix-qmf_wxmp_h5",
  260. 'yyyb_wx_h5', "coin-yyyb_wx_h5", "mix-yyyb_wx_h5",
  261. "dh_wx"
  262. ];
  263. $condition['p.paytype'] = ['IN', $paytype];
  264. } else if ($paytype == "zfb") {
  265. $paytype = [
  266. "zfb", "coin-zfb", "mix-zfb",
  267. "old-zfb-wap", "coin-old-zfb-wap", "mix-old-zfb-wap",
  268. 'ldys_zfb_h5', "coin-ldys_zfb_h5", "mix-ldys_zfb_h5",
  269. "xty_ali_h5", "coin-xty_ali_h5", "mix-xty_ali_h5",
  270. 'yyyb_ali_h5', "coin-yyyb_ali_h5", "mix-yyyb_ali_h5",
  271. "dh_zfb"
  272. ];
  273. $condition['p.paytype'] = ['IN', $paytype];
  274. } else if ($paytype == "coin") {
  275. $paytype = [
  276. "coinpay",
  277. "coin-zfb", "coin-old-zfb-wap",
  278. "coin-ldys_zfb_h5", "coin-xty_ali_h5", "coin-yyyb_ali_h5",
  279. "coin-qzl_wx_h5", "coin-ldys_wx_h5", "coin-yyyb_wx_h5", "coin-ybzf_wxmp_h5", "coin-xty_wx_h5",
  280. ];
  281. $condition['p.paytype'] = ['IN', $paytype];
  282. } else if ($paytype == "coupon") {
  283. $paytype = [
  284. "coupon",
  285. "mix-zfb", "mix-old-zfb-wap",
  286. "mix-ldys_zfb_h5", "mix-xty_ali_h5", "mix-yyyb_ali_h5",
  287. "mix-qzl_wx_h5", "mix-ldys_wx_h5", "mix-yyyb_wx_h5", "mix-ybzf_wxmp_h5", "mix-xty_wx_h5",
  288. ];
  289. $condition['p.paytype'] = ['IN', $paytype];
  290. }
  291. }
  292. $cp_status = $this->request->param('cp_status'); // 游戏通知状态:0(通知失败)1(通知成功)
  293. if (is_numeric($cp_status)) {
  294. $condition['paycpinfo.status'] = (int)$cp_status;
  295. }
  296. $gh_status = input('gh_status', 0); // 是否聚合用户:0=否、1=是
  297. if ($gh_status <> '') {
  298. $condition['channel.gh_status'] = $gh_status;
  299. }
  300. // 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
  301. $list = $PayModel->alias('p')
  302. ->join('nw_channel channel', 'p.channel_id=channel.id')
  303. ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
  304. ->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')
  305. ->where($condition)
  306. // ->whereNotIn('gameid',$this->gameIds) // 排除海外游戏
  307. ->order('p.pay_time desc')
  308. // ->fetchSql(true)
  309. // ->select();
  310. ->paginate($pageSize, false, ['query' => input('get.')]);
  311. // dump($list);
  312. $parent_list = model('Common/Channel')->getParentChannel(); // 获取所有父类渠道
  313. if ($list->total() > 0) {
  314. $data = $list->toArray()['data'];
  315. $userIdArr = $paytype = $gameIdArr = $channelIdArr = $ttbhistoryArr = [];
  316. foreach ($data as $v) {
  317. $userIdArr[] = $v['userid'];
  318. $paytype[] = $v['paytype'];
  319. $gameIdArr[] = $v['gameid'];
  320. $channelIdArr[] = $v['channel_id'];
  321. }
  322. //关联数据查询
  323. $gameNameArr = model('Common/Game')->whereIn('id', array_unique($gameIdArr))->column('name', 'id');
  324. $regTimeArr = model('Common/Members')->whereIn('id', array_unique($userIdArr))->column('reg_time', 'id');
  325. foreach ($list as $key => $item) {
  326. $default = '--';
  327. $list[$key]['game_name'] = isset($gameNameArr[$item['gameid']]) ? $gameNameArr[$item['gameid']] : $default;
  328. $list[$key]['reg_time'] = isset($regTimeArr[$item['userid']]) ? date("Y-m-d H:i:s", $regTimeArr[$item['userid']]) : $default;
  329. $channel = get_top_second_channel_name($list[$key]['channel_id']);
  330. $list[$key]['channel_name'] = $channel['channel_name'];
  331. $list[$key]['second_channel'] = $channel['second_name'];
  332. $list[$key]['top_channel'] = $channel['top_name'];
  333. $list[$key]['union_name'] = get_union_channel($list[$key]['channel_id'])['name'];
  334. }
  335. //支付成功 或者支付查询条件未选择时
  336. if (input('status') == 1 || input('status') == '') {
  337. //充值完成总金额
  338. $totalAmount = $PayModel->alias('p')
  339. ->join('nw_channel channel', 'p.channel_id=channel.id')
  340. ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
  341. ->field('sum(pay_amount) as total_amount,paycpinfo.status as cp_status')
  342. ->where($condition)
  343. // ->whereNotIn('gameid', $this->gameIds)
  344. ->where('p.status=1')->find()['total_amount'];
  345. }
  346. }
  347. $where['p.create_time'] = [
  348. ['>=', strtotime(date('Y-m-d'))],
  349. ['<=', strtotime(date('Y-m-d') . ' 23:59:59')],
  350. ];
  351. unset($condition["p.create_time"]);
  352. $todayTotalAmount = floatval(model('Pay')->alias("p")
  353. ->join('nw_channel channel', 'p.channel_id=channel.id')
  354. ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
  355. ->where($condition)
  356. // ->whereNotIn('gameid',$this->gameIds)
  357. ->field('sum(pay_amount) as total_amount,paycpinfo.status as cp_status')->where('p.status=1')->where($where)->find()['total_amount']);
  358. $where['p.create_time'] = [
  359. ['>=', strtotime(date("Y-m-d", strtotime("-1 day")))],
  360. ['<', strtotime(date('Y-m-d'))],
  361. ];
  362. $lastDayTotalAmount = floatval(model('Pay')
  363. ->alias("p")->where($condition)
  364. ->join('nw_channel channel', 'p.channel_id=channel.id')
  365. ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
  366. // ->whereNotIn('gameid',$this->gameIds)
  367. ->field('sum(pay_amount) as total_amount,paycpinfo.status as cp_status')->where('p.status=1')->where($where)->find()['total_amount']);
  368. $this->assign('list', $list);
  369. $this->assign('page', $list->render());
  370. $this->assign('paytype', config('paytype'));
  371. $this->assign('new_pay_type', config('new_pay_type'));
  372. $this->assign('game_list', $this->selfGameList);
  373. $this->assign('channel_id', $this->request->get('channel_id')); //查询条件中的渠道ID
  374. $this->assign('parent_list', $parent_list); //顶级渠道列表
  375. $this->assign('start', $this->start);
  376. $this->assign('end', $this->end);
  377. $this->assign('totalAmount', $totalAmount);
  378. $this->assign('todayTotalAmount', $todayTotalAmount);
  379. $this->assign('lastDayTotalAmount', $lastDayTotalAmount);
  380. $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
  381. $channelWhere = [];
  382. if ($business != -1) {
  383. if ($business && $business != -2) {
  384. $channelWhere['id'] = ['in', $business];
  385. } else {
  386. $channelWhere['id'] = -1;
  387. }
  388. }
  389. $uniom = model('Channel')->where(['level' => 0])->where($channelWhere)->field('id,name')->select();
  390. $this->assign('uniom', $uniom); //顶级渠道列表
  391. return $this->fetch();
  392. }
  393. // 充值记录管理展示
  394. public function list()
  395. {
  396. $this->_beforeGetParams();
  397. $condition = $this->getCondition();
  398. $PayModel = model('Common/Pay');
  399. $paytype = $this->request->param('paytype', '', 'trim');
  400. $pageSize = input('page_size', 15);
  401. if (!empty($paytype)) {
  402. if ($paytype == "wx") {
  403. $paytype = [
  404. "wxpay-h5", "coin-wxpay-h5", "mix-wxpay-h5",
  405. "ybzf_wxmp_h5", "coin-ybzf_wxmp_h5", "mix-ybzf_wxmp_h5",
  406. "qzl_wx_h5", "coin-qzl_wx_h5", "mix-qzl_wx_h5",
  407. 'xty_wx_h5', "coin-xty_wx_h5", "mix-xty_wx_h5",
  408. 'qmf_wxmp_h5', "coin-qmf_wxmp_h5", "mix-qmf_wxmp_h5",
  409. 'yyyb_wx_h5', "coin-yyyb_wx_h5", "mix-yyyb_wx_h5",
  410. "dh_wx"
  411. ];
  412. $condition['p.paytype'] = ['IN', $paytype];
  413. } else if ($paytype == "zfb") {
  414. $paytype = [
  415. "zfb",
  416. "coin-zfb",
  417. "mix-zfb",
  418. "old-zfb-wap",
  419. "coin-old-zfb-wap",
  420. "mix-old-zfb-wap",
  421. 'ldys_zfb_h5',
  422. "coin-ldys_zfb_h5",
  423. "mix-ldys_zfb_h5",
  424. "xty_ali_h5",
  425. "coin-xty_ali_h5",
  426. "mix-xty_ali_h5",
  427. 'yyyb_ali_h5',
  428. "coin-yyyb_ali_h5",
  429. "mix-yyyb_ali_h5",
  430. "dh_zfb"
  431. ];
  432. $condition['p.paytype'] = ['IN', $paytype];
  433. } else if ($paytype == "coin") {
  434. $paytype = [
  435. "coinpay",
  436. "coin-zfb", "coin-old-zfb-wap",
  437. "coin-ldys_zfb_h5", "coin-xty_ali_h5", "coin-yyyb_ali_h5",
  438. "coin-qzl_wx_h5", "coin-ldys_wx_h5", "coin-yyyb_wx_h5", "coin-ybzf_wxmp_h5", "coin-xty_wx_h5",
  439. ];
  440. $condition['p.paytype'] = ['IN', $paytype];
  441. } else if ($paytype == "coupon") {
  442. $paytype = [
  443. "coupon",
  444. "mix-zfb", "mix-old-zfb-wap",
  445. "mix-ldys_zfb_h5", "mix-xty_ali_h5", "mix-yyyb_ali_h5",
  446. "mix-qzl_wx_h5", "mix-ldys_wx_h5", "mix-yyyb_wx_h5", "mix-ybzf_wxmp_h5", "mix-xty_wx_h5",
  447. ];
  448. $condition['p.paytype'] = ['IN', $paytype];
  449. }
  450. }
  451. $cp_status = $this->request->param('cp_status');
  452. if (is_numeric($cp_status)) {
  453. $condition['paycpinfo.status'] = (int)$cp_status;
  454. }
  455. $gh_status = input('gh_status', 0); // 是否聚合用户:0=否、1=是
  456. if ($gh_status <> '') {
  457. $condition['channel.gh_status'] = $gh_status;
  458. }
  459. $test_status = input('test_status', 0); // 是否测试:0=否、1=是
  460. if($test_status == 1){
  461. $testMemberIds = Db::table('cy_members')
  462. ->where('test_status', 1)
  463. ->column('id');
  464. // 如果有测试账户,加入查询条件
  465. if (!empty($testMemberIds)) {
  466. $condition['p.userid'] = ['not in', $testMemberIds];
  467. }
  468. }
  469. // dump($condition);
  470. // 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=
  471. $list = $PayModel->alias('p')
  472. ->join('nw_channel channel', 'p.channel_id=channel.id', 'left')
  473. ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
  474. ->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')
  475. ->where($condition)
  476. // ->whereNotIn('gameid', $this->gameIds)
  477. ->order('p.id desc')
  478. ->paginate($pageSize, false, ['query' => input('get.')]);
  479. $parent_list = model('Common/Channel')->getParentChannel();
  480. if ($list->total() > 0) {
  481. $data = $list->toArray()['data'];
  482. $userIdArr = $paytype = $gameIdArr = $channelIdArr = $ttbhistoryArr = $roleIdsArr = [];
  483. $userIdArr = array_column($data, 'userid');
  484. // $paytype = array_column($data, 'paytype');
  485. $gameIdArr = array_column($data, 'gameid');
  486. // $channelIdArr = array_column($data, 'channel_id');
  487. $roleIdsArr = array_column($data, 'roleid');
  488. //关联数据查询
  489. $gameNameArr = model('Common/Game')->whereIn('id', array_unique($gameIdArr))->column('name', 'id');
  490. $regTimeArr = model('Common/Members')->whereIn('id', array_unique($userIdArr))->column('reg_time', 'id');
  491. $roleListByRegtime = model('Common/MemberGameServer')->whereIn('roleid', array_unique($roleIdsArr))->column('create_time', 'roleid');
  492. foreach ($list as $key => $item) {
  493. $default = '--';
  494. $list[$key]['game_name'] = isset($gameNameArr[$item['gameid']]) ? $gameNameArr[$item['gameid']] : $default;
  495. $list[$key]['reg_time'] = isset($regTimeArr[$item['userid']]) ? date("Y-m-d H:i:s", $regTimeArr[$item['userid']]) : $default;
  496. $list[$key]['role_reg_time'] = isset($roleListByRegtime[$item['roleid']]) ? date("Y-m-d H:i:s", $roleListByRegtime[$item['roleid']]) : $default;
  497. // $channel = get_top_second_channel_name($list[$key]['channel_id']);
  498. $channel = get_top_second_channel_name_v2($list[$key]['channel_id']);
  499. $list[$key]['channel_name'] = $channel['channel_name'];
  500. $list[$key]['second_channel'] = $channel['second_name'];
  501. $list[$key]['top_channel'] = $channel['top_name'];
  502. $list[$key]['union_name'] = $channel['union_name'];
  503. }
  504. }
  505. // ## 统计数据
  506. $condition['p.status'] = 1; // 只统计支付成功的订单
  507. $totalData = model('Common/Pay')->alias('p')
  508. ->join('nw_channel channel', 'p.channel_id=channel.id', 'left')
  509. ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
  510. ->where($condition)
  511. ->field([
  512. 'SUM(p.amount) as totalAmount',
  513. 'SUM(p.coupon_amount) as couponAmount',
  514. 'SUM(p.pay_amount) as payAmount',
  515. 'SUM(p.coupon_amount + p.pay_amount) as couponBypayAmount'
  516. ])
  517. ->find();
  518. $statisticsData = [
  519. 'totalAmount' => $totalData['totalAmount']??0, // 订单金额
  520. 'couponAmount' => $totalData['couponAmount']??0, // 代金卷抵扣
  521. 'payAmount' => $totalData['payAmount']??0, // 实付金额
  522. 'couponBypayAmount' => $totalData['couponBypayAmount']??0, // 代金卷+实付
  523. ];
  524. $this->assign('statisticsData', $statisticsData);
  525. // 获取公司列表
  526. $companyList = (new CompanyGameBind())->field('id,company_name,company_alias')->order('id desc')->select();
  527. $companyArr = [];
  528. foreach ($companyList as $company) {
  529. $companyArr[] = [
  530. 'id' => $company['id'],
  531. 'name' => $company['company_name'] . ' (' . $company['company_alias'] . ')'
  532. ];
  533. }
  534. $this->assign('list', $list);
  535. $this->assign('page', $list->render());
  536. $this->assign('paytype', config('paytype'));
  537. $this->assign('new_pay_type', config('new_pay_type'));
  538. $this->assign('game_list', $this->selfGameList);
  539. $this->assign('company_list', $companyArr);
  540. $this->assign('channel_id', $this->request->get('channel_id')); //查询条件中的渠道ID
  541. $this->assign('parent_list', $parent_list); //顶级渠道列表
  542. $this->assign('start', $this->start);
  543. $this->assign('end', $this->end);
  544. $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
  545. $channelWhere = [];
  546. if ($business != -1) {
  547. if ($business && $business != -2) {
  548. $channelWhere['id'] = ['in', $business];
  549. } else {
  550. $channelWhere['id'] = -1;
  551. }
  552. }
  553. $uniom = model('Channel')->where(['level' => 0])->where($channelWhere)->field('id,name')->select();
  554. $this->assign('uniom', $uniom); //顶级渠道列表
  555. return $this->fetch();
  556. }
  557. /**
  558. * 前置方法(参数获取)
  559. */
  560. protected function _beforeChannelPayGetParams()
  561. {
  562. $start = $this->request->param('start');
  563. $end = $this->request->param('end');
  564. $b_channel_id = $this->request->param('b_channel_id', 0, 'intval');
  565. $bplus_channel_id = $this->request->param('bplus_channel_id', 0, 'intval');
  566. $gameid = $this->request->param('gameid', 0, 'intval');
  567. $condition = [];
  568. $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
  569. if ($business != -1) {
  570. if ($bplus_channel_id) {
  571. if (!in_array($bplus_channel_id, $business)) {
  572. $bplus_channel_id = [-1];
  573. }
  574. } else {
  575. if ($business && $business != -2) {
  576. $bplus_channel_id = implode(',', $business);
  577. } else {
  578. $bplus_channel_id = [-1];
  579. }
  580. }
  581. }
  582. if (!empty($gameid)) {
  583. $condition['gameid'] = $gameid;
  584. }
  585. if (!empty($b_channel_id) && !empty($bplus_channel_id)) {
  586. unset($condition['channel_id']);
  587. $bChannelIds = get_child_channel_arr($b_channel_id);
  588. array_push($bChannelIds, $b_channel_id);
  589. $bplusChannelIds = get_child_channel_arr($bplus_channel_id);
  590. array_push($bplusChannelIds, $bplus_channel_id);
  591. $channelIds = array_intersect($bChannelIds, $bplusChannelIds);
  592. // var_dump($channelIds);
  593. $condition['channel_id'] = ['in', $channelIds];
  594. } elseif (!empty($b_channel_id)) {
  595. unset($condition['channel_id']); // 如果同时输入渠道名称和顶级渠道,出于性能考虑,只查询渠道名称这个条件
  596. $channelIds = get_child_channel_arr($b_channel_id);
  597. array_push($channelIds, $b_channel_id);
  598. $condition['channel_id'] = ['in', $channelIds];
  599. }
  600. //顶级渠道存到pay表中 存在渠道改变时候 需要定期刷表的情况后续开发
  601. elseif (!empty($bplus_channel_id)) {
  602. unset($condition['channel_id']); // 如果同时输入渠道名称和顶级渠道,出于性能考虑,只查询渠道名称这个条件
  603. $channelIds = get_child_channel_arr($bplus_channel_id);
  604. array_push($channelIds, $bplus_channel_id);
  605. $condition['channel_id'] = ['in', $channelIds];
  606. }
  607. //开始时间和结束时间不为空时
  608. if ($start != '' && $end != '') {
  609. $condition['create_time'] = [
  610. ['>=', strtotime($start)],
  611. ['<=', strtotime($end . ' 23:59:59')],
  612. ];
  613. } //开始时间不为空时
  614. elseif ($start != '') {
  615. $condition['create_time'] = ['>=', strtotime($start)];
  616. } //结束时间不为空时
  617. elseif ($end != '') {
  618. $condition['create_time'] = ['<=', strtotime($end . ' 23:59:59')];
  619. } else {
  620. $start = date('Y-m-d', time());
  621. $end = date('Y-m-d', time());
  622. $condition['create_time'] = [
  623. ['>=', strtotime($start)],
  624. ['<=', strtotime($end . ' 23:59:59')],
  625. ];
  626. }
  627. /*
  628. if(strtotime($end.' 23:59:59')-strtotime($start)>31*24*3600){
  629. $this->error('单次查询日期的最长跨度为31天');
  630. }
  631. */
  632. $this->start = $start;
  633. $this->end = $end;
  634. $this->setCondition($condition);
  635. }
  636. /**
  637. * 推广员数据
  638. * @return mixed|string
  639. */
  640. public function channelPay()
  641. {
  642. $this->_beforeChannelPayGetParams();
  643. $condition = $this->getCondition();
  644. $regCondition = $condition;
  645. $condition['status'] = 1;
  646. if (isset($regCondition['gameid'])) {
  647. $regCondition['game_id'] = $regCondition['gameid'];
  648. unset($regCondition['gameid']);
  649. }
  650. $page_size = input('page_size', 20);
  651. $PayModel = model('Common/Pay');
  652. //充值完成总金额
  653. $totalAmount = 0;
  654. $totalRegCnt = 0;
  655. $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();
  656. $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();
  657. $unionSqlNew = Db::table($unionSql . ' bb')
  658. ->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')
  659. ->group('bb.game_id,bb.channel_id')
  660. ->buildSql();
  661. $list = Db::table($unionSqlNew . ' cc')
  662. ->order('total_pay_amount desc,total_reg_cnt desc,game_id desc,channel_id desc')
  663. ->paginate($page_size, false, ['query' => input('get.')]);
  664. // echo Db::table($unionSql . ' bb')->getLastSql() . "----sql-------<br>";
  665. $listData = array();
  666. if ($list->total() > 0) {
  667. //关联数据查询
  668. foreach ($list as $key => $item) {
  669. $channel = get_top_second_channel_name($list[$key]['channel_id']);
  670. $item['game_name'] = get_game_name($list[$key]['game_id']);
  671. $item['channel_name'] = $channel['channel_name'];
  672. $item['second_channel'] = $channel['second_name'];
  673. $item['top_channel'] = $channel['top_name'];
  674. $item['bplus_channel_name'] = get_union_channel($list[$key]['channel_id'])['name'];
  675. $listData[] = $item;
  676. }
  677. //充值完成总金额
  678. $totalAmount = $PayModel->field('sum(pay_amount) as total_amount')->where($condition)->find()['total_amount'];
  679. //玩家新增
  680. $totalRegCnt = model('MemberGameServer')->field('count(*) as total_reg_cnt')->where($regCondition)->find()['total_reg_cnt'];
  681. }
  682. $this->assign('list', $list);
  683. $this->assign('listData', $listData);
  684. $this->assign('page', $list->render());
  685. $this->assign('game_list', $this->selfGameList);
  686. $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
  687. $channelWhere = [];
  688. if ($business != -1) {
  689. if ($business && $business != -2) {
  690. $channelWhere['id'] = ['in', $business];
  691. } else {
  692. $channelWhere['id'] = -1;
  693. }
  694. }
  695. $uniom = model('Channel')->where(['level' => 0])->where($channelWhere)->field('id,name')->select();
  696. $this->assign('uniom', $uniom); //顶级渠道列表
  697. $this->assign('start', $this->start);
  698. $this->assign('end', $this->end);
  699. $this->assign('totalAmount', $totalAmount);
  700. $this->assign('totalRegCnt', $totalRegCnt);
  701. return $this->fetch();
  702. }
  703. /**
  704. * 推广员数据报表-下载
  705. */
  706. public function channelPayDownload()
  707. {
  708. if (request()->isAjax()) {
  709. $this->_beforeChannelPayGetParams();
  710. $condition = $this->getCondition();
  711. $regCondition = $condition;
  712. $condition['status'] = 1;
  713. if (isset($regCondition['gameid'])) {
  714. $regCondition['game_id'] = $regCondition['gameid'];
  715. unset($regCondition['gameid']);
  716. }
  717. $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();
  718. $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();
  719. $unionSqlNew = Db::table($unionSql . ' bb')
  720. ->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')
  721. ->group('bb.game_id,bb.channel_id')
  722. ->buildSql();
  723. $sql = Db::table($unionSqlNew . ' cc')
  724. ->order('total_pay_amount desc,total_reg_cnt desc,game_id desc,channel_id desc')
  725. ->fetchSql(true)->select();
  726. // $PayModel = model('Common/Pay');
  727. // $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();
  728. // $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();
  729. // $sql = Db::table($unionSql.' bb')
  730. // ->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')
  731. // ->group('bb.game_id,bb.channel_id')
  732. // ->order('total_pay_amount desc,total_reg_cnt desc')
  733. // ->fetchSql(true)->select();
  734. if ((new MakeReportGo())->addTask('admin.channelPay', $sql, session_id())) {
  735. $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  736. } else {
  737. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  738. }
  739. } else {
  740. $this->error('非法请求');
  741. }
  742. }
  743. /**
  744. * 充值记录管理页-查看玩家账号
  745. */
  746. public function showUsername()
  747. {
  748. $userid = input('userid');
  749. $game_id = input('game_id');
  750. if (empty($userid)) {
  751. $this->error('玩家ID不能为空');
  752. }
  753. $username = model('Common/Members')->where(['id' => $userid])->value('username');
  754. if (!empty($username)) {
  755. //充值记录管理页
  756. if (!empty($game_id)) {
  757. $game_name = model('Common/Game')->where(['id' => $game_id])->value('name');
  758. $this->insertLog($this->current_node, '查看账号:' . $username . ',关联游戏:' . $game_name, 81);
  759. } else {
  760. $this->insertLog($this->current_node, '查看账号:' . $username, 82);
  761. }
  762. $this->result($username, 1);
  763. } else {
  764. $this->error('玩家信息不存在');
  765. }
  766. }
  767. /**
  768. * ajax获取非聚合渠道列表
  769. *
  770. */
  771. public function ajaxGetNoComplexChannel()
  772. {
  773. $where = ['flag' => ['in', '1,2,3']];
  774. $level = input('level', '');
  775. if($level){
  776. $where['level'] = ['in', $level];
  777. }
  778. $channel_list = model('Common/Channel')->getAllByCondition('id,name', $where);
  779. echo json_encode($channel_list);
  780. // exit;
  781. }
  782. /**
  783. * ajax获取渠道列表
  784. */
  785. public function getChannel()
  786. {
  787. $channel_list = model('Common/Channel')->getChannleList();
  788. echo json_encode($channel_list);
  789. // exit;
  790. }
  791. /**
  792. * 报表-下载
  793. */
  794. public function download()
  795. {
  796. if (request()->isAjax()) {
  797. $makeReportGo = new MakeReportGo();
  798. $auth = new \app\common\logic\Auth();
  799. $is_show = input('is_show');
  800. if ($is_show > (int)$auth->check(session('ADMIN_ID'), 'admin/pay/rechargeDowmExcel')) {
  801. $this->error('您没有访问权限!');
  802. }
  803. $this->_beforeGetParams();
  804. $condition = $this->getCondition();
  805. $test_status = input('test_status', 0); // 是否测试:0=否、1=是
  806. if($test_status == 1){
  807. $testMemberIds = Db::table('cy_members')
  808. ->where('test_status', 1)
  809. ->column('id');
  810. // 如果有测试账户,加入查询条件(与列表 index 保持一致)
  811. if (!empty($testMemberIds)) {
  812. $condition['p.userid'] = ['not in', $testMemberIds];
  813. }
  814. }
  815. $cp_status = $this->request->param('cp_status');
  816. $paytype = $this->request->param('paytype', '', 'trim');
  817. if (!empty($paytype)) {
  818. if ($paytype == "wx") {
  819. $condition['p.paytype'] = ['IN', [
  820. 'wxpay-h5', 'coin-wxpay-h5', 'mix-wxpay-h5',
  821. 'ybzf_wxmp_h5', 'coin-ybzf_wxmp_h5', 'mix-ybzf_wxmp_h5',
  822. 'qzl_wx_h5', 'coin-qzl_wx_h5', 'mix-qzl_wx_h5',
  823. 'xty_wx_h5', 'coin-xty_wx_h5', 'mix-xty_wx_h5',
  824. 'qmf_wxmp_h5', 'coin-qmf_wxmp_h5', 'mix-qmf_wxmp_h5',
  825. 'yyyb_wx_h5', 'coin-yyyb_wx_h5', 'mix-yyyb_wx_h5',
  826. ]];
  827. } else if ($paytype == "zfb") {
  828. $condition['p.paytype'] = ['IN', [
  829. 'zfb', 'coin-zfb', 'mix-zfb',
  830. 'old-zfb-wap', 'coin-old-zfb-wap', 'mix-old-zfb-wap',
  831. 'xty_ali_h5', 'coin-xty_ali_h5', 'mix-xty_ali_h5',
  832. 'ldys_zfb', 'coin-ldys_zfb', 'mix-ldys_zfb',
  833. 'yyyb_ali_h5', 'coin-yyyb_ali_h5', 'mix-yyyb_ali_h5',
  834. ]];
  835. } else if ($paytype == "coin") {
  836. $condition['p.paytype'] = ['IN', [
  837. 'coinpay',
  838. "coin-zfb", "coin-old-zfb-wap",
  839. "coin-ldys_zfb_h5", "coin-xty_ali_h5", "coin-yyyb_ali_h5",
  840. "coin-qzl_wx_h5", "coin-ldys_wx_h5", "coin-yyyb_wx_h5", "coin-ybzf_wxmp_h5", "coin-xty_wx_h5", "coin-qmf_wxmp_h5",
  841. ]];
  842. } else if ($paytype == "coupon") {
  843. $condition['p.paytype'] = ['IN', [
  844. 'coupon',
  845. "mix-zfb", "mix-old-zfb-wap",
  846. "mix-ldys_zfb_h5", "mix-xty_ali_h5", "mix-yyyb_ali_h5",
  847. "mix-qzl_wx_h5", "mix-ldys_wx_h5", "mix-yyyb_wx_h5", "mix-ybzf_wxmp_h5", "mix-xty_wx_h5", "mix-qmf_wxmp_h5",
  848. ]];
  849. }
  850. }
  851. if (is_numeric($cp_status)) {
  852. $condition['paycpinfo.status'] = (int)$cp_status;
  853. }
  854. if (!$condition) {
  855. $this->error('导出需要至少一个查询条件!');
  856. }
  857. if(!empty($condition['p.pay_time']) && input('gh', 0) != 1){
  858. $condition['p.create_time'] = $condition['p.pay_time'];
  859. unset($condition['p.pay_time']);
  860. }
  861. $sql = Db::table('cy_pay p')
  862. ->join('nw_channel channel', 'p.channel_id=channel.id', 'left')
  863. ->join('cy_paycpinfo paycpinfo', 'p.orderid=paycpinfo.orderid', 'left')
  864. ->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')
  865. ->where($condition)
  866. // ->whereNotIn('gameid', $this->gameIds)
  867. // 海外游戏
  868. // ->where(function ($query) use ($is_haiwei) {
  869. // if ($is_haiwei == 1) {
  870. // $query->whereIn('p.gameid', $this->gameIds);
  871. // } else {
  872. // $query->whereNotIn('p.gameid', $this->gameIds);
  873. // }
  874. // })
  875. ->order('p.id desc')
  876. ->fetchSql(true)->select();
  877. // if($makeReport->addTask('payList',$sql,session_id(),['is_show'=>boolval($is_show)])){
  878. if ($makeReportGo->addTask('payList', $sql, session_id(), ['is_show' => boolval($is_show)])) {
  879. //高级报表下载
  880. if ($is_show == 1) {
  881. $this->insertLog($this->current_node, $this->getDownloadLogContent(), 83);
  882. }
  883. $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  884. } else {
  885. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  886. }
  887. } else {
  888. $this->error('非法请求');
  889. }
  890. }
  891. /**
  892. * 高级报表下载时的,操作日志内容
  893. */
  894. private function getDownloadLogContent()
  895. {
  896. $start = $this->request->param('start');
  897. $end = $this->request->param('end');
  898. $gameid = $this->request->param('gameid', 0, 'intval');
  899. $username = $this->request->param('username', '', 'trim');
  900. $content = '';
  901. //开始时间和结束时间不为空时
  902. if ($start != '' && $end != '') {
  903. $content .= '时间:' . $start . '~' . $end;
  904. } //开始时间不为空时
  905. elseif ($start != '') {
  906. $content .= '时间:' . $start . '~';
  907. } //结束时间不为空时
  908. elseif ($end != '') {
  909. $content .= '时间:' . '~' . $end;
  910. } else {
  911. $start = date('Y-m-d', time());
  912. $end = date('Y-m-d', time());
  913. $content .= '时间:' . $start . '~' . $end;
  914. }
  915. if (!empty($gameid)) {
  916. $content .= ',游戏:' . model('Common/Game')->where(['id' => $gameid])->value('name');
  917. } else {
  918. $content .= ',游戏:全部游戏';
  919. }
  920. if (!empty($username)) {
  921. $content .= ',玩家账号:' . $username;
  922. } else {
  923. $content .= ',玩家账号:';
  924. }
  925. return $content;
  926. }
  927. public function setCondition($condition)
  928. {
  929. return $this->condition = $condition;
  930. }
  931. public function getCondition()
  932. {
  933. return $this->condition;
  934. }
  935. /**
  936. * 充值用户列表
  937. */
  938. public function user()
  939. {
  940. $this->_beforeGetParams();
  941. $condition = $this->getCondition();
  942. $PayModel = model('Common/Pay');
  943. /*
  944. // 如果没有选择条件,那么默认显示当天的数据
  945. if (! count($condition)) {
  946. $start_time = $this->request->get('start', date('Y-m-d'));
  947. $condition['create_time'] = makeTimeCondition($start_time);
  948. }
  949. */
  950. $order = '';
  951. $amount_total = input('amount_total', 'desc');
  952. if ($amount_total) {
  953. $order = 'amount_total ' . $amount_total;
  954. }
  955. $condition['status'] = 1; //只统计充值成功的
  956. $sql = $PayModel->alias('p')
  957. ->where($condition)
  958. ->field('username,userid,sum(pay_amount) as amount_total ,count(1) as pay_total,max(id) as max_id, gameid, p.roleid, p.rolename')
  959. ->group('username')
  960. ->order($order);
  961. if (request()->isAjax() && input('down') == true) {
  962. $makeReportGo = new MakeReportGo();
  963. $auth = new \app\common\logic\Auth();
  964. if (!$auth->check(session('ADMIN_ID'), 'admin/pay/userPayDowmExcel')) {
  965. $this->error('您没有访问权限!!');
  966. }
  967. $downSql = $sql->fetchSql(true)->select();
  968. if ($makeReportGo->addTask('userPayList', $downSql, session_id())) {
  969. $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  970. } else {
  971. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  972. }
  973. }
  974. $list = $sql->paginate(20, false, ['query' => input('get.')]);
  975. $idArr = array_column($list->toArray()['data'], 'max_id');
  976. $rencentPayArr = $PayModel->where('id', 'in', $idArr)->column('pay_amount', 'id');
  977. foreach ($list as $key => $value) {
  978. if (!empty($value['max_id'])) {
  979. $list[$key]['recent_pay'] = $rencentPayArr[$value['max_id']];
  980. } else {
  981. $list[$key]['recent_pay'] = 0;
  982. }
  983. }
  984. $this->assign('game_list_by_ids', $this->selfGameList);
  985. $this->assign('game_list', $this->gameList);
  986. $this->assign('list', $list);
  987. $this->assign('page', $list->render());
  988. $this->assign('start', $this->start);
  989. $this->assign('end', $this->end);
  990. return $this->fetch();
  991. }
  992. /**
  993. *充值规则 列表
  994. */
  995. public function ruleList()
  996. {
  997. $condition = [];
  998. $gameid = $this->request->param('gameid', 0, 'intval');
  999. if (!empty($gameid)) {
  1000. $condition['game_id'] = $gameid;
  1001. }
  1002. $list = DB::table('cy_payrule')->where($condition)->order('create_time desc')->paginate(10);
  1003. $gameidArr = [];
  1004. foreach ($list as $v) {
  1005. $gameidArr[] = $v['game_id'];
  1006. }
  1007. $payTypelist = DB::table('cy_paytype')->column('paytype,payname');
  1008. $game_name = model('game')->whereIn('id', array_unique($gameidArr))->column('id,name');
  1009. $this->assign('paytype_list', $payTypelist);
  1010. $this->assign('game_list', $this->selfGameList);
  1011. $this->assign('list', $list);
  1012. $this->assign('game_name', $game_name);
  1013. $this->assign('page', $list->render());
  1014. return $this->fetch('rulelist');
  1015. }
  1016. /**
  1017. *充值规则添加
  1018. */
  1019. public function ruleAdd()
  1020. {
  1021. if ($this->request->isPost()) {
  1022. $data = $this->request->post();
  1023. if (true !== ($res = $this->validate($data, 'payrule'))) {
  1024. $this->error($res);
  1025. }
  1026. $payruleModel = model('Common/Payrule');
  1027. $data['create_time'] = NOW_TIMESTAMP;
  1028. if ($payruleModel->save($data)) {
  1029. $this->success('添加成功', url('ruleList'));
  1030. }
  1031. $this->error($payruleModel->getError() ?: '添加失败');
  1032. }
  1033. $payTypelist = DB::table('cy_paytype')->field('paytype,payname')->select();
  1034. $this->assign('paytype_list', $payTypelist);
  1035. $this->assign('game_list', $this->selfGameList);
  1036. return $this->fetch();
  1037. }
  1038. /**
  1039. *充值规则修改
  1040. */
  1041. public function ruleEdit()
  1042. {
  1043. $id = $this->request->param('id', '', 'intval');
  1044. $payruleModel = model('Common/Payrule');
  1045. if (empty($id)) {
  1046. $this->error('参数错误!');
  1047. }
  1048. if (!$data = $payruleModel->find($id)) {
  1049. $this->error('参数错误,不存在该数据');
  1050. }
  1051. if ($this->request->isPost()) {
  1052. $data = $this->request->post();
  1053. if (true !== ($res = $this->validate($data, 'payrule'))) {
  1054. $this->error($res);
  1055. }
  1056. if ($payruleModel->save($data, ['id' => $id]) !== false) {
  1057. $this->success('修改成功', url('ruleList'));
  1058. }
  1059. $this->error($payruleModel->getError() ?: '修改失败');
  1060. }
  1061. $payTypelist = DB::table('cy_paytype')->field('paytype,payname')->select();
  1062. $this->assign('paytype_list', $payTypelist);
  1063. $this->assign('game_list', $this->selfGameList);
  1064. $this->assign('data', $data);
  1065. return $this->fetch();
  1066. }
  1067. /**
  1068. * 充值规则删除
  1069. */
  1070. public function ruleDelete()
  1071. {
  1072. $id = $this->request->param('id', '', 'intval');
  1073. if (empty($id)) {
  1074. $this->error('参数错误!');
  1075. }
  1076. $payruleModel = model('Common/Payrule');
  1077. if (!$payruleModel->find($id)) {
  1078. $this->error('参数错误,不存在该数据');
  1079. }
  1080. if ($payruleModel->where('id', '=', $id)->delete()) {
  1081. $this->success('删除成功', url('ruleList'));
  1082. }
  1083. $error = $payruleModel->getError();
  1084. $this->error($error ?: '删除失败');
  1085. }
  1086. /**
  1087. * 平台币补单记录
  1088. * @throws \think\exception\DbException
  1089. */
  1090. public function ptblist()
  1091. {
  1092. $where = [];
  1093. $order = 'create_time desc';
  1094. $orderid = $this->request->get('orderid', '', 'trim');
  1095. $username = $this->request->get('username', '', 'trim');
  1096. $cname = $this->request->get('cname', '', 'trim');
  1097. if (isset($orderid) && !empty($orderid)) {
  1098. $where['a.orderid'] = $orderid;
  1099. }
  1100. if (isset($username) && !empty($username)) {
  1101. $where['m.username'] = $username;
  1102. }
  1103. if (isset($cname) && !empty($cname)) {
  1104. $where['c.username'] = $cname;
  1105. }
  1106. $list = Db::name('nw_channel_member_pay')->alias('a')
  1107. ->join('nw_channel_admin c', 'c.id = a.channel_id', 'left')
  1108. ->join('nw_channel cc', 'cc.id = a.qd_id', 'left')
  1109. ->join('cy_members m', 'm.id = a.member_id', 'left')
  1110. ->field('a.*,c.username,m.username as uname,cc.name as ccname')
  1111. ->where($where)
  1112. ->order($order)
  1113. ->paginate();
  1114. $this->assign('list', $list);
  1115. $this->assign('page', $list->render());
  1116. return $this->fetch();
  1117. }
  1118. /**
  1119. * 补单通知CP
  1120. *
  1121. */
  1122. public function ptbreCallback()
  1123. {
  1124. if ($this->request->isPost()) {
  1125. $orderid = input('post.orderid', '', 'trim');
  1126. if (empty($orderid)) {
  1127. $this->error('订单号不能为空');
  1128. }
  1129. $payCpInfoModel = model('Common/PayCpinfo');
  1130. $where['orderid'] = $orderid;
  1131. $paycpInfo = $payCpInfoModel->field('id,fcallbackurl,params,payflag,status')->where($where)->find();
  1132. // if(empty($paycpInfo)){
  1133. // $this->error('订单通知回调记录不存在');
  1134. // }
  1135. // elseif($paycpInfo['status']!=1){
  1136. // $this->error('订单已完成');
  1137. // }
  1138. $guzzle = new Client();
  1139. //将字符串转换成数组
  1140. parse_str($paycpInfo['params'], $param);
  1141. $pay = Db::name('cy_pay')->where(['orderid' => $orderid])->find();
  1142. $userid = $pay['userid']; //用户
  1143. $user_amount = $pay['amount']; //用户金额
  1144. $members = Db::name('cy_members')->where(['id' => $userid])->find(); //用户表
  1145. $chal_id = $members['channel_id']; //用户属于渠道
  1146. $pyb = Db::name('nw_channel_admin')->where(['id' => $chal_id])->find(); //找到渠道 3519
  1147. $pyb_channel_admin = Db::name('nw_channel')->where(['id' => $pyb['channel_id']])->find(); //在找到所属渠道 3544
  1148. $pyb_channel_z = Db::name('nw_channel')->where(['id' => $pyb_channel_admin['parent_id']])->find(); //找到渠道 3543
  1149. $pyb_channel_cz = Db::name('nw_channel_admin')->where(['channel_id' => $pyb_channel_z['id']])->find(); //找到渠道 3543
  1150. if ($pyb_channel_cz['pyb'] < $user_amount) {
  1151. $this->error("订单通知失败,平台币不足: ");
  1152. }
  1153. $data_info['pyb'] = $pyb_channel_cz['pyb'] - $user_amount;
  1154. Db::name('nw_channel_admin')->where(['id' => $pyb_channel_cz['id']])->update($data_info);
  1155. $data_infos['total_pay_amount'] = $members['total_pay_amount'] + $user_amount;
  1156. Db::name('cy_members')->where(['id' => $userid])->update($data_infos);
  1157. $data_pay['status'] = 1;
  1158. $data_pay['payflag'] = 1;
  1159. Db::name('cy_paycpinfo')->where(['orderid' => $orderid])->update($data_pay);
  1160. $ds = [
  1161. 'orderid' => $orderid,
  1162. 'qd_id' => $chal_id,
  1163. 'user_amount' => $user_amount,
  1164. 'channel_id' => $pyb_channel_cz['id'],
  1165. 'member_id' => $userid,
  1166. 'create_time' => time()
  1167. ];
  1168. Db::name('nw_channel_member_pay')->insertGetId($ds);
  1169. try {
  1170. $response = $guzzle->request('post', $paycpInfo['fcallbackurl'], ['form_params' => $param, 'timeout' => 10]);
  1171. //通知成功
  1172. if (0 == strcasecmp($response->getBody(), 'success')) {
  1173. $payCpInfoModel->save(['status' => 1, 'update_time' => NOW_TIMESTAMP], ['id' => $paycpInfo['id']]);
  1174. $this->success('订单通知成功', url('ptblist'));
  1175. } else {
  1176. $this->error('订单通知已发送给对方,但对方未返回[success]信息');
  1177. }
  1178. } catch (GuzzleException $e) {
  1179. $this->error("订单通知失败: " . $e->getMessage());
  1180. }
  1181. }
  1182. return $this->fetch('ptbre_callback');
  1183. }
  1184. public function reCallback()
  1185. {
  1186. if ($this->request->isPost()) {
  1187. $orderid = input('post.orderid', '', 'trim');
  1188. if (empty($orderid)) {
  1189. $this->error('订单号不能为空');
  1190. }
  1191. $payCpInfoModel = model('Common/PayCpinfo');
  1192. $where['orderid'] = $orderid;
  1193. $paycpInfo = $payCpInfoModel->field('id,fcallbackurl,params,payflag')->where($where)->find();
  1194. if (empty($paycpInfo)) {
  1195. $this->error('订单通知回调记录不存在');
  1196. } elseif ($paycpInfo['payflag'] != 1) {
  1197. $this->error('订单未完成支付或支付失败');
  1198. }
  1199. $guzzle = new Client();
  1200. //将字符串转换成数组
  1201. parse_str($paycpInfo['params'], $param);
  1202. try {
  1203. $response = $guzzle->request('post', $paycpInfo['fcallbackurl'], ['form_params' => $param, 'timeout' => 10]);
  1204. log_message("[ADMIN-CP补单-SUCCESS]: " . 'orderid:' . $orderid . " url: " . $paycpInfo['fcallbackurl'] . " - params:" . json_encode($paycpInfo['params']) . " - result:" . $response->getBody()->getContents(), 'log', LOG_PATH . 'callBacklog/');
  1205. //通知成功
  1206. if (0 == strcasecmp($response->getBody(), 'success')) {
  1207. $payCpInfoModel->save(['status' => 1, 'update_time' => NOW_TIMESTAMP], ['id' => $paycpInfo['id']]);
  1208. $this->success('订单通知成功');
  1209. } else {
  1210. $this->error('订单通知已发送给对方,但对方未返回[success]信息');
  1211. }
  1212. } catch (GuzzleException $e) {
  1213. log_message("[ADMIN-CP补单-ERROR]: " . 'orderid:' . $orderid . " url: " . $paycpInfo['fcallbackurl'] . " - params:" . json_encode($paycpInfo['params']), 'log', LOG_PATH . 'callBacklog/');
  1214. $this->error("订单通知失败: " . $e->getMessage());
  1215. }
  1216. }
  1217. return $this->fetch('re_callback');
  1218. }
  1219. /**
  1220. * ajax 获取cp订单号
  1221. */
  1222. public function showAttach()
  1223. {
  1224. $order_id = input('post.orderid', '', 'filterAndTrimInput'); // 订单号
  1225. $this->_showAttach($order_id);
  1226. }
  1227. /**
  1228. * 查看订单的attach信息
  1229. * @param $orderid string 订单号
  1230. */
  1231. private function _showAttach($orderid)
  1232. {
  1233. $runnable = true;
  1234. $msg = '';
  1235. $status = false;
  1236. if (empty($orderid)) {
  1237. $runnable = false;
  1238. $msg = '参数错误';
  1239. }
  1240. if ($runnable) {
  1241. $result = model('Pay')
  1242. ->where(['orderid' => $orderid])
  1243. ->field('attach')
  1244. ->find();
  1245. if (empty($result)) {
  1246. $runnable = false;
  1247. $msg = '订单不存在';
  1248. }
  1249. }
  1250. // 查看attach
  1251. if ($runnable) {
  1252. $status = 1;
  1253. $result['attach'] = 'attach=' . $result['attach'];
  1254. parse_str($result['attach'], $arr);
  1255. $msg = $arr['attach']; // 变量由上一个函数解析出来的
  1256. }
  1257. echo json_encode(['code' => $status, 'msg' => $msg]);
  1258. }
  1259. // 支付中控
  1260. public function paySupcon()
  1261. {
  1262. // ## 支付方式列表
  1263. $paySupconList = (new \app\common\model\PaySupconModel())->select()->toArray();
  1264. $newPaySupconList = [
  1265. 'wx_h5' => [
  1266. "id" => 1,
  1267. "pay_type" => "微信支付-H5",
  1268. "pay_channel" => "",
  1269. "mark" => "wx_h5",
  1270. "type" => 1,
  1271. "probability" => "",
  1272. "description" => "-",
  1273. "parentId" => null,
  1274. "cascade" => "all",
  1275. "children" => [],
  1276. ],
  1277. // 'wx_app' => [],
  1278. 'ali_h5' => [
  1279. "id" => 3,
  1280. "pay_type" => "支付宝-H5",
  1281. "pay_channel" => "",
  1282. "mark" => "ali_h5",
  1283. "type" => 1,
  1284. "probability" => "",
  1285. "description" => "-",
  1286. "parentId" => null,
  1287. "cascade" => "all",
  1288. "children" => [],
  1289. ],
  1290. 'ali_app' => [
  1291. "id" => 4,
  1292. "pay_type" => "支付宝-APP",
  1293. "pay_channel" => "",
  1294. "mark" => "ali_app",
  1295. "type" => 1,
  1296. "probability" => "",
  1297. "description" => "-",
  1298. "parentId" => null,
  1299. "cascade" => "all",
  1300. "children" => [],
  1301. ],
  1302. 'coinpay' => [
  1303. "id" => 5,
  1304. "pay_type" => "平台币",
  1305. "pay_channel" => "",
  1306. "mark" => "coinpay",
  1307. "type" => 1,
  1308. "probability" => "",
  1309. "description" => "-",
  1310. "parentId" => null,
  1311. "cascade" => "all",
  1312. "children" => [],
  1313. ]
  1314. ];
  1315. foreach ($paySupconList as $key => $value) {
  1316. $parentId = 1;
  1317. switch ($value['pay_scene']) {
  1318. case "wx_h5":
  1319. $parentId = 1;
  1320. break;
  1321. case "ali_h5":
  1322. $parentId = 3;
  1323. break;
  1324. case "ali_app":
  1325. $parentId = 4;
  1326. break;
  1327. case "coinpay":
  1328. $parentId = 5;
  1329. break;
  1330. }
  1331. $game_ids = $value['game_ids'];
  1332. if ($value['game_ids'] != 'all') {
  1333. $game_ids = explode(',', substr($value['game_ids'], 1, -1));
  1334. }
  1335. $sdk_versions = $value['sdk_versions'];
  1336. if ($value['sdk_versions'] != 'all') {
  1337. $sdk_versions = explode(',', substr($value['sdk_versions'], 1, -1));
  1338. }
  1339. $children = [
  1340. "id" => $value['id'],
  1341. "pay_type" => "",
  1342. "pay_channel" => $value['paytype_name'],
  1343. "mark" => $value['pay_mark'],
  1344. "type" => 0,
  1345. "probability" => $value['probability'],
  1346. "parentId" => $parentId,
  1347. "description" => "-",
  1348. "isParent" => false,
  1349. "game_ids" => $game_ids,
  1350. "sdk_versions" => $sdk_versions,
  1351. "status" => $value['status'],
  1352. ];
  1353. $newPaySupconList[$value['pay_scene']]['children'][] = $children;
  1354. }
  1355. if ($newPaySupconList) {
  1356. $newPaySupconList = array_values($newPaySupconList);
  1357. }
  1358. $this->assign('paySupconList', json_encode($newPaySupconList));
  1359. // ## 游戏列表
  1360. $gameList = (new \app\common\model\Game())->where(['status' => 1])->order('id desc')->field(['id', 'name', 'type'])->select()->toArray();
  1361. $newGameList = [
  1362. "android" => [
  1363. "id" => "",
  1364. "title" => "Android",
  1365. "field" => "android",
  1366. "checked" => false,
  1367. "spread" => false,
  1368. "children" => []
  1369. ],
  1370. "ios" => [
  1371. "id" => "",
  1372. "title" => "IOS",
  1373. "field" => "ios",
  1374. "checked" => false,
  1375. "spread" => false,
  1376. "children" => []
  1377. ],
  1378. "h5" => [
  1379. "id" => "",
  1380. "title" => "H5",
  1381. "field" => "h5",
  1382. "checked" => false,
  1383. "spread" => false,
  1384. "children" => []
  1385. ],
  1386. ];
  1387. foreach ($gameList as $key => $value) {
  1388. $children = [
  1389. "id" => $value['id'],
  1390. "field" => $value['id'],
  1391. "title" => $value['name'],
  1392. "checked" => false,
  1393. "href" => "",
  1394. ];
  1395. // 游戏类型:1=ios、2=安卓、3=h5
  1396. if ($value['type'] == 2) {
  1397. $newGameList['android']['children'][] = $children;
  1398. } else if ($value['type'] == 3) {
  1399. $newGameList['h5']['children'][] = $children;
  1400. } else if ($value['type'] == 1) {
  1401. $newGameList['ios']['children'][] = $children;
  1402. }
  1403. }
  1404. if ($newGameList) {
  1405. $newGameList = array_values($newGameList);
  1406. }
  1407. $this->assign('gameList', json_encode($newGameList));
  1408. // ## SDK版本
  1409. $versionList = (new \app\common\model\AndroidSdk())->field(['id', 'version', 'num'])->order('id desc')->select()->toArray();
  1410. $newVersionList = [
  1411. "version" => [
  1412. "id" => "",
  1413. "title" => "SDK 版本",
  1414. "field" => "version",
  1415. "checked" => false,
  1416. "spread" => true,
  1417. "children" => []
  1418. ],
  1419. ];
  1420. foreach ($versionList as $key => $value) {
  1421. $children = [
  1422. "id" => $value['id'],
  1423. "field" => $value['num'],
  1424. "title" => $value['version'],
  1425. "checked" => false,
  1426. "href" => "",
  1427. ];
  1428. $newVersionList['version']['children'][] = $children;
  1429. }
  1430. if ($newVersionList) {
  1431. $newVersionList = array_values($newVersionList);
  1432. }
  1433. // dump($newGameList);
  1434. $this->assign('versionList', json_encode($newVersionList));
  1435. return $this->fetch();
  1436. }
  1437. // 处理绑定
  1438. public function saveSupcon()
  1439. {
  1440. try {
  1441. $parame = $this->request->only(['game_ids', 'sdk_versions', 'probability']);
  1442. $id = input('id');
  1443. $result = PaySupconModel::where(['id' => $id])->update($parame);
  1444. if ($result) {
  1445. echo json_encode(['code' => 200, 'msg' => 'success', 'data' => $result]);
  1446. return;
  1447. }
  1448. echo json_encode(['code' => 200, 'msg' => '没有变动!', 'data' => $result]);
  1449. return;
  1450. } catch (\Exception $e) {
  1451. // dump($e->getFile(), $e->getLine());
  1452. echo json_encode(['code' => -110, 'msg' => 'error:' . $e->getMessage(), 'data' => []]);
  1453. return;
  1454. }
  1455. echo json_encode(['code' => -100, 'msg' => 'error', 'data' => []]);
  1456. }
  1457. // 处理状态
  1458. public function saveSupconStatus()
  1459. {
  1460. $parame = $this->request->only(['status']);
  1461. $id = input('id');
  1462. if (empty($id) || empty($id)) {
  1463. echo json_encode(['code' => -100, 'msg' => '参数有误!', 'data' => []]);
  1464. return;
  1465. }
  1466. $supconInfo = PaySupconModel::get($id);
  1467. if (empty($supconInfo)) {
  1468. echo json_encode(['code' => -110, 'msg' => '数据不存在!', 'data' => []]);
  1469. return;
  1470. }
  1471. try {
  1472. $result = (new PaySupconModel())->update($parame, ['id' => $id]);
  1473. if ($result) {
  1474. $this->insertLog($this->current_node, '支付场景:' . $supconInfo['pay_scene'] . ' - 支付渠道:' . $supconInfo['paytype_name'] . ' - 状态:' . ($parame['status'] == 0 ? '关' : '开'), 569);
  1475. echo json_encode(['code' => 200, 'msg' => 'success', 'data' => $result]);
  1476. return;
  1477. }
  1478. } catch (Exception $e) {
  1479. echo json_encode(['code' => -120, 'msg' => 'error:' . $e->getMessage(), 'data' => []]);
  1480. return;
  1481. }
  1482. echo json_encode(['code' => -100, 'msg' => 'error', 'data' => []]);
  1483. }
  1484. // 处理权重
  1485. public function saveProbability()
  1486. {
  1487. try {
  1488. $parame = $this->request->post();
  1489. if (!$parame) {
  1490. echo json_encode(['code' => -100, 'msg' => 'error: 缺少必要参数!', 'data' => []]);
  1491. }
  1492. $result = (new PaySupconModel())->isUpdate()->saveAll($parame['formData']);
  1493. if ($result!== false) {
  1494. echo json_encode(['code' => 200, 'msg' => 'success', 'data' => []]);
  1495. return;
  1496. }
  1497. } catch (Exception $e) {
  1498. echo json_encode(['code' => -110, 'msg' => 'error:' . $e->getMessage(), 'data' => []]);
  1499. return;
  1500. }
  1501. echo json_encode(['code' => -100, 'msg' => 'error', 'data' => []]);
  1502. }
  1503. }