123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\facade\Db;
- use app\admin\model\ActionLog;
- class Salezx extends \app\BaseController
- {
- public $post="";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post=$this->request->post();
- }
- public function create(){
- $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
- $orderCode=makeNo("CX");
- $zxNo=isset($this->post['zxNo']) && $this->post['zxNo'] !=="" ?trim($this->post['zxNo']):"";
- if($zxNo==''){
- return error_show(1004,"参数zxNo不能为空");
- }
- $zxinfo = Db::name("consult")->where(["zxNo"=>$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=[
- "orderCode"=>$orderCode,
- "good_code"=>isset($zxinfo['cpNo'])&&$zxinfo['cpNo']!==''?$zxinfo['cpNo']:'',
- "customer_code"=>$customer_code,
- "good_name"=>isset($zxinfo['cpName'])&&$zxinfo['cpName']!==''?$zxinfo['cpName']:'',
- "good_num"=>$good_num,
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "origin_price"=>$zxinfo['sale_fee'],
- "sale_price"=>$zxinfo['last_price'],
- "post_fee"=>$zxinfo['delivery_fee'],
- "status"=>0,
- "send_num"=>0,
- "wsend_num"=>$good_num,
- "send_status"=>1,
- "good_type"=>$goodtype,
- "send_type"=>$sendtype,
- "supplierNo"=>$supplierNo,
- "is_del"=>0,
- "zxNo"=>$zxNo,
- "remark"=>$remark,
- "order_type"=>2,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'total_price'=>round($zxinfo['last_price']*$good_num,2),
- ];
- $datainfo = Db::name('sale')->insert($data,true);
- $vat=[];
- if($datainfo>0){
- $st = ["order_code"=>$orderCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$st,"zxd",0,$st);
- $addgood=$this->addGood($zxinfo);
- if($addgood==false){
- Db::rollback();
- return error_show(1002,"咨询订单创建商品失败");
- }
- $saleinfo=[
- "orderCode"=>$orderCode,
- "wsm_code"=>$wsm['wsm_code'],
- "num"=>$good_num,
- "sale_price"=>$zxinfo['last_price'],
- "total_price"=>round($zxinfo['last_price']*$good_num,2),
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $info = Db::name("sale_info")->insert($saleinfo);
- 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']:'';
- }
- $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'];
- $vat[]=$temp;
- }
- $vmp = Db::name('order_addr')->insertAll($vat);
- if($vmp){
- Db::commit();
- return error_show(0,"咨询订单创建成功");
- }
- }else{
- Db::commit();
- return error_show(0,"咨询订单创建成功");
- }
- }
- Db::rollback();
- return error_show(1002,"咨询订单创建失败");
- }catch(\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- /**咨询新建商品
- * @param $data
- * @return bool
- */
- public function addGood($data){
- $isgood = Db::name("good")->where(["good_code"=>"GD-".$data["cpNo"]])->find();
- if($isgood){
- return true;
- }
- $good=[
- "good_code"=>"GD-".$data["cpNo"],
- "item"=>'咨询订单',
- "good_name"=>$data["cpName"],
- "good_desc"=>$data["desc"],
- "brand"=>$data["brank"],
- "original_price"=>$data["sale_fee"],
- "cg_saler"=>$data["saler"],
- "good_type"=>$data["zxtype"],
- "unit"=>$data["unit"],
- "good_addr"=>$data["addr"],
- "gys_code"=>$data["gysNo"],
- "market_fee"=>$data["sale_fee"],
- "is_online"=>'产品上线',
- "sort_f"=>$data["cat_f"],
- "sort_s"=>$data["cat_s"],
- "cat_id"=>$data["cat_id"],
- "status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $insert = Db::name("good")->insert($good);
- if($insert){
- $st = ["order_code"=>$data["cpNo"],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$st,"resign_info",1,$st);
- $type=[
- "type_code"=>$data['cpNo'],
- "good_code"=>"GD-".$data["cpNo"],
- "color"=>$data["color"],
- "material"=>$data["material"],
- "attribute"=>$data["model"],
- "specs"=>$data["specs"],
- "is_diff"=>$data["is_diff"],
- "cert_fee"=>$data["cert_fee"],
- "packing_fee"=>$data["package_fee"],
- "mark_fee"=>$data["mark_fee"],
- "cost_fee"=>$data["bare_fee"],
- "logistics_fee"=>$data["delivery_fee"],
- "logistics"=>$data["delivery_day"],
- "min_num"=>$data["min_num"],
- "unit_price"=>$data["sale_price"],
- "status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $ert = Db::name("good_type")->insert($type);
- if($ert){
- $sti = ["order_code"=>$data["cpNo"],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$sti,"resign_info",1,$sti);
- return true;
- }
- }
- 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['gsyNo'],"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"=>$customer_code,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$st,"resign_info",0,$st);
- $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(["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,"仓库库存不足");
- }
- $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) {
- // $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'],'good_type_code'=>$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, "状态更新失败");
- }
- 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("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){
- $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);
- if(!$datainfo){
- $sio = ["order_code"=>$orderCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$sio,"zxd",0,$sio);
- Db::rollback();
- return error_show(1003,"创建失败");
- }
- $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){
- $sio = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$sio,"zxd",$der['status'],$sio);
- Db::rollback();
- return error_show(1003,"创建失败");
- }
- Db::commit();
- return error_show(0,"创建成功");
- }catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- }
|