<?php

namespace App\Http\Services;

use App\Http\Controllers\Filter\LogFilter;
use App\Http\Transformers\LogTransformer;
use App\Http\Transformers\SkuUploadLogTransformer;
use App\Http\Transformers\SupplierTransformer;
use App\Model\LogModel;
use App\Model\SkuUploadLogModel;
use App\Model\SupplierChannelModel;

class SkuUploadLogService
{
    public function getSkuUploadLogList($params)
    {
        $limit = array_get($params, 'limit', 10);
        $query = SkuUploadLogModel::withCount('upload_items')->orderBy('id', 'desc');
        if (!empty($params['supplier_id'])) {
            $supplierCode = SupplierChannelModel::where('supplier_id', $params['supplier_id'])->value('supplier_code');
            $query->where('supplier_code', $supplierCode);
        }

        $list = $query->paginate($limit)->toArray();
        $list['data'] = (new SkuUploadLogTransformer())->transformList($list['data']);
        return $list;
    }

    //获取上传次数
    public function getSkuUploadLogCount($supplierId)
    {
        $supplierCode = SupplierChannelModel::where('supplier_id', $supplierId)->value('supplier_code');
        return SkuUploadLogModel::where('supplier_code', $supplierCode)->count();
    }
}