123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ProcessOrder;
- use think\facade\Db;
- use think\App;
- use app\admin\model\ActionLog;
- class Reorder extends \app\BaseController
- {
- public $post=[];
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post =$this->request->post();
- }
- public function create(){
- $ordeCode = isset($this->post['orderCode']) &&$this->post['orderCode']!=''?trim($this->post['orderCode']) :"";
- if($ordeCode==''){
- return error_show(1004,"参数orderCode 不能为空");
- }
- $order= Db::name("sale")->where(["orderCode"=>$ordeCode,"is_del"=>0])->find();
- if(empty($order)){
- return error_show(1005,"未找到订单数据");
- }
- $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
- if($errorCode==''){
- return error_show(1004,"参数errorCode 不能为空");
- }
- $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
- if(empty($error)){
- return error_show(1005,"未找到退货原因数据");
- }
- $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
- $data = isset($this->post['list'])&&$this->post['list']!='' ? $this->post['list'] :'';
- if($data=='' || empty($data)){
- return error_show(1005,"参数list不能为空");
- }
- $addr = isset($this->post['addr'])&&$this->post['addr']!='' ? $this->post['addr'] :'';
- if($addr=='' || empty($addr)){
- return error_show(1005,"参数addr不能为空");
- }
- $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(1005,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $total = array_sum(array_column($data,"return_num"));
- $addrnum = array_sum(array_column($addr,"return_num"));
- if($total!=$addrnum){
- return error_show(1002,"仓库退货数据与地址退货数据不一致");
- }
- // var_dump($order['good_code']);
- $returnCode=makeNo("RXS");
- Db::startTrans();
- try{
- $in = [
- "returnCode"=>$returnCode,
- "orderCode"=>$ordeCode,
- "good_code"=>$order['good_code'],
- "good_name"=>$order['good_name'],
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "error_code"=>$errorCode,
- "num"=>$total,
- "remark"=>$remark,
- "order_type"=>1,
- "status"=>0,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $create = Db::name("sale_return")->insert($in,true);
- if($create>0){
- $stn = ["order_code"=>$returnCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$stn,"QRTHD",0,$stn);
- $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>'QRTHD'];
- ProcessOrder::AddProcess($this->post['token'],$process);
- $addrinfo=[];
- foreach ($addr as $value){
- $addrorder= Db::name("order_addr")->where(['orderCode'=>$ordeCode,"id"=>$value['addrid']])
- ->find();
- if(empty($addrorder)){
- Db::rollback();
- return error_show(1002,"订单地址数据不存在");
- }
- $total = Db::name("sale_returnaddr")->where(['orderCode'=>$ordeCode,"id"=>$value['addrid'],"is_del"=>0])
- ->sum("return_num");
- if($addrorder['receipt_quantity']-$total<$value['return_num']){
- Db::rollback();
- return error_show(1002,"订单地址退货数量超出发货数量");
- }
- $temp=[];
- $temp['returnCode']=$returnCode;
- $temp['orderCode']=$ordeCode;
- $temp['addrid']=$value['addrid'];
- $temp['return_num']=$value['return_num'];
- $temp['send_num']= $addrorder['receipt_quantity'];
- $temp['addtime']= date("Y-m-d H:i:s");
- $temp['updatetime']= date("Y-m-d H:i:s");
- $addrinfo[]=$temp;
- }
- $return = Db::name("sale_returnaddr")->insertAll($addrinfo);
- if($return<=0){
- Db::rollback();
- return error_show(1002,"订单地址退货数据更新失败");
- }
- $info=[];
- foreach ($data as $value){
- $wsmorder= Db::name("sale_info")->where(['orderCode'=>$ordeCode,"wsm_code"=>$value['wsm_code']])
- ->find();
- if(empty($wsmorder)){
- Db::rollback();
- return error_show(1002,"订单仓库数据不存在");
- }
- $total_wsm = Db::name("sale_returninfo")->where(['orderCode'=>$ordeCode,"wsm_code"=>$value['wsm_code'],"is_del"=>0])
- ->sum("return_num");
- if($wsmorder['num']-$total_wsm<$value['return_num']){
- Db::rollback();
- return error_show(1002,"仓库退货数量超出发货数量");
- }
- $temp=[];
- $temp['returnCode']=$returnCode;
- $temp['orderCode']=$ordeCode;
- $temp['wsm_code']=$value['wsm_code'];
- $temp['return_num']=$value['return_num'];
- $temp['total_num']= $wsmorder['num'];
- $temp['addtime']= date("Y-m-d H:i:s");
- $temp['updatetime']= date("Y-m-d H:i:s");
- $info[]=$temp;
- }
- $return = Db::name("sale_returninfo")->insertAll($info);
- if($return){
- Db::commit();
- return app_show(0,"退货单新建成功");
- }
- }
- Db::rollback();
- return error_show(1005,"退货单新建失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- public function list(){
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
- $where =[['is_del',"=",0]];
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode!=""){
- $where[]=['returnCode',"like", "%{$bkcode}%"];
- }
- $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
- if($status!==""){
- $where[]=['status',"=", $status];
- }
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
- :"";
- if($orderCode!=""){
- $where[]=['orderCode',"like", "%{$orderCode}%"];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name'])
- :"";
- if($apply_name!=""){
- $where[]=['apply_name',"like", "%{$apply_name}%"];
- }
- $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
- if($start!==""){
- $where[]=['addtime',">=", $start];
- }
- $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
- if($end!==""){
- $where[]=['addtime',"<=", $end];
- }
- $count=Db::name("sale_return")->where($where)->count();
- $total = ceil($count/$size);
- $page = $total>=$page ? $page :$total;
- $list = Db::name("sale_return")->where($where)->order("addtime desc")->page($page,$size)->select();
- // echo Db::name("sale_return")->getLastSql();
- $data=[];
- foreach ($list as $value){
- $value['error_msg']='';
- if($value['error_code']!=''){
- $error = Db::name("result_info")->where(["result_code"=>$value['error_code']])->find();
- $value['error_msg']= isset($error['result'])?$error['result']:"";
- }
- $order =Db::name("sale")->where(["orderCode"=>$value['orderCode'],"is_del"=>0])->find();
- $value['sale_price'] = isset($order['sale_price']) ?$order['sale_price']:0;
- $value['return_total'] =$value['sale_price']*$value['num'] ;
- $value['total_num'] =$order['good_num'] ;
- $data[]=$value ;
- }
- return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
- }
- public function info(){
- $code = isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode'])
- :"";
- if($code==""){
- return error_show(1004,"参数returnCode不能为空");
- }
- $info = Db::name("sale_return")->where(["returnCode"=>$code,"is_del"=>0])->find();
- if(empty($info)){
- return error_show(1004,"未找到退货数据");
- }
- $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
- $goon = Db::name('good')->alias('b')->join("good_type a", "a.good_code=b.good_code", "left")
- ->where(['a.type_code' => $info['good_code']])->find();
- if (empty($goon)) {
- return error_show(1003, "未找到商品数据");
- }
- $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
- $info['good_code'] = isset($orderinfo['good_code'])?$orderinfo['good_code']:'';
- $info['good_name'] = isset($orderinfo['good_name'])?$orderinfo['good_name']:'';
- $info['good_num'] = isset($orderinfo['good_num'])?$orderinfo['good_num']:'';
- $info['sale_price'] = isset($orderinfo['sale_price'])?$orderinfo['sale_price']:'0';
- $info['origin_price'] = isset($orderinfo['origin_price'])?$orderinfo['origin_price']:'0';
- $info['return_total'] = $info['sale_price']*$info['num'] ;
- $info['send_num'] = isset($orderinfo['send_num'])?$orderinfo['send_num']:'0';
- $info['wsend_num'] = isset($orderinfo['wsend_num'])?$orderinfo['wsend_num']:'0';
- $info['send_status'] = isset($orderinfo['send_status'])?$orderinfo['send_status']:'';
- $info['total_price'] = isset($orderinfo['total_price'])?$orderinfo['total_price']:'0';
- $info['post_fee'] = isset($orderinfo['post_fee'])?$orderinfo['post_fee']:'0';
- $info['customer_code'] = isset($orderinfo['customer_code'])?$orderinfo['customer_code']:'';
- $info['customer_name']='';
- if(isset($orderinfo['customer_code'])&&$orderinfo['customer_code']!=''){
- $customerinfo = Db::name("customer_info")->where(['companyNo'=>$orderinfo['customer_code']])->find();
- $info['customer_name'] = isset($customerinfo['companyName']) ? $customerinfo['companyName']:"";
- }
- $info['cgd_wsend']="";
- $info['cgd_send']="";
- $info['cgd_total']="";
- if($orderinfo['order_type']==2){
- $cgd = Db::name("purchease_order")->where(["bkcode"=>$info["orderCode"],"order_type"=>2])->find();
- $info['cgd_wsend'] = isset($cgd['wsend_num']) ? $cgd['wsend_num']:0;
- $info['cgd_send'] = isset($cgd['send_num']) ? $cgd['send_num']:0;
- $info['cgd_total'] = isset($cgd['good_num']) ? $cgd['good_num']:0;
- }
- $info['error_msg']='';
- if($info['error_code']!=''){
- $error = Db::name("result_info")->where(["result_code"=>$info['error_code']])->find();
- $info['error_msg']= isset($error['result'])?$error['result']:"";
- }
- $wsm_return = Db::name("sale_returninfo")->where(["returnCode"=>$info["returnCode"],"is_del"=>0])->select()->toArray();
- $wsm=[];
- if(!empty($wsm_return)){
- foreach ($wsm_return as $value){
- $value['wsm_name']="";
- $value['wsm_supplier']="";
- $value['wsm_supplierNo']="";
- 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']:"";
- }
- $orderwsm = Db::name("sale_info")->where(["orderCode"=>$info["orderCode"],"wsm_code"=>$value["wsm_code"]])->find();
- $value["wsm_total"] = isset($orderwsm["num"]) ? $orderwsm["num"]:0;
- $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $info['orderCode']])->sum("send_num");
- $value['wsm_send'] = $send ?? 0;
- $value['wsm_wsend'] = $value['wsm_total'] - $value['wsm_send'];
- $wsm[]=$value;
- }
- }
- $info['wsminfo']=$wsm;
- $addr =Db::name("sale_returnaddr")->where(["returnCode"=>$info["returnCode"],"is_del"=>0])->select()->toArray();
- $addrinfo=[];
- if(!empty($addr)){
- foreach ( $addr as $value){
- $addrlist = Db::name("order_addr")->where(["id"=>$value["addrid"]])->find();
- $value['addr']=isset($addrlist['addr'])?$addrlist['addr']:"";
- $value['addr_code']=isset($addrlist['addr_code'])?$addrlist['addr_code']:"";
- $value['contactor']=isset($addrlist['contactor'])?$addrlist['contactor']:"";
- $value['mobile']=isset($addrlist['mobile'])?$addrlist['mobile']:"";
- $value['post_fee']=isset($addrlist['post_fee'])?$addrlist['post_fee']:"";
- $value['addive_time']=isset($addrlist['addive_time'])?$addrlist['addive_time']:"";
- $value['customer_code']=isset($addrlist['customer_code']) ?$addrlist['customer_code']:"" ;
- $value['receipt_quantity']=isset($addrlist['receipt_quantity']) ?$addrlist['receipt_quantity']:"" ;
- $send = Db::name("order_out")->where(['addrid' => $addrlist['id'], 'orderCode' => $addrlist['orderCode']])->sum("send_num");
- $value['addr_send'] = $send ?? 0;
- $value['addr_wsend'] = $value['receipt_quantity'] - $value['addr_send'];
- $customer = Db::name("customer_info")->where(['companyNo'=>$addrlist['customer_code']])->find();
- $value['customer_name'] = isset($customer['companyName']) ? $customer['companyName']:"";
- $addrinfo[]=$value;
- }
- }
- $info['addrinfo']=$addrinfo;
- $info['can']=$int;
- return app_show(0,"获取成功",$info);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function delete(){
- $code = isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode'])
- :"";
- if($code==""){
- return error_show(1004,"参数returnCode不能为空");
- }
- $info = Db::name("sale_return")->where(["returnCode"=>$code,"is_del"=>0])->find();
- if(empty($info)){
- return error_show(1004,"未找到退货数据");
- }
- $info["is_del"]=1;
- $info["updatetime"]=date("Y-m-d H:i:s");
- $del = Db::name("sale_return")->save($info);
- if($del){
- $ste = ["order_code"=>$code,"status"=>0,"action_remark"=>'',"action_type"=>"delete"];
- ActionLog::logAdd($this->post['token'],$ste,$info['order_type'] == 2?"ZXTHD":"QRTHD",0,$ste);
- $process=["order_code"=>$code,"order_id"=>$info['id'],"order_status"=>0,"order_type"=>$info['order_type'] == 2?"ZXTHD":"QRTHD"];
- ProcessOrder::workdel($process);
- return app_show(0,"删除成功");
- }else{
- return error_show(1004,"删除失败");
- }
- }
- /**审核
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function exam(){
- $code = isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode'])
- :"";
- if($code==""){
- return error_show(1004,"参数returnCode不能为空");
- }
- $info = Db::name("sale_return")->where(["returnCode"=>$code,"is_del"=>0])->find();
- if(empty($info)){
- return error_show(1004,"未找到退货数据");
- }
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
- :"";
- if($status===""){
- return error_show(1004,"参数status不能为空");
- }
- $remark = isset($this->post['remark']) && $this->post['remark'] !="" ? trim($this->post['remark']) :"";
- $var = $info['status'];
- if($info['order_type']==2){
- $wsend_th = isset($this->post['wsend_th']) && $this->post['wsend_th'] !=="" ? intval($this->post['wsend_th']) :"";
- if($status==3){
- if($wsend_th===''){
- return error_show(1004,"参数wsend_th不能为空");
- }
- $info['wsend_th'] =$wsend_th;
- }
- $return_wsm = isset($this->post['return_wsm']) && $this->post['return_wsm'] !="" ? trim($this->post['return_wsm']) :"";
- if($status==4){
- if($return_wsm===''){
- return error_show(1004,"参数return_wsm不能为空");
- }
- $info['return_wsm'] =$return_wsm;
- $cgd = Db::name("purchease_order")->where(["bkcode"=>$info['orderCode'],"order_type"=>2])->find();
- if(empty($cgd)){
- return error_show(1002,"未找到采购单数据");
- }
- $gd= Db::name('good')->where(['good_code'=>$cgd['good_code']])->find();
- if($gd==""){
- return error_show(1002,"未找到商品数据");
- }
- }
- }
- $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
- $apply_id =GetUserInfo($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rid= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $rname= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- Db::startTrans();
- try{
- $temp= $info['status'];
- $info['status'] =$status;
- $remark!=""? $info['remark'] =$remark:"";
- $info["updatetime"]=date("Y-m-d H:i:s");
- $up = Db::name("sale_return")->save($info);
- if($up){
- $process=["order_code"=>$code,"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type'] == 2?"ZXTHD":"QRTHD"];
- ProcessOrder::AddProcess($this->post['token'],$process);
- $ste = ["order_code"=>$code,"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
- ActionLog::logAdd($this->post['token'],$ste,$info['order_type'] == 2?"ZXTHD":"QRTHD",$status,$info);
- if($info['order_type']==2&&$status==4){
- $returnCode=makeNo("TH");
- $data = [
- "returnCode"=>$returnCode,
- "cgdNo"=>$cgd['cgdNo'],
- "good_code"=>$cgd['good_type_code'],
- "return_num"=>$cgd['wsend_num'],
- "good_name"=>$cgd['good_name'],
- "good_price"=>$cgd['good_price'],
- "good_catid"=>$gd['cat_id'],
- "apply_name"=>$rname,
- "apply_id"=>$rid,
- "good_total"=>$cgd['good_num'],
- "post_company"=>"",
- "post_code"=>"",
- "post_fee"=>"",
- "status"=>1,
- "remark"=>'',
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $pd = Db::name('purchease_back')->insert($data,true);
- if($pd>0){
- $process=["order_code"=>$returnCode,"order_id"=>$pd,"order_status"=>1,"order_type"=>'CGTHD'];
- ProcessOrder::AddProcess($this->post['token'],$process);
- $ste = ["order_code"=>$returnCode,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$ste,"CGTHD",1,$data);
- $cg_status=$cgd['status'];
- $cgd['wsend_num']=0;
- $cgd['status']=3;
- $cgd['send_status']=3;
- $cgd['updatetime']=date("Y-m-d H:i:s");
- $up=Db::name('purchease_order')->save($cgd);
- if($up){
- $process=["order_code"=>$cgd['cgdNo'],"order_id"=>$cgd['id'],"order_status"=>1,"order_type"=>'CGD'];
- ProcessOrder::AddProcess($this->post['token'],$process);
- $ste = ["order_code"=>$cgd['cgdNo'],"status"=>$cg_status,"action_remark"=>'',
- "action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$ste,"CGD",3,$data);
- Db::commit();
- return app_show(0,"更新成功");
- }else{
- Db::rollback();
- return error_show(1004,"更新失败");
- }
- }else{
- Db::rollback();
- return error_show(1004,"更新失败");
- }
- }
- Db::commit();
- return app_show(0,"更新成功");
- }else{
- Db::rollback();
- return error_show(1004,"更新失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,"更新失败");
- }
- }
- public function zxcreate(){
- $ordeCode = isset($this->post['orderCode']) &&$this->post['orderCode']!=''?trim($this->post['orderCode']) :"";
- if($ordeCode==''){
- return error_show(1004,"参数orderCode 不能为空");
- }
- $order= Db::name("sale")->where(["orderCode"=>$ordeCode,"is_del"=>0])->find();
- if(empty($order)){
- return error_show(1005,"未找到订单数据");
- }
- $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
- if($errorCode==''){
- return error_show(1004,"参数errorCode 不能为空");
- }
- $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
- if(empty($error)){
- return error_show(1005,"未找到退货原因数据");
- }
- $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
- $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
- if($token==''){
- return error_show(1005,"参数token不能为空");
- }
- $user =GetUserInfo($token);
- if(empty($user)||$user['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- $num = isset($this->post['num'])&&$this->post['num']!='' ? intval($this->post['num']):"";
- if($num==''){
- return error_show(1005,"参数num不能为空");
- }
- if($order['wsend_num']<$num){
- return error_show(1002,"仓库未发货数量不足退货");
- }
- $returnCode=makeNo("RXS");
- Db::startTrans();
- try{
- $in = [
- "returnCode"=>$returnCode,
- "orderCode"=>$ordeCode,
- "good_code"=>$order['good_code'],
- "good_name"=>$order['good_name'],
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "error_code"=>$errorCode,
- "num"=>$num,
- "remark"=>$remark,
- "order_type"=>2,
- "status"=>0,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $create = Db::name("sale_return")->insert($in,true);
- if($create>0) {
- $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>'ZXTHD'];
- ProcessOrder::AddProcess($this->post['token'],$process);
- $ste = ["order_code"=>$returnCode,"status"=>0,"action_remark"=>'',
- "action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$ste,"ZXTHD",3,$in);
- if ($order['send_type'] == 1) {
- $wsend = Db::name("order_out")->where(['orderCode' => $ordeCode, "status" => 1, "order_type"
- =>2])->select();
- // ->save(["status" => 0, "updatetime" => date("Y-m-d H:i:s")]);
- if(!empty($wsend)){
- foreach ($wsend as $value){
- $tt = $value['status'];
- $value['status']=0;
- $value['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("order_out")->save($value);
- if($up){
- $process=["order_code"=> $value['outCode'],"order_id"=>$value['id'],"order_status"=>0,"order_type"=>'CKD'];
- ProcessOrder::AddProcess($this->post['token'],$process);
- $ste = ["order_code"=>$value['outCode'],"status"=>$tt,"action_remark"=>'',"action_type"=>"status"];
- ActionLog::logAdd($this->post['token'],$ste,"CKD",0,$value);
- }else{
- Db::rollback();
- return error_show(1005,"退货单新建失败");
- }
- }
- }
- }
- Db::commit();
- return error_show(0,"退货单新建成功");
- }
- Db::rollback();
- return error_show(1005,"退货单新建失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- }
|