1.提交缺失的东西

This commit is contained in:
2025-05-28 10:33:41 +08:00
parent 5f597e478a
commit ae8d8565dc
2 changed files with 377 additions and 62 deletions

View File

@ -20,6 +20,7 @@ use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\GoodsLists;
use app\adminapi\logic\GoodsLogic;
use app\adminapi\validate\GoodsValidate;
use think\facade\Db;
/**
@ -132,12 +133,84 @@ class GoodsController extends BaseAdminController
*/
public function edit()
{
$params = (new GoodsValidate())->post()->goCheck('edit');
$result = GoodsLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
if ($this->request->isAjax() && $this->request->isPost()) {
$post = $this->request->post();
$post['del'] = 0;
$post['id'] = $post['goods_id'];
//主表验证
$result = $this->validate($post, 'app\adminapi\validate\GoodsValidate');
if ($result !== true) {
return $this->fail($result);
}
//单规格验证
if ($post['spec_type'] == 1) {
$result = $this->validate($post, 'app\adminapi\validate\GoodsOneSpecValidate');
if ($result !== true) {
return $this->fail($result);
}
}
//多规格验证
$spec_lists = [];
if ($post['spec_type'] == 2) {
$spec_lists = $post;
unset($spec_lists['goods_image']);
unset($spec_lists['spec_name']);
unset($spec_lists['spec_values']);
unset($spec_lists['spec_id']);
unset($spec_lists['spec_value_ids']);
$spec_lists = form_to_linear($spec_lists);
//规格验证
if (empty($spec_lists)) {
return $this->fail('至少添加一个规格');
}
$result = $this->validate($post, 'app\adminapi\validate\GoodsMoreSpecValidate');
if ($result !== true) {
return $this->fail($result);
}
//规格商品列表验证
foreach ($spec_lists as $v) {
$result = $this->validate($v, 'app\adminapi\validate\GoodsMoreSpecListsValidate');
if ($result !== true) {
return $this->fail($result);
}
}
// 校验规格
$total_stock = array_sum(array_column($spec_lists, 'stock'));
if ($total_stock <= 0) {
$this->fail('至少有一个规格的库存大于0');
}
}
if ($post['status'] == 0) {
$status = Db::name('goods')
->where(['id' => $post['goods_id']])
->value('status');
if ($status == 1) {
$res = Db::name('team_activity')
->where(['status' => 1, 'goods_id'=> $post['goods_id']])
->find();
if ($res) {
return $this->fail('该商品正在参与拼团,请先关闭后才允许下架');
}
}
}
//添加商品
$result = GoodsLogic::edit($post, $spec_lists);
if ($result !== true) {
return $this->fail('添加失败:' . $result);
}
return $this->success('修改成功');
}
return $this->fail(GoodsLogic::getError());
}