ChannelTrade.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * 交易记录接口控制器
  4. *
  5. */
  6. namespace app\mcpsapi\controller;
  7. use app\mcpsapi\controller\Guild;
  8. use think\Db;
  9. use think\Config;
  10. use app\common\model\Setting;
  11. use think\Exception;
  12. use app\common\library\MakeReport;
  13. class ChannelTrade extends Guild {
  14. protected $nowTime;
  15. /**
  16. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  17. */
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->nowTime = NOW_TIMESTAMP;
  22. }
  23. /**
  24. * 我的交易记录列表
  25. * @return [type] [description]
  26. */
  27. public function index()
  28. {
  29. //判断当前账号是否有此功能
  30. if(!in_array($this->_channelLevel,[1,2])){
  31. $this->jsonResult('', 0, '您无权限使用该功能');
  32. }
  33. $list_rows = $this->input('list_rows',10);
  34. $page = $this->input('page',1);
  35. $type = $this->input('type','0','intval'); //1转账(收入),2转账(支出),3充值(收入),4充值(支出),5(直充),6结算充值(收入)
  36. $account = $this->input('account','','trim'); //收入账号
  37. $apply_begin_time = $this->input('apply_begin_time','','trim');
  38. $apply_end_time = $this->input('apply_end_time','','trim');
  39. $finish_begin_time = $this->input('finish_begin_time','','trim');
  40. $finish_end_time = $this->input('finish_end_time','','trim');
  41. $download = $this->input('download',0,'intval');
  42. if(!in_array($type,[1,2,3,4,5,6])){
  43. $this->jsonResult('', 0, '请选择交易类型');
  44. }
  45. $condition = [];
  46. if(in_array($type,[1,2])){
  47. $condition['t.status'] = 1;
  48. if($account){
  49. $condition['t.det_username'] = $account;
  50. }
  51. if($type==1){
  52. $condition['t.det_userid'] = $this->_channelId;
  53. if($this->_channelLevel==1){ //公会
  54. $condition['t.transfer_type'] = 0;
  55. }
  56. else{ //子会长
  57. $condition['t.transfer_type'] = 1;
  58. }
  59. }
  60. else if($type==2){
  61. $condition['t.src_channel_id'] = $this->_channelId;
  62. if($this->_channelLevel==1){
  63. $condition['t.transfer_type'] = array('in',[1,2]);
  64. }
  65. else{
  66. $condition['t.transfer_type'] = 3;
  67. }
  68. }
  69. //申请开始时间和结束时间不为空时
  70. if ($apply_begin_time != '' && $apply_end_time != '') {
  71. $condition['t.create_time'] = [
  72. ['>=', strtotime($apply_begin_time)],
  73. ['<=', strtotime($apply_end_time . ' 23:59:59')],
  74. ];
  75. } //开始时间不为空时
  76. elseif ($apply_begin_time != '') {
  77. $condition['t.create_time'] = ['>=', strtotime($apply_begin_time)];
  78. } //结束时间不为空时
  79. elseif ($apply_end_time != '') {
  80. $condition['t.create_time'] = ['<=', strtotime($apply_end_time . ' 23:59:59')];
  81. }
  82. //到账开始时间和结束时间不为空时
  83. if ($finish_begin_time != '' && $finish_end_time != '') {
  84. $condition['t.create_time'] = [
  85. ['>=', strtotime($finish_begin_time)],
  86. ['<=', strtotime($finish_end_time . ' 23:59:59')],
  87. ];
  88. } //开始时间不为空时
  89. elseif ($finish_begin_time != '') {
  90. $condition['t.create_time'] = ['>=', strtotime($finish_begin_time)];
  91. } //结束时间不为空时
  92. elseif ($finish_end_time != '') {
  93. $condition['t.create_time'] = ['<=', strtotime($finish_end_time . ' 23:59:59')];
  94. }
  95. if($download){
  96. $sql = model('CoinTransfer')->alias('t')
  97. ->join('cy_game g', 't.game_id = g.id','left')
  98. ->join('nw_channel channel', 't.cuser_id = channel.id','left')
  99. ->field("t.id,t.orderid,t.det_username,t.src_channel_name,t.amount,t.amount as real_amount,t.status,t.create_time,t.status as finish_status,t.create_time as finish_time,t.remark,g.name as game_name,t.cuser_id,channel.name as cuser_name")
  100. ->order("t.id desc")
  101. ->where($condition)
  102. ->whereRaw('src_channel_id='.$this->_channelId.' or det_userid='.$this->_channelId.' and transfer_kind=2')
  103. ->fetchSql(true)
  104. ->select();
  105. // echo $sql;
  106. if ((new MakeReport())->addTask('guild.ChannelTradeIndex', $sql, 'cps'.session('guild_info')['id'])){
  107. $this->jsonResult('', 20000, '报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  108. }
  109. else{
  110. $this->jsonResult('', 20013, '报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  111. }
  112. }
  113. $tradeList = model('CoinTransfer')->alias('t')
  114. ->join('cy_game g', 't.game_id = g.id','left')
  115. ->join('nw_channel channel', 't.cuser_id = channel.id','left')
  116. ->field("t.id,t.orderid,t.det_username,t.src_channel_name,t.amount,t.amount as real_amount,t.status,t.create_time,t.status as finish_status,t.create_time as finish_time,t.remark,g.name as game_name,t.cuser_id,channel.name as cuser_name")
  117. ->order("t.id desc")
  118. ->where($condition)
  119. ->whereRaw('src_channel_id='.$this->_channelId.' or det_userid='.$this->_channelId.' and transfer_kind=2')
  120. ->paginate(['list_rows'=>$list_rows,'page'=>$page])
  121. ->toArray();
  122. // echo model('CoinTransfer')->getLastSql()."-----lastsql------<br>";
  123. }
  124. else{
  125. $condition['status'] = 1;
  126. if($account){
  127. $condition['channel_name'] = $account;
  128. }
  129. if($type==3){
  130. $condition['channel_id'] = $this->_channelId;
  131. $condition['recharge_type'] = 1;
  132. }
  133. else if($type==4){
  134. $condition['send_channel_id'] = $this->_channelId;
  135. $condition['recharge_type'] = 1;
  136. }
  137. else if($type==5){
  138. $condition['channel_id'] = $this->_channelId;
  139. $condition['recharge_type'] = 2;
  140. }
  141. else if($type==6){
  142. $condition['channel_id'] = $this->_channelId;
  143. $condition['recharge_type'] = 3;
  144. }
  145. //申请开始时间和结束时间不为空时
  146. if ($apply_begin_time != '' && $apply_end_time != '') {
  147. $condition['create_time'] = [
  148. ['>=', strtotime($apply_begin_time)],
  149. ['<=', strtotime($apply_end_time . ' 23:59:59')],
  150. ];
  151. } //开始时间不为空时
  152. elseif ($apply_begin_time != '') {
  153. $condition['create_time'] = ['>=', strtotime($apply_begin_time)];
  154. } //结束时间不为空时
  155. elseif ($apply_end_time != '') {
  156. $condition['create_time'] = ['<=', strtotime($apply_end_time . ' 23:59:59')];
  157. }
  158. //到账开始时间和结束时间不为空时
  159. if ($finish_begin_time != '' && $finish_end_time != '') {
  160. $condition['finish_time'] = [
  161. ['>=', strtotime($finish_begin_time)],
  162. ['<=', strtotime($finish_end_time . ' 23:59:59')],
  163. ];
  164. } //开始时间不为空时
  165. elseif ($finish_begin_time != '') {
  166. $condition['finish_time'] = ['>=', strtotime($finish_begin_time)];
  167. } //结束时间不为空时
  168. elseif ($finish_end_time != '') {
  169. $condition['finish_time'] = ['<=', strtotime($finish_end_time . ' 23:59:59')];
  170. }
  171. if($download){
  172. $sql = model('ChannelRecharge')
  173. ->where($condition)
  174. ->whereRaw('channel_id='.$this->_channelId.' or send_channel_id='.$this->_channelId)
  175. ->field("id,orderid,channel_name as det_username,send_channel_name as src_channel_name,amount,real_amount,status,create_time,finish_status,finish_time,paytype,remark,'' as game_name,'' as cuser_id,'' as cuser_name")
  176. ->order("id desc")
  177. ->fetchSql(true)
  178. ->select();
  179. // echo $sql;
  180. if ((new MakeReport())->addTask('guild.ChannelTradeIndex', $sql, 'cps'.session('guild_info')['id'])){
  181. $this->jsonResult('', 20000, '报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  182. }
  183. else{
  184. $this->jsonResult('', 20013, '报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  185. }
  186. }
  187. $tradeList = model('ChannelRecharge')
  188. ->where($condition)
  189. ->whereRaw('channel_id='.$this->_channelId.' or send_channel_id='.$this->_channelId)
  190. ->field("id,orderid,channel_name as det_username,send_channel_name as src_channel_name,amount,real_amount,status,create_time,finish_status,finish_time,paytype,remark,'' as game_name,'' as cuser_id,'' as cuser_name")
  191. ->order("id desc")
  192. ->paginate(['list_rows'=>$list_rows,'page'=>$page])
  193. ->toArray();
  194. }
  195. // var_dump($condition);
  196. // echo model('ChannelRecharge')->getLastSql()."-----lastsql------<br>";
  197. $this->jsonResult($tradeList, 20000, '获取列表成功');
  198. }
  199. }