ChannelRatio.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <?php
  2. /**
  3. * 游戏管理控制器
  4. */
  5. namespace app\admin\controller;
  6. use app\common\library\FileUpload;
  7. use app\common\model\GameBand;
  8. use app\common\model\Game as GameModel;
  9. use app\common\model\SdkGameList;
  10. use app\common\model\GameInfo;
  11. use Overtrue\Pinyin\Pinyin;
  12. use app\common\model\PromotionShortLink;
  13. use think\Db;
  14. use think\Exception;
  15. class ChannelRatio extends Admin
  16. {
  17. /**
  18. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  19. */
  20. protected function _initialize()
  21. {
  22. parent::_initialize();
  23. $tmpChannelList = Db::table('nw_channel')->field('id,name')->where(['level'=>1])->select();
  24. $channeList = array();
  25. foreach ($tmpChannelList as $game) {
  26. $channeList[ $game['id']] = $game;
  27. }
  28. $this->channeList = $channeList;
  29. }
  30. public function index()
  31. {
  32. $channelId = input('channel_id');
  33. $where = ['level'=>1];
  34. if ($channelId) {
  35. $where['c.id'] = $channelId;
  36. }
  37. $list = Db::name('nw_channel_recharge_ratio')->alias('r')
  38. ->join('nw_channel c', 'r.channel_id = c.id','inner')
  39. ->field('r.id,r.channel_name,FROM_UNIXTIME(r.create_time) as create_time,FROM_UNIXTIME(r.begin_time,"%Y-%m-%d") as begin_time,FROM_UNIXTIME(r.end_time,"%Y-%m-%d") as end_time,r.ratio,r.channel_id')
  40. ->where($where)
  41. ->paginate(10, false, ['query' => $where]);
  42. $page = $list->render();
  43. $this->assign('channel_id', $channelId);
  44. $this->assign('channel_list', $this->channeList);
  45. $this->assign("page", $page);
  46. $this->assign("list", $list);
  47. return $this->fetch();
  48. }
  49. /**
  50. * 删除成功
  51. * @return [type] [description]
  52. */
  53. public function delete()
  54. {
  55. $id = $this->request->param('id', '', 'intval');
  56. $channel_id = $this->request->param('channel_id', '', 'intval');
  57. if (empty($id) || empty($channel_id)) {
  58. $this->error('参数错误!');
  59. }
  60. if (!Db::name('nw_channel_recharge_ratio')->find($id)) {
  61. $this->error('参数错误,不存在该数据');
  62. }
  63. Db::startTrans();
  64. try{
  65. //添加充值比例记录
  66. $res = Db::name('nw_channel_recharge_ratio')->where('id', '=', $id)->delete();
  67. if ( !$res) {
  68. throw new Exception("删除充值比例失败");
  69. }
  70. $logData['ratio_id'] = $id;
  71. $logData['channel_id'] = $channel_id;
  72. $logData['type'] = 3;
  73. $logData['create_time'] = NOW_TIMESTAMP;
  74. $logData['admin_type'] = 2;
  75. $logData['admin_name'] = session('USERNAME');
  76. $insertLogId = model("ChannelRechargeRatioLog")->insert($logData);
  77. if(!$insertLogId){
  78. throw new Exception("创建充值比例日志失败! ");
  79. }
  80. // 提交事务
  81. Db::commit();
  82. } catch (\Exception $e) {
  83. // 回滚事务
  84. Db::rollback();
  85. $this->error('', 0, '充值比例删除失败'.$e->getMessage());
  86. }
  87. $this->success('删除比例成功',url('index'));
  88. }
  89. /**
  90. * 添加分成比例
  91. * @param string $value [description]
  92. */
  93. public function add()
  94. {
  95. $this->assign('channel_list', $this->channeList);
  96. return $this->fetch();
  97. }
  98. /**
  99. * 增加接口
  100. * @param string $value [description]
  101. */
  102. public function addPost()
  103. {
  104. $postParam = $this->request->param();
  105. if (!empty($postParam['ratio'])) {
  106. $ratio = intval($postParam['ratio']);
  107. }
  108. if($ratio < 1 || $ratio > 100){
  109. $this->error("分成比例范围必须在1-100内");
  110. }
  111. if (!$postParam['channel_id'] || !$postParam['date']) {
  112. $this->error("参数错误!");
  113. }
  114. if (Db::name('nw_channel_recharge_ratio')->where(['channel_id'=>$postParam['channel_id']])->value('id')) {
  115. $this->error('参数错误,该公会已经设置过充值比例');
  116. }
  117. $begin_time = explode('/', $postParam['date'])[0];
  118. $end_time = explode('/', $postParam['date'])[1];
  119. $cont = array();
  120. $cont['channel_id'] = $postParam['channel_id'];
  121. $cont['channel_name'] = db::name('nw_channel')->where('id','=',$postParam['channel_id'])->value('name');
  122. $cont['ratio'] = $postParam['ratio'];
  123. $cont['admin_type'] = 1;
  124. $cont['create_time'] = NOW_TIMESTAMP;
  125. $cont['update_time'] = NOW_TIMESTAMP;
  126. $cont['begin_time'] = strtotime(date($begin_time));
  127. $cont['end_time'] = strtotime(date($end_time));
  128. $cont['admin_name'] = session('USERNAME');
  129. Db::startTrans();
  130. try{
  131. $channelInfo = model('Channel')->where(['id'=>$postParam['channel_id']])->find();
  132. if(empty($channelInfo) || $channelInfo['level']<>1){
  133. throw new Exception("存在账号异常,请核对账号名称后再进行操作");
  134. }
  135. //添加充值比例记录
  136. $insertRatioId = model('ChannelRechargeRatio')->insertGetId($cont);
  137. if ( !$insertRatioId) {
  138. throw new Exception("添加充值比例失败");
  139. }
  140. $logData['ratio_id'] = $insertRatioId;
  141. $logData['channel_id'] = $postParam['channel_id'];
  142. $logData['ratio'] = $postParam['ratio'];
  143. $logData['begin_time'] = strtotime(date($begin_time));
  144. $logData['end_time'] = strtotime(date($end_time));
  145. $logData['type'] = 1;
  146. $logData['create_time'] = NOW_TIMESTAMP;
  147. $logData['admin_type'] = 2;
  148. $logData['admin_name'] = session('USERNAME');
  149. $insertLogId = model("ChannelRechargeRatioLog")->insert($logData);
  150. if(!$insertLogId){
  151. throw new Exception("创建充值比例日志失败! ");
  152. }
  153. // 提交事务
  154. Db::commit();
  155. } catch (\Exception $e) {
  156. // 回滚事务
  157. Db::rollback();
  158. $this->error('', 0, '充值比例添加失败'.$e->getMessage());
  159. }
  160. $this->success('添加比例成功',url('index'));
  161. }
  162. /**
  163. * 编辑
  164. * @return [type] [description]
  165. */
  166. public function update()
  167. {
  168. if (request()->isPost()) {
  169. $postParam = $this->request->param();
  170. if (!empty($postParam['ratio'])) {
  171. $ratio = intval($postParam['ratio']);
  172. }
  173. if($ratio < 1 || $ratio > 100){
  174. $this->error("分成比例范围必须在1-100内");
  175. }
  176. if (!$postParam['channel_id'] || !$postParam['date'] || !$postParam['id']) {
  177. $this->error("参数错误!");
  178. }
  179. if (!Db::name('nw_channel_recharge_ratio')->where(['channel_id'=>$postParam['channel_id'],'id'=>$postParam['id']])->value('id')) {
  180. $this->error('参数错误,该公会还未设置过充值比例');
  181. }
  182. $begin_time = explode('/', $postParam['date'])[0];
  183. $end_time = explode('/', $postParam['date'])[1];
  184. $cont = array();
  185. $cont['ratio'] = $postParam['ratio'];
  186. $cont['admin_type'] = 1;
  187. $cont['update_time'] = NOW_TIMESTAMP;
  188. $cont['begin_time'] = strtotime(date($begin_time));
  189. $cont['end_time'] = strtotime(date($end_time));
  190. $cont['admin_name'] = session('USERNAME');
  191. Db::startTrans();
  192. try{
  193. $channelInfo = model('Channel')->where(['id'=>$postParam['channel_id']])->find();
  194. if(empty($channelInfo) || $channelInfo['level']<>1){
  195. throw new Exception("存在账号异常,请核对账号名称后再进行操作");
  196. }
  197. //添加充值比例记录
  198. $res = Db::name('nw_channel_recharge_ratio')->where('id',$postParam['id'])->update($cont);
  199. if (!$res) {
  200. $this->error("更新失败");
  201. }
  202. $logData['ratio_id'] = $postParam['id'];
  203. $logData['channel_id'] = $postParam['channel_id'];
  204. $logData['ratio'] = $postParam['ratio'];
  205. $logData['begin_time'] = strtotime(date($begin_time));
  206. $logData['end_time'] = strtotime(date($end_time));
  207. $logData['type'] = 2;
  208. $logData['create_time'] = NOW_TIMESTAMP;
  209. $logData['admin_type'] = 2;
  210. $logData['admin_name'] = session('USERNAME');
  211. $insertLogId = model("ChannelRechargeRatioLog")->insert($logData);
  212. if(!$insertLogId){
  213. throw new Exception("创建充值比例日志失败! ");
  214. }
  215. // // 提交事务
  216. Db::commit();
  217. } catch (\Exception $e) {
  218. // 回滚事务
  219. Db::rollback();
  220. $this->error('', 0, '充值比例添加失败'.$e->getMessage());
  221. }
  222. $this->success('修改比例成功',url('index'));
  223. }else{
  224. $id = $this->request->param('id', '', 'intval');
  225. if (empty($id)) {
  226. $this->error('参数错误!');
  227. }
  228. if (!Db::name('nw_channel_recharge_ratio')->find($id)) {
  229. $this->error('参数错误,不存在该数据');
  230. }
  231. $data = model('ChannelRechargeRatio')->where(['id'=>$id])->find();
  232. $this->assign('data', $data);
  233. return $this->fetch();
  234. }
  235. }
  236. /**
  237. * 查看记录
  238. * @return [type] [description]
  239. */
  240. public function checklog()
  241. {
  242. $postParam = $this->request->param();
  243. if (empty($postParam['id']) || empty($postParam['channelid'])) {
  244. $this->error("参数错误");
  245. }
  246. $res = model('ChannelRechargeRatioLog')->where(['channel_id'=>$postParam['channelid']])->order('id desc')->select();
  247. foreach ($res as $key => $value) {
  248. $res[$key]['begin_time'] = date('Y-m-d',$value['begin_time']);
  249. $res[$key]['end_time'] = date('Y-m-d',$value['end_time']);
  250. switch ($value['type']) {
  251. case '1':
  252. $res[$key]['type'] = '增加';
  253. break;
  254. case '2':
  255. $res[$key]['type'] = '修改';
  256. break;
  257. case '3':
  258. $res[$key]['type'] = '删除';
  259. $res[$key]['begin_time'] = '--';
  260. $res[$key]['ratio'] = '--';
  261. $res[$key]['end_time'] = '--';
  262. break;
  263. }
  264. }
  265. if ($res) {
  266. $this->success('获取数据成功',null,$res);
  267. }else{
  268. $this->error("暂无数据");
  269. }
  270. }
  271. /**
  272. * 审核列表
  273. * @return [type] [description]
  274. */
  275. public function applyCheck()
  276. {
  277. $channelId = input('channel_id');
  278. $orderid = input('orderid');
  279. $recharge_type = input('recharge_type');
  280. $status = input('status');
  281. $where = ['c.level'=>1];
  282. if ($channelId) {
  283. $where['c.id'] = $channelId;
  284. }
  285. if ($orderid) {
  286. $where['r.orderid'] = $orderid;
  287. }
  288. if ($recharge_type) {
  289. $where['r.recharge_type'] = $recharge_type;
  290. }
  291. if ($status || $status == "0") {
  292. $where['r.status'] = $status;
  293. }
  294. $list = model('ChannelRecharge')->alias('r')
  295. ->join('nw_channel c', 'r.channel_id = c.id','inner')
  296. ->field('r.*')
  297. ->order("r.id desc")
  298. ->where($where)
  299. ->paginate(10, false, ['query' => input('get.')]);
  300. if (!empty($list)) {
  301. foreach ($list as $key => $value) {
  302. $list[$key]['ratio'] = @round($value['real_amount']/$value['amount']*100,2);
  303. switch ($value['status']) {
  304. case '0':
  305. $list[$key]['status'] = '未审核';
  306. break;
  307. case '1':
  308. $list[$key]['status'] = '审核成功';
  309. break;
  310. case '2':
  311. $list[$key]['status'] = '审核失败';
  312. break;
  313. }
  314. }
  315. }
  316. $page = $list->render();
  317. $this->assign('channel_id', $channelId);
  318. $this->assign('channel_list', $this->channeList);
  319. $this->assign("page", $page);
  320. $this->assign("list", $list);
  321. return $this->fetch();
  322. }
  323. /**
  324. * 审核页面
  325. * @param string $value [description]
  326. * @return [type] [description]
  327. */
  328. public function examine()
  329. {
  330. $postParam = $this->request->param();
  331. if (empty($postParam['id'])) {
  332. $this->error("参数错误");
  333. }
  334. $list = db::name('nw_channel_recharge')
  335. ->where(['id'=>$postParam['id']])->find();
  336. if (!empty($list)) {
  337. $list['ratio'] = @round($list['real_amount']/$list['amount']*100,2);
  338. $list['create_time'] = date('Y-m-d H:i:s',$list['create_time']);
  339. switch ($list['status']) {
  340. case '0':
  341. $list['status_type'] = '未审核';
  342. break;
  343. case '1':
  344. $list['status_type'] = '审核成功';
  345. break;
  346. case '2':
  347. $list['status_type'] = '审核失败';
  348. break;
  349. }
  350. }
  351. $this->assign("list", $list);
  352. return $this->fetch();
  353. }
  354. /**
  355. * 审核
  356. * @return [type] [description]
  357. */
  358. public function doAudit()
  359. {
  360. $postParam = $this->request->param();
  361. $id = $postParam['id']; //渠道ID
  362. $status = $postParam['status']; //审核状态:1(审核通过),2(审核不通过)
  363. $remark = $postParam['check_remark']; //审核备注
  364. if(!$id){
  365. $this->error('请选择要审核的记录!');
  366. }
  367. if($status<>1 && $status<>2){
  368. $this->error('非法审核状态');
  369. }
  370. $auditData = array();
  371. $auditData['id'] = $id;
  372. $auditData['status'] = $status;
  373. $auditData['finish_time'] = NOW_TIMESTAMP;
  374. $auditData['check_remark'] = $remark;
  375. $auditData['check_admin_type'] = 1;
  376. $auditData['check_admin_name'] = SESSION('USERNAME');
  377. Db::startTrans();
  378. try {
  379. //审核通过
  380. if($status==1){
  381. $list = db::name('nw_channel_recharge')->where(['id'=>$postParam['id'],'status'=>array('in',[0])])->find();
  382. if (!$list) {
  383. throw new Exception("获取系统数据异常");
  384. }
  385. $detData = array();
  386. $detData['channel_id'] = $list['channel_id'];
  387. $detData['channel_name'] = $list['channel_name'];
  388. $detData['change_amount'] = +$list['amount'];
  389. $detData['account_type'] = 1; //通用账户
  390. $detData['type'] = 4; //充值收入
  391. $detData['out_orderid'] = $list['orderid'];
  392. $detData['create_time'] = NOW_TIMESTAMP;
  393. $insertDetId = model('ChannelAccountDet')->insertGetId($detData);
  394. if ( !$insertDetId) {
  395. throw new Exception("添加账户变动明细失败");
  396. }
  397. $updData = array();
  398. $updData['amount'] = Db::raw("amount+".$list['amount']);
  399. $updData['update_time'] = time();
  400. $updFromResult = model('Channel')->where(['id'=>$list['channel_id']])->update($updData);
  401. if (!$updFromResult) {
  402. throw new Exception("账户金额变动失败");
  403. }
  404. $auditData['finish_status'] = 1;
  405. $result = model('ChannelRecharge')->where(['id'=>$id,'status'=>array('in',[0])])->update($auditData);
  406. if (!$result) {
  407. throw new Exception("充值审核失败");
  408. }
  409. }
  410. else if($status==2){ //审核不通过
  411. $result = model('ChannelRecharge')->where(['id'=>$id,'status'=>array('in',[0])])->update($auditData);
  412. if (!$result) {
  413. throw new Exception("充值审核失败");
  414. }
  415. }
  416. Db::commit();
  417. } catch (\Exception $e) {
  418. Db::rollback();
  419. $this->error('', 0, '充值审核失败'.$e->getMessage());
  420. }
  421. $this->success('审核成功',url('applyCheck'));
  422. }
  423. }