Card.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Card extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function index()
  11. {
  12. $param = input();
  13. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  14. $param['limit'] = intval($param['limit']) <1 ? $this->_pagesize : $param['limit'];
  15. $where=[];
  16. if(in_array($param['sale_status'],['0','1'],true)){
  17. $where['card_sale_status'] = ['eq',$param['sale_status']];
  18. }
  19. if(in_array($param['use_status'],['0','1'],true)){
  20. $where['card_use_status'] = ['eq',$param['use_status']];
  21. }
  22. if(!empty($param['wd'])){
  23. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  24. $where['card_no'] = ['like','%'.$param['wd'].'%'];
  25. }
  26. if(isset($param['time'])){
  27. $t=0;
  28. if($param['time']=='1'){
  29. $t = model('Card')->max('card_add_time');
  30. }
  31. else{
  32. $t = strtotime(date('Y-m-d',strtotime('-'.$param['time'] .' day')));
  33. }
  34. $where['card_add_time'] = ['egt', intval($t) ];
  35. }
  36. if($param['export'] =='1'){
  37. $param['page'] = 1;
  38. $param['limit'] = 9999;
  39. }
  40. $order='card_id desc';
  41. $res = model('Card')->listData($where,$order,$param['page'],$param['limit']);
  42. if($param['export'] =='1'){
  43. $filename = 'card_' . date('Y-m-d'). '.csv';
  44. header("Content-type:text/csv");
  45. header("Accept-Ranges:bytes");
  46. header("Content-Disposition:attachment;filename=".$filename."");
  47. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  48. header('Expires:0');
  49. header('Pragma:public');
  50. echo ''.lang('admin/card/import_tip') . "\n";
  51. foreach($res['list'] as $k=>$v){
  52. echo '="' . $v['card_no'] . '"' . ",=\"" . $v['card_pwd'] . "\"," . date('Y-m-d H:i:s',$v['card_add_time']) . "\n";
  53. }
  54. exit;
  55. }
  56. $this->assign('list',$res['list']);
  57. $this->assign('total',$res['total']);
  58. $this->assign('page',$res['page']);
  59. $this->assign('limit',$res['limit']);
  60. $param['page'] = '{page}';
  61. $param['limit'] = '{limit}';
  62. $this->assign('param',$param);
  63. $this->assign('title',lang('admin/card/title'));
  64. return $this->fetch('admin@card/index');
  65. }
  66. public function info()
  67. {
  68. if (Request()->isPost()) {
  69. $param = input('post.');
  70. if(empty($param['num']) || empty($param['money']) || empty($param['point']) ){
  71. return $this->error(lang('param_err'));
  72. }
  73. $res = model('Card')->saveAllData(intval($param['num']),intval($param['money']),intval($param['point']),$param['role_no'],$param['role_pwd']);
  74. if($res['code']>1){
  75. return $this->error($res['msg']);
  76. }
  77. return $this->success($res['msg']);
  78. }
  79. $id = input('id');
  80. $where=[];
  81. $where['card_id'] = ['eq',$id];
  82. $res = model('Card')->infoData($where);
  83. $this->assign('info',$res['info']);
  84. return $this->fetch('admin@card/info');
  85. }
  86. public function del()
  87. {
  88. $param = input();
  89. $ids = $param['ids'];
  90. $all = $param['all'];
  91. if(!empty($ids)){
  92. $where=[];
  93. $where['card_id'] = ['in',$ids];
  94. if($all==1){
  95. $where['card_id'] = ['gt',0];
  96. }
  97. $res = model('Card')->delData($where);
  98. if($res['code']>1){
  99. return $this->error($res['msg']);
  100. }
  101. return $this->success($res['msg']);
  102. }
  103. return $this->error(lang('param_err'));
  104. }
  105. }