GeoConfirm.php
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2025/10/22
* Time: 17:03
*/
namespace App\Models\Geo;
use App\Models\Base;
use App\Models\Workchat\MessagePush;
/**
* GEO 客户确认相关数据
* Class GeoConfirm
* @package App\Models\Geo
*/
class GeoConfirm extends Base
{
/**
* @var string table
*/
protected $table = 'gl_project_geo_confirm';
/**
* 客户确认类型
*/
const TYPE_TITLE = 1;
const TYPE_KEYWORD = 2;
/**
* 数据状态
*/
const STATUS_INIT = 1; # 初始化数据,仅保存完成
const STATUS_RUNNING = 2; # 已推送客户,等待客户确认
const STATUS_FINISH = 3; # 客户已确认完成
/**
* 客户确认数据类型
* @return array
*/
public static function typeMapping()
{
return [
self::TYPE_TITLE => '确认标题',
self::TYPE_KEYWORD => '确认关键词'
];
}
/**
* 客户确认数据状态
* @return array
*/
public static function statusMapping()
{
return [
self::STATUS_INIT => '初始数据',
self::STATUS_RUNNING => '数据确认中',
self::STATUS_FINISH => '客户已确认'
];
}
/**
* 保存确认数据
* @param $project_id
* @param $type
* @param $confirm
* @param $confirm_num
* @param $confirm_ip
* @return bool
*/
public static function saveConfirm($project_id, $type, $confirm, $confirm_num, $confirm_ip)
{
$data = self::where(compact('project_id', 'type'))->first();
if (empty($data))
return false;
$data->confirm = $confirm;
$data->confirm_ip = $confirm_ip;
$data->confirm_num = $confirm_num;
$data->confirm_at = now();
$data->status = self::STATUS_FINISH;
$data->save();
return $data;
}
/**
* 推送确认消息
* @param $id
* @return bool
*/
public static function sendConfirmMessage($id, $friend_id)
{
$data = self::where(compact('id'))->first();
$project_id = $data->project_id;
$content_type = 'Link';
$send_time = now();
$type = MessagePush::TYPE_GEO_CONFIRM;
$token = uniqid().$friend_id;
$created_at = $updated_at = now();
$content_array = [
'title' => self::typeMapping()[$data->type],
'desc' => self::typeMapping()[$data->type],
'size' => 0,
'thumbSize' => 0,
'thumbUrl' => 'https://hub.globalso.com/logocm.png',
'url' => 'https://oa.quanqiusou.cn/public-geo-confirm?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'));
// 消息推送, 更新数据
$data->confirm = '';
$data->send_at = now();
$data->uniqid = $token;
$data->status = self::STATUS_RUNNING;
$data->save();
return $data;
}
}