InquiryRelayDetail.php 2.3 KB
<?php
/**
 * Created by PhpStorm.
 * User: zhl
 * Date: 2024/9/30
 * Time: 14:56
 */

namespace App\Models\Inquiry;

use App\Models\Base;

/**
 * 询盘转发详情
 * Class ReInquiryDetail
 * @package App\Models\Inquiry
 */
class InquiryRelayDetail extends Base
{
    /**
     * @var string
     */
    protected $table = 'gl_inquiry_relay_detail';

    /**
     * 任务状态, 0:待处理,1:处理中,2:待转发,3:转发成功,9:转发失败
     */
    const STATUS_INIT = 0;
    const STATUS_PEND = 1;
    const STATUS_SUCCESS = 2;
    const STATUS_SEND = 3;
    const STATUS_FAIL = 9;

    /**
     * 状态映射
     * @return array
     */
    public static function statusMap()
    {
        return [
            self::STATUS_INIT => '待处理',
            self::STATUS_PEND => '处理中',
            self::STATUS_SUCCESS => '待转发',
            self::STATUS_SEND => '转发成功',
            self::STATUS_FAIL => '转发失败',
        ];
    }

    /**
     * 创建询盘转发详情待处理任务
     * @param $form_id
     * @param $website
     * @param $country
     * @param $ip
     * @param $name
     * @param $email
     * @param $phone
     * @param $message
     * @param $is_v6
     * @param $urls
     * @param $start_at
     * @param int $status
     */
    public static function createInquiry($form_id, $website, $country, $ip, $name, $email, $phone, $message, $is_v6, $urls, $start_at, $status = self::STATUS_INIT)
    {
        $self = self::where(compact('form_id', 'website'))->first();
        if(!$self){
            $self = new self();
            $self->form_id = $form_id;
            $self->website = $website;
            $self->country = $country;
            $self->ip = $ip;
            $self->name = $name;
            $self->email = $email;
            $self->phone = $phone;
            $self->message = $message;
            $self->is_v6 = $is_v6;
            $self->urls = $urls;
            $self->start_at = $start_at;
            $self->status = $status;
            $self->save();
        }
    }

    /**
     * 转发日志详情
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function detailLog()
    {
        return $this->hasMany(InquiryRelayDetailLog::class, 'detail_id', 'id');
    }
}