|
|
|
@ -304,15 +304,17 @@ class AgentProductController extends AdminController |
|
|
|
if ($form->is_rec !== null) { |
|
|
|
$form->model()->is_rec = $form->is_rec ? 1 : 0; |
|
|
|
$form->model()->save(); |
|
|
|
return $form->response()->success('更新成功!'); |
|
|
|
return $form->response()->success('更新成功!')->refresh(); |
|
|
|
} |
|
|
|
|
|
|
|
if ($form->stock !== null || $form->status !== null) { |
|
|
|
$ids = explode(',', $form->model()->product_ids); |
|
|
|
$count = Product::where([['status', '=', ProductStatus::ON_SALE], ['stock', '>=', $form->model()->stock]]) |
|
|
|
->whereIn('id', $ids)->count(); |
|
|
|
$count = Product::where([ |
|
|
|
['status', '=', ProductStatus::ON_SALE], |
|
|
|
['stock', '>=', $form->stock ?? $form->model()->stock], |
|
|
|
])->whereIn('id', $ids)->count(); |
|
|
|
if (count($ids) != $count) { |
|
|
|
return $form->response()->error('供应商产品已下架或库存不足!'); |
|
|
|
return $form->response()->error('供应商产品已下架或库存小于你设置的库存' . $form->stock)->refresh(); |
|
|
|
} |
|
|
|
|
|
|
|
//修改库存
|
|
|
|
@ -325,14 +327,14 @@ class AgentProductController extends AdminController |
|
|
|
if ($form->status !== null) { |
|
|
|
//待审核和拒绝的状态不允许修改
|
|
|
|
if (in_array($form->model()->status, [ProductStatus::UNAUDITED, ProductStatus::REFUSE])) { |
|
|
|
return $form->response()->error('产品待审核或审核拒绝,不允许修改!'); |
|
|
|
return $form->response()->error('产品待审核或审核拒绝,不允许修改!')->refresh(); |
|
|
|
} |
|
|
|
|
|
|
|
//计调云产品处理
|
|
|
|
if ($form->type == 2) { |
|
|
|
$cloud_product = AgentProduct::find($form->agent_cloud_pid); |
|
|
|
if (!$cloud_product || $cloud_product->status != ProductStatus::ON_SALE) { |
|
|
|
return $form->response()->error('你选择的计调云产品状态异常,上架失败!'); |
|
|
|
return $form->response()->error('你选择的计调云产品状态异常,上架失败!')->refresh(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -343,7 +345,7 @@ class AgentProductController extends AdminController |
|
|
|
|
|
|
|
$form->model()->status = $form->status == 1 ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; |
|
|
|
$form->model()->save(); |
|
|
|
return $form->response()->success('更新成功!'); |
|
|
|
return $form->response()->success('更新成功!')->refresh(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -402,7 +404,7 @@ class AgentProductController extends AdminController |
|
|
|
->pluck('id') |
|
|
|
->toArray(); |
|
|
|
if ($not_in_id) { |
|
|
|
return $form->response()->error('产品ID ' . join(',', $not_in_id) . ' 库存小于你设置的库存' . $form->stock . ',或不存在、已下架等'); |
|
|
|
return $form->response()->error('产品ID ' . join(',', $not_in_id) . ' 库存小于你设置的库存' . $form->stock . ',或已下架'); |
|
|
|
} |
|
|
|
|
|
|
|
$total_price = Product::query()->whereIn('id', $product_ids)->sum('price'); |
|
|
|
|