|
@@ -244,7 +244,7 @@ class Sale extends BaseController
|
|
if($good_code==""){
|
|
if($good_code==""){
|
|
return error_show(1002,"商品code不能为空");
|
|
return error_show(1002,"商品code不能为空");
|
|
}
|
|
}
|
|
- $customer_code=isset($this->post['customer_code']) && $this->post['customer_code'] !=="" ? intval($this->post['customer_code']):"";
|
|
|
|
|
|
+ $customer_code=isset($this->post['customer_code']) && $this->post['customer_code'] !=="" ? trim($this->post['customer_code']):"";
|
|
if($customer_code==""){
|
|
if($customer_code==""){
|
|
return error_show(1002,"客户code不能为空");
|
|
return error_show(1002,"客户code不能为空");
|
|
}
|
|
}
|
|
@@ -263,11 +263,11 @@ class Sale extends BaseController
|
|
$status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
|
|
$status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
|
|
|
|
|
|
$vr= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ? $this->post['order_addr']:"";
|
|
$vr= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ? $this->post['order_addr']:"";
|
|
- if($vr==""){
|
|
|
|
|
|
+ if($vr=="" &&$etid['order_type']==1 ){
|
|
return error_show(1002,"参数order_addr不能为空");
|
|
return error_show(1002,"参数order_addr不能为空");
|
|
}
|
|
}
|
|
$vi= isset($this->post['good_stock']) && $this->post['good_stock'] !=="" ? $this->post['good_stock']:"";
|
|
$vi= isset($this->post['good_stock']) && $this->post['good_stock'] !=="" ? $this->post['good_stock']:"";
|
|
- if($vi==""){
|
|
|
|
|
|
+ if($vi=="" &&$etid['send_type']==1){
|
|
return error_show(1002,"参数good_stock不能为空");
|
|
return error_show(1002,"参数good_stock不能为空");
|
|
}
|
|
}
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
@@ -289,42 +289,44 @@ class Sale extends BaseController
|
|
"updatetime"=>date("Y-m-d H:i:s")
|
|
"updatetime"=>date("Y-m-d H:i:s")
|
|
];
|
|
];
|
|
$datninfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->save($datn);
|
|
$datninfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->save($datn);
|
|
- //$vat=[];
|
|
|
|
if($datninfo>0){
|
|
if($datninfo>0){
|
|
- foreach ($vi as $ion){
|
|
|
|
- $iten=[];
|
|
|
|
- isset($ion['id'])&&$ion['id']!=="" ? $iten['id'] = $ion['id']:'';
|
|
|
|
- $iten['orderCode']=$etid['orderCode'];
|
|
|
|
- $iten['wsm_code']=$ion['wsm_code'];
|
|
|
|
- $iten['stock_id']=$ion['stock_id'];
|
|
|
|
- $iten['num']=$ion['num'];
|
|
|
|
- $iten['status']=$ion['status'];
|
|
|
|
- $iten['sale_price']=$ion['sale_price'];
|
|
|
|
- isset($ion['id'])&&$ion['id']!=="" ? '' : $iten['addtime'] =date("Y-m-d H:i:s");
|
|
|
|
- $iten['updatetime'] =date("Y-m-d H:i:s");
|
|
|
|
- //$inn[]=$iten;
|
|
|
|
- $vp= Db::name('sale_info')->save($iten);
|
|
|
|
|
|
+ if($etid['order_type']==1) {
|
|
|
|
+ foreach ($vi as $ion) {
|
|
|
|
+ $iten = [];
|
|
|
|
+ isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
|
|
|
|
+ $iten['orderCode'] = $etid['orderCode'];
|
|
|
|
+ $iten['wsm_code'] = $ion['wsm_code'];
|
|
|
|
+ $iten['stock_id'] = $ion['stock_id'];
|
|
|
|
+ $iten['num'] = $ion['num'];
|
|
|
|
+ $iten['status'] = $ion['status'];
|
|
|
|
+ $iten['sale_price'] = $ion['sale_price'];
|
|
|
|
+ isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
|
|
|
|
+ $iten['updatetime'] = date("Y-m-d H:i:s");
|
|
|
|
+ //$inn[]=$iten;
|
|
|
|
+ $vp = Db::name('sale_info')->save($iten);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- foreach ($vr as $value){
|
|
|
|
- $temp=[];
|
|
|
|
- isset($value['id'])&&$value['id']!=="" ? $temp['id'] = $value['id']:'';
|
|
|
|
- $temp['orderCode']=$etid['orderCode'];
|
|
|
|
- $temp['contactor']=$value['contactor'];
|
|
|
|
- $temp['mobile'] = $value['mobile'];
|
|
|
|
- $temp['addr'] = $value['addr'];
|
|
|
|
- $temp['addr_code'] =$value['addr_code'];
|
|
|
|
- $temp['customer_code'] =$customer_code;
|
|
|
|
- $temp['receipt_quantity']=$value['receipt_quantity'];
|
|
|
|
- $temp['post_fee'] =0;
|
|
|
|
- $temp['is_del'] =$value['is_del'];
|
|
|
|
- isset($value['id'])&&$value['id']!=="" ? '' : $temp['addtime'] =date("Y-m-d H:i:s");
|
|
|
|
- $temp['updatetime'] =date("Y-m-d H:i:s");
|
|
|
|
- $temp['arrive_time']=date("Y-m-d H:i:s");
|
|
|
|
- $dat = Db::name('order_addr')->save($temp);
|
|
|
|
- if($dat==false){
|
|
|
|
- Db::rollback();
|
|
|
|
- return error_show(1002,"更新失败");
|
|
|
|
|
|
+ if($etid['send_type']==1){
|
|
|
|
+ foreach ($vr as $value) {
|
|
|
|
+ $temp = [];
|
|
|
|
+ isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
|
|
|
|
+ $temp['orderCode'] = $etid['orderCode'];
|
|
|
|
+ $temp['contactor'] = $value['contactor'];
|
|
|
|
+ $temp['mobile'] = $value['mobile'];
|
|
|
|
+ $temp['addr'] = $value['addr'];
|
|
|
|
+ $temp['addr_code'] = $value['addr_code'];
|
|
|
|
+ $temp['customer_code'] = $customer_code;
|
|
|
|
+ $temp['receipt_quantity'] = $value['receipt_quantity'];
|
|
|
|
+ $temp['post_fee'] = 0;
|
|
|
|
+ $temp['is_del'] = $value['is_del'];
|
|
|
|
+ isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
|
|
|
|
+ $temp['updatetime'] = date("Y-m-d H:i:s");
|
|
|
|
+ $temp['arrive_time'] = date("Y-m-d H:i:s");
|
|
|
|
+ $dat = Db::name('order_addr')->save($temp);
|
|
|
|
+ if ($dat == false) {
|
|
|
|
+ Db::rollback();
|
|
|
|
+ return error_show(1002, "更新失败");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Db::commit();
|
|
Db::commit();
|
|
@@ -365,62 +367,68 @@ class Sale extends BaseController
|
|
$fo = Db::name('order_addr')->where(['orderCode'=>$einfo['orderCode'],'is_del'=>0])->select();
|
|
$fo = Db::name('order_addr')->where(['orderCode'=>$einfo['orderCode'],'is_del'=>0])->select();
|
|
$bum = Db::name('order_out')->where(['orderCode'=>$einfo['orderCode']])->select();
|
|
$bum = Db::name('order_out')->where(['orderCode'=>$einfo['orderCode']])->select();
|
|
$ins=[];
|
|
$ins=[];
|
|
- foreach ($bum as $stn){
|
|
|
|
- $so = Db::name('order_addr')->where(['id'=>$stn['addrid']])->find();
|
|
|
|
- $addr = GetAddr($so['addr_code']);
|
|
|
|
- $stn['addr_info']=$addr;
|
|
|
|
- $stn['add_code']=json_decode($so['addr_code'],true);
|
|
|
|
- $stn['addr']=$so['addr'];
|
|
|
|
- $stn['contact']=$so['contactor'];
|
|
|
|
- $stn['mobile']=$so['mobile'];
|
|
|
|
- $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
|
|
|
|
- ->where(["a.wsm_code" => $stn['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
|
|
|
|
- $stn['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
|
|
|
|
- $stn['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
|
|
|
|
- $stn['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
|
|
|
|
- $ins[]=$stn;
|
|
|
|
|
|
+ if(!empty($bum)){
|
|
|
|
+ foreach ($bum as $stn){
|
|
|
|
+ $so = Db::name('order_addr')->where(['id'=>$stn['addrid']])->find();
|
|
|
|
+ $addr = GetAddr($so['addr_code']);
|
|
|
|
+ $stn['addr_info']=$addr;
|
|
|
|
+ $stn['add_code']=json_decode($so['addr_code'],true);
|
|
|
|
+ $stn['addr']=$so['addr'];
|
|
|
|
+ $stn['contact']=$so['contactor'];
|
|
|
|
+ $stn['mobile']=$so['mobile'];
|
|
|
|
+ $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
|
|
|
|
+ ->where(["a.wsm_code" => $stn['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
|
|
|
|
+ $stn['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
|
|
|
|
+ $stn['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
|
|
|
|
+ $stn['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
|
|
|
|
+ $ins[]=$stn;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
$addrs=[];
|
|
$addrs=[];
|
|
- foreach ($fo as $value){
|
|
|
|
- $value['addr_info']="";
|
|
|
|
- $value['send_num']=0;
|
|
|
|
- if($value['addr_code']!=""){
|
|
|
|
- $addr=GetAddr($value['addr_code']);
|
|
|
|
- $value['addr_info'] = $addr;
|
|
|
|
- $value['addr_code'] = json_decode($value['addr_code'],true);
|
|
|
|
|
|
+ if(!empty($fo)){
|
|
|
|
+ foreach ($fo as $value){
|
|
|
|
+ $value['addr_info']="";
|
|
|
|
+ $value['send_num']=0;
|
|
|
|
+ if($value['addr_code']!=""){
|
|
|
|
+ $addr=GetAddr($value['addr_code']);
|
|
|
|
+ $value['addr_info'] = $addr;
|
|
|
|
+ $value['addr_code'] = json_decode($value['addr_code'],true);
|
|
|
|
|
|
- $send = Db::name("order_out")->where(['addrid'=>$value['id'],'orderCode' => $einfo['orderCode']])->sum("send_num");
|
|
|
|
|
|
+ $send = Db::name("order_out")->where(['addrid'=>$value['id'],'orderCode' => $einfo['orderCode']])->sum("send_num");
|
|
|
|
|
|
- $value['send_num'] = $send ?? 0;
|
|
|
|
|
|
+ $value['send_num'] = $send ?? 0;
|
|
|
|
+ }
|
|
|
|
+ $value['wsend_num']=$value['receipt_quantity']-$value['send_num'];
|
|
|
|
+ $addrs[]=$value;
|
|
}
|
|
}
|
|
- $value['wsend_num']=$value['receipt_quantity']-$value['send_num'];
|
|
|
|
- $addrs[]=$value;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
//->field('num,sale_price,wsm_code,stock_id')
|
|
//->field('num,sale_price,wsm_code,stock_id')
|
|
$st = Db::name('sale_info')->where(['orderCode'=>$einfo['orderCode']])->select();
|
|
$st = Db::name('sale_info')->where(['orderCode'=>$einfo['orderCode']])->select();
|
|
$data=[];
|
|
$data=[];
|
|
- foreach ($st as $value){
|
|
|
|
- $value['wsm_name']="";
|
|
|
|
- $value['wsm_supplier']="";
|
|
|
|
- $value['wsm_supplierNo']="";
|
|
|
|
- $value['usable_stock']=0;
|
|
|
|
- $value['send_num']=0;
|
|
|
|
- if($value['wsm_code']!="") {
|
|
|
|
- $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
|
|
|
|
- ->where(["a.wsm_code" => $value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
|
|
|
|
- $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
|
|
|
|
- $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
|
|
|
|
- $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
|
|
|
|
- $dn = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $einfo['good_code']])->find();
|
|
|
|
- $value['usable_stock'] = isset($dn['usable_stock']) ? $dn['usable_stock'] : "0";
|
|
|
|
- $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
|
|
|
|
- $value['send_num'] = $send ?? 0;
|
|
|
|
- }
|
|
|
|
- $value['wsend_num']=$value['num']-$value['send_num'];
|
|
|
|
- $data[]=$value;
|
|
|
|
- }
|
|
|
|
|
|
+ if(!empty($fo)) {
|
|
|
|
+ foreach ($st as $value) {
|
|
|
|
+ $value['wsm_name'] = "";
|
|
|
|
+ $value['wsm_supplier'] = "";
|
|
|
|
+ $value['wsm_supplierNo'] = "";
|
|
|
|
+ $value['usable_stock'] = 0;
|
|
|
|
+ $value['send_num'] = 0;
|
|
|
|
+ if ($value['wsm_code'] != "") {
|
|
|
|
+ $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
|
|
|
|
+ ->where(["a.wsm_code" => $value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
|
|
|
|
+ $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
|
|
|
|
+ $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
|
|
|
|
+ $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
|
|
|
|
+ $dn = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $einfo['good_code']])->find();
|
|
|
|
+ $value['usable_stock'] = isset($dn['usable_stock']) ? $dn['usable_stock'] : "0";
|
|
|
|
+ $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
|
|
|
|
+ $value['send_num'] = $send ?? 0;
|
|
|
|
+ }
|
|
|
|
+ $value['wsend_num'] = $value['num'] - $value['send_num'];
|
|
|
|
+ $data[] = $value;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
$einfo['info']=$data;
|
|
$einfo['info']=$data;
|
|
$einfo['companyName']=isset($in['companyName']) ? $in['companyName']:"";
|
|
$einfo['companyName']=isset($in['companyName']) ? $in['companyName']:"";
|
|
$einfo['addrs']=$addrs;
|
|
$einfo['addrs']=$addrs;
|
|
@@ -461,6 +469,27 @@ class Sale extends BaseController
|
|
if(empty($dio)){
|
|
if(empty($dio)){
|
|
return error_show(1002,"销售单信息未找到");
|
|
return error_show(1002,"销售单信息未找到");
|
|
}
|
|
}
|
|
|
|
+ if($status==1 && $dio['order_type']==2) {
|
|
|
|
+ $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
|
|
|
|
+ if ($zxinfo == false) {
|
|
|
|
+ return error_show(1004, "未找到咨询单数据");
|
|
|
|
+ }
|
|
|
|
+ if ($zxinfo['zx_type'] == 2) {
|
|
|
|
+ if ($zxinfo['metals'] == "") {
|
|
|
|
+ return error_show(1004, "未找到咨询单贵金属类型数据");
|
|
|
|
+ }
|
|
|
|
+ $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
|
|
|
|
+ $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
|
|
|
|
+ if (empty($gold)) {
|
|
|
|
+ return error_show(1004, "未找到咨询单贵金属类型数据");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
|
|
|
|
+ if (empty($wsm)) {
|
|
|
|
+ return error_show(1002, "供应商仓库未找到");
|
|
|
|
+ }
|
|
|
|
+ $dio['gold_price']=$gold['gold_price'];
|
|
|
|
+ }
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
try {
|
|
try {
|
|
$dio['status']=$status;
|
|
$dio['status']=$status;
|
|
@@ -492,6 +521,49 @@ class Sale extends BaseController
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if($status==1 && $dio['order_type']==2){
|
|
|
|
+ $cgd =makeNo("CG");
|
|
|
|
+ $clll=[
|
|
|
|
+ "cgdNo"=>$cgd,
|
|
|
|
+ "bkcode"=>$dio['orderCode'],
|
|
|
|
+ "wsm_code"=>$wsm['wsm_code'],
|
|
|
|
+ "cgder_id"=>"0",
|
|
|
|
+ "cgder"=>$zxinfo['saler'],
|
|
|
|
+ "good_code"=>"GD-".$zxinfo['cpNo'],
|
|
|
|
+ "good_name"=>$zxinfo['cpName'],
|
|
|
|
+ "good_type_code"=>$zxinfo['cpNo'],
|
|
|
|
+ "good_num"=>$dio['good_num'],
|
|
|
|
+ "good_price"=>$zxinfo['total_fee'],
|
|
|
|
+ "total_fee"=>round($zxinfo['total_fee']*$dio['good_num'],2),
|
|
|
|
+ "pakge_fee"=>$zxinfo['package_fee'],
|
|
|
|
+ "cert_fee"=>$zxinfo['cert_fee'],
|
|
|
|
+ "open_fee"=>$zxinfo['open_fee'],
|
|
|
|
+ "delivery_fee"=>$zxinfo['delivery_fee'],
|
|
|
|
+ "mark_fee"=>$zxinfo['mark_fee'],
|
|
|
|
+ "teach_fee"=>$zxinfo['cost_fee'],
|
|
|
|
+ "demo_fee"=>$zxinfo['demo_fee'],
|
|
|
|
+ "nake_fee"=>$zxinfo['bare_fee'],
|
|
|
|
+ "weight"=>isset($zxinfo['weight'])?$zxinfo['weight']:0,
|
|
|
|
+ "supplierNo"=>$zxinfo['gysNo'],
|
|
|
|
+ "supplier_name"=>$zxinfo['gysname'],
|
|
|
|
+ "gold_price"=>$gold['gold_price'],
|
|
|
|
+ "send_num"=>0,
|
|
|
|
+ "wsend_num"=>$dio['good_num'],
|
|
|
|
+ "remark"=>'',
|
|
|
|
+ "lasttime"=>date("Y-m-d H:i:s"),
|
|
|
|
+ "is_del"=>0,
|
|
|
|
+ "status"=>$dio['send_type']==1?1:0,
|
|
|
|
+ "order_type"=>2,
|
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
|
+ ];
|
|
|
|
+ $cgin = Db::name("purchease_order")->insert($clll);
|
|
|
|
+ // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
|
|
|
|
+ if($cgin==false){
|
|
|
|
+ Db::rollback();
|
|
|
|
+ return error_show(1002,"咨询采购单创建商品失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
Db::commit();
|
|
Db::commit();
|
|
return error_show(0,"订单状态更新成功");
|
|
return error_show(0,"订单状态更新成功");
|