<?php
namespace app\api\lists;
use app\common\model\orders\OrderEffectiveLog;

/**
 * @author 林海涛
 * @date 2024/7/24 下午3:29
 */
class OrderEffectiveLogLists  extends BaseApiDataLists
{
   public function queryWhere()
   {
       $where = [];
       $where[] = ['user_id','=',$this->userId];
       $where[] = ['end_effective_time','>=',time()];
       return $where;
   }

   public function  lists():array
   {
       return OrderEffectiveLog::with(['goods'=>function ($query) {
           $query->with(['goodsCategory'=>function ($query1) {
               $query1->field(['name','picture']);
           }]);
       }])->where($this->queryWhere())
           ->limit($this->limitOffset, $this->limitLength)
           ->field(['id','goods_id','sn','effective_unit','effective_num','remark','end_effective_time'])
           ->append(['effective_unit_text'])
           ->order('create_time desc')
           ->select()
           ->toArray();
   }

    public function count(): int
    {
        return OrderEffectiveLog::where($this->queryWhere())->count();
    }
}