|
|
|
@ -4,7 +4,6 @@ namespace App\AdminAgent\Controllers; |
|
|
|
|
|
|
|
use App\AdminAgent\Renderable\SelectGuide; |
|
|
|
use App\AdminAgent\Renderable\SelectProduct; |
|
|
|
use App\AdminAgent\Renderable\SelectUser; |
|
|
|
use App\AdminAgent\Repositories\AgentProduct; |
|
|
|
use App\Common\AgentType; |
|
|
|
use App\Common\ProductStatus; |
|
|
|
@ -14,7 +13,6 @@ use App\Models\Channel; |
|
|
|
use App\Models\Guide; |
|
|
|
use App\Models\Product; |
|
|
|
use App\Models\Supplier; |
|
|
|
use App\Models\User; |
|
|
|
use Dcat\Admin\Admin; |
|
|
|
use Dcat\Admin\Form; |
|
|
|
use Dcat\Admin\Grid; |
|
|
|
@ -41,7 +39,7 @@ class AgentProductController extends AdminController |
|
|
|
$grid->column('price'); |
|
|
|
$grid->column('original_price'); |
|
|
|
$grid->column('sale'); |
|
|
|
$grid->column('stock'); |
|
|
|
$grid->column('stock')->editable(); |
|
|
|
|
|
|
|
$channels = Channel::where('agent_id', $agent_id)->pluck('name', 'id')->toArray(); |
|
|
|
$grid->column('channel_id', '频道') |
|
|
|
@ -238,13 +236,28 @@ class AgentProductController extends AdminController |
|
|
|
return $form->response()->error('数据不存在'); |
|
|
|
} |
|
|
|
|
|
|
|
if ($form->product_id === null && $form->product_ids === null) { |
|
|
|
if ($form->isEditing() && $form->product_id === null && $form->product_ids === null) { |
|
|
|
//推荐按钮开关
|
|
|
|
if ($form->is_rec !== null) { |
|
|
|
$form->model()->is_rec = $form->is_rec ? 1 : 0; |
|
|
|
$form->model()->save(); |
|
|
|
return $form->response()->success('更新成功!'); |
|
|
|
} |
|
|
|
|
|
|
|
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(); |
|
|
|
if (count($ids) != $count) { |
|
|
|
return $form->response()->success('供应商产品已下架或库存不足!'); |
|
|
|
} |
|
|
|
|
|
|
|
//修改库存
|
|
|
|
if ($form->stock !== null) { |
|
|
|
$form->model()->stock = $form->stock; |
|
|
|
$form->model()->save(); |
|
|
|
return $form->response()->success('更新成功!'); |
|
|
|
} |
|
|
|
//上下架状态按钮开关
|
|
|
|
if ($form->status !== null) { |
|
|
|
$form->model()->status = $form->status == 1 ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; |
|
|
|
@ -252,6 +265,7 @@ class AgentProductController extends AdminController |
|
|
|
return $form->response()->success('更新成功!'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (is_null($form->type)) { |
|
|
|
return $form->response()->error('请选择销售类型!'); |
|
|
|
@ -269,7 +283,7 @@ class AgentProductController extends AdminController |
|
|
|
if ($product->status != ProductStatus::ON_SALE) { |
|
|
|
return $form->response()->error('产品ID '. $form->product_id .' 已下架'); |
|
|
|
} else if ($product->stock < $form->stock) { |
|
|
|
return $form->response()->error('库存不足,你设置的库存应小于等于' . $form->stock); |
|
|
|
return $form->response()->error("供应商当前库存为{$form->stock},你设置的库存不能超过该数值"); |
|
|
|
} |
|
|
|
$form->title = $product->title; |
|
|
|
$form->pictures = $product->pictures; |
|
|
|
@ -305,7 +319,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 . ',或不存在、已下架等'); |
|
|
|
} |
|
|
|
} else { |
|
|
|
return $form->response()->error('不存在此销售方式'); |
|
|
|
|