ChannelAccount.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. /**
  3. * 前台注册用户管理控制器
  4. */
  5. namespace app\admin\controller;
  6. use app\common\library\MakeReportGo;
  7. use think\Db;
  8. use app\common\logic\Member as MemberService;
  9. //use app\common\library\MakeReport;
  10. use app\common\library\FileUpload;
  11. use think\Exception;
  12. class ChannelAccount extends Admin
  13. {
  14. protected $where;
  15. protected $start_time;
  16. protected $end_time;
  17. /**
  18. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  19. */
  20. protected function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->where = [];
  24. }
  25. /**
  26. * 公会账户余额
  27. */
  28. public function index()
  29. {
  30. $this->indexWhere();
  31. if (request()->isAjax() && input('download')) {
  32. $sql = model("Channel")->field('id,name,level,status,amount_coin,amount,js_amount,cps_settle_period,mcps_settle_period')
  33. ->where($this->where)
  34. ->order('id desc')
  35. ->fetchSql(true)->select();
  36. // echo $sql;
  37. if((new MakeReportGo())->addTask('admin.channelAccountIndex',$sql,session_id())){
  38. $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  39. }
  40. else{
  41. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  42. }
  43. }
  44. $param = input('get.');
  45. $list = model("Channel")->field('id,name,level,status,amount,amount_coin,js_amount,cps_settle_period,mcps_settle_period')
  46. ->where($this->where)
  47. ->order('id desc')
  48. ->paginate(10, false, array('query' => $param));
  49. $data = $list->toArray()['data'];
  50. $this->assign('list', $data);
  51. $this->assign('total', $list->total()); //总条数
  52. $this->assign('start_time', $this->start_time);
  53. $this->assign('end_time', $this->end_time);
  54. $this->assign('page', $list->render());
  55. $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
  56. $channelWhere = [];
  57. if( $business != -1){
  58. if($business && $business != -2){
  59. $channelWhere['id'] = ['in',$business];
  60. }else{
  61. $channelWhere['id'] = -1;
  62. }
  63. }
  64. $uniom = model('Channel')->where(['level'=>0])->where($channelWhere)->field('id,name')->select();
  65. $this->assign('uniom', $uniom); //顶级渠道列表
  66. return $this->fetch();
  67. }
  68. // 用户信息汇总查询条件
  69. public function indexWhere()
  70. {
  71. $where = array();
  72. $userid = input('request.userid',0,'intval');
  73. $username = input('request.username');
  74. $status = input('request.status');
  75. $bplus_channel_id = input('request.bplus_channel_id',0,'intval');
  76. $where['level'] = 1;
  77. //用户ID
  78. if ($userid) {
  79. $where['id'] = $userid;
  80. }
  81. //用户名
  82. if ($username != '') {
  83. $where['name'] = $username;
  84. }
  85. $business = model('common/Business')->getChannelIds(session('ADMIN_ID'));
  86. if( $business != -1){
  87. if($bplus_channel_id){
  88. if(!in_array($bplus_channel_id,$business)){
  89. $where['parent_id'] = -1;
  90. }
  91. }else{
  92. if($business && $business != -2){
  93. $where['parent_id'] = implode(',',$business);
  94. }else{
  95. $where['parent_id'] = -1;
  96. }
  97. }
  98. }else{
  99. //商务账号
  100. if ($bplus_channel_id) {
  101. $where['parent_id'] = $bplus_channel_id;
  102. }
  103. }
  104. //账户状态
  105. if ($status != '') {
  106. $where['status'] = $status;
  107. }
  108. $this->where = $where;
  109. }
  110. /**
  111. * 渠道账户明细列表
  112. */
  113. public function detList()
  114. {
  115. $where = $this->_getDetListCondition();
  116. //var_dump($where);
  117. if (request()->isAjax() && input('download')) {
  118. $sql = model("ChannelAccountDet")->alias('d')
  119. ->join('nw_channel channel', 'd.channel_id = channel.id','left')
  120. ->field("d.id,d.channel_id,d.channel_name,d.change_amount,d.change_amount,d.account_type,d.type,d.out_orderid,d.create_time,channel.level,channel.status,channel.amount,channel.js_amount")
  121. ->where($where)
  122. ->order('d.create_time desc')
  123. ->fetchSql(true)->select();
  124. // echo $sql;
  125. if((new MakeReportGo())->addTask('admin.channelAccountDetList',$sql,session_id())){
  126. $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  127. }
  128. else{
  129. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  130. }
  131. }
  132. $list = model("ChannelAccountDet")->alias('d')
  133. ->join('nw_channel channel', 'd.channel_id = channel.id','left')
  134. ->field("d.id,d.channel_id,d.channel_name,d.change_amount,d.change_amount,d.account_type,d.type,d.out_orderid,d.create_time,channel.level,channel.status,channel.amount,channel.js_amount")
  135. ->where($where)
  136. ->order('d.create_time desc')
  137. ->paginate(10, false, ['query' => input('get.')]);
  138. $data = $list->toArray()['data'];
  139. $this->assign('list', $data);
  140. $showTotal = $incomeAmt = $payoutAmt = 0;
  141. if((isset($where['d.channel_id'])&&$where['d.channel_id'] || isset($where['d.channel_name'])&&$where['d.channel_name']) && (isset($where['d.account_type'])&&$where['d.account_type'])){
  142. $showTotal = 1;
  143. $incomeAmt = model("ChannelAccountDet")->alias('d')->where($where)->where(['change_amount'=>['egt',0]])->sum('change_amount');
  144. $payoutAmt = model("ChannelAccountDet")->alias('d')->where($where)->where(['change_amount'=>['lt',0]])->sum('change_amount');
  145. }
  146. $this->assign('showTotal',$showTotal);
  147. $this->assign('incomeAmt',$incomeAmt);
  148. $this->assign('payoutAmt',$payoutAmt);
  149. $this->assign('total', $list->total()); //总条数
  150. $this->assign('page', $list->render());
  151. $this->assign('start_time', $this->start_time);
  152. $this->assign('end_time', $this->end_time);
  153. return $this->fetch('det_list');
  154. }
  155. /**
  156. * 账户变动明细 条件查询
  157. * @return array
  158. */
  159. protected function _getDetListCondition()
  160. {
  161. $start_time = input('request.start_time', '', 'trim');
  162. $end_time = input('request.end_time', '', 'trim');
  163. $channel_name = input('request.channel_name', '', 'trim');
  164. $channel_id = input('request.channel_id', 0, 'intval');
  165. $type = input('request.type', '', 'trim');
  166. $account_type = input('request.account_type', '', 'trim');
  167. $out_orderid = input('request.out_orderid', '', 'trim');
  168. $where = array();
  169. // 获取查询日期
  170. if (!empty($start_time) || !empty($end_time)){
  171. $where['d.create_time'] = $this->getTimeCondition($start_time,$end_time,false);
  172. }
  173. //渠道ID
  174. if ($channel_id) {
  175. $where['d.channel_id'] = $channel_id;
  176. }
  177. //渠道名称
  178. if ($channel_name != '') {
  179. $where['d.channel_name'] = $channel_name;
  180. }
  181. //账户类型
  182. if ($account_type != '') {
  183. $where['d.account_type'] = $account_type;
  184. }
  185. //类型
  186. if ($type != '') {
  187. $where['d.type'] = $type;
  188. }
  189. //游戏ID
  190. if ($out_orderid != '') {
  191. $where['d.out_orderid'] = $out_orderid;
  192. }
  193. return $where;
  194. }
  195. /**
  196. * 获取日期查询条件
  197. * @param int $start_time 开始时间
  198. * @param int $end_time 结束时间
  199. * @param bool $isdefault 是否默认今天日期
  200. * @return
  201. */
  202. private function getTimeCondition($start_time,$end_time,$isdefault = true)
  203. {
  204. $this->start_time = $start_time;
  205. $this->end_time = $end_time;
  206. $time = [];
  207. //开始时间和结束时间不为空时
  208. if ($start_time != '' && $end_time != '') {
  209. $time = [
  210. ['>=', strtotime($start_time)],
  211. ['<=', strtotime($end_time . ' 23:59:59')],
  212. ];
  213. } //开始时间不为空时
  214. elseif ($start_time != '') {
  215. $time = ['>=', strtotime($start_time)];
  216. } //结束时间不为空时
  217. elseif ($end_time != '') {
  218. $time = ['<=', strtotime($end_time . ' 23:59:59')];
  219. } else {
  220. if($isdefault){
  221. $this->start_time = $this->end_time = date('Y-m-d', time());
  222. $time = [
  223. ['>=', strtotime($this->start_time)],
  224. ['<=', strtotime($this->end_time . ' 23:59:59')],
  225. ];
  226. }
  227. }
  228. return $time;
  229. }
  230. }