|
|
|
@ -8,6 +8,7 @@ use App\Models\AgentProduct; |
|
|
|
use App\Models\AgentProductItem; |
|
|
|
use App\Models\Category; |
|
|
|
use App\Models\DiyForm; |
|
|
|
use App\Models\Special; |
|
|
|
use Dcat\Admin\Admin; |
|
|
|
use Dcat\Admin\Form; |
|
|
|
use Dcat\Admin\Form\NestedForm; |
|
|
|
@ -305,8 +306,11 @@ class ProductController extends AdminController |
|
|
|
$form->hidden(['status', 'supplier_id']); //表单没有的字段,必须加上这句才能重置值
|
|
|
|
$form->supplier_id = Admin::user()->id; |
|
|
|
$form->status = ProductStatus::UNAUDITED; |
|
|
|
} else if ($form->isEditing() && in_array($form->model()->status, $user_status) && in_array($form->status, $user_status)) { //如果原来是下架或上架状态才允许修改
|
|
|
|
$form->status = $form->status == ProductStatus::ON_SALE ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; |
|
|
|
} else if ($form->isEditing()) { |
|
|
|
//如果原来是下架或上架状态才允许修改
|
|
|
|
if (in_array($form->model()->status, $user_status) && in_array($form->status, $user_status)) { |
|
|
|
$form->status = $form->status == ProductStatus::ON_SALE ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; |
|
|
|
} |
|
|
|
|
|
|
|
//因extends是数组,具有一定的特殊性,不能直接用$form->saved方法中的wasChanged判断是否修改,所以只能在这里做特殊处理
|
|
|
|
if (!is_null($form->extends)) { |
|
|
|
@ -321,6 +325,28 @@ class ProductController extends AdminController |
|
|
|
$form->status = ProductStatus::UNAUDITED; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//删除规格不处理,新增规格、修改规格价格或日期,状态都要变为已审核
|
|
|
|
$new_spec = array_filter($form->spec, fn($v) => $v['_remove_'] === null); |
|
|
|
//判断是否新增规格
|
|
|
|
if (array_filter($new_spec, fn($v) => $v['id'] === null)) { |
|
|
|
$form->status = ProductStatus::UNAUDITED; |
|
|
|
} |
|
|
|
//判断是否修改价格
|
|
|
|
else if ($new_spec) { |
|
|
|
// $item是旧数据,$form->spec是新修改的数据
|
|
|
|
foreach ($form->model()->spec as $item) { |
|
|
|
//删除的规格不处理
|
|
|
|
if (!isset($new_spec[$item->id])) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
//修改价格或日期的,设置为未审核,退出循环
|
|
|
|
if ($item->price != $new_spec[$item->id]['price'] || $item->date != $new_spec[$item->id]['date']) { |
|
|
|
$form->status = ProductStatus::UNAUDITED; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
$form->deleteInput('status'); |
|
|
|
} |
|
|
|
|