|
@@ -267,25 +267,50 @@ class OrderImport extends Base
|
|
|
public function relationStockBatch()
|
|
|
{
|
|
|
|
|
|
- $ids = $this->request->post('ids/a', [], 'trim');
|
|
|
+ $param = $this->request->only(['ids','plat_code'], 'post', 'trim');
|
|
|
|
|
|
- if (empty($ids)) return error_show(1004, 'ids参数不允许为空');
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'ids'=>'require',
|
|
|
+ 'plat_code|平台商品编号'=>'require',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if(!$val->check($param)) return error_show(1004, $val->getError());
|
|
|
|
|
|
- $userinfo = GetUserInfo($this->post['token']);
|
|
|
+ $info = Db::name('order_import_from_c_extend')
|
|
|
+ ->field('id,spuCode,companyNo')
|
|
|
+ ->whereIn('id', $param['ids'])
|
|
|
+ ->find();
|
|
|
|
|
|
- $res = Db::name('order_import_from_c')
|
|
|
- ->whereIn('id', $ids)
|
|
|
+ //判断库存是否充足
|
|
|
+ $num = Db::name('order_import_from_c')
|
|
|
+ ->whereIn('id', $param['ids'])
|
|
|
->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_stock_not_enough])
|
|
|
- ->update([
|
|
|
- 'status' => OIFCModel::$status_wait_relation,
|
|
|
- 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
- 'updateid'=>isset($user["data"]['id']) ? $userinfo["data"]['id'] : 0,
|
|
|
- 'updater'=>isset($user["data"]['nickname']) ? $userinfo["data"]['nickname'] : '',
|
|
|
- ]);
|
|
|
+ ->sum('num');
|
|
|
+ $wsm_code = Db::name('warehouse_info')
|
|
|
+ ->where(['companyNo'=>$info['companyNo'],'is_del'=>0])
|
|
|
+ ->value('wsm_code');
|
|
|
+ $usable_stock = Db::name('good_stock')
|
|
|
+ ->where(['spuCode'=> $info['spuCode'],'wsm_code'=>$wsm_code,'is_del'=>0])
|
|
|
+ ->value('usable_stock',0);
|
|
|
+
|
|
|
+ if($usable_stock<$num) return error_show(1005,'可用库存只有'.$usable_stock);
|
|
|
+ else {
|
|
|
|
|
|
- if ($res) return app_show(0, '批量关联库存成功');
|
|
|
- else return error_show(1005, '批量关联库存失败');
|
|
|
+ $userinfo = GetUserInfo($this->post['token']);
|
|
|
|
|
|
+ $res = Db::name('order_import_from_c')
|
|
|
+ ->whereIn('id', $param['ids'])
|
|
|
+ ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_stock_not_enough])
|
|
|
+ ->update([
|
|
|
+ 'status' => OIFCModel::$status_wait_relation,
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ 'updateid' => isset($user["data"]['id']) ? $userinfo["data"]['id'] : 0,
|
|
|
+ 'updater' => isset($user["data"]['nickname']) ? $userinfo["data"]['nickname'] : '',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($res) return app_show(0, '批量关联库存成功');
|
|
|
+ else return error_show(1005, '批量关联库存失败');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//【辅助1】获取线上商品详情
|