<?php

namespace App\Services;

use App\OrderCommodityAssign;
use App\Traits\ServiceAppAop;


class OrderCommodityAssignService
{
    use ServiceAppAop;
    protected $modelClass=OrderCommodityAssign::class;

    public function paginate(array $params = null)
    {
        $query = OrderCommodityAssign::query()->with(["order","commodity.barcodes","user"])->orderByDesc("id");
        return $query->paginate($params["paginate"] ?? 50);
    }

    public function create(array $params)
    {
        return OrderCommodityAssign::query()->create($params);
    }

    public function get(array $params)
    {
        $query = OrderCommodityAssign::query()->with(["order","commodity.barcodes","user"]);
        foreach ($params as $column=>$param){
            if (is_array($param))$query->whereIn($column,$param);
            else $query->where($column,$param);
        }
        return $query->get();
    }

}
