|
@@ -305,6 +305,8 @@ class Product extends Auth{
|
|
|
if( $skuList ) $data['stock'] = array_sum(array_column($skuList,'stock'));
|
|
|
// 总库存
|
|
|
$data['stock_total'] = $data['stock'];
|
|
|
+ // 总库存提醒
|
|
|
+ if( $data['stock_total'] <= 0 ) return json_send(['code'=>'error','msg'=>'请设置库存','data'=>['error'=>'请设置库存']]);
|
|
|
// 获取规格属性
|
|
|
$specAttr = $this->getSpecAttr($attr,$ProductSpec,true);
|
|
|
// 开启事务
|
|
@@ -450,6 +452,11 @@ class Product extends Auth{
|
|
|
*
|
|
|
* */
|
|
|
public function edit(Request $request, Model $Model, WeiBanTags $WeiBanTags, ProductPhoto $ProductPhoto, Producer $Producer, Business $Business, ProductType $ProductType, ProductSpec $ProductSpec, ProductAttr $ProductAttr, ProductSkus $ProductSkus, City $City, ProductCity $ProductCity){
|
|
|
+ // 接收参数
|
|
|
+ $id = request('id',0);
|
|
|
+ // 查询数据
|
|
|
+ $oldData = $Model->where(['id'=>$id])->first();
|
|
|
+ // 修改
|
|
|
if(request()->isMethod('post')){
|
|
|
// 验证参数
|
|
|
$request->scene('edit')->validate();
|
|
@@ -526,6 +533,8 @@ class Product extends Auth{
|
|
|
if( $skuList ) $data['stock'] = array_sum(array_column($skuList,'stock'));
|
|
|
// 总库存
|
|
|
$data['stock_total'] = $data['stock'];
|
|
|
+ // 总库存提醒
|
|
|
+ if( $data['stock_total'] <= 0 ) return json_send(['code'=>'error','msg'=>'请设置库存','data'=>['error'=>'请设置库存']]);
|
|
|
// 获取规格属性
|
|
|
$specAttr = $this->getSpecAttr($attr,$ProductSpec,true);
|
|
|
// 开启事务
|
|
@@ -621,7 +630,7 @@ class Product extends Auth{
|
|
|
// 提交
|
|
|
DB::commit();
|
|
|
// 记录行为
|
|
|
- $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,[],$data);
|
|
|
+ $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
|
|
|
// 告知结果
|
|
|
return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
|
|
|
} catch (\Throwable $th) {
|
|
@@ -631,10 +640,6 @@ class Product extends Auth{
|
|
|
return json_send(['code'=>'error','msg'=>'系统异常,写入失败','data'=>$th->getMessage() .'=>'.$th->getLine()]);
|
|
|
}
|
|
|
}
|
|
|
- // 接收参数
|
|
|
- $id = request('id',0);
|
|
|
- // 查询数据
|
|
|
- $oldData = $Model->where(['id'=>$id])->first();
|
|
|
// 如果是没有数据
|
|
|
if( !$oldData ) return $this->error('查无数据');
|
|
|
// 产品信息转格式
|
|
@@ -769,6 +774,8 @@ class Product extends Auth{
|
|
|
}
|
|
|
// 总库存
|
|
|
$data['stock_total'] = $data['stock'];
|
|
|
+ // 总库存提醒
|
|
|
+ if( $data['stock_total'] <= 0 ) return json_send(['code'=>'error','msg'=>'请设置库存','data'=>['error'=>'请设置库存']]);
|
|
|
// 获取规格属性
|
|
|
$specAttr = $this->getSpecAttr($attr,$ProductSpec,true);
|
|
|
// 开启事务
|