ChannelRatioCoin.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. /**
  3. * 游戏管理控制器
  4. */
  5. namespace app\admin\controller;
  6. use app\common\library\FileUpload;
  7. use app\common\library\MakeReportGo;
  8. use app\common\model\GameBand;
  9. use app\common\model\Game as GameModel;
  10. use app\common\model\SdkGameList;
  11. use app\common\model\GameInfo;
  12. use Overtrue\Pinyin\Pinyin;
  13. use app\common\model\PromotionShortLink;
  14. use think\Db;
  15. use think\Exception;
  16. class ChannelRatioCoin extends Admin
  17. {
  18. /**
  19. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  20. */
  21. protected function _initialize()
  22. {
  23. parent::_initialize();
  24. $tmpChannelList = Db::table('nw_channel')->field('id,name')->where(['level'=>1])->select();
  25. $channeList = array();
  26. foreach ($tmpChannelList as $game) {
  27. $channeList[ $game['id']] = $game;
  28. }
  29. $this->channeList = $channeList;
  30. }
  31. /**
  32. * 审核列表
  33. * @return [type] [description]
  34. */
  35. public function applyCheck()
  36. {
  37. $start = $this->request->param('start');
  38. $end = $this->request->param('end');
  39. $channelId = input('channel_id');
  40. $orderid = input('orderid');
  41. $recharge_type = input('recharge_type');
  42. $status = input('status');
  43. $where = ['c.level'=>1];
  44. if ($channelId) {
  45. $where['c.id'] = $channelId;
  46. }
  47. if ($orderid) {
  48. $where['r.orderid'] = $orderid;
  49. }
  50. if ($recharge_type) {
  51. $where['r.recharge_type'] = $recharge_type;
  52. }
  53. if ($status || $status == "0") {
  54. $where['r.status'] = $status;
  55. }
  56. //开始时间和结束时间不为空时
  57. if ($start != '' && $end != '') {
  58. $where['r.create_time'] = [
  59. ['>=', strtotime($start)],
  60. ['<=', strtotime($end . ' 23:59:59')],
  61. ];
  62. } //开始时间不为空时
  63. elseif ($start != '') {
  64. $where['r.create_time'] = ['>=', strtotime($start)];
  65. } //结束时间不为空时
  66. elseif ($end != '') {
  67. $where['r.create_time'] = ['<=', strtotime($end . ' 23:59:59')];
  68. }
  69. if (request()->isAjax()) {
  70. $sql = model('ChannelRechargeCoin')->alias('r')
  71. ->join('nw_channel c', 'r.channel_id = c.id','inner')
  72. ->field('r.*')
  73. ->order("r.id desc")
  74. ->where($where)->fetchSql(true)->select();
  75. $makeReportGo = new MakeReportGo();
  76. if ($makeReportGo->addTask('channelRatioCoin', $sql, session_id(), [])) {
  77. $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  78. } else {
  79. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  80. }
  81. }
  82. $list = model('ChannelRechargeCoin')->alias('r')
  83. ->join('nw_channel c', 'r.channel_id = c.id','inner')
  84. ->field('r.*')
  85. ->order("r.id desc")
  86. ->where($where)
  87. ->paginate(10, false, ['query' => input('get.')]);
  88. if (!empty($list)) {
  89. foreach ($list as $key => $value) {
  90. $list[$key]['ratio'] = @round($value['real_amount']/$value['amount']*100,2);
  91. switch ($value['status']) {
  92. case '0':
  93. if($value['recharge_type'] == 1){
  94. $list[$key]['status'] = '审核中';
  95. }else{
  96. $list[$key]['status'] = '待支付';
  97. }
  98. break;
  99. case '1':
  100. if($value['recharge_type'] == 1){
  101. $list[$key]['status'] = '审核通过';
  102. }else {
  103. $list[$key]['status'] = '充值成功';
  104. }
  105. break;
  106. case '2':
  107. if($value['recharge_type'] == 1){
  108. $list[$key]['status'] = '审核不通过';
  109. }else {
  110. $list[$key]['status'] = '充值失败';
  111. }
  112. break;
  113. }
  114. }
  115. }
  116. $page = $list->render();
  117. $this->assign('channel_id', $channelId);
  118. $this->assign('channel_list', $this->channeList);
  119. $this->assign("page", $page);
  120. $this->assign("list", $list);
  121. $this->assign("start", $start);
  122. $this->assign("end", $end);
  123. return $this->fetch();
  124. }
  125. /**
  126. * 审核页面
  127. * @param string $value [description]
  128. * @return [type] [description]
  129. */
  130. public function examine()
  131. {
  132. $postParam = $this->request->param();
  133. if (empty($postParam['id'])) {
  134. $this->error("参数错误");
  135. }
  136. $list = db::name('nw_channel_recharge_coin')
  137. ->where(['id'=>$postParam['id']])->find();
  138. if (!empty($list)) {
  139. $list['ratio'] = @round($list['real_amount']/$list['amount']*100,2);
  140. $list['create_time'] = date('Y-m-d H:i:s',$list['create_time']);
  141. switch ($list['status']) {
  142. case '0':
  143. $list['status_type'] = '未审核';
  144. break;
  145. case '1':
  146. $list['status_type'] = '审核成功';
  147. break;
  148. case '2':
  149. $list['status_type'] = '审核失败';
  150. break;
  151. }
  152. }
  153. $this->assign("list", $list);
  154. return $this->fetch();
  155. }
  156. /**
  157. * 审核
  158. * @return [type] [description]
  159. */
  160. public function doAudit()
  161. {
  162. $postParam = $this->request->param();
  163. $id = $postParam['id']; //渠道ID
  164. $status = $postParam['status']; //审核状态:1(审核通过),2(审核不通过)
  165. $remark = $postParam['check_remark']; //审核备注
  166. if(!$id){
  167. $this->error('请选择要审核的记录!');
  168. }
  169. if($status<>1 && $status<>2){
  170. $this->error('非法审核状态');
  171. }
  172. $auditData = array();
  173. $auditData['id'] = $id;
  174. $auditData['status'] = $status;
  175. $auditData['finish_time'] = NOW_TIMESTAMP;
  176. $auditData['check_remark'] = $remark;
  177. $auditData['check_admin_type'] = 1;
  178. $auditData['check_admin_name'] = SESSION('USERNAME');
  179. Db::startTrans();
  180. try {
  181. //审核通过
  182. if($status==1){
  183. $list = db::name('nw_channel_recharge_coin')->where(['id'=>$postParam['id'],'status'=>array('in',[0])])->find();
  184. if (!$list) {
  185. throw new Exception("获取系统数据异常");
  186. }
  187. $detData = array();
  188. $detData['channel_id'] = $list['channel_id'];
  189. $detData['channel_name'] = $list['channel_name'];
  190. $detData['change_amount'] = +$list['amount'];
  191. $detData['account_type'] = 3; //通用账户
  192. $detData['type'] = 4; //充值收入
  193. $detData['out_orderid'] = $list['orderid'];
  194. $detData['create_time'] = NOW_TIMESTAMP;
  195. $insertDetId = model('ChannelAccountDet')->insertGetId($detData);
  196. if ( !$insertDetId) {
  197. throw new Exception("添加账户变动明细失败");
  198. }
  199. $updData = array();
  200. $updData['amount_coin'] = Db::raw("amount_coin+".$list['amount']);
  201. $updData['update_time'] = time();
  202. $updFromResult = model('Channel')->where(['id'=>$list['channel_id']])->update($updData);
  203. if (!$updFromResult) {
  204. throw new Exception("账户金额变动失败");
  205. }
  206. $auditData['finish_status'] = 1;
  207. $result = model('ChannelRechargeCoin')->where(['id'=>$id,'status'=>array('in',[0])])->update($auditData);
  208. if (!$result) {
  209. throw new Exception("充值审核失败");
  210. }
  211. }
  212. else if($status==2){ //审核不通过
  213. $result = model('ChannelRechargeCoin')->where(['id'=>$id,'status'=>array('in',[0])])->update($auditData);
  214. if (!$result) {
  215. throw new Exception("充值审核失败");
  216. }
  217. }
  218. Db::commit();
  219. } catch (\Exception $e) {
  220. Db::rollback();
  221. $this->error('', 0, '充值审核失败'.$e->getMessage());
  222. }
  223. $this->success('审核成功',url('applyCheck'));
  224. }
  225. }