Browse Source

优化产品重复发布逻辑

dev
李可松 4 years ago
parent
commit
dff926542a
  1. 11
      app/AdminAgent/Controllers/AgentProductController.php

11
app/AdminAgent/Controllers/AgentProductController.php

@ -198,19 +198,12 @@ class AgentProductController extends AdminController
$where = [
['agent_id', '=', $agent_id],
['product_id', '=', $form->product_id],
['product_ids', '=', $form->product_ids],
];
if ($form->isEditing()) {
$where[] = ['id', '<>', $form->getKey()];
}
$agent_product = $form->repository()->model()->withTrashed()->where($where)->first();
if ($agent_product) {
//如果已经软删除了,解除软删除后再更新
if ($agent_product->deleted_at) {
$agent_product->deleted_at = null;
$form->deleteInput('sale'); //保留原来的销量
$agent_product->update($form->input());
return $form->response()->success('保存成功')->script('history.back();');
}
if ($form->repository()->model()->where($where)->exists()) {
return $form->response()->error('该产品已经存在,请勿重复发布');
}
});

Loading…
Cancel
Save