Manage.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. */
  7. namespace app\guard\controller\home;
  8. use app\common\controller\Official;
  9. use app\guard\model\Guard;
  10. use app\guard\model\GuardHistory;
  11. use app\guard\model\GuardUser;
  12. class Manage extends Official {
  13. public function initialize() {
  14. parent::initialize();
  15. $this->view->engine->layout(false);
  16. }
  17. public function index(){
  18. $view['guard'] = Guard::where(['member_miniapp_id' => $this->member_miniapp_id, 'id' => $this->request->param('id/d')])->find();
  19. return view()->assign($view);
  20. }
  21. public function list($types = 1){
  22. $condition = [];
  23. $where = [];
  24. $name = $this->request->param('name/s');
  25. $phone = $this->request->param('phone/s');
  26. $idcard = $this->request->param('idcard/s');
  27. $start = $this->request->param('start/s');
  28. $end = $this->request->param('end/s');
  29. if($start){
  30. $condition[] = ['update_time','>=',strtotime($start)];
  31. }
  32. if($end){
  33. $condition[] = ['update_time','<=',strtotime($end)];
  34. }
  35. if($name){
  36. $where[] = ['name','=',$name];
  37. }
  38. if($phone){
  39. $where[] = ['phone','=',$phone];
  40. }
  41. if($idcard){
  42. $where[] = ['idcard','=',$idcard];
  43. }
  44. if($types){
  45. $info = GuardHistory::where(['member_miniapp_id' => $this->member_miniapp_id])->where($condition)
  46. ->whereIn('uid',GuardUser::where($where)->column('uid'))->paginate(10, false)->order('id');
  47. foreach ($info as $key => $value) {
  48. $info[$key]['account'] = $value->account;
  49. $info[$key]['update_time'] = date('Y-m-d H:i:s',$value->update_time);
  50. }
  51. return enjson(200,'成功',$info);
  52. }else{
  53. header("Content-type: text/plain");
  54. header("Accept-Ranges: bytes");
  55. header("Content-type:application/vnd.ms-excel");
  56. header("Content-Disposition:attachment;filename=cash_".date('Y-m-d').".xls");
  57. header("Pragma: no-cache");
  58. header("Expires: 0");
  59. $info = GuardHistory::where(['member_miniapp_id' => $this->member_miniapp_id])->where($condition)
  60. ->whereIn('uid',GuardUser::where($where)->column('uid'))->order('id')->select();
  61. foreach ($info as $key => $value) {
  62. $info[$key]['account'] = $value->account;
  63. $info[$key]['update_time'] = date('Y-m-d H:i:s',$value->update_time);
  64. }
  65. $view['list'] = $info;
  66. return view('excel',$view);
  67. }
  68. }
  69. }