<?php

namespace app\admin\model;

use support\Db;
use support\Model;

/**
 * 悦活健康美食订单详情
 * Class Users
 * @package app\admin\model
 */
class LifeFoodOrderDetail extends Model
{
    /**
     *
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'life_healthy_order_detail';

    public $timestamps = false;

    /**
     * Notes:获取产品列表
     * @param string $keywords
     * @param int $page
     * @param int $limit
     * @return array
     * User: ZQ
     * Date: 2022/10/13
     */
    public static function getOrderList(int $page, int $limit,$keywords)
    {
        $list = static::select('*')
            ->with(['user'])
            ->when($keywords != '', function ($query) use ($keywords){
                $query->where('order_sn', 'like', '%' . $keywords . '%');
            })
            ->orderBy('order_create_time','DESC')
            ->forPage($page, $limit)
            ->get();

        $count = static::when($keywords != '', function ($query) use ($keywords){
            $query->where('order_sn', 'like', '%' . $keywords . '%');
        })->count();
        return [$list, $count];
    }

    //关联店铺
    public function Shop(){
        return $this->belongsTo(MerchantShop::class,'order_shop_id','shop_id');
    }
    //获取器修改产品标签
   public function User(){
        return $this->belongsTo(User::class,'order_user_id','user_id');
   }
}