|
@@ -333,11 +333,13 @@ class Salezx extends \app\BaseController
|
|
|
$temp['mobile'] = $value['mobile'];
|
|
|
$temp['addr'] = $value['addr'];
|
|
|
$temp['addr_code']=$addr;
|
|
|
+ $temp['orderCode']=$saleinfo['orderCode'];
|
|
|
$temp['customer_code'] =$customer_code;
|
|
|
$temp['receipt_quantity']=$value['receipt_quantity'];
|
|
|
$temp['post_fee'] =0;
|
|
|
$temp['is_del'] =$value['is_del'];
|
|
|
$temp['updatetime'] =date("Y-m-d H:i:s");
|
|
|
+ isset($value["id"])&&$value["id"]!=""?"":$temp['addtime'] =date("Y-m-d H:i:s");
|
|
|
$temp['arrive_time']=$value['arrive_time'];
|
|
|
$vmp = Db::name('order_addr')->save($temp);
|
|
|
if(!$vmp){
|
|
@@ -345,7 +347,6 @@ class Salezx extends \app\BaseController
|
|
|
return error_show(0,"咨询订单地址更新失败");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
Db::commit();
|
|
|
return error_show(0,"咨询订单更新成功");
|
|
@@ -360,27 +361,27 @@ class Salezx extends \app\BaseController
|
|
|
|
|
|
public function out(){
|
|
|
$token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
|
|
|
- $outCode=makeNo("CK");
|
|
|
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
|
|
|
- if($orderCode==""){
|
|
|
- return error_show(1002,"参数orderCoder不能为空");
|
|
|
+ $outCode = isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode']) :"";
|
|
|
+ if($outCode==""){
|
|
|
+ return error_show(1002,"参数outCode不能为空");
|
|
|
}
|
|
|
- $der = Db::name('sale')->where(['orderCode'=>$orderCode])->find();
|
|
|
+ $der = Db::name('order_out')->where(['outCode'=>$outCode])->find();
|
|
|
if($der==""){
|
|
|
- return error_show(1002,"未找到出库订单单号");
|
|
|
+ return error_show(1002,"未找到出库单数据");
|
|
|
}
|
|
|
- if($der['order_type']!=2){
|
|
|
- return error_show(1002,"订单不是咨询单无法出库");
|
|
|
- }
|
|
|
- $wsm= Db::name('sale_info')->where(['orderCode'=>$der['orderCode']])->find();
|
|
|
- if(empty($wsm)){
|
|
|
- return error_show(1002,"未找到仓库信息");
|
|
|
+ $order= Db::name('sale')->where(['orderCode'=>$der['orderCode']])->find();
|
|
|
+ if(empty($order)){
|
|
|
+ return error_show(1002,"未找到咨询订单信息");
|
|
|
+ }
|
|
|
+ $stock= Db::name("good_stock")->where(["good_type_code"=>$order['good_code'],"wsm_code"=>$der['wsm_code']])
|
|
|
+ ->find();
|
|
|
+ // echo Db::name("good_stock")->getLastSql();
|
|
|
+ if(empty($stock)){
|
|
|
+ return error_show(1002,"未找到仓库库存信息");
|
|
|
+ }
|
|
|
+ if($der['send_num'] > $stock['wait_out_stock']){
|
|
|
+ return error_show(1002,"仓库库存不足");
|
|
|
}
|
|
|
-// $stock= Db::name("good_stock")->where(["good_type_code"=>$der['good_code'],"wsm_code"=>$wsm['wsm_code']])
|
|
|
-// ->find();
|
|
|
-// if(empty($stock)){
|
|
|
-// return error_show(1002,"未找到仓库库存信息");
|
|
|
-// }
|
|
|
$post_name= isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"";
|
|
|
if($post_name==""){
|
|
|
return error_show(1002,"物流公司不能为空");
|
|
@@ -394,90 +395,46 @@ class Salezx extends \app\BaseController
|
|
|
return error_show(1002,"物流费不能为空");
|
|
|
}
|
|
|
|
|
|
- $apply_id =GetUserInfo($token);
|
|
|
- if(empty($apply_id)||$apply_id['code']!=0){
|
|
|
- return error_show(1002,"申请人数据不存在");
|
|
|
- }
|
|
|
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
|
|
|
- $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
|
|
|
- if($der['send_type']==1){
|
|
|
- $addrid = isset($this->post['addrid']) && $this->post['addrid'] !=="" ? intval($this->post['addrid']) :"";
|
|
|
- $dr = Db::name('order_addr')->where(['id'=>$addrid,"orderCode"=>$orderCode,'is_del'=>0])->find();
|
|
|
- if(empty($dr)){
|
|
|
- return error_show(1003,"收货人信息未找到");
|
|
|
- }
|
|
|
- $send_num = $dr['receipt_quantity'];
|
|
|
- }else{
|
|
|
- $send_num = isset($this->post['send_num']) && $this->post['send_num'] !=="" ? $this->post['send_num'] :"";
|
|
|
- if($send_num==""){
|
|
|
- return error_show(1002,"发货数量不能为空");
|
|
|
- }
|
|
|
- }
|
|
|
-// if($send_num>$stock['usable_stock']){
|
|
|
-// return error_show(1002,"超出可发货数量");
|
|
|
-// }
|
|
|
$sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !=="" ? $this->post['sendtime']:date("Y-m-d H:i:s");
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"1";
|
|
|
+ // $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"1";
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
- $data=[
|
|
|
- "wsm_code"=>$wsm['wsm_code'],
|
|
|
- "orderCode"=>$orderCode,
|
|
|
- "outCode"=>$outCode,
|
|
|
- "order_type"=>$der['order_type'],
|
|
|
- "apply_id"=>$rm,
|
|
|
- "apply_name"=>$ri,
|
|
|
- "addrid"=>$dr['id'],
|
|
|
- "post_name"=>$post_name,
|
|
|
- "post_code"=>$post_code,
|
|
|
- "post_fee"=>$post_fee,
|
|
|
- "sendtime"=>$sendtime,
|
|
|
- "send_num"=>$send_num,
|
|
|
- "check_num"=>0,
|
|
|
- "error_num"=>0,
|
|
|
- "status"=>$status,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- $datainfo = Db::name('order_out')->insert($data);
|
|
|
+ $der['post_name'] = $post_name;
|
|
|
+ $der['post_code'] = $post_code;
|
|
|
+ $der['post_fee'] = $post_fee;
|
|
|
+ $der['sendtime'] = $sendtime;
|
|
|
+ $der['status'] = 1;
|
|
|
+ $der['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $datainfo = Db::name('order_out')->save($der);
|
|
|
if($datainfo) {
|
|
|
- if ($status==1) {
|
|
|
-
|
|
|
- $var = Db::name('sale_info')->where(['orderCode' =>$orderCode,'wsm_code'=>$wsm['wsm_code']])->find();
|
|
|
- //var_dump(Db::name('sale_info')->getLastSql());
|
|
|
- if($var==""){
|
|
|
- return error_show(1002,"未找到数据");
|
|
|
- }
|
|
|
- $send =Db::name("order_out")->where(["wsm_code"=>$wsm['wsm_code'],'orderCode'=>$orderCode])->sum("send_num");
|
|
|
- $der['send_num']+= $send;
|
|
|
- $der['wsend_num']-=$send ;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
|
|
|
- $der['send_status']=$der['send_num']==0 ? 1 :($der['wsend_num']==0?3:2);
|
|
|
- $der['status']=$der['send_num']==0 ? 3 :($der['wsend_num']==0?5:4);
|
|
|
- $der['updatetime'] = date("Y-m-d H:i:s");
|
|
|
- $si = Db::name('sale')->save($der);
|
|
|
+ $send =Db::name("order_out")->where(["wsm_code"=>$der['wsm_code'],'orderCode'=>$der['orderCode']])->sum("send_num");
|
|
|
+ $order['send_num']+= $send;
|
|
|
+ $order['wsend_num']-=$send ;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
|
|
|
+ $order['send_status']=$order['send_num']==0 ? 1 :($order['wsend_num']==0?3:2);
|
|
|
+ $order['status']=$order['send_num']==0 ? 3 :($order['wsend_num']==0?5:4);
|
|
|
+ $order['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $si = Db::name('sale')->save($order);
|
|
|
if($si==false){
|
|
|
Db::rollback();
|
|
|
return error_show(1003,"更新失败");
|
|
|
}
|
|
|
- $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'],'good_type_code'=>$der['good_code']])->find();
|
|
|
+ $str = Db::name('good_stock')->where(['wsm_code' => $der['wsm_code'],'good_type_code'=>$order['good_code']])->find();
|
|
|
if ($str == false) {
|
|
|
Db::rollback();
|
|
|
return error_show(1002, "商品数据未找到");
|
|
|
}
|
|
|
- if ($var['num'] > $str['usable_stock']) {
|
|
|
+ if ($der['send_num'] > $str['wait_out_stock']) {
|
|
|
Db::rollback();
|
|
|
return error_show(1002, "超出库存数量");
|
|
|
}
|
|
|
- $str['wait_out_stock'] -= $var['num'];
|
|
|
- $str['intra_stock'] += $var['num'];
|
|
|
+ $str['wait_out_stock'] -= $der['send_num'];
|
|
|
+ $str['intra_stock'] += $der['send_num'];
|
|
|
$str['updatetime'] = date("Y-m-d H:i:s");
|
|
|
$stre = Db::name('good_stock')->save($str);
|
|
|
if ($stre == false) {
|
|
|
Db::rollback();
|
|
|
return error_show(1002, "状态更新失败");
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
Db::commit();
|
|
|
return error_show(0,"创建成功");
|
|
|
}else{
|
|
@@ -489,4 +446,133 @@ class Salezx extends \app\BaseController
|
|
|
return error_show(1005, $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public function outaddr(){
|
|
|
+ $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
|
|
|
+ $outCode=makeNo("CK");
|
|
|
+ $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
|
|
|
+ if($orderCode==""){
|
|
|
+ return error_show(1002,"参数orderCoder不能为空");
|
|
|
+ }
|
|
|
+ $der = Db::name('sale')->where(['orderCode'=>$orderCode])->find();
|
|
|
+ if($der==""){
|
|
|
+ return error_show(1002,"未找到出库订单单号");
|
|
|
+ }
|
|
|
+ if($der['order_type']!=2){
|
|
|
+ return error_show(1002,"订单不是咨询单无法出库");
|
|
|
+ }
|
|
|
+ $wsm= Db::name('sale_info')->where(['orderCode'=>$der['orderCode']])->find();
|
|
|
+ if(empty($wsm)){
|
|
|
+ return error_show(1002,"未找到仓库信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ $apply_id =GetUserInfo($token);
|
|
|
+ if(empty($apply_id)||$apply_id['code']!=0){
|
|
|
+ return error_show(1002,"申请人数据不存在");
|
|
|
+ }
|
|
|
+ $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
|
|
|
+ $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
|
|
|
+
|
|
|
+ if($der['send_type']==2){
|
|
|
+ $contactor= isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor'])
|
|
|
+ :"";
|
|
|
+ if($contactor==""){
|
|
|
+ return error_show(1002,"收货人不能为空");
|
|
|
+ }
|
|
|
+ $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile'])
|
|
|
+ :"";
|
|
|
+ if($mobile==""){
|
|
|
+ return error_show(1002,"收货人联系方式不能为空");
|
|
|
+ }
|
|
|
+ $addr = isset($this->post['addr']) && $this->post['addr'] !=="" ? trim($this->post['addr']) :"";
|
|
|
+ if($addr==""){
|
|
|
+ return error_show(1002,"参数addr不能为空");
|
|
|
+ }
|
|
|
+ $receipt_quantity= isset($this->post['receipt_quantity']) && $this->post['receipt_quantity'] !=="" ? intval
|
|
|
+ ($this->post['receipt_quantity']) :"";
|
|
|
+ if($receipt_quantity===""){
|
|
|
+ return error_show(1002,"参数receipt_quantity不能为空");
|
|
|
+ }
|
|
|
+ $addrcode = isset($this->post['addr_code']) && $this->post['addr_code'] !=="" ? $this->post['addr_code'] :"";
|
|
|
+ if($addrcode==""){
|
|
|
+ return error_show(1002,"参数addr_code不能为空");
|
|
|
+ }
|
|
|
+ $addrs=[];
|
|
|
+ if(is_array($addrcode)){
|
|
|
+ $addrs['provice_code'] = $addrcode['addr_code'][0];
|
|
|
+ $addrs['city_code'] = $addrcode['addr_code'][1];
|
|
|
+ $addrs['area_code'] = $addrcode['addr_code'][2];
|
|
|
+ $addrstr = json_encode($addrs);
|
|
|
+ }else{
|
|
|
+ $addrstr = $addrcode;
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $addrid = isset($this->post['addrid']) && $this->post['addrid'] !=="" ? intval($this->post['addrid']) :"";
|
|
|
+ $dr = Db::name('order_addr')->where(['id'=>$addrid,"orderCode"=>$orderCode,'is_del'=>0])->find();
|
|
|
+ if(empty($dr)){
|
|
|
+ return error_show(1003,"收货人信息未找到");
|
|
|
+ }
|
|
|
+ $receipt_quantity = $dr['receipt_quantity'];
|
|
|
+ }
|
|
|
+// if($send_num>$stock['usable_stock']){
|
|
|
+// return error_show(1002,"超出可发货数量");
|
|
|
+// }
|
|
|
+ $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !=="" ? $this->post['sendtime']:date("Y-m-d H:i:s");
|
|
|
+ // $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"1";
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ if($der['send_type']==2){
|
|
|
+ $addr=[
|
|
|
+ "orderCode"=>$orderCode,
|
|
|
+ "addr"=>$addr,
|
|
|
+ "addr_code"=>$addrstr,
|
|
|
+ "contactor"=>$contactor,
|
|
|
+ "mobile"=>$mobile,
|
|
|
+ "customer_code"=>$der['customer_code'],
|
|
|
+ "post_fee"=>0,
|
|
|
+ "is_del"=>0,
|
|
|
+ "receipt_quantity"=>$receipt_quantity,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
+ "arrive_time"=>date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ $addrid = Db::name('order_addr')->insert($addr,true);
|
|
|
+ if($addrid<=0){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"创建失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $data=[
|
|
|
+ "wsm_code"=>$wsm['wsm_code'],
|
|
|
+ "orderCode"=>$orderCode,
|
|
|
+ "outCode"=>$outCode,
|
|
|
+ "order_type"=>$der['order_type'],
|
|
|
+ "apply_id"=>$rm,
|
|
|
+ "apply_name"=>$ri,
|
|
|
+ "addrid"=>$addrid,
|
|
|
+ "post_name"=>'',
|
|
|
+ "post_code"=>'',
|
|
|
+ "post_fee"=>'',
|
|
|
+ "sendtime"=>$sendtime,
|
|
|
+ "send_num"=>$receipt_quantity,
|
|
|
+ "check_num"=>0,
|
|
|
+ "error_num"=>0,
|
|
|
+ "status"=>0,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $datainfo = Db::name('order_out')->insert($data);
|
|
|
+ if(!$datainfo){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"创建失败");
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return error_show(0,"创建成功");
|
|
|
+ }catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|