UserEquityLists.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_image','goods_name','goods_banners','good_unit','sell_num','base_service_fee',
  23. 'service_total','service_fee','service_image','fee_schedule','warranty_period','goods_payment_type','goods_category_id']);
  24. }])->where($this->queryWhere())
  25. ->field(['id','user_id','equity_id','goods_id','number','end_time'])
  26. ->limit($this->limitOffset, $this->limitLength)
  27. ->order('end_time')
  28. ->select()
  29. ->each(function ($item) {
  30. $item->end_time = date('Y-m-d H:i:s',$item['end_time']);
  31. })
  32. ->toArray();
  33. /*foreach ($list as &$item) {
  34. $item['all_num'] = $item['equityConfig']['number'];
  35. $item['price'] = $item['equityConfig']['price'];
  36. $item['equity_name'] = $item['equityConfig']['equity_name'];
  37. $item['goods_name'] = $item['goods']['goods_name'];
  38. }*/
  39. return $list;
  40. }
  41. public function count(): int
  42. {
  43. return UserEquity::where($this->queryWhere())->count();
  44. }
  45. }