DetailLogic.php
2.5 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
<?php
/**
* @remark :
* @name :DetailLogic.php
* @author :lyh
* @method :post
* @time :2024/11/12 15:14
*/
namespace App\Http\Logic\Bside\Product;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\Column;
use App\Models\Product\Detail;
class DetailLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new Detail();
}
/**
* @remark :保存栏目
* @name :saveColumn
* @author :lyh
* @method :post
* @time :2024/11/12 15:15
*/
public function saveColumn(){
$columnModel = new Column();
if(isset($this->param['id']) && !empty($this->param['id'])){
$id = $this->param['id'];
$rs = $columnModel->edit(['column_name'=>$this->param['column_name']],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('保存失败,请联系管理员');
}
}else{
$id = $columnModel->addReturnId($this->param);
}
return $this->success(['id'=>$id]);
}
/**
* @remark :保存数据
* @name :saveDetail
* @author :lyh
* @method :post
* @time :2024/11/13 9:30
*/
public function saveDetail($product_id,$data){
if(!empty($data)){
try {
foreach ($data as $val){
foreach ($val as $v){
$save_data = [
'sort'=>$v['sort'],
'column_id'=>$v['column_id'],
'product_id'=>$product_id,
'text_type'=>$v['text_type'],
'title'=>$v['title'] ?? '',
'content'=>json_encode($v['content'] ?? [],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'css'=>json_encode($v['css'] ?? [],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
];
if(isset($v['id']) && !empty($v['id'])){
$this->edit($save_data,['id'=>$v['id']]);
}else{
$this->model->add($save_data);
}
}
}
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员.错误:'.$e->getMessage());
}
}
return $this->success(['product_id'=>$product_id]);
}
}