Getvalue.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\admin\controller\party;
  3. use app\common\controller\Backend;
  4. /**
  5. * 礼物赠送记录管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Getvalue extends Backend
  10. {
  11. /**
  12. * Getvalue模型对象
  13. * @var \app\admin\model\party\Getvalue
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\party\Getvalue;
  20. }
  21. public function import()
  22. {
  23. parent::import();
  24. }
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. /**
  31. * 查看
  32. */
  33. public function index()
  34. {
  35. //当前是否为关联查询
  36. $this->relationSearch = true;
  37. //设置过滤方法
  38. $this->request->filter(['strip_tags', 'trim']);
  39. if ($this->request->isAjax()) {
  40. //如果发送的来源是Selectpage,则转发到Selectpage
  41. if ($this->request->request('keyField')) {
  42. return $this->selectpage();
  43. }
  44. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  45. $filter = $this->request->request('filter');
  46. $wheres = json_decode($filter,true);
  47. $where = [];
  48. isset($wheres["room_type"]) && $where["party.room_type"] = $wheres["room_type"];
  49. isset($wheres["live_type"]) && $where["party.live_type"] = $wheres["live_type"];
  50. isset($wheres["party_id"]) && $where["party.party_id"] = $wheres["party_id"];
  51. // $list = $this->model->alias("getvalue")
  52. // ->field("user.u_id,party.room_type,party.party_id,party.live_type,sum(getvalue.value) as value,lt.name as live_type,getvalue.createtime")
  53. // ->join("hx_party party","party.id = getvalue.party_id","inner")
  54. // ->join("hx_user user","user.id = party.user_id","left")
  55. // ->join("hx_party_live_type lt","lt.id = party.live_type","left")
  56. // ->order($sort, $order)
  57. // ->where($where)
  58. // ->group("getvalue.party_id")
  59. // ->select();
  60. $listObj = \app\common\model\Party::alias("party")
  61. ->field("user.u_id,party.room_type,party.party_id,party.party_name,party.live_type,sum(getvalue.value) as value,lt.name as live_type,getvalue.createtime");
  62. if(isset($wheres["createtime"])) {
  63. $createtime = explode(" - ",$wheres["createtime"]);
  64. $starttime = strtotime($createtime[0]);
  65. $endtime = strtotime($createtime[1]);
  66. // $createtimearr = ["between",strtotime($createtime[0]).",".strtotime($createtime[1])];
  67. $listObj->join("hx_gift_user_party getvalue","party.id = getvalue.party_id and (getvalue.createtime between $starttime and $endtime ) ","left");
  68. } else {
  69. $listObj->join("hx_gift_user_party getvalue","party.id = getvalue.party_id","left");
  70. }
  71. $list = $listObj->join("hx_user user","user.id = party.user_id","left")
  72. ->join("hx_party_live_type lt","lt.id = party.live_type","left")
  73. ->order("value", "desc")
  74. ->where($where)
  75. ->group("party.party_id")
  76. ->select();
  77. //echo \app\common\model\Party::getLastSql();exit;
  78. $result = array("total" => 1, "rows" => $list);
  79. return json($result);
  80. }
  81. return $this->view->fetch();
  82. }
  83. // public function index()
  84. // {
  85. // //当前是否为关联查询
  86. // $this->relationSearch = true;
  87. // //设置过滤方法
  88. // $this->request->filter(['strip_tags', 'trim']);
  89. // if ($this->request->isAjax()) {
  90. // //如果发送的来源是Selectpage,则转发到Selectpage
  91. // if ($this->request->request('keyField')) {
  92. // return $this->selectpage();
  93. // }
  94. // list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  95. //
  96. // $list = $this->model
  97. // ->with(['party'])
  98. // ->where($where)
  99. // ->order($sort, $order)
  100. // ->sum("value")
  101. // ->group()
  102. // ->paginate($limit);
  103. //
  104. // foreach ($list as $k => $row) {
  105. // $row->getRelation('party')->visible(['user_id']);
  106. // //获取 房主ID
  107. // $list[$k]['u_id'] = \app\common\model\User::where(["id"=>$row->party->user_id])->value("u_id");
  108. //
  109. // }
  110. //
  111. // $result = array("total" => $list->total(), "rows" => $list->items());
  112. //
  113. // return json($result);
  114. // }
  115. // return $this->view->fetch();
  116. // }
  117. }