1
0

UserEquityLists.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\api\lists;
  3. use app\common\model\equity\UserEquity;
  4. class UserEquityLists extends BaseApiDataLists
  5. {
  6. public function queryWhere()
  7. {
  8. $where = [];
  9. $where[] = ['user_id','=',$this->userId];
  10. $where[] = ['number','>',0];
  11. $where[] = ['end_time','>=',time()];
  12. if(isset($this->params['goods_id']) && !empty($this->params['goods_id'])){
  13. $where[] = ['goods_id','=',$this->params['goods_id']];
  14. }
  15. return $where;
  16. }
  17. public function lists():array
  18. {
  19. $list = UserEquity::with(['equityConfig'=>function ($query) {
  20. $query->field(['*']);
  21. },'goods'=>function ($query) {
  22. $query->field(['id','goods_name']);
  23. }])->where($this->queryWhere())
  24. ->field(['id','user_id','equity_id','goods_id','number','end_time'])
  25. ->limit($this->limitOffset, $this->limitLength)
  26. ->order('end_time')
  27. ->select()
  28. ->toArray();
  29. /*foreach ($list as &$item) {
  30. $item['all_num'] = $item['equityConfig']['number'];
  31. $item['price'] = $item['equityConfig']['price'];
  32. $item['equity_name'] = $item['equityConfig']['equity_name'];
  33. $item['goods_name'] = $item['goods']['goods_name'];
  34. }*/
  35. return $list;
  36. }
  37. public function count(): int
  38. {
  39. return UserEquity::where($this->queryWhere())->count();
  40. }
  41. }