DetailLogic.php
1.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
<?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->add($this->param);
}
return $this->success(['id'=>$id]);
}
public function saveDetail(){
foreach ($this->param['data'] as $k => $data){
$i = 1;
$save_data = [];
foreach ($data as $key => $v){
$save_data[] = [
'sort'=>$i,
'column_id'=>$v['column_id'],
'product_id'=>$this->param['product_id'],
'title'=>$v['title'] ?? '',
'content'=>json_encode($v['content'] ?? []),
'css'=>json_encode($v['css'] ?? []),
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
$i++;
}
$this->model->insert($save_data);
}
}
}