ProductLogic.php
21.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
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<?php
namespace App\Http\Logic\Bside\Product;
use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplate;
use App\Services\CosService;
use Illuminate\Support\Facades\DB;
/**
* Class ProductLogic
* @package App\Http\Logic\Bside\APublicModel
* @author zbj
* @date 2023/4/14
*/
class ProductLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new Product();
}
/**
* @remark :保存产品
* @name :productSave
* @author :lyh
* @method :post
* @time :2023/8/21 18:35
*/
public function productSave(){
//参数处理
$this->param = $this->handleSaveParam($this->param);
DB::beginTransaction();
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
//查看路由是否更新
$id = $this->editProductRoute($this->param['id'],$this->param['route']);
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$this->param['project_id'] = $this->user['project_id'];
$this->param['created_at'] = date('Y-m-d H:i:s');
$this->param['updated_at'] = $this->param['created_at'];
$id = $this->model->addReturnId($this->param);
}
//路由映射
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
$this->model->edit(['route'=>$route],['id'=>$id]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('系统错误请联系管理员');
}
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT, 'route'=>$route]);
return $this->success();
}
/**
* @remark :不使用save处理参数
* @name :handleSaveParam
* @author :lyh
* @method :post
* @time :2023/8/21 17:03
*/
public function handleSaveParam(&$param){
//产品图
if(isset($param['gallery']) && !empty($param['gallery'])){
foreach ($param['gallery'] as $k => $v){
$v['url'] = str_replace_url($v['url']);
$param['gallery'][$k] = $v;
}
$param['thumb'] = Arr::a2s($param['gallery'][0] ?? '');
$param['gallery'] = Arr::a2s($param['gallery'] ?? '');
}
$param['attrs'] = Arr::a2s($param['attrs'] ?? '');
$param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
if(isset($param['category_id']) && !empty($param['category_id'])){
$param['category_id'] = ','.Arr::arrToSet($param['category_id']).',';
}
if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
$param['keyword_id'] = ','.Arr::arrToSet($param['keyword_id']).',';
}
$param['describe'] = Arr::a2s($param['describe'] ?? '');
$param['describe_id'] = Arr::arrToSet($param['describe_id'] ?? '');
$param['seo_mate'] = Arr::a2s($param['seo_mate'] ?? '');
$param['related_product_id'] = Arr::arrToSet($param['related_product_id'] ?? '');
if(isset($param['icon']) && !empty($param['icon'])){
foreach ($param['icon'] as $k1 => $v1){
$param['icon'][$k1] = str_replace_url($v1);
}
$param['icon'] = Arr::a2s($param['icon'] ?? '');
}
$param['created_uid'] = $this->user['id'];
return $param;
}
/**
* @remark :编辑产品
* @name :editProduct
* @author :lyh
* @method :post
* @time :2023/9/7 10:02
*/
public function editProductRoute($id,$route){
$info = $this->model->read(['id'=>$this->param['id']]);
if($info['route'] != $route){
//生成一条删除路由记录
$data = [
'source'=>RouteMap::SOURCE_PRODUCT,
'route'=>$route,
];
$this->setRouteDeleteSave($data);
}
return $id;
}
/**
* @remark :删除数据
* @name :delete
* @author :lyh
* @method :post
* @time :2023/8/21 17:11
*/
public function productDelete(){
DB::beginTransaction();
try {
foreach ($this->param['ids'] as $k => $id) {
$info = $this->model->read(['id'=>$id],['id','status']);
if($info['status'] == Product::STATUS_RECYCLE){
$this->delRoute($id);
//删除当前产品模版
$this->delProductModule($id);
$this->model->del(['id'=>$id]);
}else{
//回收站
$this->model->edit(['status'=>Product::STATUS_RECYCLE],['id'=>$id]);
}
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('删除失败');
}
return $this->success();
}
/**
* @remark :删除路由
* @name :delRoute
* @author :lyh
* @method :post
* @time :2023/9/7 10:50
*/
public function delRoute($id){
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
//生成一条删除路由记录
$info = $this->model->read(['id'=>$id],['id','route']);
$data = [
'source'=>RouteMap::SOURCE_PRODUCT,
'route'=>$info['route'],
];
$this->setRouteDeleteSave($data);
return $this->success();
}
/**
* @remark :统计数据
* @name :getStatusNumber
* @author :lyh
* @method :post
* @time :2023/8/9 10:17
*/
public function getStatusNumber(){
//三种状态 0:草稿 1:发布 2:回收站
$data = ['dra'=>0,'pub'=>1,'del'=>2,'tal'=>3];
foreach ($data as $k => $v){
if($v == 3){
$data[$k] = $this->model->where(['project_id'=>$this->user['project_id']])->count();
}else{
$data[$k] = $this->model->where(['status'=>$v,'project_id'=>$this->user['project_id']])->count();
}
}
return $this->success($data);
}
/**
* @remark :复制产品
* @name :setCopyProduct
* @author :lyh
* @method :post
* @time :2023/7/29 15:03
*/
public function setCopyProduct(){
$info = $this->model->read(['id'=>$this->param['id']]);
$param = $this->setProductParams($info);
$save_id = $this->model->insertGetId($param);
$route = RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $save_id, $this->user['project_id']);
$this->model->edit(['route'=>$route],['id'=>$save_id]);
//同步可视化装修数据
$this->copyTemplate($this->param['id'],$info['project_id'],$save_id);
return $this->success();
}
/**
* @remark :同步模版数据
* @name :copyTemplate
* @author :lyh
* @method :post
* @time :2023/7/29 15:53
*/
public function copyTemplate($id,$project_id,$save_id){
$BTemplateModel = new BTemplate();
$list = $BTemplateModel->list(['source'=>2,'source_id'=>$id,'project_id'=>$project_id]);
if(!empty($list)){
$data = [];
foreach ($list as $k => $v){
$data[] = $this->setTemplateParams($v,$project_id,$save_id);
}
$rs = $BTemplateModel->insert($data);
if($rs === false){
$this->fail('error');
}
}
return $this->success();
}
/**
* @remark :组装模版数据
* @name :setTemplateParams
* @author :lyh
* @method :post
* @time :2023/7/29 15:54
*/
public function setTemplateParams($v,$project_id,$save_id){
$param = [
'html'=>$v['html'],
'project_id'=>$project_id,
'source'=>$v['source'],
'source_id'=>$save_id,
'template_id'=>$v['template_id'],
'section_list_id'=>$v['section_list_id'],
'head_html'=>$v['head_html'],
'main_html'=>$v['main_html'],
'footer_html'=>$v['footer_html'],
'head_css'=>$v['head_css'],
'main_css'=>$v['main_css'],
'footer_css'=>$v['footer_css'],
'created_at'=>$v['created_at'],
'updated_at'=>$v['updated_at']
];
return $this->success($param);
}
/**
* @remark :组装数据
* @name :setParams
* @author :lyh
* @method :post
* @time :2023/7/29 15:45
*/
public function setProductParams($info){
$param = [
'project_id'=>$info['project_id'],
'title'=>$info['title']."-copy",
'attrs'=>Arr::a2s($info['attrs']),
'attr_id'=>Arr::arrToSet($info['attr_id']),
'category_id'=>!empty($info['category_id']) ? ','.Arr::arrToSet($info['category_id']).',' : '',
'keyword_id'=>!empty($info['keyword_id']) ? ','.Arr::arrToSet($info['keyword_id']).',' : '',
'intro'=>$info['intro'],
'content'=>$info['content'],
'describe'=>Arr::a2s($info['describe']),
'describe_id'=>Arr::arrToSet($info['describe_id']),
'seo_mate'=>Arr::a2s($info['seo_mate']),
'related_product_id'=>Arr::arrToSet($info['related_product_id']),
'sort'=>$info['sort'],
'status'=>0,
'route'=>$info['route'],
'product_type'=>$info['product_type'],
'created_uid'=>$this->user['id'],
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s'),
];
if(isset($info['icon']) && !empty($info['icon'])){
foreach ($info['icon'] as $k1 => $v1){
$info['icon'][$k1] = str_replace_url($v1);
}
$param['icon'] = Arr::a2s($info['icon'] ?? '');
}
//产品图
if(isset($info['gallery']) && !empty($info['gallery'])){
foreach ($info['gallery'] as $k => $v){
$v['url'] = str_replace_url($v['url']);
$info['gallery'][$k] = $v;
}
$param['thumb'] = Arr::a2s($info['gallery'][0] ?? '');
$param['gallery'] = Arr::a2s($info['gallery'] ?? '');
}
return $param;
}
/**
* @remark :删除当前产品所有模块
* @name :delProductModule
* @author :lyh
* @method :post
* @time :2023/7/31 10:31
*/
public function delProductModule($id){
$param = [
'source' => BTemplate::SOURCE_PRODUCT,
'source_id' => $id,
'project_id'=>$this->user['project_id'],
];
$bTemplateModel = new BTemplate();
$rs = $bTemplateModel->del($param);
if($rs === false){
$this->fail('error');
}
return $rs;
}
/**
* @remark :批量设置产品分类及状态
* @name :batchSetCategory
* @author :lyh
* @method :post
* @time :2023/8/15 17:53
*/
public function batchSetCategory(){
DB::beginTransaction();
try {
//删除分类关联表记录
$categoryRelatedModel = new CategoryRelated();
$categoryRelatedModel->del(['product_id'=>['in',$this->param['id']]]);
//批量
$param = [
'category_id'=>Arr::arrToSet($this->param['category_id']),
'status'=>$this->param['status']
];
$this->model->edit($param,['id'=>['in',$this->param['id']]]);
DB::commit();
//对应添加关联表
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
return $this->success();
}
/**
* @remark :排序
* @name :setSort
* @author :lyh
* @method :post
* @time :2023/8/19 11:16
*/
public function setSort(){
$rs = $this->model->edit(['sort'=>$this->param['sort']],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* 产品导入
* @param $project_id
* @param $user_id
* @param $data
* @return bool
* @throws \Exception
* @author Akun
* @date 2023/09/21 14:55
*/
public function importProduct($project_id, $user_id, $data)
{
$category_id = '';
if ($data[2]) {
//处理分类
$categoryLogic = new CategoryLogic();
$category_id = $categoryLogic->importProductCategory($project_id, $data[2]);
}
$keyword_id = '';
if($data[3]){
//处理关键词
$keywordLogic = new KeywordLogic();
$keyword_id = $keywordLogic->importProductKeyword($project_id, $data[3]);
}
$gallery = [];
$thumb = '';
if($data[7]){
//处理图片
$img_arr = explode(',',$data[7]);
foreach ($img_arr as $v_img){
if($v_img){
$one_img = CosService::uploadRemote($project_id,'image_product',$v_img);
if($one_img){
$one_gallery = [
'alt' => '这是一张产品图',
'url' => $one_img
];
if(!$thumb){
$thumb = Arr::a2s($one_gallery);
}
$gallery[] = $one_gallery;
}
}
}
}
//处理seo
$seo_mate = [
'title' => $data[8]??'',
'keyword' => $data[9]??'',
'description' => $data[10]??''
];
$product = $this->model->read(['title' => $data[0]]);
if (!$product) {
$id = $this->model->addReturnId(
[
'project_id' => $project_id,
'title' => $data[0],
'thumb' => $thumb,
'gallery' => Arr::a2s($gallery),
'attrs' => $data[4] ? $data[4] : Arr::a2s([]),
'category_id' => $category_id,
'keyword_id' => $keyword_id,
'intro' => $data[5] ?? '',
'content' => '<h3>Treatment Principle</h3> <p><img src="http://www.beijinghomibeauty.com/img/pro-1.jpg" alt="" style="width: 40%;padding: 0 0 3% 3%;float: right;">VelaShape is a practical, non-surgical, and non-invasive body contouring treatment that has gained popularity over the last two decades. <br>The treatment targets cellulite under the skin in hard-to-reach places where diet and exercise don’t seem to get. <br><br>Infrared RF Vacuum Roller technology combines infrared light, bi-polar radio frequency energy and vacuum, which cause deep heating of the fat cells, their surrounding connective tissue and the underlying dermal collagen fibers. This type of efficient heating and vacuum stimulates the growth of new and better collagen and elastin which results in localized reduction in skin laxity, body volume, and an overall improvement in skin structure and texture.</p> <h3>Applications</h3> <p><img src="http://www.beijinghomibeauty.com/img/pro-2.png" alt="" style="width: 50%;float: right;">● Body slimming, contouring & shaping <br>● Fat and cellulite reduction <br>● Skin Tightening, Wrinkle Removal <br>● Eyes’ area and Face wrinkle removal & lifting <br>● Warm vacuum cellulite massage? <br>● Promote cell metabolism? <br>● Improve blood circulation? <br>● Increase skin elasticity</p> <div class="clear"></div> <h3>What is cellulite?</h3> <p>Cellulite is a structural skin change that occurs in most post pubertal females whether they are thin or overweight. <br>It presents itself as a modification of skin morphology evident by skin dimpling and nodularity that occurs mainly in women on the pelvic region, lower limbs, and abdomen, and is caused by the herniation of subcutaneous fat within fibrous connective tissue, leading to a padded or orange peellike appearance. <br>Cellulite can occur in women of all ages and tends to become more visible with age. <br>Over time, the skin loses its thickness and thereby enhances the visibility of the unsightly cellulite bumps.</p> <h3>How does Infrared RF Vacuum Roller work to help get rid of cellulite?</h3> <p><img src="http://www.beijinghomibeauty.com/img/pro-3.jpg" alt="" style="width: 65%;float: left;padding: 0 3% 3% 0">The Infrared RF Vacuum Roller combines four different technologies including IR (infrared), BiPolar RF (radio-frequency) and mechanical tissue manipulation using pulsed vacuum and massage rollers.</p> <p>The combination of the IR and vacuum coupled RF technologies causes deep heating of the connective tissue including the fibrous septae which in turn promotes an increase in collagen depositing and local cellular metabolism resulting in a localized reduction in skin laxity and volume. The additional mechanical tissue manipulation of the Vela causes an immediate increase in circulation and lymphatic drainage, both essential components for healthy skin structure.</p> <h3>Three Different Treatment Handpieces for Whole Body Treatment</h3> <ul class="pro-25"> <li><img src="http://www.beijinghomibeauty.com/img/pro-4.jpg" alt=""> <p>Big Handpiece: For Abdomen, Flank, Buttock, Thigh treatment area.</p> <img src="http://www.beijinghomibeauty.com/img/pro-4.png" alt=""> </li> <li><img src="http://www.beijinghomibeauty.com/img/pro-5.jpg" alt=""> <p>Middle Handpiece: For Arm, Leg, Back, Neck treatment area.</p> <img src="http://www.beijinghomibeauty.com/img/pro-5.png" alt=""> </li> <li><img src="http://www.beijinghomibeauty.com/img/pro-6.jpg" alt=""> <p>For Face, Eye arrounding treatment area.</p> <img src="http://www.beijinghomibeauty.com/img/pro-6.png" alt=""> </li> <li><img src="http://www.beijinghomibeauty.com/img/pro-7.jpg" alt=""> <p>For whole body massage shaping</p> <img src="http://www.beijinghomibeauty.com/img/pro-7.png" alt=""> </li> </ul> <div class="clear"></div> <h3>Specification</h3> <table border="0" class="table"> <tbody> <tr> <td>LCD Screen </td> <td>1) Display screen: 10.4” <br> 2) Display screen of handpiece <br> Display screen on handpiece 1: 2.4″ <br> Display screen on handpiece 2: 1.9″ </td> </tr> <tr> <td>Working Mode</td> <td>Pulse</td> </tr> <tr> <td>Pulse width</td> <td>0.5s-7.5s</td> </tr> <tr> <td>Negative pressure</td> <td>1) Absolute value: 80kPa -10kPa (60.8cmHg - 7.6cmHg) <br>2) Relative value: 20kPa -90kPa (15.2cmHg – 68.4cmHg)</td> </tr> <tr> <td>Rev of roller</td> <td>0-36 rpm</td> </tr> <tr> <td>Working mode for roller</td> <td>4 types (In, out, left, right)</td> </tr> <tr> <td>RF frequency</td> <td>1MHz/ 5MHz</td> </tr> <tr> <td>RF energy density</td> <td>Max: 60J/cm</td> </tr> <tr> <td>Safety checking</td> <td>Real time on line</td> </tr> <tr> <td>Treatment area</td> <td>4mmx7mm、 6mmx13mm、 8mmx25mm、 30mmx50mm、 40mmx60mm、 90mmx120mm</td> </tr> <tr> <td>Laser wavelength/ power</td> <td>940nm/MAX 20W</td> </tr> <tr> <td>Mode of power supply</td> <td>AC230V±10%, 50Hz±1Hz/ AC110V±10%, 60Hz±1Hz </td> </tr> <tr> <td>Machine size</td> <td></td> </tr> </tbody> </table> <div class="clear"></div> <div class="clear"></div> <h3>Before & After</h3> <ul class="pro-50"> <li><img src="http://www.beijinghomibeauty.com/img/pro-12.jpg" alt=""></li> <li><img src="http://www.beijinghomibeauty.com/img/pro-13.jpg" alt=""></li> <li><img src="http://www.beijinghomibeauty.com/img/pro-14.jpg" alt=""></li> <li><img src="http://www.beijinghomibeauty.com/img/pro-15.jpg" alt=""></li> </ul> <div class="clear"></div> </div> <br> <div class="clear"></div>',
'seo_mate' => Arr::a2s($seo_mate),
'created_uid' => $user_id,
'status' => Product::STATUS_ON
]
);
//更新路由
$route = RouteMap::setRoute($data[1] ?: $data[0], RouteMap::SOURCE_PRODUCT, $id, $project_id);
$this->edit(['route' => $route], ['id' => $id]);
return true;
}
return false;
}
}