<?php
namespace app\api\lists\group_activity;

use app\api\lists\BaseApiDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\group_activity\GroupUserOrder;

/**
 * 拼团用户订单列表
 * Class RechargeLists
 * @package app\api\lists\group_activity
 */
class UserOrderLists extends BaseApiDataLists implements ListsSearchInterface
{
    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author likeadmin
     * @date 2024/07/07 18:37
     */
    public function setSearch(): array
    {
        return [
            '=' => ['a.status'],
        ];
    }
    
    /**
     * @notes 获取列表
     * @return array
     */
    public function lists(): array
    {
        $lists = GroupUserOrder::alias('a')->leftJoin('group_order b','a.group_order_id=b.id')
            ->leftJoin('group_activity c','a.group_activity_id=c.id')
            ->field('a.id,a.sn,a.group_activity_id,a.status,a.order_amount,a.paid_amount,a.pay_status,a.refund_status,a.create_time,b.goods_id,b.num,b.origin_price,b.end_time,c.title,c.image')
            ->where([
                'a.user_id' => $this->userId,
            ])
            ->where($this->searchWhere)
            ->limit($this->limitOffset, $this->limitLength)
            ->order('a.create_time', 'desc')
            ->select()
            ->toArray();
        return $lists;
    }


    /**
     * @notes  获取数量
     * @return int
     */
    public function count(): int
    {
        return GroupUserOrder::alias('a')->where([
                'user_id' => $this->userId,
            ])
            ->where($this->searchWhere)
            ->count();
    }

}