<?php
/**
 * Created by PhpStorm.
 * User: zilongs
 * Date: 20-10-5
 * Time: 下午3:37
 */
namespace App\Models;

class DocterMessage extends BaseModel
{
    protected $table='docter_messages';
    public $timestamps = true;

    public static function saveMessage($docter_id, $user_id, $type, $relation_id = 0, $param = [], $content = '')
    {
        if (empty($content)) {
            $content = config('config.docter_message_map')[$type] ?? '';
            $content = vsprintf($content, $param);
        }
        $add = [
            'docter_id' => $docter_id,
            'status' => 1,
            'user_id' => $user_id,
            'type' => $type,
            'relation_id' => $relation_id,
            'content' => $content,
        ];
        if (in_array($type, [1,4])) {
            $product_type = Order::where('id', $relation_id)->value('product_type');
            $add['order_type'] = $product_type;
        }
        DocterMessage::create($add);

        return true;
    }
}
