post=$this->request->post(); } public function create(){ $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):""; $orderCode=makeNo("QR"); $customer_code= isset($this->post['customer_code'])&& $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :""; if($customer_code==""){ return error_show(1002,"客户code不能为空"); } $zxinfoNo= isset($this->post['zxinfoNo'])&& $this->post['zxinfoNo'] !=="" ? trim($this->post['zxinfoNo']) :""; if($zxinfoNo==""){ return error_show(1002,"参数zxinfoNo 不能为空"); } // $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find(); // if($customer==false){ // return error_show(1004,"未找到客户数据"); // } $supplierNo= isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :""; if($supplierNo==""){ return error_show(1002,"参数supplierNo不能为空"); } // $supplier=Db::name("business")->where(["companyNo"=>$supplierNo])->find(); // if($supplier==false){ // return error_show(1004,"未找到平台供应商数据"); // } $sendtype =isset($this->post['sendtype']) && $this->post['sendtype'] !=="" ?trim($this->post['sendtype']):""; if($sendtype==''){ return error_show(1004,"参数sendtype不能为空"); } $platform_id =isset($this->post['platform_id']) && $this->post['platform_id'] !=="" ?intval($this->post['platform_id']):""; if($platform_id==''){ return error_show(1004,"参数platform_id不能为空"); } $platform_order =isset($this->post['platform_order']) && $this->post['platform_order'] !=="" ?trim($this->post['platform_order']):""; if($platform_order==''){ return error_show(1004,"参数platform_order不能为空"); } $good_code =isset($this->post['good_code']) && $this->post['good_code'] !=="" ?trim($this->post['good_code']):""; if($good_code==''){ return error_show(1004,"参数good_code不能为空"); } $good=Db::name("good_zixun")->where(["spuCode"=>$good_code])->find(); if($good==false){ return error_show(1004,"未找到商品数据"); } $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$good['spuCode'],"is_del"=>0])->find(); if($goodinfo==false){ return error_show(1004,"未找到商品数据"); } $good_num =isset($this->post['good_num']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):""; if($good_num===''){ return error_show(1004,"参数good_num不能为空"); } $good_num =isset($this->post['p']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):""; if($good_num===''){ return error_show(1004,"参数good_num不能为空"); } // $goodtype =isset($this->post['goodtype']) && $this->post['goodtype'] !=="" ?intval($this->post['goodtype']):""; // if($goodtype===''){ // return error_show(1004,"参数goodtype不能为空"); // } $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:""; if($arrtime==""){ return error_show(1004,"参数arrtime不能为空"); } $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):""; if($sendtype==1){ $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:""; if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){ return error_show(1004,"参数addrlist不能为空"); } } $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'] : ""; Db::startTrans(); try { $userCommon = \app\admin\common\User::getIns(); $tmp = $userCommon->handle('sInfo',['code'=>$good['supplierNo']]); if(!isset($tmp['code']) || $tmp['code']!=0) throw new Exception($tmp['message']); $supplier_temp_info = $tmp['data']; // $supplier_temp_info=Db::name("supplier") // ->field('id,person,personid') // ->where(["code"=>$good['supplierNo']]) // ->findOrEmpty(); $data=[ "orderCode"=>$orderCode, "good_code"=>$good_code, "customer_code"=>$customer_code, "good_name"=>isset($good['good_name'])&&$good['good_name']!==''?$good['good_name']:'', "good_num"=>$good_num, "cat_id"=>$goodinfo['cat_id'], "apply_id"=>$rm, "apply_name"=>$ri, "origin_price"=>$goodinfo['total_fee'], "sale_price"=>$goodinfo['sale_price'], "post_fee"=>0, "status"=>0, "send_num"=>0, "wsend_num"=>$good_num, "send_status"=>1, "good_type"=>1, "send_type"=>$sendtype, "supplierNo"=>$supplierNo, "is_del"=>0, "zxNo"=>$zxinfoNo, "platform_order"=>$platform_order, "platform_id"=>$platform_id, "remark"=>$remark, "order_type"=>2,//非库存品 "order_source"=>2,//咨询 "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), 'total_price'=>round($goodinfo['sale_price']*$good_num,2), 'cgderid' => $supplier_temp_info['personid'], 'cgder' => $supplier_temp_info['person'],//采购员(采购单对应的供应商负责人) 'good_createrid' => $good['createrid'], 'good_creater' => $good['creater'],//商品创建人id ]; $datainfo = Db::name('sale')->insert($data,true); $vat=[]; if($datainfo>0){ $standing_bood_data=[ "orderCode"=>$orderCode, "sale_id"=>$datainfo, "customer_code"=>$customer_code, "supplierNo"=>$supplierNo, "order_type"=>$data['order_type'], "order_source"=>$data['order_source'], "spuCode"=>$good_code, 'updatetime'=>date("Y-m-d H:i:s"), ]; $bol= $this->createCgd($data,$good,$goodinfo,$standing_bood_data); if($bol==false){ Db::rollback(); return error_show(1002,"咨询订单创建失败"); } if($sendtype!=2){ foreach ($addrlist as $value){ $temp=[]; $addrs=[]; if($value['addr_code']!==''&&is_array($value['addr_code'])){ $addrs['provice_code'] = $value['addr_code'][0]; $addrs['city_code'] = $value['addr_code'][1]; $addrs['area_code'] = $value['addr_code'][2]; $addr = json_encode($addrs); }else{ $addr = isset($value['addr_code'])?$value['addr_code']:''; } $temp['orderCode']=$orderCode; $temp['contactor']=$value['contactor']; $temp['mobile'] = $value['mobile']; $temp['addr'] = $value['addr']; $temp['addr_code']=$addr; $temp['customer_code'] =$customer_code; $temp['receipt_quantity']=$value['receipt_quantity']; $temp['post_fee'] =0; $temp['is_del'] =0; $temp['addtime'] =date("Y-m-d H:i:s"); $temp['updatetime'] =date("Y-m-d H:i:s"); $temp['arrive_time']=$value['arrive_time']; $vmp = Db::name('order_addr')->insert($temp,true); if($vmp>0){ $outCode=makeNo("DF"); $out=[ "orderCode"=>$orderCode, "outCode"=>$outCode, "apply_id"=>$rm, "apply_name"=>$ri, "addrid"=>$vmp, "post_name"=>"", "post_code"=>"", "post_fee"=>0, "sendtime"=>date("Y-m-d H:i:s"), "send_num"=>$value['receipt_quantity'], "check_num"=>0, "error_num"=>0, "wsm_code"=>"", "order_type"=>2, "status"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $ou =Db::name("order_out")->insertGetId($out); if($ou==false){ Db::rollback(); return error_show(1002,"咨询订单创建失败"); }else{ //修改状态,添加待办 ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [ "order_code" => $outCode,//出库单号 "status" => $out['status'],//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "create"//新建create,编辑edit,更改状态status ], "CKD", $out['status'], $out); ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [ "order_type" => 'CKD', "order_code" => $outCode,//出库单号 "order_id" => $ou, "order_status" => $out['status'], 'before_status'=>0, 'holder_id' => $out['apply_id'] ]); $standing_bood_data['outCode'][]=$outCode; } }else{ Db::rollback(); return error_show(1002,"咨询订单创建失败"); } } } //修改状态,添加待办 ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [ "order_code" => $orderCode,//销售单code "status" => 0,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "create"//新建create,编辑edit,更改状态status ], "XSQRD", 0, $data); ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [ "order_type" => 'XSQRD', "order_code" => $orderCode,//销售单code "order_id" => $datainfo, "order_status" => 0, 'holder_id=' => $data['apply_id'] ]); //根据zxinfoNo查找infoNo,找到则更新台账,否则就新增台账 if (isset($standing_bood_data['outCode'])) $standing_bood_data['outCode'] = implode(',', $standing_bood_data['outCode']); $infoNo = Db::name('consult_bids')->where('bidNo', $zxinfoNo)->value('infoNo'); if (empty($infoNo)) Db::name('standing_book')->insert(array_merge($standing_bood_data, ['addtime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo("IO")])); else Db::name('standing_book')->where('infoNo', $infoNo)->update($standing_bood_data); //将采购单数据塞入到队列中 if ($this->cgd_data) { $push_data = json_encode([ 'supplierNo' => $this->cgd_data['supplierNo'], 'type' => 1,//1销售订单(采销的采购单),2上线结果 'data' => [ 'cgdNo' => $this->cgd_data['cgdNo'], 'spuCode' => $this->cgd_data['spuCode'], 'good_name' => $this->cgd_data['good_name'], 'good_num' => $this->cgd_data['good_num'], 'good_price' => $this->cgd_data['good_price'], 'total_fee' => $this->cgd_data['total_fee'], 'weight' => $this->cgd_data['weight'], 'addtime' => $this->cgd_data['addtime'], ], ], JSON_UNESCAPED_UNICODE); // Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data); } Db::commit(); return error_show(0,"咨询订单创建成功"); } Db::rollback(); return error_show(1002,"咨询订单创建失败"); }catch(\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } public function createCgd($data,$good,$good_info,array &$standing_bood_data=[]){ $cgdCode = makeNo("CG"); $supplier=Db::name("supplier")->where(["code"=>$good['supplierNo'],"is_del"=>0])->find(); if($supplier==false){ return false; } $wsm= Db::name("warehouse_info")->where(["supplierNo"=>$good["supplierNo"],"companyNo"=>$data['supplierNo'],"is_del"=>0])->find(); if($wsm==false){ $wsm_code = makeNo("WSM"); $inwsm=[ "wsm_code"=>$wsm_code, "name"=>$supplier['name'], "wsm_type"=>2, "supplierNo"=>$supplier['code'], "addr"=>"", "addrs_code"=>"", "contactor"=>0, "contactor_name"=>0, "mobile"=>"", "position"=>"", "companyNo"=>$data['supplierNo'], "status"=>1, "is_del"=>0, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $in = Db::name("warehouse_info")->insert($inwsm); if($in==false){ return false; } }else{ $wsm_code =$wsm['wsm_code']; } $cg =["cgdNo"=>$cgdCode, "bkcode"=>"", "wsm_code"=>$wsm_code, "cgder"=>$supplier['person'], "cgder_id"=>$supplier['personid'], "good_code"=>$good['spuCode'], "good_name"=>$good['good_name'], "good_num"=>$data['good_num'], "good_price"=>$good_info['sale_price'], "total_fee"=>$good_info['total_fee'], "pakge_fee"=>$good_info['pakge_fee'], "cert_fee"=>$good_info['cert_fee'], "open_fee"=>$good_info['open_fee'], "delivery_fee"=>$good_info['delivery_fee'], "mark_fee"=>$good_info['mark_fee'], "demo_fee"=>$good_info['demo_fee'], #"weight"=>$data['weight'], "diff_weight"=>"0", "diff_fee"=>"0", "gold_price"=>"0", "supplierNo"=>$good['supplierNo'], "supplier_name"=>$supplier['name'], "send_status"=>1, "send_num"=>"0", "wsend_num"=>$data['good_num'], "remark"=>"", "status"=>0, "lasttime"=>date("Y-m-d H:i:s"), "is_del"=>0, "order_type"=>$data['order_type'], "order_source"=>$data['order_source'], "good_type"=>$good['good_type'], "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s"), 'good_createrid' => $good['createrid'], 'good_creater' => $good['creater'],//商品创建人 ]; $up =Db::name("purchease_order")->insert($cg,true); if($up){ //修改状态,添加待办 ActionLog::logAdd($this->post['token'], [ "order_code" => $cg['cgdNo'],//销售单code "status" => 0,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "create"//新建create,编辑edit,更改状态status ], "CGD", $cg['status'], $cg); //当采购单是节点0待与供应商确认,推给供应商负责人 ProcessOrder::AddProcess($this->post['token'], [ "order_type" => 'CGD', "order_code" => $cg['cgdNo'],//销售单code "order_id" => $up, "order_status" => $cg['status'], 'holder_id'=>$supplier['personid'], 'wait_id'=>$supplier['personid'], 'wait_name'=>$supplier['person'], ]); $standing_bood_data['cgdNo']=$cgdCode; $this->cgd_data = $cg; return true; }else{ return false; } } // public function edit(){ // $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):""; // // $zxNo=isset($this->post['id']) && $this->post['id'] !=="" ?intval($this->post['id']):""; // if($zxNo==''){ // return error_show(1004,"参数id不能为空"); // } // $saleinfo = Db::name("sale")->where(["id"=>$zxNo,"is_del"=>0])->find(); // if($saleinfo==false){ // return error_show(1003,"未找到咨询单数据"); // } // $zxinfo = Db::name("consult")->where(["zxNo"=>$saleinfo['zxNo'],"is_del"=>0])->find(); // if($zxinfo==false){ // return error_show(1004,"未找到咨询单数据"); // } // $customer_code= $this->post['customer_code'] && $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :""; // if($customer_code==""){ // return error_show(1002,"客户code不能为空"); // } // $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find(); // if($customer==false){ // return error_show(1004,"未找到客户数据"); // } // $supplierNo= $this->post['supplierNo'] && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :""; // if($supplierNo==""){ // return error_show(1002,"参数supplierNo不能为空"); // } // $supplier=Db::name("supplier")->where(["code"=>$supplierNo])->find(); // if($supplier==false){ // return error_show(1004,"未找到平台供应商数据"); // } // $wsm=Db::name("warehouse_info")->where(["supplierNo"=>$zxinfo['gysNo'],"wsm_type"=>2])->find(); // if(empty($wsm)){ // return error_show(1004,"未找到供应商仓库数据"); // } // $sendtype =isset($this->post['sendtype']) && $this->post['sendtype'] !=="" ?trim($this->post['sendtype']):""; // if($sendtype==''){ // return error_show(1004,"参数sendtype不能为空"); // } // $good_num =isset($this->post['good_num']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):""; // if($good_num===''){ // return error_show(1004,"参数good_num不能为空"); // } // $goodtype =isset($this->post['goodtype']) && $this->post['goodtype'] !=="" ?intval($this->post['goodtype']):""; // if($goodtype===''){ // return error_show(1004,"参数goodtype不能为空"); // } // $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):""; // if($sendtype!=2){ // $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:""; // if($addrlist=="" || empty($addrlist)){ // return error_show(1004,"参数addrlist不能为空"); // } // } // $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'] : ""; // Db::startTrans(); // try { // $data=[ // "customer_code"=>$customer_code, // "good_num"=>$good_num, // "apply_id"=>$rm, // "apply_name"=>$ri, // "wsend_num"=>$good_num, // "good_type"=>$goodtype, // "send_type"=>$sendtype, // "supplierNo"=>$supplierNo, // "remark"=>$remark, // "updatetime"=>date("Y-m-d H:i:s"), // 'total_price'=>round($zxinfo['last_price']*$good_num,2), // ]; // $datainfo = Db::name('sale')->where(["id"=>$zxNo])->save($data); // if($datainfo!=false){ // $st = ["order_code"=>$saleinfo['orderCode'],"status"=>0,"action_remark"=>'',"action_type"=>"edit"]; // ActionLog::logAdd($this->post['token'],$st,"ZXQRD",0,$data); // $order=["order_type"=>"ZXQRD","order_code"=>$saleinfo['orderCode'],"order_id"=>$saleinfo['id'],"order_status"=>$saleinfo['status']]; // ProcessOrder::AddProcess($this->post['token'],$order); // $saleinfos=[ // "wsm_code"=>$wsm['wsm_code'], // "num"=>$good_num, // "sale_price"=>$zxinfo['last_price'], // "total_price"=>round($zxinfo['last_price']*$good_num,2), // "updatetime"=>date("Y-m-d H:i:s"), // ]; // $info = Db::name("sale_info")->where(["orderCode"=>$saleinfo['orderCode']])->save($saleinfos); // if($info==false){ // Db::rollback(); // return error_show(1002,"咨询订单创建失败"); // } // if($sendtype!=2){ // foreach ($addrlist as $value){ // $temp=[]; // $addrs=[]; // if($value['addr_code']!==''&&is_array($value['addr_code'])){ // $addrs['provice_code'] = $value['addr_code'][0]; // $addrs['city_code'] = $value['addr_code'][1]; // $addrs['area_code'] = $value['addr_code'][2]; // $addr = json_encode($addrs); // }else{ // $addr = isset($value['addr_code'])?$value['addr_code']:''; // } // isset($value["id"])&&$value["id"]!=""? $temp['id']=$value['id']:""; // $temp['contactor']=$value['contactor']; // $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){ // Db::rollback(); // return error_show(0,"咨询订单地址更新失败"); // } // } // }else{ // if($saleinfo['send_type']==1 && $sendtype==2){ // $up=Db::name('order_addr')->where(["orderCode"=>$saleinfo['orderCode']])->save(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]); // if(!$up){ // Db::rollback(); // return error_show(0,"咨询订单地址更新失败"); // } // } // } // Db::commit(); // return error_show(0,"咨询订单更新成功"); // } // Db::rollback(); // return error_show(1002,"咨询订单更新失败"); // }catch(\Exception $e){ // Db::rollback(); // return error_show(1005,$e->getMessage()); // } // } public function out(){ $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :""; $outCode = isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode']) :""; if($outCode==""){ return error_show(1002,"参数outCode不能为空"); } $der = Db::name('order_out')->where(['outCode'=>$outCode])->find(); if($der==""){ 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(["spuCode"=>$order['good_code'],"wsm_code"=>$der['wsm_code']]) ->find(); if(empty($stock)){ return error_show(1002,"未找到仓库库存信息"); } if($der['send_num'] > $stock['wait_out_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,"物流公司不能为空"); } $post_code = isset($this->post['post_code']) && $this->post['post_code'] !=="" ? trim($this->post['post_code']) :""; if($post_code==""){ return error_show(1002,"物流单号不能为空"); } $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? intval($this->post['post_fee']) :""; if($post_fee==""){ 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 { $var = $der['status']; $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); $st = ["order_code"=>$outCode,"status"=>$var,"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$st,"resign_info",$der['status'] ,$st); if($datainfo) { $st = ["order_code"=>$der['outCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$st,"CKD",1,$der); //是否库存品,待办数据推送到的人有区别, $ord = []; // if ($order['is_stock'] == 1) { // //库存品,推给库管和库管-张凯旋 // $roleid = config('app.wsm_cgder_role'); // $uids = Db::name('user_role') // ->where('is_del', 0) // ->whereIn('roleid', $roleid) // ->column('uid'); // $ord = ["order_type" => "CKD", "order_code" => $der['outCode'], "order_id" => $der['id'], "order_status" => $der['status'], 'holder_id' => $der['apply_id'], 'handle_user_list' => implode(',', $uids)]; // } elseif ($order['is_stock'] == 0 || $order['order_typee'] == 3) { //推给供应商负责人 // $supplier = Db::name('supplier') // ->alias('a') // ->field('a.id,a.person,a.personid') // ->leftJoin('purchease_order b', 'b.is_del=0 AND b.supplierNo=a.code') // ->leftJoin('order_num c', 'c.cgdNo=b.cgdNo') // ->where('c.orderCode', $der['orderCode']) // ->findOrEmpty(); //查找供应商编码 $supplierNo = Db::name('order_num') ->alias('a') ->where(['a.orderCode'=>$der['orderCode']]) ->leftJoin('purchease_order b','b.is_del=0 AND b.cgdNo=a.cgdNo') ->value('supplierNo',''); if($supplierNo !=''){ $userCommon=\app\admin\common\User::getIns(); $tmp = $userCommon->handle('sInfo',['code'=>$supplierNo]); if(isset($tmp['data'])){ $ord = ["order_type" => "CKD", "order_code" => $der['outCode'], "order_id" => $der['id'], "order_status" => $der['status'], 'holder_id' => $der['apply_id'], 'wait_id' => $tmp['data']['personid'], 'wait_name' => $tmp['data']['person']]; ProcessOrder::AddProcess($this->post['token'], $ord); } } // } // if (empty($ord)) $ord = ["order_type" => "CKD", "order_code" => $der['outCode'], "order_id" => $der['id'], "order_status" => $der['status'], 'holder_id' => $der['apply_id']]; // $send =Db::name("order_out")->where(["wsm_code"=>$der['wsm_code'],'orderCode'=>$der['orderCode']])->sum("send_num"); // $order['send_num']+= $der['send_num']; // $order['wsend_num']-=$der['send_num'] ;//($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 ? 2 :($order['wsend_num']==0?4:3); // $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' => $der['wsm_code'],'spuCode'=>$order['good_code']]) ->find(); if ($str == false) { Db::rollback(); return error_show(1002, "商品数据未找到"); } if ($der['send_num'] > $str['wait_out_stock']) { Db::rollback(); return error_show(1002, "超出库存数量"); } $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, "状态更新失败"); } //商品变动日志表,good_log_code字段存储销售订单编号 $good_data[] = ['good_log_code' => $outCode, "stock_id" => $str['id'], "type" => 1, 'stock' => $der['send_num'], "stock_name" => "intra_stock"]; $good_data[] = ['good_log_code' => $outCode, "stock_id" => $str['id'], "type" => 2, 'stock' => $der['send_num'], "stock_name" => "wait_out_stock"]; GoodLog::LogAdd($this->post['token'], $good_data, 'CKD'); Db::commit(); return error_show(0,"创建成功"); }else{ Db::rollback(); return error_show(1003,"创建失败"); } }catch (\Exception $e) { Db::rollback(); return error_show(1005, $e->getMessage()); } } public function outaddr(){ $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :""; $outCode=makeNo("DF"); $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){ $st = ["order_code"=>$orderCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"]; ActionLog::logAdd($this->post['token'],$st,"zxd",0,$st); 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,true); if($datainfo<=0){ Db::rollback(); return error_show(1003,"创建失败"); } $sio = ["order_code"=>$outCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"]; ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri],$sio,"CKD",0,$data); $order=["order_type"=>"CKD","order_code"=>$data['outCode'],"order_id"=>$datainfo,"order_status"=>$data['status'],'before_status'=>0, 'holder_id' => $data['apply_id']]; ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri],$order); $item = $der['status']; $der['send_num']+= $receipt_quantity; $der['wsend_num']-=$receipt_quantity;//($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 ? 2 :($der['wsend_num']==0?4:3); $der['updatetime'] = date("Y-m-d H:i:s"); $si = Db::name('sale')->save($der); if($si==false){ Db::rollback(); return error_show(1003,"创建失败"); }else{ //修改状态,添加待办 ActionLog::logAdd($this->post['token'], [ "order_code" => $der['orderCode'],//销售单code "status" => $item,//这里的status是之前的值 "action_remark" => '',//备注 "action_type" => "status"//新建create,编辑edit,更改状态status ], "XSQRD", $der['status'], $der); ProcessOrder::AddProcess($this->post['token'], [ "order_type" => 'XSQRD', "order_code" => $der['orderCode'],//销售单code "order_id" => $der['id'], "order_status" => $der['status'], 'holder_id=' => $der['apply_id'] ]); } $sio = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"]; ActionLog::logAdd($this->post['token'],$sio,"zxd",$der['status'],$der); $order=["order_type"=>"CKD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$der['status'], 'holder_id' => $data['apply_id']]; ProcessOrder::AddProcess($this->post['token'],$order); Db::commit(); return error_show(0,"创建成功"); }catch (\Exception $e) { Db::rollback(); return error_show(1005, $e->getMessage()); } } }