ChannelShare.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\library\MakeReport;
  4. use think\Config;
  5. use think\Db;
  6. use think\Exception;
  7. use app\common\logic\SubPackage as SubChannel;
  8. use GuzzleHttp\Client;
  9. use GuzzleHttp\Exception\GuzzleException;
  10. use app\common\library\FileUpload;
  11. use think\Env;
  12. class ChannelShare extends Admin
  13. {
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. $this->adminModel = Db::table('nw_channel_admin');
  18. $this->channelModel = Db::table('nw_channel');
  19. $this->divideModel = Db::table('nw_game_channel_divide');
  20. $tmpGameList = model('Common/Game')->getAllByCondition('id,name', [],'','self');
  21. $gameList = array();
  22. foreach ($tmpGameList as $game) {
  23. $gameList[ $game['id']] = $game;
  24. }
  25. $this->gameList = $gameList;
  26. $temGameAgglist = db::name('nw_extra_game')->field('id,extra_game_name as name')->select();
  27. $gameAggList = array();
  28. foreach ($temGameAgglist as $game) {
  29. $gameAggList[ $game['id']] = $game;
  30. }
  31. $this->gameAggList = $gameAggList;
  32. $tmpChannelList = Db::table('nw_channel')->field('id,name')->where(['level'=>1])->select();
  33. $channeList = array();
  34. foreach ($tmpChannelList as $game) {
  35. $channeList[ $game['id']] = $game;
  36. }
  37. $this->channeList = $channeList;
  38. }
  39. //首页渲染
  40. public function index()
  41. {
  42. $channelId = input('channel_id');
  43. $gameId = input('game_id');
  44. $where = [];
  45. if ($channelId) {
  46. $where['channel_id'] = $channelId;
  47. }
  48. if ($gameId) {
  49. $where['game_id'] = $gameId;
  50. }
  51. $list = $this->divideModel->alias('divide')
  52. ->field('divide.id,divide.channel_id,divide.game_id,from_unixtime(divide.create_time) as create_time,divide.ratio,game.name as game_name,divide.channel_name')
  53. ->where($where)
  54. ->order("id desc")
  55. ->join('cy_game game', 'divide.game_id = game.id','LEFT')
  56. ->paginate(10, false, ['query' => $where]);
  57. //获取分页显示
  58. $page = $list->render();
  59. $this->assign('game_list', $this->gameList);
  60. $this->assign('channel_id', $channelId);
  61. $this->assign('channel_list', $this->channeList);
  62. $this->assign('game_id', $gameId);
  63. $this->assign("page", $page);
  64. $this->assign("list", $list);
  65. return $this->fetch();
  66. }
  67. //添加分成比例
  68. public function add()
  69. {
  70. $this->assign('channel_list', $this->channeList);
  71. $this->assign('game_list', $this->gameList);
  72. return $this->fetch();
  73. }
  74. //添加分成比例
  75. public function addPost()
  76. {
  77. $postParam = $this->request->param();
  78. $ratio = intval($postParam['ratio']);
  79. if(is_int($ratio) == false){
  80. $this->error("分成比例必须是正整数");
  81. }
  82. if($ratio < 0 || $ratio >= 100){
  83. $this->error("分成比例范围必须在0-99内");
  84. }
  85. $gameInfo = model("Game")->field('id,name')->where('id',$postParam['game_id'])->find();
  86. if(!$gameInfo){
  87. $this->error("您选择的游戏不存在");
  88. }
  89. $channelInfo = model("Channel")->field('id,name')->where('id',$postParam['channel_id'])->find();
  90. if(!$channelInfo){
  91. $this->error("您选择的公会不存在");
  92. }
  93. else{
  94. $channel_name = $channelInfo['name'];
  95. }
  96. Db::startTrans();
  97. try {
  98. if (Db::table('nw_game_channel_divide_log')->where(['channel_id'=>$postParam['channel_id'],'game_id'=>$postParam['game_id']])->value('id')) {
  99. throw new Exception("已经添加过分成比例,请不要重复添加");
  100. }
  101. $res = $this->divideModel->insertGetId([
  102. 'channel_id' => $postParam['channel_id'],
  103. 'channel_name' => $channel_name,
  104. 'game_id' => $postParam['game_id'],
  105. 'ratio' => $postParam['ratio'],
  106. 'create_time' => NOW_TIMESTAMP,
  107. ]);
  108. if ($res === false) {
  109. throw new Exception("添加分成比例失败");
  110. }
  111. $cont['divide_id'] = $res;
  112. $cont['channel_id'] = $postParam['channel_id'];
  113. $cont['game_id'] = $postParam['game_id'];
  114. $cont['ratio'] = $postParam['ratio'];
  115. $cont['type'] = 1;
  116. $cont['create_time'] = NOW_TIMESTAMP;
  117. Db::table('nw_game_channel_divide_log')->insertGetId($cont);
  118. Db::commit();
  119. $template = '公会结算分成比例新增:管理员"'.session('USERNAME').'" 新增了公会结算分成比例,游戏名:'.$gameInfo['name'].',公会账号:'.$channel_name.',分成比例:'.$postParam['ratio'].'% 。操作时间:'.date('Y-m-d H:i:s');
  120. $this->insertLog($this->current_node,$template, 102);
  121. $ddurl = Env::get('operat_url');
  122. //curlDD($template, $ddurl,true);
  123. } catch (Exception $e) {
  124. Db::rollback();
  125. $this->error("添加失败: " . $e->getMessage());
  126. }
  127. $this->success("添加成功" , url("ChannelShare/index"));
  128. }
  129. //修改分成比例
  130. public function edit()
  131. {
  132. $postParam = $this->request->param();
  133. $ratio = intval($postParam['value']);
  134. if(is_int($ratio) == false){
  135. $this->error("分成比例必须是正整数");
  136. }
  137. if($ratio < 0 || $ratio >= 100){
  138. $this->error("分成比例范围必须在0-99内");
  139. }
  140. if(!intval($postParam['gameid'])){
  141. $this->error("请选择要修改的游戏");
  142. }
  143. $divideInfo = $this->divideModel->where('id',$postParam['id'])->find();
  144. if(!$divideInfo){
  145. $this->error("您选择的游戏不存在");
  146. }
  147. else if(floatval($divideInfo['ratio']) == floatval($ratio)){
  148. $this->success("分成比例未做任何更改");
  149. }
  150. $gameInfo = model("Game")->field('id,name')->where('id',$postParam['gameid'])->find();
  151. if(!$gameInfo){
  152. $this->error("您选择的游戏不存在");
  153. }
  154. $channelInfo = model("Channel")->field('id,name')->where('id',$postParam['channelid'])->find();
  155. if(!$channelInfo){
  156. $this->error("您选择的公会不存在");
  157. }
  158. Db::startTrans();
  159. try {
  160. $res = model("GameChannelDivide")->where('id',$postParam['id'])->update(['update_time' => NOW_TIMESTAMP,'ratio' => $ratio]);
  161. if (!$res) {
  162. $this->error("更新失败");
  163. }
  164. $cont['divide_id'] = $postParam['id'];
  165. $cont['channel_id'] = $postParam['channelid'];
  166. $cont['game_id'] = $postParam['gameid'];
  167. $cont['ratio'] = $postParam['value'];
  168. $cont['type'] = 2;
  169. $cont['create_time'] = NOW_TIMESTAMP;
  170. $insertId = Db::table('nw_game_channel_divide_log')->insertGetId($cont);
  171. Db::commit();
  172. $template = '公会结算分成比例更新:管理员"'.session('USERNAME').'" 更改了公会结算分成比例,游戏名:'.$gameInfo['name'].',公会账号:'.$channelInfo['name'].',分成比例:'.$postParam['value'].'% 。操作时间:'.date('Y-m-d H:i:s');
  173. $this->insertLog($this->current_node,$template, 103);
  174. $ddurl = Env::get('operat_url');
  175. //curlDD($template, $ddurl,true);
  176. } catch (Exception $e) {
  177. Db::rollback();
  178. $this->error("添加失败: " . $e->getMessage());
  179. }
  180. $this->success("更新成功");
  181. }
  182. /**
  183. * 补点设置页面
  184. *
  185. * @Author yxon 564556921@qq.com
  186. * @DateTime 2020-12-07
  187. * @return void
  188. */
  189. public function edithtml()
  190. {
  191. $id = input('id');
  192. $name = input('name');
  193. if(empty($id)||empty($name)){
  194. $this->error("参数错误");
  195. }
  196. $data = db::name('nw_game_extra_divide')->where(['game_id'=>$id])->value('divide');
  197. if ($data) {
  198. $data = json_decode($data,1);
  199. }
  200. $this->assign('data',$data);
  201. $this->assign('id',$id);
  202. $this->assign('name',$name);
  203. return $this->fetch('edit');
  204. }
  205. //添加分成比例
  206. public function checklog()
  207. {
  208. $postParam = $this->request->param();
  209. if (empty($postParam['gameid']) || empty($postParam['channelid'])) {
  210. $this->error("参数错误");
  211. }
  212. $res = Db::table('nw_game_channel_divide_log')->where(['game_id'=>$postParam['gameid'],'channel_id'=>$postParam['channelid']])->order("id desc")->select();
  213. foreach ($res as $key => $value) {
  214. $res[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']);
  215. $res[$key]['type'] = $value['type'] == 1?'增加':'修改';
  216. }
  217. if ($res) {
  218. $this->success('添加成功',null,$res);
  219. }else{
  220. $this->error("暂无数据");
  221. }
  222. }
  223. //游戏默认公会分成比例
  224. public function gamesplit()
  225. {
  226. $gameId = input('game_id');
  227. $where = [];
  228. $where['game.is_default'] = 0;
  229. if ($gameId) {
  230. $where['game.id'] = $gameId;
  231. }
  232. //查询参数
  233. $param = input('get.');
  234. $list = model('Game')->alias('game')
  235. ->join('cy_gameinfo info', 'game.id = info.game_id', 'left')
  236. ->field('game.id,game.name as game_name,game.origin_name,game.cooperation_status,game.create_time,game.game_kind,game.channel_split_ratio')
  237. ->where($where)
  238. ->order('game.id desc')
  239. ->paginate(10, false, array('query' => $param));
  240. $this->assign('list', $list);
  241. $this->assign('page', $list->render());
  242. $tmpGameList = $this->cyModel('game')->field('id,name')->select();
  243. $gameList = array();
  244. foreach ($tmpGameList as $game) {
  245. $gameList[ $game['id']] = $game;
  246. }
  247. $this->assign('game_list',$gameList);
  248. $this->assign('game_id',$gameId);
  249. return $this->fetch();
  250. }
  251. //修改游戏默认公会分成比例
  252. public function editGameSplit()
  253. {
  254. $postParam = $this->request->param();
  255. $ratio = intval($postParam['value']);
  256. if(is_int($ratio) == false){
  257. $this->error("分成比例必须是正整数");
  258. }
  259. if($ratio < 0 || $ratio >= 100){
  260. $this->error("分成比例范围必须在0-99内");
  261. }
  262. if(!intval($postParam['gameid'])){
  263. $this->error("请选择要修改的游戏");
  264. }
  265. $where = array();
  266. $where['id'] = intval($postParam['gameid']);
  267. $gameInfo = model("Game")->field('id,name,channel_split_ratio')->where($where)->find();
  268. if(!$gameInfo){
  269. $this->error("您选择的游戏不存在");
  270. }
  271. else if(floatval($gameInfo['channel_split_ratio']) == floatval($ratio)){
  272. $this->success("分成比例未做任何更改");
  273. }
  274. Db::startTrans();
  275. try {
  276. $res = model("Game")->where($where)->update(['channel_split_ratio' => $ratio]);
  277. if ($res != 1) {
  278. throw new Exception("分成比例未做任何更改");
  279. }
  280. $cont['divide_id'] = 0;
  281. $cont['channel_id'] = 0;
  282. $cont['game_id'] = $postParam['gameid'];
  283. $cont['ratio'] = $ratio;
  284. $cont['type'] = 2;
  285. $cont['create_time'] = NOW_TIMESTAMP;
  286. Db::table('nw_game_channel_divide_log')->insertGetId($cont);
  287. Db::commit();
  288. $template = '游戏默认公会分成比例更改:管理员"'.session('USERNAME').'" 更改了游戏公会默认分成比例,游戏名:'.$gameInfo['name'].',分成比例:'.$ratio.'% 。操作时间:'.date('Y-m-d H:i:s');
  289. $this->insertLog($this->current_node,$template, 101);
  290. $ddurl = Env::get('operat_url');
  291. // curlDD($template, $ddurl,true);
  292. //$this->success("更新成功");
  293. } catch (Exception $e) {
  294. Db::rollback();
  295. $this->error("添加失败: " . $e->getMessage());
  296. }
  297. $this->success("更新成功");
  298. }
  299. //获取游戏默认公会分成比例日志
  300. public function gameSplitLog()
  301. {
  302. $postParam = $this->request->param();
  303. if (empty($postParam['gameid'])) {
  304. $this->error("参数错误");
  305. }
  306. $res = Db::table('nw_game_channel_divide_log')->where(['game_id'=>$postParam['gameid'],'channel_id'=>0])->order("id desc")->select();
  307. foreach ($res as $key => $value) {
  308. $res[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']);
  309. $res[$key]['type'] = $value['type'] == 1?'增加':'修改';
  310. }
  311. if ($res) {
  312. $this->success('获取成功',null,$res);
  313. }else{
  314. $this->error("暂无数据");
  315. }
  316. }
  317. /**
  318. * 获取补点记录
  319. *
  320. * @Author yxon 564556921@qq.com
  321. * @DateTime 2020-12-08
  322. * @return void
  323. */
  324. public function divideLog()
  325. {
  326. $postParam = $this->request->param();
  327. if (empty($postParam['gameid'])) {
  328. $this->error("参数错误");
  329. }
  330. $res = Db::table('nw_game_extra_divide_log')->where(['extra_game_id'=>$postParam['gameid']])->order("id desc")->select();
  331. foreach ($res as $key => $value) {
  332. $res[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']);
  333. switch ($value['type']) {
  334. case '1':
  335. $res[$key]['type'] = '增加';
  336. break;
  337. case '2':
  338. $res[$key]['type'] = '修改';
  339. break;
  340. case '3':
  341. $res[$key]['type'] = '删除';
  342. break;
  343. default:
  344. $res[$key]['type'] = '增加';
  345. break;
  346. }
  347. }
  348. if ($res) {
  349. $this->success('获取成功',null,$res);
  350. }else{
  351. $this->error("暂无数据");
  352. }
  353. }
  354. /**
  355. * 游戏补点设置
  356. *
  357. * @Author yxon 564556921@qq.com
  358. * @DateTime 2020-12-08
  359. * @param Type $var
  360. * @return void
  361. */
  362. public function gameDivideEdit()
  363. {
  364. $postParam = $this->request->param();
  365. $where = array();
  366. $data = [];
  367. $where['extra_game_id'] = intval($postParam['game_agg_id']);;
  368. if (empty($postParam['game_agg_id']) || empty($postParam['data'])) {
  369. $this->error("参数错误,请刷新后重试!");
  370. }
  371. $gameInfo = db::name('nw_extra_game')->field('id,extra_game_name as name')->where(['id'=>$postParam['game_agg_id']])->find();
  372. $data['divide'] = json_encode($postParam['data'],1);
  373. $data['remark'] = $postParam['remark'];
  374. $type = 1;
  375. Db::startTrans();
  376. try {
  377. if (db::name('nw_game_extra_divide')->where($where)->value('id')) { //存在记录
  378. if (db::name('nw_game_extra_divide')->where($where)->value('divide') == $data['divide']) {
  379. throw new Exception("阶梯分成比例未做任何更改");
  380. }
  381. $type = 2;
  382. $data['update_time'] = NOW_TIMESTAMP;
  383. $data['update_admin_name'] = session('USERNAME');
  384. $res = db::name('nw_game_extra_divide')->where($where)->update($data);
  385. }else{
  386. $type = 1;
  387. $data['extra_game_id'] = intval($postParam['game_agg_id']);
  388. $data['create_time'] = NOW_TIMESTAMP;
  389. $data['add_admin_name'] = session('USERNAME');
  390. $res = db::name('nw_game_extra_divide')->insert($data);
  391. }
  392. if ($res != 1) {
  393. throw new Exception("阶梯分成比例未做任何更改");
  394. }
  395. $cont['extra_game_id'] = $postParam['game_agg_id'];
  396. $cont['divide'] = json_encode($postParam['data'],1);
  397. $cont['remark'] = $postParam['remark'];
  398. $cont['type'] = $type;
  399. $cont['create_time'] = NOW_TIMESTAMP;
  400. $cont['admin_name'] = session('USERNAME');
  401. Db::table('nw_game_extra_divide_log')->insertGetId($cont);
  402. Db::commit();
  403. $template = '游戏集默认补点比例更改:管理员"'.session('USERNAME').'" 更改了游戏集补点比例,游戏集名:'.$gameInfo['name'].'。操作时间:'.date('Y-m-d H:i:s');
  404. $this->insertLog($this->current_node,$template, 101);
  405. $ddurl = Env::get('operat_url');
  406. //curlDD($template, $ddurl,true);
  407. } catch (Exception $e) {
  408. Db::rollback();
  409. $this->error("添加失败: " . $e->getMessage());
  410. }
  411. $this->success("更新成功");
  412. }
  413. /**
  414. * Undocumented function
  415. *
  416. * @Author yxon 564556921@qq.com
  417. * @DateTime 2020-12-09
  418. * @param Type $var
  419. * @return void
  420. */
  421. public function checkdel()
  422. {
  423. $postParam = $this->request->param();
  424. $where = array();
  425. $data = [];
  426. $where['game_id'] = intval($postParam['game_id']);
  427. if (empty($postParam['game_id'])) {
  428. $this->error("参数错误,请刷新后重试!");
  429. }
  430. $gameInfo = model("Game")->field('id,name')->where(['id'=>$postParam['game_id']])->find();
  431. if(!$gameInfo){
  432. $this->error("您选择的游戏不存在");
  433. }
  434. Db::startTrans();
  435. try {
  436. if (db::name('nw_game_extra_divide')->where($where)->value('id')) { //存在记录
  437. $type = 3;
  438. $data['divide'] = '';
  439. $data['update_time'] = NOW_TIMESTAMP;
  440. $data['update_admin_name'] = session('USERNAME');
  441. $res = db::name('nw_game_extra_divide')->where($where)->update($data);
  442. }else{
  443. throw new Exception("该游戏补点不存在");
  444. }
  445. if ($res != 1) {
  446. throw new Exception("阶梯分成比例未做任何更改");
  447. }
  448. $cont['game_id'] = $postParam['game_id'];
  449. $cont['divide'] = '';
  450. $cont['remark'] = '';
  451. $cont['type'] = 3;
  452. $cont['create_time'] = NOW_TIMESTAMP;
  453. $cont['admin_name'] = session('USERNAME');
  454. Db::table('nw_game_extra_divide_log')->insertGetId($cont);
  455. Db::commit();
  456. $template = '游戏默认游戏补点比例更改:管理员"'.session('USERNAME').'" 删除了游戏补点比例,游戏名:'.$gameInfo['name'].'。操作时间:'.date('Y-m-d H:i:s');
  457. $this->insertLog($this->current_node,$template, 101);
  458. $ddurl = Env::get('operat_url');
  459. //curlDD($template, $ddurl,true);
  460. } catch (Exception $e) {
  461. Db::rollback();
  462. $this->error("操作失败: " . $e->getMessage());
  463. }
  464. $this->success("操作成功");
  465. }
  466. /**
  467. * 公会补点页面
  468. *
  469. * @Author yxon 564556921@qq.com
  470. * @DateTime 2020-12-09
  471. * @param Type $var
  472. * @return void
  473. */
  474. public function dividehtml()
  475. {
  476. $channelId = input('channel_id');
  477. $gameId = input('game_id');
  478. $where = [];
  479. $where['channel_type'] = 1;
  480. $channelId && $where['channel_id'] = $channelId;
  481. $gameId && $where['extra_game_id'] = $gameId;
  482. //内部公会账号
  483. $tmpChannelList = Db::table('nw_channel')->alias('channel')
  484. ->field('channel.id,channel.name,parent.channel_tg_type')
  485. ->join('nw_channel parent','channel.parent_id = parent.id','left')
  486. ->where(['channel.level'=>1,'channel.channel_tg_type'=>0,'parent.channel_tg_type'=>0])
  487. ->select();
  488. $list = db::name('nw_game_channel_extra_divide')->alias('divide')
  489. ->field('divide.id,divide.channel_id,divide.extra_game_id,from_unixtime(divide.create_time) as create_time,divide.divide,game.extra_game_name,channel.name as c_name')
  490. ->where($where)
  491. ->order("id desc")
  492. ->join('nw_extra_game game', 'divide.extra_game_id = game.id','LEFT')
  493. ->join('nw_channel channel', 'divide.channel_id = channel.id','LEFT')
  494. ->paginate(10, false, ['query' => $where]);
  495. //获取分页显示
  496. $page = $list->render();
  497. $this->assign('game_list', $this->gameAggList);
  498. $this->assign('channel_id', $channelId);
  499. $this->assign('channel_list', $tmpChannelList);
  500. $this->assign('game_id', $gameId);
  501. $this->assign("page", $page);
  502. $this->assign("list", $list);
  503. return $this->fetch();
  504. }
  505. /**
  506. * 新增公会补点设置页面
  507. *
  508. * @Author yxon 564556921@qq.com
  509. * @DateTime 2020-12-10
  510. * @return void
  511. */
  512. public function adddividehtml()
  513. {
  514. $postParam = $this->request->param();
  515. if (isset($postParam['game_agg_id'])&&isset($postParam['channel_id'])&&isset($postParam['divide'])) {
  516. $this->assign('game_agg_id', $postParam['game_agg_id']);
  517. $this->assign('channel_id', $postParam['channel_id']);
  518. $this->assign('data', json_decode($postParam['divide']));
  519. $this->assign('type', 2);
  520. }else{
  521. $this->assign('type', 1);
  522. }
  523. if (isset($postParam['type']) && $postParam['type'] == 'uniom') {
  524. $tmpChannelList = Db::table('nw_channel')->alias('channel')
  525. ->field('channel.id,channel.name')
  526. ->where(['channel.level'=>0,'channel.channel_tg_type'=>['neq',0]])
  527. ->select();
  528. $this->assign('typename', '选择联盟');
  529. $this->assign('channel_type', '2');
  530. }else{
  531. $tmpChannelList = Db::table('nw_channel')->alias('channel')
  532. ->field('channel.id,channel.name,parent.channel_tg_type')
  533. ->join('nw_channel parent','channel.parent_id = parent.id','left')
  534. ->where(['channel.level'=>1,'channel.channel_tg_type'=>0,'parent.channel_tg_type'=>0])
  535. ->select();
  536. $temarray = Db::table('nw_channel')->alias('channel')
  537. ->join('nw_channel parent','channel.parent_id = parent.id','left')
  538. ->where(['channel.level'=>1,'channel.channel_tg_type'=>0,'parent.channel_tg_type'=>0])
  539. ->column('channel.id');
  540. if (isset($postParam['channel_id']) && !in_array($postParam['channel_id'],$temarray)) {
  541. $this->error("该公会的商务已经更改为外放,无法编辑");
  542. }
  543. $this->assign('typename', '选择公会');
  544. $this->assign('channel_type', '1');
  545. }
  546. $list = db::name('nw_extra_game')->column('id,extra_game_name as game');
  547. $this->assign('channel_list', $tmpChannelList);
  548. $this->assign('game_agg_list', $list);
  549. return $this->fetch();
  550. }
  551. /**
  552. * 新增公会补点设置功能
  553. *
  554. * @Author yxon 564556921@qq.com
  555. * @DateTime 2020-12-10
  556. * @param Type $var
  557. * @return void
  558. */
  559. public function gameChannelDivideEdit()
  560. {
  561. $postParam = $this->request->param();
  562. $type = $postParam['type'];
  563. $where = array();
  564. $data = [];
  565. $where['extra_game_id'] = intval($postParam['game_agg_id']);
  566. $where['channel_id'] = intval($postParam['channel_id']);
  567. if (empty($postParam['game_agg_id']) || empty($postParam['channel_id'])) {
  568. $this->error("参数错误,请刷新后重试!");
  569. }
  570. $gameInfo = db::name('nw_extra_game')->field('id,extra_game_name as name')->where(['id'=>$postParam['game_agg_id']])->find();
  571. if(!$gameInfo){
  572. $this->error("您选择的游戏集不存在");
  573. }
  574. $channelInfo = model("Channel")->field('id,name,channel_tg_type,level,parent_id')->where('id',$postParam['channel_id'])->find();
  575. if(!$channelInfo){
  576. $this->error("您选择的公会不存在");
  577. }
  578. else{
  579. $channel_name = $channelInfo['name'];
  580. }
  581. if ($channelInfo['level'] == 1) {//会长情况:对应商务必须是内部
  582. $flag = model("Channel")->where('id',$channelInfo['parent_id'])->value('channel_tg_type');
  583. if ($flag) {
  584. $this->error("该会长渠道为外放商务下的渠道,无法编辑");
  585. }
  586. //查看之前是否有商务补点(考虑更改过外放);
  587. $temp_array = db::name('nw_game_channel_extra_divide')->where('channel_id',$channelInfo['parent_id'])->value('id');
  588. if ($temp_array) {
  589. $this->error("创建失败:该公会的商务之前已经创建过外放商务补点请先删除后再创建");
  590. }
  591. }else{//商务情况:必须外放
  592. $flag = model("Channel")->where('id',$postParam['channel_id'])->value('channel_tg_type');
  593. if (!$flag) {
  594. $this->error("该商务渠道非外放");
  595. }
  596. //判断之前是否有公会补点(考虑更改过外放类型)
  597. $temp_array = db::name('nw_game_channel_extra_divide')->alias('divide')
  598. ->join('nw_channel channel', 'channel.id = divide.channel_id','LEFT')
  599. ->where(['channel.level'=>1,'channel.id_path'=>['LIKE', '%,' . $postParam['channel_id'] . ',%']])
  600. ->column('divide.id');
  601. if ($temp_array) {
  602. $this->error("创建失败:该外放商务之前已经创建过子公会补点请先删除后再创建");
  603. }
  604. }
  605. $data['divide'] = json_encode($postParam['data'],1);
  606. $data['remark'] = $postParam['remark'];
  607. $data['channel_type'] = $postParam['channel_type'];
  608. Db::startTrans();
  609. try {
  610. switch ($type) {
  611. case '1'://新增
  612. if (db::name('nw_game_channel_extra_divide')->where($where)->value('id')) {
  613. throw new Exception("该公会下的该游戏补点已经设置");
  614. }
  615. $data['channel_id'] = $postParam['channel_id'];
  616. $data['extra_game_id'] = intval($postParam['game_agg_id']);
  617. $data['create_time'] = NOW_TIMESTAMP;
  618. $data['add_admin_name'] = session('USERNAME');
  619. $res = db::name('nw_game_channel_extra_divide')->insertGetId($data);
  620. $cont['divide_id'] = $res;
  621. break;
  622. case '2'://编辑
  623. if (db::name('nw_game_channel_extra_divide')->where($where)->value('divide') == $data['divide']) {
  624. throw new Exception("补点信息未做任何更改");
  625. }
  626. $cont['divide_id'] = db::name('nw_game_channel_extra_divide')->where($where)->value('id');
  627. $data['update_time'] = NOW_TIMESTAMP;
  628. $data['update_admin_name'] = session('USERNAME');
  629. $res = db::name('nw_game_channel_extra_divide')->where($where)->update($data);
  630. break;
  631. }
  632. if (empty($res)) {
  633. throw new Exception("补点信息添加失败");
  634. }
  635. $cont['channel_id'] = $postParam['channel_id'];
  636. $cont['extra_game_id'] = $postParam['game_agg_id'];
  637. $cont['divide'] = json_encode($postParam['data'],1);
  638. $cont['remark'] = $postParam['remark'];
  639. $cont['type'] = $type;
  640. $cont['create_time'] = NOW_TIMESTAMP;
  641. $cont['admin_name'] = session('USERNAME');
  642. Db::table('nw_game_channel_extra_divide_log')->insertGetId($cont);
  643. Db::commit();
  644. $template = '公会补点比例新增:管理员"'.session('USERNAME').'" 新增了公会补点比例,游戏名:'.$gameInfo['name'].',公会账号:'.$channel_name.'。操作时间:'.date('Y-m-d H:i:s');
  645. $this->insertLog($this->current_node,$template, 101);
  646. $ddurl = Env::get('operat_url');
  647. //curlDD($template, $ddurl,true);
  648. } catch (Exception $e) {
  649. Db::rollback();
  650. $this->error("添加失败: " . $e->getMessage());
  651. }
  652. $this->success("更新成功");
  653. }
  654. /**
  655. * 删除游戏补点信息
  656. *
  657. * @Author yxon 564556921@qq.com
  658. * @DateTime 2020-12-10
  659. * @param Type $var
  660. * @return void
  661. */
  662. public function deldividepost()
  663. {
  664. $postParam = $this->request->param();
  665. if(empty($postParam['id'])){
  666. $this->error("参数错误");
  667. }
  668. $where = array();
  669. $data = [];
  670. $where['id'] = intval($postParam['id']);
  671. $info = db::name('nw_game_channel_extra_divide')->where(['id'=>$postParam['id']])->find();
  672. if(!$info){
  673. $this->error("参数错误");
  674. }
  675. Db::startTrans();
  676. try {
  677. $res = db::name('nw_game_channel_extra_divide')->where(['id'=>$postParam['id']])->delete();//删除
  678. if (empty($res)) {
  679. throw new Exception("补点信息删除失败");
  680. }
  681. $cont['channel_id'] = $info['channel_id'];
  682. $cont['extra_game_id'] = $info['extra_game_id'];
  683. $cont['divide'] = 0;
  684. $cont['remark'] = '';
  685. $cont['type'] = 3;
  686. $cont['create_time'] = NOW_TIMESTAMP;
  687. $cont['admin_name'] = session('USERNAME');
  688. Db::table('nw_game_channel_extra_divide_log')->insertGetId($cont);
  689. Db::commit();
  690. } catch (Exception $e) {
  691. Db::rollback();
  692. $this->error("操作失败: " . $e->getMessage());
  693. }
  694. $this->success("操作成功");
  695. }
  696. /**
  697. * 删除游戏补点信息
  698. *
  699. * @Author yxon 564556921@qq.com
  700. * @DateTime 2020-12-10
  701. * @param Type $var
  702. * @return void
  703. */
  704. public function delgamedividepost()
  705. {
  706. $postParam = $this->request->param();
  707. if(empty($postParam['id'])){
  708. $this->error("参数错误");
  709. }
  710. $where = array();
  711. $data = [];
  712. $where['id'] = intval($postParam['id']);
  713. $info = db::name('nw_game_extra_divide')->where(['id'=>$postParam['id']])->find();
  714. if(!$info){
  715. $this->error("参数错误");
  716. }
  717. Db::startTrans();
  718. try {
  719. $res = db::name('nw_game_extra_divide')->where(['id'=>$postParam['id']])->delete();//删除
  720. if (empty($res)) {
  721. throw new Exception("补点信息删除失败");
  722. }
  723. $cont['extra_game_id'] = $info['extra_game_id'];
  724. $cont['divide'] = 0;
  725. $cont['remark'] = '';
  726. $cont['type'] = 3;
  727. $cont['create_time'] = NOW_TIMESTAMP;
  728. $cont['admin_name'] = session('USERNAME');
  729. Db::table('nw_game_extra_divide_log')->insertGetId($cont);
  730. Db::commit();
  731. } catch (Exception $e) {
  732. Db::rollback();
  733. $this->error("操作失败: " . $e->getMessage());
  734. }
  735. $this->success("操作成功");
  736. }
  737. /**
  738. * 查看公会补点修改记录
  739. *
  740. * @Author yxon 564556921@qq.com
  741. * @DateTime 2020-12-11
  742. * @return void
  743. */
  744. public function checkdividelog()
  745. {
  746. $postParam = $this->request->param();
  747. $where = array();
  748. $where['extra_game_id'] = intval($postParam['game_id']);
  749. $where['channel_id'] = intval($postParam['channel_id']);
  750. $res = Db::table('nw_game_channel_extra_divide_log')->where($where)->order("id desc")->select();
  751. foreach ($res as $key => $value) {
  752. $res[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']);
  753. switch ($value['type']) {
  754. case '1':
  755. $res[$key]['type'] = '增加';
  756. break;
  757. case '2':
  758. $res[$key]['type'] = '修改';
  759. break;
  760. case '3':
  761. $res[$key]['type'] = '删除';
  762. break;
  763. default:
  764. $res[$key]['type'] = '增加';
  765. break;
  766. }
  767. }
  768. if ($res) {
  769. $this->success('获取成功',null,$res);
  770. }else{
  771. $this->error("暂无数据");
  772. }
  773. }
  774. /**
  775. * 外放商务补点
  776. *
  777. * @Author yxon 564556921@qq.com
  778. * @DateTime 2020-12-11
  779. * @return void
  780. */
  781. public function uniomdividehtml()
  782. {
  783. $channelId = input('channel_id');
  784. $extra_game_id = input('extra_game_id');
  785. $where = [];
  786. $where['channel_type'] = 2;
  787. $channelId && $where['channel_id'] = $channelId;
  788. $extra_game_id && $where['extra_game_id'] = $extra_game_id;
  789. //内部公会账号
  790. $tmpChannelList = Db::table('nw_channel')->alias('channel')
  791. ->field('channel.id,channel.name')
  792. ->where(['channel.level'=>0,'channel.channel_tg_type'=>1])
  793. ->select();
  794. $list = db::name('nw_game_channel_extra_divide')->alias('divide')
  795. ->field('divide.id,divide.channel_id,divide.extra_game_id,from_unixtime(divide.create_time) as create_time,divide.divide,game.extra_game_name,channel.name as c_name')
  796. ->where($where)
  797. ->order("id desc")
  798. ->join('nw_extra_game game', 'divide.extra_game_id = game.id','LEFT')
  799. ->join('nw_channel channel', 'divide.channel_id = channel.id','LEFT')
  800. ->paginate(10, false, ['query' => $where]);
  801. //获取分页显示
  802. $page = $list->render();
  803. $this->assign('game_list', $this->gameAggList);
  804. $this->assign('type', "uniom");
  805. $this->assign('channel_id', $channelId);
  806. $this->assign('channel_list', $tmpChannelList);
  807. $this->assign('game_id', $extra_game_id);
  808. $this->assign("page", $page);
  809. $this->assign("list", $list);
  810. return $this->fetch();
  811. }
  812. /**
  813. * 游戏补点设置
  814. *
  815. * @Author yxon 564556921@qq.com
  816. * @DateTime 2020-12-18
  817. * @param Type $var
  818. * @return void
  819. */
  820. public function gamedevide()
  821. {
  822. $id = input('game_id');
  823. $where = [];
  824. if ($id) {
  825. $where['g.id'] = $id;
  826. }
  827. //查询参数
  828. $param = input('get.');
  829. $list = Db::table('nw_game_extra_divide')->alias('d')
  830. ->join('nw_extra_game g', 'g.id = d.extra_game_id', 'left')
  831. ->field('d.id, from_unixtime(d.create_time) as create_time,d.divide,g.extra_game_name,d.extra_game_id')
  832. ->where($where)
  833. ->order('d.id desc')
  834. ->paginate(10, false, array('query' => $param));
  835. $this->assign('list', $list);
  836. $this->assign('page', $list->render());
  837. $this->assign('game_list',$this->gameAggList);
  838. $this->assign('game_id',$id);
  839. return $this->fetch();
  840. }
  841. /**
  842. * 创建游戏集页面
  843. *
  844. * @Author yxon 564556921@qq.com
  845. * @DateTime 2020-12-21
  846. * @return void
  847. */
  848. public function gamesAggDivide()
  849. {
  850. $postParam = $this->request->param();
  851. if (isset($postParam['game_agg_id'])&&isset($postParam['channel_id'])&&isset($postParam['divide'])) {
  852. $this->assign('game_agg_id', $postParam['game_agg_id']);
  853. $this->assign('channel_id', $postParam['channel_id']);
  854. $this->assign('data', json_decode($postParam['divide']));
  855. $this->assign('type', 2);
  856. }else{
  857. $this->assign('type', 1);
  858. }
  859. $list = db::name('nw_extra_game')->column('id,extra_game_name as game');
  860. $this->assign('channel_list', $this->channeList);
  861. $this->assign('game_agg_list',$list);
  862. return $this->fetch();
  863. }
  864. /**
  865. * 添加游戏合集
  866. *
  867. * @Author yxon 564556921@qq.com
  868. * @DateTime 2020-12-22
  869. * @return void
  870. */
  871. public function addGameAgg()
  872. {
  873. $postParam = $this->request->param();
  874. if (isset($postParam['title'])&&isset($postParam['id'])) {
  875. $res = db::name('nw_extra_subgame')->where(['extra_game_id'=>$postParam['id']])->column('game_id');
  876. $this->assign('title', $postParam['title']);
  877. $this->assign('id', $postParam['id']);
  878. $this->assign('selected', $res);
  879. $this->assign('type', 2);
  880. }else{
  881. $this->assign('selected', []);
  882. $this->assign('id', '');
  883. $this->assign('type', 1);
  884. }
  885. $this->assign('game_list',$this->gameList );
  886. return $this->fetch();
  887. }
  888. public function addaggpost()
  889. {
  890. $postParam = $this->request->param();
  891. $data = $postParam['game'];
  892. $type = $postParam['type'];
  893. if (empty($postParam['title'])) {
  894. $this->error("请输入集合名称");
  895. }
  896. if (!isset($data[0]) || empty($data[0])) {
  897. $this->error("请选择至少一款游戏");
  898. }
  899. if ($type == 2) {
  900. if (empty($postParam['id'])) {
  901. $this->error("参数错误");
  902. }
  903. }
  904. $data = explode(',',$data[0]);
  905. $cont = [];
  906. $cont['extra_game_name'] = $postParam['title'];
  907. $cont['create_time'] = NOW_TIMESTAMP;
  908. $cont['add_admin_name'] = session('USERNAME');
  909. $backIds = [];
  910. $back_msg = '';
  911. Db::startTrans();
  912. try {
  913. switch ($type) {
  914. case '1'://新增
  915. $res = db::name('nw_extra_game')->insertGetId($cont);//创建游戏集
  916. if (empty($res)) {
  917. throw new Exception("游戏集创建失败");
  918. }
  919. foreach ($data as $key => $value) {//循环插入数据库
  920. if (db::name('nw_extra_subgame')->where(['game_id'=>$value])->value('id')) {
  921. $backIds[] = $value;
  922. }else{
  923. $any = [];
  924. $any['extra_game_id'] = $res;
  925. $any['game_id'] = $value;
  926. $any['create_time'] = NOW_TIMESTAMP;
  927. $any['add_admin_name'] = session('USERNAME');
  928. db::name('nw_extra_subgame')->insert($any);
  929. }
  930. }
  931. if ($backIds == $data){
  932. throw new Exception("所有游戏已存在在其他游戏集里面无法添加");
  933. }
  934. break;
  935. case '2'://编辑
  936. if (db::name('nw_extra_subgame')->where(['extra_game_id'=>$postParam['id']])->column('game_id') == $data) {
  937. throw new Exception("更新失败,数据未发生更改");
  938. }
  939. db::name('nw_extra_subgame')->where(['extra_game_id'=>$postParam['id']])->delete();
  940. foreach ($data as $key => $value) {//循环插入数据库
  941. if (db::name('nw_extra_subgame')->where(['game_id'=>$value])->value('id')) {
  942. $edit_backIds[] = $value;
  943. }else{
  944. $any = [];
  945. $any['extra_game_id'] = $postParam['id'];
  946. $any['game_id'] = $value;
  947. $any['create_time'] = NOW_TIMESTAMP;
  948. $any['add_admin_name'] = session('USERNAME');
  949. db::name('nw_extra_subgame')->insert($any);
  950. }
  951. }
  952. if (isset($edit_backIds)&&!empty($edit_backIds)) {
  953. $res = db::name('cy_game')->where(['id'=>['in',$edit_backIds]])->column('name');
  954. $back_msg = $res;
  955. }
  956. break;
  957. }
  958. Db::commit();
  959. } catch (Exception $e) {
  960. Db::rollback();
  961. $this->error("操作失败: " . $e->getMessage());
  962. }
  963. if ($back_msg) {
  964. $str = implode(',',$back_msg);
  965. $this->success("操作成功,部分游戏(".$str.")已存在其他游戏集未添加成功");
  966. }
  967. $this->success("操作成功");
  968. }
  969. /**
  970. * 游戏集页面
  971. *
  972. * @Author yxon 564556921@qq.com
  973. * @DateTime 2020-12-22
  974. * @param Type $var
  975. * @return void
  976. */
  977. public function gameAggSet()
  978. {
  979. $id = input('game_id');
  980. $where = [];
  981. if ($id) {
  982. $where['id'] = $id;
  983. }
  984. //查询参数
  985. $param = input('get.');
  986. $list = Db::table('nw_extra_game')
  987. ->field('id,from_unixtime(create_time) as create_time,extra_game_name,add_admin_name')
  988. ->where($where)
  989. ->order('id desc')
  990. ->paginate(10, false, array('query' => $param));
  991. $this->assign('list', $list);
  992. $this->assign('page', $list->render());
  993. $this->assign('game_list',$this->gameAggList);
  994. $this->assign('game_id',$id);
  995. return $this->fetch();
  996. }
  997. }