|
@@ -12,30 +12,31 @@ class OrderOutChild extends Base
|
|
|
{
|
|
|
|
|
|
//分单时可用仓库列表
|
|
|
- public function getWsmList(){
|
|
|
- $outCode = $this->request->post('outCode','','trim');
|
|
|
+ public function getWsmList()
|
|
|
+ {
|
|
|
+ $outCode = $this->request->post('outCode', '', 'trim');
|
|
|
|
|
|
- if($outCode=='') return json_show(1004,'发货单号不能为空');
|
|
|
+ if ($outCode == '') return json_show(1004, '发货单号不能为空');
|
|
|
|
|
|
- $out=Db::name('order_out')
|
|
|
+ $out = Db::name('order_out')
|
|
|
->alias('a')
|
|
|
->field('a.id,a.outCode,a.send_status,b.good_code')
|
|
|
- ->leftJoin('sale b','b.orderCode=a.orderCode')
|
|
|
- ->where(['a.is_del'=>0,'a.outCode'=>$outCode])
|
|
|
+ ->leftJoin('sale b', 'b.orderCode=a.orderCode')
|
|
|
+ ->where(['a.is_del' => 0, 'a.outCode' => $outCode])
|
|
|
->findOrEmpty();
|
|
|
- if(empty($out)) return json_show(1004,'该发货单不存在');
|
|
|
- if($out['send_status'] != 0) return json_show(1004,'该发货单状态错误');
|
|
|
+ if (empty($out)) return json_show(1004, '该发货单不存在');
|
|
|
+ if ($out['send_status'] != 0) return json_show(1004, '该发货单状态错误');
|
|
|
|
|
|
$list = Db::name("good_stock")
|
|
|
->alias("a")
|
|
|
- ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
|
|
|
+ ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
|
|
|
->field("a.id,a.wsm_code,b.name wsm_name,b.companyNo,b.companyName,b.supplierNo,b.supplierName,b.contactor_name,a.usable_stock")
|
|
|
- ->where(["spuCode"=>$out['good_code'],"a.is_del"=>0])
|
|
|
- ->order(['id'=>'asc'])
|
|
|
+ ->where(["spuCode" => $out['good_code'], "a.is_del" => 0])
|
|
|
+ ->order(['id' => 'asc'])
|
|
|
->select()
|
|
|
->toArray();
|
|
|
|
|
|
- return json_show(0,'获取列表成功',$list);
|
|
|
+ return json_show(0, '获取列表成功', $list);
|
|
|
}
|
|
|
|
|
|
//发货工单列表
|
|
@@ -181,7 +182,6 @@ class OrderOutChild extends Base
|
|
|
'list' => 'require|array|max:100',
|
|
|
]);
|
|
|
|
|
|
-
|
|
|
// $list=[
|
|
|
// ['wsm_code'=>'','num'=>100],
|
|
|
// ['wsm_code'=>'','num'=>100],
|
|
@@ -202,12 +202,12 @@ class OrderOutChild extends Base
|
|
|
->findOrEmpty();
|
|
|
|
|
|
if (empty($info)) return json_show(1004, '该发货单不存在或状态有误');
|
|
|
- if ($info['wsend_num'] < $info['send_num']) return json_show(1004,"订单待发货数量不足");
|
|
|
- if ($info['wsend_num'] < array_sum($param['list'],'num')) return json_show(1004,"仓库总发货数与发货单待发货数不同");
|
|
|
+ if ($info['wsend_num'] < $info['send_num']) return json_show(1004, "订单待发货数量不足");
|
|
|
+ if ($info['wsend_num'] < array_sum($param['list'], 'num')) return json_show(1004, "仓库总发货数与发货单待发货数不同");
|
|
|
|
|
|
//所有仓库信息
|
|
|
- $wsm = Db::name('warehouse_info')
|
|
|
- ->where(['is_del' => 0, 'wsm_code' => array_column($param['list'], 'wsm_code')])
|
|
|
+ $wsm = Db::name('good_stock')
|
|
|
+ ->where(['is_del' => 0, 'spuCode' => $info['good_code'], 'wsm_code' => array_column($param['list'], 'wsm_code')])
|
|
|
->column('id', 'wsm_code');
|
|
|
|
|
|
Db::startTrans();
|
|
@@ -254,12 +254,14 @@ class OrderOutChild extends Base
|
|
|
|
|
|
if (!isset($wsm[$value['wsm_code']])) throw new Exception($value['wsm_code'] . '该仓库不存在');
|
|
|
|
|
|
- //维护bn号
|
|
|
- GoodStockInfo::ChildAddBn($outChildCode, $wsm[$value['wsm_code']]);
|
|
|
}
|
|
|
|
|
|
Db::name('order_out_child')->insertAll($insert);
|
|
|
|
|
|
+ foreach ($insert as $item) {
|
|
|
+ GoodStockInfo::ChildAddBn($item['outChildCode'], $wsm[$value['wsm_code']]);//维护bn号
|
|
|
+ }
|
|
|
+
|
|
|
Db::name('order_out')
|
|
|
->where(['id' => $info['id'], 'is_del' => 0, 'outCode' => $param['outCode'], 'send_status' => 0])
|
|
|
->update(['send_status' => 1, 'status' => 1]);
|
|
@@ -277,14 +279,14 @@ class OrderOutChild extends Base
|
|
|
public function info()
|
|
|
{
|
|
|
|
|
|
- $outChildCode = $this->request->post('outChildCode','','trim');
|
|
|
- if($outChildCode=='') return json_show(1004,'发货工单号不能为空');
|
|
|
+ $outChildCode = $this->request->post('outChildCode', '', 'trim');
|
|
|
+ if ($outChildCode == '') return json_show(1004, '发货工单号不能为空');
|
|
|
|
|
|
$info = Db::name('order_out_child')
|
|
|
- ->where(['is_del'=>0,'outChildCode'=>$outChildCode])
|
|
|
+ ->where(['is_del' => 0, 'outChildCode' => $outChildCode])
|
|
|
->findOrEmpty();
|
|
|
|
|
|
- return json_show(0,'获取详情成功',$info);
|
|
|
+ return json_show(0, '获取详情成功', $info);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -292,32 +294,32 @@ class OrderOutChild extends Base
|
|
|
public function send()
|
|
|
{
|
|
|
|
|
|
- $param = $this->request->post('list/a','','trim');
|
|
|
+ $param = $this->request->post('list/a', '', 'trim');
|
|
|
|
|
|
- $temp=Db::name('order_out_child')
|
|
|
+ $temp = Db::name('order_out_child')
|
|
|
->field('id,outChildCode')
|
|
|
- ->where(['is_del'=>0,'outChildCode'=>array_column($param,'outChildCode')])
|
|
|
- ->where('status','<>',1)
|
|
|
+ ->where(['is_del' => 0, 'outChildCode' => array_column($param, 'outChildCode')])
|
|
|
+ ->where('status', '<>', 1)
|
|
|
->findOrEmpty();
|
|
|
- if(!empty($temp)) return json_show(1004,$temp['outChildCode'].'状态错误,不能发货');
|
|
|
+ if (!empty($temp)) return json_show(1004, $temp['outChildCode'] . '状态错误,不能发货');
|
|
|
|
|
|
$child = Db::name('order_out_child')
|
|
|
->where(['is_del' => 0, 'status' => 1, 'outChildCode' => array_column($param, 'outChildCode')])
|
|
|
- ->column('id,orderCode,outCode,total_num,num', 'outChildCode');
|
|
|
+ ->column('id,orderCode,outCode,num', 'outChildCode');
|
|
|
|
|
|
- $order_out = Db::name('order_out')
|
|
|
- ->where(['is_del'=>0,'outCode'=>array_unique(array_column($child,'outCode'))])
|
|
|
- ->column('id,send_num,send_status,0 already_send_num','outCode');
|
|
|
+ $order_out = Db::name('order_out')
|
|
|
+ ->where(['is_del' => 0, 'outCode' => array_unique(array_column($child, 'outCode'))])
|
|
|
+ ->column('id,send_num,send_status,0 already_send_num', 'outCode');
|
|
|
|
|
|
- $sale = Db::name('sale')
|
|
|
- ->where(['is_del'=>0,'orderCode'=>array_unique(array_column($child,'orderCode'))])
|
|
|
- ->column('id,good_num,send_num,wsend_num','orderCode');
|
|
|
+ $sale = Db::name('sale')
|
|
|
+ ->where(['is_del' => 0, 'orderCode' => array_unique(array_column($child, 'orderCode'))])
|
|
|
+ ->column('id,good_num,send_num,wsend_num,good_code', 'orderCode');
|
|
|
|
|
|
- $val=Validate::rule([
|
|
|
- 'outChildCode|发货工单号'=>'require|max:255',
|
|
|
- 'post_name|物流公司'=>'require|max:255',
|
|
|
- 'post_code|物流单号'=>'require|alphaDash|max:255',
|
|
|
- 'post_fee|物流费用'=>'require|egt:0|max:99999999.99'
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'outChildCode|发货工单号' => 'require|max:255',
|
|
|
+ 'post_name|物流公司' => 'require|max:255',
|
|
|
+ 'post_code|物流单号' => 'require|alphaDash|max:255',
|
|
|
+ 'post_fee|物流费用' => 'require|egt:0|max:99999999.99'
|
|
|
]);
|
|
|
|
|
|
Db::startTrans();
|
|
@@ -325,12 +327,12 @@ class OrderOutChild extends Base
|
|
|
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
|
|
- foreach ($param as $value){
|
|
|
+ foreach ($param as $value) {
|
|
|
|
|
|
- if($val->check($value)==false) throw new Exception($val->getError());
|
|
|
+ if ($val->check($value) == false) throw new Exception($val->getError());
|
|
|
|
|
|
//工单
|
|
|
- if(!isset($child[$value['outChildCode']])) throw new Exception($value['outChildCode'].'工单不存在或状态不允许发货');
|
|
|
+ if (!isset($child[$value['outChildCode']])) throw new Exception($value['outChildCode'] . '工单不存在或状态不允许发货');
|
|
|
|
|
|
Db::name('order_out_child')
|
|
|
->where(['id' => $child[$value['outChildCode']]['id'], 'is_del' => 0, 'status' => 1])
|
|
@@ -348,31 +350,34 @@ class OrderOutChild extends Base
|
|
|
//发货单
|
|
|
//send_status 2部分发货,3全部发货
|
|
|
Db::name('order_out')
|
|
|
- ->where(['id'=>$order_out[$child[$value['outChildCode']]['outCode']]['id']])
|
|
|
- ->update(['send_status'=>$order_out[$child[$value['outChildCode']]['outCode']]['already_send_num']>=$order_out[$child[$value['outChildCode']]['outCode']]['send_num']?3:2,'updatetime'=>$date]);
|
|
|
+ ->where(['id' => $order_out[$child[$value['outChildCode']]['outCode']]['id']])
|
|
|
+ ->update(['send_status' => $order_out[$child[$value['outChildCode']]['outCode']]['already_send_num'] >= $order_out[$child[$value['outChildCode']]['outCode']]['send_num'] ? 3 : 2, 'updatetime' => $date]);
|
|
|
+
|
|
|
+ $sale[$child[$value['outChildCode']]['orderCode']]['send_num'] += $child[$value['outChildCode']]['num'];
|
|
|
+ $sale[$child[$value['outChildCode']]['orderCode']]['wsend_num'] -= $child[$value['outChildCode']]['num'];
|
|
|
|
|
|
//销售单
|
|
|
Db::name('sale')
|
|
|
- ->where(['is_del'=>0,'id'=>$sale[$child[$value['outChildCode']]['orderCode']]['id']])
|
|
|
+ ->where(['is_del' => 0, 'id' => $sale[$child[$value['outChildCode']]['orderCode']]['id']])
|
|
|
->update([
|
|
|
- 'send_num'=>++$sale[$child[$value['outChildCode']]['orderCode']]['send_num'],
|
|
|
- 'wsend_num'=>--$sale[$child[$value['outChildCode']]['orderCode']]['wsend_num'],
|
|
|
- 'send_status'=>$sale[$child[$value['outChildCode']]['orderCode']]['send_num']>=$sale[$child[$value['outChildCode']]['orderCode']]['good_num']?3:2,
|
|
|
+ 'send_num' => $sale[$child[$value['outChildCode']]['orderCode']]['send_num'],
|
|
|
+ 'wsend_num' => $sale[$child[$value['outChildCode']]['orderCode']]['wsend_num'],
|
|
|
+ 'send_status' => $sale[$child[$value['outChildCode']]['orderCode']]['send_num'] >= $sale[$child[$value['outChildCode']]['orderCode']]['good_num'] ? 3 : 2,
|
|
|
]);
|
|
|
|
|
|
//库存
|
|
|
Db::name('good_stock')
|
|
|
- ->where(['is_del'=>0,'spuCode'=>'','wsm_code'=>''])
|
|
|
- ->dec('wait_out_stock',$child[$value['outChildCode']]['num'])
|
|
|
- ->update(['updatetime'=>$date]);
|
|
|
+ ->where(['is_del' => 0, 'spuCode' => $sale[$child[$value['outChildCode']]['orderCode']]['good_code'], 'wsm_code' => $child[$value['outChildCode']]['wsm_code']])
|
|
|
+ ->dec('wait_out_stock', $child[$value['outChildCode']]['num'])
|
|
|
+ ->update(['updatetime' => $date]);
|
|
|
|
|
|
}
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
|
- return json_show(0,'操作完成');
|
|
|
+ return json_show(0, '操作完成');
|
|
|
|
|
|
- }catch (Exception $exception){
|
|
|
+ } catch (Exception $exception) {
|
|
|
|
|
|
Db::rollback();
|
|
|
|