<?php

namespace App\Services;

use App\OrderIssue;
use App\OrderIssueProcessLog;
use Illuminate\Support\Facades\Auth;
use App\Traits\ServiceAppAop;


class OrderIssueProcessLogService
{
    use ServiceAppAop;
    protected $modelClass=OrderIssueProcessLog::class;

    public function batchStoreAndReturnLogs($params)
    {
        $ids = $params['orderIssueIds'];
        $content = $params['content'];
        $user_id = Auth::user()['id'];
        $logs = [];
        foreach ($ids as $id) {
            $logs[] = OrderIssueProcessLog::query()
                ->create(['order_issue_id' => $id, 'content' => $content, 'user_id' => $user_id, 'type' => '处理']);
        }
        return $logs;
    }

    public function create(array  $params)
    {
        $ids = $params['ids'];
        $content = $params['content'];
        $user_id = Auth::user()['id'];
        $logs = [];
        foreach ($ids as $id) {
            $logs[] = OrderIssueProcessLog::query()->create(['order_issue_id' => $id, 'content' => $content, 'user_id' => $user_id, 'type' => $params['type']]);
        }
        return OrderIssueProcessLog::query()->with('user')->whereIn('id',data_get($logs,'*.id'))->get();
    }


}
