GameDiscount.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?php
  2. /**
  3. * 游戏折扣
  4. */
  5. namespace app\admin\controller;
  6. use app\common\library\FileUpload;
  7. use app\common\library\MakeReport;
  8. use app\common\model\AndroidSdk;
  9. use app\common\model\GameBand;
  10. use app\common\model\Game as GameModel;
  11. use app\common\model\GameInfo;
  12. use app\common\model\GameNotify;
  13. use app\common\model\GameBanned;
  14. use app\common\model\GameExtraPointRatio;
  15. use Overtrue\Pinyin\Pinyin;
  16. use think\Db;
  17. use think\Exception;
  18. class GameDiscount extends Admin
  19. {
  20. protected $gameModel;
  21. // 游戏等级
  22. protected $gameLevel = ['S', 'A1', 'A2', 'B1', 'B2', 'B3', 'B4', 'C', 'D'];
  23. /**
  24. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  25. */
  26. protected function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->gameModel = new GameModel;
  30. $this->gameList = $gameList = model('Common/Game')->getAllByCondition('id,name');
  31. $this->selfGameList = $selfGameList = model('Common/Game')->getAllByCondition('id,name', [],'','self');
  32. }
  33. /**
  34. *是否显示
  35. */
  36. public function show()
  37. {
  38. $id = $this->request->param('id', '', 'intval');
  39. $status = $this->request->param('is_show', '', 'intval');
  40. $data['is_show'] = $status;
  41. if (empty($id)) {
  42. $this->error('参数错误!');
  43. }
  44. $result = $this->validate($data, [
  45. ['is_show', 'in:0,1', '状态参数错误'],
  46. ]);
  47. if (true !== $result) {
  48. $this->error($result);
  49. }
  50. $gameModel = model("Game");
  51. if (!$gameModel->find($id)) {
  52. $this->error('参数错误,不存在该数据');
  53. }
  54. if ($gameModel->update($data, ['id' => $id])) {
  55. $msg = $status ? '显示' : '隐藏';
  56. $this->insertLog($this->current_node, $msg . '游戏:' . get_game_name($id), 11);
  57. $this->success('修改成功');
  58. }
  59. $error = $gameModel->getError();
  60. $this->error($error ?: '修改失败');
  61. }
  62. /**
  63. * 游戏点位
  64. * @return mixed|string
  65. */
  66. public function gamePointList()
  67. {
  68. $where['g.cooperation_status'] = ['not in','0,3']; //对接中,下架的游戏不显示
  69. // $where['g.is_default'] = 0; //外部游戏不显示
  70. //游戏名称
  71. if (input('request.game_id') != '') {
  72. $where['g.id'] = ['=', input('request.game_id')];
  73. $game = get_game_name(input('request.game_id'));
  74. $message = "查询游戏:{$game}";
  75. $this->insertLog($this->current_node, $message, 12);
  76. }
  77. $list = Db::table('cy_game')->alias('g')->join('cy_game_point p', 'g.id = p.game_id', 'left')
  78. ->join("nw_game_channel_pointset b","b.game_id=g.id", "left")
  79. ->field("p.*,g.id as game_id,g.name,b.isset_first,b.restricted_list_1,b.isset_second,b.restricted_list_2")->order('g.id desc')->where($where)->where("g.is_default = 0")
  80. ->paginate(10, false, ['query' => input('get.')])
  81. ->each(function($item, $key){
  82. $item['restricted_list_1'] = ltrim($item['restricted_list_1'], ',');
  83. $item['restricted_list_2'] = ltrim($item['restricted_list_2'], ',');
  84. // 判断首充渠道限制名单是否为空
  85. $item['channel_name_1'] = '';
  86. $item['channel_name_2'] = '';
  87. if(!empty($item['restricted_list_1'])){
  88. $channelArr = Db::table('cy_department')
  89. ->field("name")
  90. ->where('id', 'IN', $item['restricted_list_1'])
  91. ->select();
  92. $nameStr = '';
  93. foreach ($channelArr as $v){
  94. $nameStr .=$v['name'].',';
  95. }
  96. $nameStr = substr($nameStr,0,strlen($nameStr)-3);
  97. $item['channel_name_1'] = $nameStr; //给数据集追加字段num并赋值
  98. }
  99. // 判断续充渠道限制名单是否为空
  100. if(!empty($item['restricted_list_2'])){
  101. $channelArr = Db::table('cy_department')
  102. ->field("name")
  103. ->where('id', 'IN', $item['restricted_list_2'])
  104. ->select();
  105. $nameStr = '';
  106. foreach ($channelArr as $v){
  107. $nameStr .=$v['name'].',';
  108. }
  109. $nameStr = substr($nameStr,0,strlen($nameStr)-3);
  110. $item['channel_name_2'] = $nameStr; //给数据集追加字段num并赋值
  111. }
  112. return $item;
  113. });
  114. // 获取配置表 首充默认最大天数 FIRST_MAX_DAY
  115. $FIRST_MAX_DAY = model('Setting')->where(['name'=>'FIRST_MAX_DAY'])->field('value')->find()['value'];
  116. $this->assign('game_list', $this->selfGameList);
  117. $this->assign('game_point_list', $list);
  118. $this->assign('FIRST_MAX_DAY', $FIRST_MAX_DAY);
  119. $this->assign('page', $list->render());
  120. return $this->fetch('game_point_list');
  121. }
  122. public function editPoint()
  123. {
  124. $data = $this->request->param();
  125. if (isset($data['type'])){
  126. if ($data['type'] == 'editMultiLevel'){
  127. $this->editMultiLevel();
  128. }
  129. if ($data['type'] == 'editLevel'){
  130. $this->editLevel();
  131. }
  132. if ($data['type'] == 'editPercent'){
  133. $this->editPercent();
  134. }
  135. }
  136. $type = ['third_party_pay_point', 'inner_point', 'remark', 'inner_first_point','first_max_days'];
  137. if (!in_array($data['name'], $type)) {
  138. $this->error('选择参数错误');
  139. }
  140. //返点
  141. $gamePointModel = model("GamePoint");
  142. $oldPoint = $gamePointModel->where("game_id = '{$data['pk']}'")->field('gp_id,inner_point,inner_first_point,third_party_pay_point')->find();
  143. $nameZK = '';
  144. if ($data['name'] == 'third_party_pay_point') {
  145. $result = $this->validate($data, [
  146. ['pk|ID', 'require', '参数错误'],
  147. ['value|点数', 'number|between:0,100'],
  148. ['name', 'require', '点位参数错误'],
  149. ]);
  150. } else if ($data['name'] == 'inner_first_point'){
  151. // 首充
  152. $result = $this->validate($data, [
  153. ['pk|ID', 'require', '参数错误'],
  154. ['value|首充折扣', 'number|between:0,10'],
  155. ['name', 'require', '点位参数错误'],
  156. ]);
  157. $nameZK = '首充折扣';
  158. $point_fla = true;
  159. if( $data['value'] <=0 || $data['value'] >10 || !is_numeric($data['value'])){
  160. $result = '折扣点位只能0<折扣≤10';
  161. $point_fla = false;
  162. }elseif( (float)$oldPoint['inner_point'] > 0 && $data['value'] >$oldPoint['inner_point'] && $point_fla){
  163. $result = '首充折扣要小等于续充折扣';
  164. }
  165. } else if ($data['name'] == 'inner_point'){
  166. // 续充
  167. $result = $this->validate($data, [
  168. ['pk|ID', 'require', '参数错误'],
  169. ['value|续充折扣', 'number|between:0,10'],
  170. ['name', 'require', '点位参数错误'],
  171. ]);
  172. $nameZK = '续充折扣';
  173. $point_fla = true;
  174. if( $data['value'] <=0 || $data['value'] >10 || !is_numeric($data['value'])){
  175. $result = '折扣点位只能0<折扣≤10';
  176. $point_fla = false;
  177. }elseif( (float)$oldPoint['inner_first_point']>0 && $data['value'] < $oldPoint['inner_first_point'] && $point_fla){
  178. $result = '续充折扣要大等于首充折扣';
  179. }
  180. } else if ($data['name'] == 'first_max_days'){
  181. $result = true;
  182. if($data['value'] != '' ){
  183. if( $data['value'] <=0 || !is_numeric($data['value']) || floor($data['value'])!=$data['value']){
  184. $result = '首充最大天数只能是大于0的整数';
  185. }
  186. }else{
  187. $data['value'] = null;
  188. }
  189. }
  190. else {
  191. // 备注
  192. $result = $this->validate($data, [
  193. ['pk|ID', 'require', '参数错误'],
  194. ['value|备注', 'require|max:500'],
  195. ['name', 'require', '点位参数错误'],
  196. ]);
  197. }
  198. if (true !== $result) {
  199. $this->error($result);
  200. }
  201. // 开启事务
  202. Db::startTrans();
  203. $insert[ $data['name'] ] = $data['value'];
  204. $result = $gamePointModel->updateData($insert, ['game_id' => $data['pk']]);
  205. if(!isset($oldPoint['gp_id'])){
  206. $oldPoint['gp_id'] = $gamePointModel->where("game_id = '{$data['pk']}'")->field('gp_id')->find()['gp_id'];
  207. }
  208. $logArr = [
  209. "gp_id" => $oldPoint['gp_id'] ,
  210. $data['name'] => $data['value'] ,
  211. 'operate_id' => $admin_id = session('ADMIN_ID') ? : 1
  212. ];
  213. $res = true;
  214. if(($data['name'] == 'inner_point' || $data['name'] == 'inner_first_point' || $data['name'] == 'third_party_pay_point')){
  215. $res = model('GamePointLog')->add($logArr);
  216. }
  217. if ($result && $res) {
  218. // 提交事务
  219. Db::commit();
  220. $game = get_game_name($data['pk']);
  221. if ($data['name'] == 'inner_point') {
  222. $field = '续充点位';
  223. } else if ($data['name'] == 'third_party_pay_point') {
  224. $field = '其它支付返点';
  225. }else if ($data['name'] == 'inner_first_point') {
  226. $field = '首充点位';
  227. }
  228. if (isset($field)) {
  229. $message = "更新游戏:{$game} 的{$field}:{$data['value']}";
  230. $this->insertLog($this->current_node, $message, 12);
  231. }
  232. $this->success('修改成功');
  233. } else {
  234. // 回滚事务
  235. Db::rollback();
  236. $this->error('修改失败');
  237. }
  238. }
  239. public function editPointStatus()
  240. {
  241. $id = $this->request->param('gp_id', '', 'intval');
  242. $status = $this->request->param('gp_status', '', 'intval');
  243. $data['gp_status'] = $status;
  244. if (empty($id)) {
  245. $this->error('参数错误,如果未设置游戏点位数据,请先设置!');
  246. }
  247. $result = $this->validate($data, [
  248. ['gp_status', 'in:0,1', '状态参数错误'],
  249. ]);
  250. if (true !== $result) {
  251. $this->error($result);
  252. }
  253. $gamePointModel = model("GamePoint");
  254. if (!$info = $gamePointModel->where(['gp_id' => $id])->field('gp_id')->find()) {
  255. $this->error('参数错误,如果未设置游戏点位数据,请先设置');
  256. }
  257. if ($gamePointModel->update(['gp_status' => $status], ['gp_id' => $info['gp_id']])) {
  258. $this->success('修改成功');
  259. } else {
  260. $this->error('修改失败');
  261. }
  262. }
  263. public function editPointDisplay()
  264. {
  265. $id = $this->request->param('gp_id', '', 'intval');
  266. $status = $this->request->param('gp_isdisplay', '', 'intval');
  267. $data['gp_isdisplay'] = $status;
  268. if (empty($id)) {
  269. $this->error('参数错误,如果未设置游戏点位数据,请先设置!');
  270. }
  271. $result = $this->validate($data, [
  272. ['gp_isdisplay', 'in:0,1', '状态参数错误'],
  273. ]);
  274. if (true !== $result) {
  275. $this->error($result);
  276. }
  277. $gamePointModel = model("GamePoint");
  278. if (!$info = $gamePointModel->where(['gp_id' => $id])->field('gp_id')->find()) {
  279. $this->error('参数错误,如果未设置游戏点位数据,请先设置');
  280. }
  281. if ($gamePointModel->update(['gp_isdisplay' => $status], ['gp_id' => $info['gp_id']])) {
  282. $this->success('修改成功');
  283. } else {
  284. $this->error('修改失败');
  285. }
  286. }
  287. /**
  288. * 获取改游戏历史点位修改记录
  289. */
  290. public function showPointHistory(){
  291. $gp_id = $this->request->param('gp_id', '', 'intval');
  292. $list = model("GamePointLog")->alias('a')
  293. ->join('cy_admin b','b.id = a.operate_id','left')
  294. ->field("a.*, b.username")
  295. ->where(['a.gp_id'=>$gp_id, 'a.third_party_pay_point'=>['eq',0]])
  296. ->where('a.inner_first_point <> 0 or a.inner_point <> 0')
  297. ->order('a.id', 'desc')->select();
  298. $code = 1;
  299. if(!count($list)){
  300. $code = 0;
  301. }else{
  302. foreach ($list as &$v){
  303. if (empty($v['username'])){
  304. $v['username'] = '';
  305. }
  306. }
  307. }
  308. echo json_encode(['code'=>$code,'data'=>$list]);
  309. }
  310. // 批量修改等级
  311. public function editMultiLevel()
  312. {
  313. $pks = $this->request->param('pks');
  314. $level = $this->request->param('value');
  315. $result = $this->validate(['value' => $level], [
  316. ['value', 'require|in:' . implode(',', $this->gameLevel), '游戏等级不能为空|游戏等级不存在']
  317. ]);
  318. if (true !== $result) {
  319. $this->error($result);
  320. }
  321. $pksArr = explode(',', $pks);
  322. if (empty($pksArr)) {
  323. $this->error('请选择游戏');
  324. }
  325. $result = model("GamePoint")->updateData(['game_level' => $level], ['game_id' => ['IN', $pksArr]]);
  326. if ($result) {
  327. if (isset($field)) {
  328. $message = "更新游戏:批量更新游戏ID为[{$pks}]游戏等级:{$level}";
  329. $this->insertLog($this->current_node, $message, 12);
  330. }
  331. $this->success('修改成功');
  332. } else {
  333. $this->error('修改失败');
  334. }
  335. }
  336. // 游戏等级
  337. public function editLevel()
  338. {
  339. $data = [
  340. 'pk' => $this->request->param('pk'),
  341. 'value' => $this->request->param('value')
  342. ];
  343. $result = $this->validate($data, [
  344. ['pk', 'require', '参数错误'],
  345. ['value', 'require|in:' . implode(',', $this->gameLevel), '游戏等级不能为空|游戏等级不存在']
  346. ]);
  347. if (true !== $result) {
  348. $this->error($result);
  349. }
  350. $result = model("GamePoint")->updateData(['game_level' => $data['value']], ['game_id' => $data['pk']]);
  351. if ($result) {
  352. $game = get_game_name($data['pk']);
  353. if (isset($field)) {
  354. $message = "更新游戏:{$game} 的游戏等级:{$data['value']}";
  355. $this->insertLog($this->current_node, $message, 12);
  356. }
  357. $this->success('修改成功');
  358. } else {
  359. $this->error('修改失败');
  360. }
  361. }
  362. // 最低折扣
  363. public function editPercent()
  364. {
  365. $data = [
  366. 'pk' => $this->request->param('pk'),
  367. 'value' => $this->request->param('value')
  368. ];
  369. $result = $this->validate($data, [
  370. ['pk|ID', 'require', '参数错误'],
  371. ['value|折扣', 'number|between:0,10', '必须是数字|折扣在0到10之间']
  372. ]);
  373. if (true !== $result) {
  374. $this->error($result);
  375. }
  376. $result = model("GamePoint")->updateData(['min_percent' => $data['value']], ['game_id' => $data['pk']]);
  377. if ($result) {
  378. $game = get_game_name($data['pk']);
  379. if (isset($field)) {
  380. $message = "更新游戏:{$game} 的最低折扣:{$data['value']}";
  381. $this->insertLog($this->current_node, $message, 12);
  382. }
  383. $this->success('修改成功');
  384. } else {
  385. $this->error('修改失败');
  386. }
  387. }
  388. }