<?php

namespace app\admin\service\order;

use app\model\OrderProcess;
use support\Log;

class OrderProcessService
{
    public static function insert($params)
    {
        try {
            OrderProcess::insert([
                'join_order_process_member_id' => $params['member_id'],
                'join_order_process_user_id' => $params['user_id'] ?? '',
                'join_order_process_dept_id' => $params['dept_id'] ?? 0,
                'join_process_order_id' => $params['order_id'],
                'order_process_key' => $params['process_key'],
                'order_process_name' => $params['process_name'],
                'order_process_json' => !empty($params['process_json']) ? json_encode($params['process_json']) : '[]',
                'order_process_datetimes' => date('Y-m-d H:i:s'),
                'order_process_remark' => $params['process_remark'] ?? '',
                'order_process_extend_json' => !empty($params['process_extend_json']) ? json_encode($params['process_extend_json']) : '[]',
                'order_process_addtimes' => time()
            ]);
        } catch (\Exception $e) {
            dump($e->getMessage());
            $params['msg'] = $e->getMessage();
            Log::error("WRITE_ORDER_PROCESS_ERROR", $params);
        }
    }
}