2db47680
hexiaodong
chore: 初始提交 php 遗...
|
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
|
<?php
namespace addons\antis\controller;
use addons\antis\model\Product as ProductModel;
use addons\antis\model\ProductPart;
use addons\antis\model\Producttype;
/**
* 产品
*/
class Product extends StaffApi
{
protected $noNeedLogin = [];
protected $noNeedRight = [];
/**
* 获取select产品列表
*/
public function getSelectList()
{
$name = input('name');
$type_id = input('type_id');
$where = [];
if ($name) {
$where['name|num'] = ['like', "%{$name}%"];
}
if ($type_id) {
$where['type_id'] = $type_id;
}
$list = ProductModel::where($where)->field('id,name,type,num,img,unit,price,min_price,status,cost_price,wholesale')->select();
$this->success('请求成功', $list);
}
/**
* 获取产品分类列表
*/
public function getProducttypeList()
{
$name = input('name');
$where=[];
if ($name) {
$where['name'] = ['like', "%{$name}%"];
}
$list = Producttype::where($where)->field('id,name')->select();
$this->success('请求成功', $list);
}
/**
* 获取产品配置列表
*/
public function getPartList()
{
$product_id = input('product_id');
$name = input('name');
$where = [];
if ($name) {
$where['name'] = ['like', "%{$name}%"];
}
$where['product_id'] = $product_id;
$list = ProductPart::where($where)->field('id,name,img,description')->select();
$this->success('请求成功', $list);
}
/**
* 获取产品详情
*/
public function getProductDetail()
{
$id = input('id');
$product = ProductModel::where(['id' => $id])->find();
if (empty($product)) {
$this->error('产品不存在');
}
preg_match_all("/(<img .*?src=\")(.*?)(\".*?>)/is", $product['description'], $matchpic);
foreach ($matchpic[2] as $url) {
$img = cdnurl($url, true);
$product['description'] = str_replace($url, $img, $product['description']);
}
$this->success('请求成功', $product);
}
/**
* 添加产品
*/
public function addProduct()
{
$params = $this->request->post();
if ($params) {
$parts = $params['parts'] ?? [];
$model = new ProductModel();
$model->allowField(true)->save($params);
$lastid = $model->getLastInsID();
$partModel = new ProductPart();
foreach ($parts as &$v) {
$v['product_id'] = $lastid;
}
$partModel->allowField(true)->saveAll($parts);
$this->success('添加产品成功');
}
}
/**
* 添加产品配件
*/
public function addProductPart()
{
$params = $this->request->post();
if ($params) {
$partModel = new ProductPart();
$partModel->save($params);
$this->success('添加产品配置成功');
}
}
/**
* 修改产品信息
*/
public function editProduct()
{
$params = $this->request->post();
if ($params) {
$model = new ProductModel();
$row = $model->get($params['id']);
if (empty($row)) {
$this->error('产品不存在');
}
$row->allowField(true)->save($params);
$this->success('添加产品成功');
}
}
/**
* 修改产品配件
*/
public function editProductPart()
{
$params = $this->request->post();
if ($params) {
$partModel = new ProductPart();
$row = $partModel->get($params['id']);
if (empty($row)) {
$this->error('产品配置不存在');
}
$row->allowField(true)->save($params);
$this->success('修改产品配置成功');
}
}
}
|