<?php




namespace app\common\repositories\store\coupon;


use app\common\dao\store\coupon\StoreCouponProductDao;
use app\common\repositories\BaseRepository;

/**
 * Class StoreCouponProductRepository
 * @package app\common\repositories\store\coupon
 * @author xaboy
 * @day 2020/6/1
 * @mixin StoreCouponProductDao
 */
class StoreCouponProductRepository extends BaseRepository
{

    /**
     * StoreCouponProductRepository constructor.
     * @param StoreCouponProductDao $dao
     */
    public function __construct(StoreCouponProductDao $dao)
    {
        $this->dao = $dao;
    }

    public function productList($coupon_id, $page, $limit)
    {
        $query = $this->dao->search(compact('coupon_id'));
        $query->with(['product' => function ($query) {
            $query->field('product_id,store_name,image,price,stock,sales');
        }]);
        $count = $query->count();
        $list = $query->page($page, $limit)->select();
        return compact('count', 'list');
    }
}