MemberCoin.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /**
  3. * 前台注册用户管理控制器
  4. */
  5. namespace app\admin\controller;
  6. use app\common\library\MakeReportGo;
  7. use app\common\model\Members as MembersModel;
  8. use app\common\model\MembersTwo;
  9. use think\Db;
  10. use app\common\logic\Member as MemberService;
  11. use app\common\library\MakeReport;
  12. use app\common\library\FileUpload;
  13. use think\Exception;
  14. class MemberCoin extends Admin
  15. {
  16. protected $membersModel;
  17. protected $where;
  18. protected $start_time;
  19. protected $end_time;
  20. /**
  21. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  22. */
  23. protected function _initialize()
  24. {
  25. parent::_initialize();
  26. $this->membersModel = new MembersModel;
  27. $this->gameList = $gameList = model('Common/Game')->getAllByCondition('id,name');
  28. $this->selfGameList = $selfGameList = model('Common/Game')->getAllByCondition('id,name', [],'','self');
  29. $this->where = [];
  30. }
  31. /**
  32. * 账户明细列表
  33. */
  34. public function detList()
  35. {
  36. $where = $this->_getDetListCondition();
  37. //var_dump($where);
  38. if (request()->isAjax() && input('download')) {
  39. $sql = model("MemberZscoinDet")->alias('m')
  40. ->join('cy_game g', 'm.game_id = g.id','left')
  41. ->field("m.userid,m.username,m.game_id,m.prev_amount,m.change_amount,m.after_amount,m.type,m.out_orderid,m.create_time,g.name as game_name,g.origin_name")
  42. ->where($where)
  43. ->order('m.create_time desc')
  44. ->fetchSql(true)->select();
  45. // echo $sql;
  46. if((new MakeReportGo())->addTask('admin.memberCoinDetList',$sql,session_id())){
  47. $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  48. }
  49. else{
  50. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  51. }
  52. }
  53. $list = model("MemberZscoinDet")->alias('m')
  54. ->join('cy_game g', 'm.game_id = g.id','left')
  55. ->field("m.userid,m.username,m.game_id,m.prev_amount,m.change_amount,m.after_amount,m.type,m.out_orderid,m.create_time,g.name as game_name,g.origin_name")
  56. ->where($where)
  57. ->order('m.create_time desc')
  58. ->paginate(10, false, ['query' => input('get.')]);
  59. $data = $list->toArray()['data'];
  60. $gameList = $this->selfGameList;
  61. $gList = $gameList;
  62. $gameList = array_column($gameList, 'name', 'id');
  63. $this->assign('list', $data);
  64. $this->assign('total', $list->total()); //总条数
  65. $this->assign('page', $list->render());
  66. $this->assign('start_time', $this->start_time);
  67. $this->assign('end_time', $this->end_time);
  68. $this->assign('game_list', $gameList);
  69. $this->assign('glist', $gList);
  70. return $this->fetch('det_list');
  71. }
  72. /**
  73. * 账户变动明细 条件查询
  74. * @return array
  75. */
  76. protected function _getDetListCondition()
  77. {
  78. $start_time = input('request.start_time', '', 'trim');
  79. $end_time = input('request.end_time', '', 'trim');
  80. $username = input('request.username', '', 'trim');
  81. $userid = input('request.userid', 0, 'intval');
  82. $type = input('request.type', '', 'trim');
  83. $gameid = input('request.gameid', 0, 'intval');
  84. $where = array();
  85. // 获取查询日期
  86. if (!empty($start_time) || !empty($end_time)){
  87. $where['m.create_time'] = $this->getTimeCondition($start_time,$end_time,false);
  88. }
  89. //用户ID
  90. if ($userid) {
  91. $where['m.userid'] = $userid;
  92. }
  93. //用户名
  94. if ($username != '') {
  95. $where['m.username'] = $username;
  96. }
  97. //类型
  98. if ($type != '') {
  99. $where['m.type'] = $type;
  100. }
  101. //游戏ID
  102. if ($gameid != '') {
  103. $where['m.game_id'] = $gameid;
  104. }
  105. return $where;
  106. }
  107. /**
  108. * 玩家平台币余额
  109. */
  110. public function index()
  111. {
  112. $this->indexWhere();
  113. if (request()->isAjax() && input('download')) {
  114. $sql = model("MemberZscoin")->alias('zs')
  115. ->join('cy_game g', 'zs.game_id = g.id','left')
  116. ->field('zs.*,g.name as game_name,g.origin_name')
  117. ->where($this->where)
  118. ->order('id desc')
  119. ->fetchSql(true)->select();
  120. // echo $sql;
  121. if((new MakeReportGo())->addTask('admin.memberCoinIndex',$sql,session_id())){
  122. $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  123. }
  124. else{
  125. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  126. }
  127. }
  128. $param = input('get.');
  129. $list = model("MemberZscoin")->alias('zs')
  130. ->join('cy_game g', 'zs.game_id = g.id','left')
  131. ->field('zs.*,g.name as game_name,g.origin_name')
  132. ->where($this->where)
  133. ->order('id desc')
  134. ->paginate(10, false, array('query' => $param));
  135. $gameList = $this->selfGameList;
  136. $gList = $gameList;
  137. $gameList = array_column($gameList, 'name', 'id');
  138. $data = $list->toArray()['data'];
  139. $this->assign('list', $data);
  140. $this->assign('total', $list->total()); //总条数
  141. $this->assign('start_time', $this->start_time);
  142. $this->assign('end_time', $this->end_time);
  143. $this->assign('page', $list->render());
  144. $this->assign('game_list', $gameList);
  145. $this->assign('glist', $gList);
  146. return $this->fetch();
  147. }
  148. // 用户信息汇总查询条件
  149. public function indexWhere()
  150. {
  151. $where = array();
  152. $userid = input('request.userid');
  153. $gameid = input('request.gameid');
  154. $status = input('request.status');
  155. $start_time = input('request.start_time');
  156. $end_time = input('request.end_time');
  157. $username = input('request.username');
  158. // 获取查询日期
  159. if (!empty($start_time) || !empty($end_time)){
  160. $where['zs.update_time'] =$this->getTimeCondition($start_time,$end_time,false);
  161. }
  162. //用户ID
  163. if ($userid != '') {
  164. $where['zs.userid'] = $userid;
  165. }
  166. //用户名
  167. if ($username != '') {
  168. $where['zs.username'] = $username;
  169. }
  170. //游戏ID
  171. if ($gameid != '') {
  172. $where['zs.game_id'] = $gameid;
  173. }
  174. //账户状态
  175. if ($status != '') {
  176. $where['zs.status'] = $status;
  177. }
  178. $this->where = $where;
  179. }
  180. /**
  181. * 获取日期查询条件
  182. * @param int $start_time 开始时间
  183. * @param int $end_time 结束时间
  184. * @param bool $isdefault 是否默认今天日期
  185. * @return
  186. */
  187. private function getTimeCondition($start_time,$end_time,$isdefault = true)
  188. {
  189. $this->start_time = $start_time;
  190. $this->end_time = $end_time;
  191. $time = [];
  192. //开始时间和结束时间不为空时
  193. if ($start_time != '' && $end_time != '') {
  194. $time = [
  195. ['>=', strtotime($start_time)],
  196. ['<=', strtotime($end_time . ' 23:59:59')],
  197. ];
  198. } //开始时间不为空时
  199. elseif ($start_time != '') {
  200. $time = ['>=', strtotime($start_time)];
  201. } //结束时间不为空时
  202. elseif ($end_time != '') {
  203. $time = ['<=', strtotime($end_time . ' 23:59:59')];
  204. } else {
  205. if($isdefault){
  206. $this->start_time = $this->end_time = date('Y-m-d', time());
  207. $time = [
  208. ['>=', strtotime($this->start_time)],
  209. ['<=', strtotime($this->end_time . ' 23:59:59')],
  210. ];
  211. }
  212. }
  213. return $time;
  214. }
  215. /**
  216. * 用户冻结详情
  217. */
  218. public function frozenInfo($ids)
  219. {
  220. $param = input('get.');
  221. $where['userid'] = (int)$ids;
  222. $admin_id = input('request.admin_id');
  223. $flag = input('request.flag');
  224. $start_time = input('request.start_time');
  225. $end_time = input('request.end_time');
  226. // 获取查询日期
  227. if (!empty($start_time) || !empty($end_time)){
  228. $where['create_time'] =$this->getTimeCondition($start_time,$end_time,false);
  229. }
  230. //操作人
  231. if ($admin_id != '') {
  232. $where['admin_id'] = $admin_id;
  233. }
  234. //冻结状态
  235. if ($flag != '') {
  236. $where['status'] = $flag;
  237. }
  238. $list = model('FrozenHistory')
  239. ->where($where)->order('id desc')
  240. ->paginate(10, false, array('query' => $param))->each(function($item, $key){
  241. if ( !$item['admin_id']) {
  242. $item['admin_name'] = '申诉冻结';
  243. }else{
  244. $item['admin_name'] =model('admin')->where('id',$item['admin_id'])->value('username');
  245. }
  246. return $item;
  247. });
  248. $aList = model('Common/Admin')->field('id,username as name')->where(['type'=> 1 ,'status'=> 1])->order('id')->select();
  249. $adminList = array_merge([['id'=>0,'name'=>'申诉冻结']] ,$aList);
  250. $this->assign('list', $list);
  251. $this->assign('total', $list->total()); //总条数
  252. $this->assign('start_time', $this->start_time);
  253. $this->assign('end_time', $this->end_time);
  254. $this->assign('page', $list->render());
  255. $this->assign('adminList',$adminList);
  256. return $this->fetch();
  257. }
  258. /**
  259. * 用户信息汇总冻结账户
  260. */
  261. public function informationFrozen()
  262. {
  263. $id = input('id', 0, 'intval');
  264. $flag = input('flag', 0, 'abs');
  265. if (empty($id)) {
  266. $this->error('用户ID不能为空');
  267. }
  268. if (!$info = $this->membersModel->field('id,username')->find($id)) {
  269. $this->error('非法参数');
  270. }
  271. if ($flag == 1) $msg = '冻结'; else
  272. $msg = '解冻';
  273. if ($this->membersModel->update([
  274. 'flag' => $flag,
  275. 'update_time' => time(),
  276. ], ['id' => $id])) {
  277. // 插入冻结记录
  278. $res = model('FrozenHistory')->addData($id,$flag);
  279. $info = $msg . "玩家:{$info['username']}";
  280. $this->insertLog($this->current_node, $info, 126);
  281. $this->success($msg . '账户成功');
  282. } else {
  283. $this->error($msg . '账户失败');
  284. }
  285. }
  286. }