|
@@ -69,13 +69,6 @@ class Product extends Auth{
|
|
|
$salesList = $OrdersProduct->query()->where([['status','<>',4]])->whereIn('product_id',array_column($list->items(),'id'))->groupBy('product_id')->select([DB::raw('sum(`buy_num`) as sales_total'),'product_id'])->pluck('sales_total','product_id')->toArray();
|
|
|
// 循环处理数据
|
|
|
foreach ($list as $key => $value) {
|
|
|
- // 判断总库存
|
|
|
- if( !$value['stock_total'] ) {
|
|
|
- // 以首次添加时的为准
|
|
|
- $value['stock_total']= (int) $AdminHistory->query()->where([['table_name','=','product'],['primary_id','=',$value['id']],['notes_type','=',1],['column_name','=','stock']])->orderBy('update_time')->value('after_value');
|
|
|
- // 修改库存
|
|
|
- $Model->edit($value['id'],['stock_total'=>$value['stock_total']]);
|
|
|
- }
|
|
|
// id转编号
|
|
|
$value['product_code'] = $Model->idToCode($value['id']);
|
|
|
// id转编号
|
|
@@ -354,6 +347,11 @@ class Product extends Auth{
|
|
|
*
|
|
|
* */
|
|
|
public function edit( Request $request, Model $Model,Course $Course,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();
|
|
@@ -509,7 +507,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) {
|
|
@@ -519,10 +517,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('查无数据');
|
|
|
// 产品信息转格式
|