| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace app\api\lists;
- use app\common\model\equity\UserEquity;
- class UserEquityLists extends BaseApiDataLists
- {
- public function queryWhere()
- {
- $where = [];
- $where[] = ['user_id','=',$this->userId];
- $where[] = ['number','>',0];
- $where[] = ['end_time','>=',time()];
- if(isset($this->params['goods_id']) && !empty($this->params['goods_id'])){
- $where[] = ['goods_id','=',$this->params['goods_id']];
- }
- return $where;
- }
- public function lists():array
- {
- $list = UserEquity::with(['equityConfig'=>function ($query) {
- $query->field(['*']);
- },'goods'=>function ($query) {
- $query->field(['id','goods_name']);
- }])->where($this->queryWhere())
- ->field(['id','user_id','equity_id','goods_id','number','end_time'])
- ->limit($this->limitOffset, $this->limitLength)
- ->order('end_time')
- ->select()
- ->toArray();
- /*foreach ($list as &$item) {
- $item['all_num'] = $item['equityConfig']['number'];
- $item['price'] = $item['equityConfig']['price'];
- $item['equity_name'] = $item['equityConfig']['equity_name'];
- $item['goods_name'] = $item['goods']['goods_name'];
- }*/
- return $list;
- }
- public function count(): int
- {
- return UserEquity::where($this->queryWhere())->count();
- }
- }
|