AyrShareLogic.php
6.8 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
namespace App\Http\Logic\Bside\AyrShare;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\AyrShare\AyrShare;
use App\Models\File\File as FileModel;
use App\Models\File\Image as ImageModel;
/**
* @name:社交发布图片数量
* Facebook Pages and Groups: 10 images, including a carousel post.
* Instagram: 10 images.
* Google : 1 image.
* LinkedIn: 9 images.
* Pinterest: 1 image.
* Reddit: 1 image.
* Telegram: 1 image.
* Twitter:4 image
*/
class AyrShareLogic extends BaseLogic
{
/**
* @var :发布图片数量
*/
public $send_num = [
'facebook' => 10,
'instagram' => 10,
'google' => 1,
'linkedin'=>9,
'reddit'=>1,
'pinterest'=>1,
'telegram'=>1,
'Twitter'=>1,
];
public function __construct()
{
parent::__construct();
$this->model = new AyrShare();
$this->param = $this->requestAll;
}
/**
* @name :(创建账号并绑定写入数据库)ayr_add
* @author :lyh
* @method :post
* @time :2023/5/6 9:19
*/
public function ayr_share_save($res){
//插入数据库
$param = [
'title'=>$res['title'],
'ref_id'=>$res['refId'],
'profile_key'=>$res['profileKey'],
'operator_id'=>$this->user['id'],
'project_id'=>$this->user['project_id'],
'name'=>$this->param['name'],
];
$info = $this->model->read(['name'=>$this->param['name']]);
if($info !== false){
$rs = $this->model->edit($param,['id'=>$info['id']]);
}else{
$rs = $this->model->add($param);
}
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :(获取当前数据详情)ayr_share_del
* @author :lyh
* @method :post
* @time :2023/5/6 10:16
*/
public function ayr_share_info($share_id = ''){
if(isset($this->param['id'])){
$share_id = $this->param['id'];
}
$info = $this->model->read(['id'=>$share_id]);
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
return $this->success($info);
}
/**
* @name :(更新)ayr_share_edit
* @author :lyh
* @method :post
* @time :2023/5/9 14:44
*/
public function ayr_share_edit($param,$id = ''){
$rs = $this->model->edit($param,['id'=>$id]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :(删除ayr数据并同步删除)
* @author :lyh
* @method :post
* @time :2023/5/6 10:18
*/
public function ayr_share_del(){
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('删出失败');
}
return $this->success();
}
/**
* @name :(根据hash获取图片详情)save_info_info
* @author :lyh
* @method :post
* @time :2023/5/10 15:01
*/
public function save_img_info($hash){
$imageModel = new ImageModel();
$info = $imageModel->read(['hash'=>$hash]);
if($info === false){
$this->fail('error');
}
return $this->success($info);
}
/**
* @name :(根据hash视频详情)save_info_info
* @author :lyh
* @method :post
* @time :2023/5/10 15:01
*/
public function save_file_info($hash){
$fileModel = new FileModel();
$info = $fileModel->read(['hash'=>$hash]);
if($info === false){
$this->fail('error');
}
return $this->success($info);
}
/**
* @name :(更新图片库)save_img
* @author :lyh
* @method :post
* @time :2023/5/10 15:01
*/
public function save_img($param_data){
//根据文件hash存入数据库
$ayr_data = [
'ayr_id'=>$param_data['id'],
'ayr_url'=>$param_data['url'],
'ayr_url_link'=>$param_data['url_1080']
];
$imageModel = new ImageModel();
$rs = $imageModel->edit($ayr_data,['hash'=>$this->param['hash']]);
if($rs === false){
$this->fail('更新失败');
}
return $this->success();
}
/**
* @name :(获取图片的base64)base_img_content
* @author :lyh
* @method :post
* @time :2023/5/12 9:28
*/
public function base_img_content($hash){
$imageModel = new ImageModel();
$info = $imageModel->read(['hash'=>$hash]);
if($info === false){
$this->fail('当前数据不存在');
}
$content = file_get_contents($info['path']);
$img_type = $info['type'];
$content = base64_encode($content);
$img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
return $img_base64;
}
/**
* @name :(更新文件库)save_img
* @author :lyh
* @method :post
* @time :2023/5/10 15:01
*/
public function save_file($param_data){
//根据文件hash存入数据库
$ayr_data = [
'ayr_id'=>$param_data['id'],
'ayr_url'=>$param_data['url'],
'ayr_url_link'=>$param_data['url_1080']
];
$imageModel = new FileModel();
$rs = $imageModel->edit($ayr_data,['hash'=>$this->param['hash']]);
if($rs === false){
$this->fail('更新失败');
}
return $this->success();
}
/**
* @name :(验证平台参数)verify_param
* @author :lyh
* @method :post
* @time :2023/5/16 9:19
* ["facebook","fbg","gmb","instagram","linkedin","pinterest","reddit","telegram","tiktok","twitter","youtube"]
*/
public function verify_param($info){
//验证发送平台
foreach ($this->param['platforms'] as $k => $v){
if(!in_array($v,json_decode($info['bind_platforms']))){
$this->fail('未绑定平台');
}
if($v == 'reddit' && isset($this->param['video'])){
$this->fail('不支持视频');
}
//验证图片数
if(isset($this->param['images']) && !empty($this->param['images'])){
$img_num = count($this->param['images']);
if($img_num > $this->send_num[$v]){
$this->fail('发布图片数量超过最大限制,'.$v.'只允许'.$this->send_num[$v].'张图');
}
}
//验证图片数
// $img_num = count($this->param['video']);
// if($img_num > 1){
// $this->fail('发布视频数量超过最大限制,'.$v.'只允许'.$this->send_num[$v].'个视频');
// }
}
return $this->success();
}
}