refactor(api): 重构 IndexController 中的数据处理逻辑
- 优化了数据查询和处理的代码结构 - 提高了代码的可读性和维护性 - 新增 wps_product 方法用于处理采购商品下载
This commit is contained in:
parent
f43f1b0886
commit
ab347de4f1
@ -279,4 +279,36 @@ class IndexController extends BaseApiController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 采购商品下载
|
||||||
|
*/
|
||||||
|
public function wps_product()
|
||||||
|
{
|
||||||
|
$data = $this->request->post();
|
||||||
|
if ($data) {
|
||||||
|
if ($data['product_id'] > 0) {
|
||||||
|
$find = Db::name('wps_product')->where('product_id', $data['product_id'])->find();
|
||||||
|
$arr = [];
|
||||||
|
if ($data['purchase'] > 0) {
|
||||||
|
$arr['purchase'] = $data['purchase'];
|
||||||
|
}
|
||||||
|
if ($data['cost'] > 0) {
|
||||||
|
$arr['cost'] = $data['cost'];
|
||||||
|
}
|
||||||
|
if ($data['price'] > 0) {
|
||||||
|
$arr['price'] = $data['price'];
|
||||||
|
}
|
||||||
|
if ($find) {
|
||||||
|
Db::name('wps_product')->where('id', $find['id'])->update($arr);
|
||||||
|
} else {
|
||||||
|
$arr['product_id']=$data['product_id'];
|
||||||
|
$arr['name']=$data['name'];
|
||||||
|
Db::name('wps_product')->insert($arr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->success('ok');
|
||||||
|
} else {
|
||||||
|
return $this->fail('时间不能为空');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user