GeoWritings.php 2.9 KB
<?php
/**
 * Created by PhpStorm.
 * User: zhl
 * Date: 2025/10/22
 * Time: 17:25
 */
namespace App\Models\Geo;

use App\Models\Base;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\Workchat\MessagePush;
use Illuminate\Support\Facades\Crypt;

/**
 * GEO 文章相关
 * Class GeoWritings
 * @package App\Models\Geo
 */
class GeoWritings extends Base
{
    /**
     * @var string $table
     */
    protected $table = 'gl_project_geo_writings';

    /**
     * 文章来源类型
     */
    const TYPE_AI_CREATE = 1;
    const TYPE_SUBMIT = 2;

    /**
     * 文章状态类型
     */
    const STATUS_INIT = 1;          # 文章仅保存完成,未推送给客户
    const STATUS_RUNNING = 2;       # 已推送客户,等待客户确认
    const STATUS_FINISH = 3;        # 客户已确认完成
    const STATUS_AI_WAIT = 7;       # 任务提交成功,等待AI生成
    const STATUS_AI_RUNNING = 8;    # AI生成中

    const IS_DEL_FALSE = 0;
    const IS_DEL_TRUE = 1;

    /**
     * @return array
     */
    public static function typeMapping()
    {
        return [
            self::TYPE_AI_CREATE => 'AI生成文章',
            self::TYPE_SUBMIT => '上传已有文章'
        ];
    }

    /**
     * 状态隐私
     * @return array
     */
    public static function statusMapping()
    {
        return [
            self::STATUS_INIT => '已就绪,待推送',
            self::STATUS_RUNNING => '已推送,待确认',
            self::STATUS_FINISH => '已确认',
            self::STATUS_AI_WAIT => '等待生成',
            self::STATUS_AI_RUNNING => '生成中',
        ];
    }

    /**
     * 推送确认消息
     * TODO 通过项目ID,时间生成推送token,页面打开后, 回传token解码确定展示项目数据
     * @param $project_id
     * @return bool
     * @throws \Exception
     */
    public static function sendConfirmMessage($project_id)
    {
        $friend = ProjectAssociation::where(['project_id' => $project_id])->first();
        if (empty($friend)) {
            return false;
        }
        $content_type = 'Link';
        $send_time = now();
        $type = MessagePush::TYPE_GEO_CONFIRM;
        $friend_id = $friend->friend_id;
        $created_at = $updated_at = now();
        $param = [
            'project_id' => $project_id,
            'send_at' => time()
        ];
        $token = Crypt::encrypt($param);
        $content_array = [
            'title' => "确认核心文章",
            'desc' => '确认核心文章',
            'size' => 0,
            'thumbSize' => 0,
            'thumbUrl' => 'https://hub.globalso.com/logocm.png',
            'url' => 'https://oa.quanqiusou.cn/public-geo-article-list?token=' . $token
        ];
        $content = json_encode($content_array, JSON_UNESCAPED_UNICODE);
        MessagePush::insert(compact('project_id', 'friend_id', 'type', 'content_type', 'content', 'send_time', 'updated_at', 'created_at'));
        return true;
    }

}