|
@@ -603,23 +603,12 @@ class Reorder extends Base
|
|
|
if(empty($info)){
|
|
|
return error_show(1004,"未找到退货数据");
|
|
|
}
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
|
|
|
- :"";
|
|
|
+ $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'];
|
|
|
-
|
|
|
- $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'] : "";
|
|
|
-
|
|
|
+ $var = $info['status'];
|
|
|
$orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
|
|
|
if($orderinfo==false){
|
|
|
return error_show(1004,"未找到订单数据");
|
|
@@ -631,11 +620,8 @@ class Reorder extends Base
|
|
|
if(empty($addr)){
|
|
|
return error_show(1004,"未找到发货单地址数据");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
if($status==3){
|
|
|
$is_th =isset($this->post['is_th'])&&$this->post['is_th']!=="" ? intval($this->post['is_th']):"";
|
|
|
if($is_th===""){
|
|
@@ -651,7 +637,6 @@ class Reorder extends Base
|
|
|
return error_show(1004,"为找到仓库数据");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
$info['return_wsm'] =$return_wsm ;
|
|
|
$info['is_th'] =$is_th ;
|
|
|
}
|
|
@@ -833,6 +818,10 @@ class Reorder extends Base
|
|
|
Db::rollback();
|
|
|
return error_show(1005, '未找到采购单数据');
|
|
|
}
|
|
|
+ if( $info['is_all']==1 && $cgd['send_status']!=1){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, '采购单已入库无法全部退货');
|
|
|
+ }
|
|
|
$lor=$cgd['status'];
|
|
|
if($cgd['wsend_num']<$info['num']){
|
|
|
$cgd['send_num'] += $cgd['wsend_num']==0?0 :($info['num']-$cgd['wsend_num']);
|
|
@@ -1115,6 +1104,274 @@ class Reorder extends Base
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function allReturn(){
|
|
|
+ $orderCode =isset($this->post['orderCode'])&&$this->post['orderCode']!=''? trim($this->post['orderCode']):"";
|
|
|
+ if($orderCode==''){
|
|
|
+ return error_show(1004,"参数orderCode 不能为空");
|
|
|
+ }
|
|
|
+ $order= Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->find();
|
|
|
+ if(empty($order)){
|
|
|
+ return error_show(1005,"未找到订单数据");
|
|
|
+ }
|
|
|
+ if($order['wsend_num']!=$order['good_num']){
|
|
|
+ return error_show(1005,"订单未发货数量与总数不等,无法全退");
|
|
|
+ }
|
|
|
+ $retrun =Db::name("sale_return")->where([["orderCode","=",$orderCode],["is_del","=",0],["status","<",4]])
|
|
|
+ ->count();
|
|
|
+ if($retrun>0){
|
|
|
+ return error_show(1005,"存在退货订单数据");
|
|
|
+ }
|
|
|
+ if($order['order_type']==3){
|
|
|
+ $goon = Db::name("good_zixun")->where(["spuCode"=>$order['good_code'],"is_del"=>0])->find();
|
|
|
+ }else {
|
|
|
+ $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
|
|
|
+ ->where(['a.skuCode' => $order['skuCode']])->field("b.creater,b.createrid,b.supplierNo")->find();
|
|
|
+ }
|
|
|
+ if($goon==false){
|
|
|
+ return error_show(1005,"未找到商品数据");
|
|
|
+ }
|
|
|
+ $supplier =Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
|
|
|
+ if($supplier==false){
|
|
|
+ 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']) :"";
|
|
|
+ $addr =Db::name("order_addr")->where([["orderCode","=",$orderCode],["is_del","=",0]])->select()->toArray();
|
|
|
+ $ordernum = Db::name("order_num")->where(['orderCode' => $orderCode])->find();
|
|
|
+ if ($ordernum == false) {
|
|
|
+ return error_show(1005, '未找到关联采购单');
|
|
|
+ }
|
|
|
+ $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
|
|
|
+ if ($cgd == false) {
|
|
|
+ return error_show(1005, '未找到采购单数据');
|
|
|
+ }
|
|
|
+ if($order['is_stock']==0&&$cgd['send_status']!=1){
|
|
|
+ return error_show(1005, '采购单已发起入库');
|
|
|
+ }
|
|
|
+ $returnCode=makeNo("RN");
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ $in = [
|
|
|
+ "returnCode"=>$returnCode,
|
|
|
+ "orderCode"=>$orderCode,
|
|
|
+ "good_code"=>$order['good_code'],
|
|
|
+ "good_name"=>$order['good_name'],
|
|
|
+ "apply_id"=>$this->uid,
|
|
|
+ "apply_name"=>$this->uname,
|
|
|
+ "cgderid"=>$goon['createrid'],
|
|
|
+ "cgder"=>$goon['creater'],
|
|
|
+ "error_code"=>$errorCode,
|
|
|
+ "num"=>$order['wsend_num'],
|
|
|
+ "total_fee"=>round($order['sale_price']*$order['wsend_num'],2),
|
|
|
+ "good_price"=>$order['sale_price'],
|
|
|
+ "platform_id"=>$order['platform_id'],
|
|
|
+ "remark"=>$remark,
|
|
|
+ "order_type"=>$order['order_type'],
|
|
|
+ "is_addr"=>count($addr)>0 ?1:0,
|
|
|
+ "status"=>$order['is_stock']==1?4:1,
|
|
|
+ "is_del"=>0,
|
|
|
+ "is_all"=>1,
|
|
|
+ "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(["id"=>$this->uid,"nickname"=>$this->uname],$stn,"XSTHD",$in['status'],$in);
|
|
|
+ $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>$in['status'],"order_type"=>'XSTHD',"before_status"=>0];
|
|
|
+ ProcessOrder::AddProcess(["id"=>$this->uid,"nickname"=>$this->uname],$process);
|
|
|
+ //维护台账信息
|
|
|
+ Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(IFNULL(`returnGoodCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `orderCode`='{$orderCode}'");
|
|
|
+ if(count($addr)!=0){
|
|
|
+ $inf=[];
|
|
|
+ foreach ($addr as $val){
|
|
|
+ if ($val['receipt_quantity'] == 0) continue;//当退货数量为0时,跳过
|
|
|
+
|
|
|
+ $temp=[];
|
|
|
+ $send =Db::name('order_out')->where([["addrid","=",$val['id']]])->find();
|
|
|
+ if ($send == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004, "地址发货单未找到");
|
|
|
+ }
|
|
|
+ if($send['status']>=2){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005,"地址已发货");
|
|
|
+ }
|
|
|
+ if($order['is_stock']==1){
|
|
|
+ $val['is_del'] = 1;
|
|
|
+ $val['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $addrup = Db::name("order_addr")->save($val);
|
|
|
+ if ($addrup == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004, "地址更新失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ $send['is_del'] = 1;
|
|
|
+ $send['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $outup = Db::name("order_out")->save($send);
|
|
|
+ if ($outup == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004, "地址发货单更新失败");
|
|
|
+ }
|
|
|
+ $ordersend = Db::name("order_send")->where(["outCode" => $send['outCode']])->find();
|
|
|
+ if($ordersend==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004, "发货单关联数据未找到");
|
|
|
+ }
|
|
|
+ $ordersend['status'] = 0;
|
|
|
+ $ordersend['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $sendip = Db::name("order_send")->save($ordersend);
|
|
|
+ if ($sendip == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004, "发货单更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $temp['returnCode']=$returnCode;
|
|
|
+ $temp['orderCode']=$orderCode;
|
|
|
+ $temp['outCode']=isset($send['outCode'])?$send['outCode']:"";
|
|
|
+ $temp['addrid']=$val['id'];
|
|
|
+ $temp['send_num']=$val['receipt_quantity'];
|
|
|
+ $temp['return_num']=$val['receipt_quantity'];
|
|
|
+ $temp['is_del']=0;
|
|
|
+ $temp['addtime']=date("Y-m-d H:i:s");
|
|
|
+ $temp['updatetime']=date("Y-m-d H:i:s");
|
|
|
+ $inf[]=$temp;
|
|
|
+ }
|
|
|
+ $inadd=Db::name("sale_returnaddr")->insertAll($inf);
|
|
|
+ if($inadd==0){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005,"退货单新建失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if($order['is_stock']==1){
|
|
|
+ $lor=$order['status'];
|
|
|
+ $thnum = $order['wsend_num'];
|
|
|
+ $order['send_num'] += $thnum;
|
|
|
+ $order['th_num'] += $thnum;
|
|
|
+ $order['wsend_num'] =0;
|
|
|
+ $order['status'] = 3;
|
|
|
+ $order['send_status']=3;
|
|
|
+ $order['th_fee'] += round($thnum * $order['sale_price'], 2);
|
|
|
+ $order['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $uap = Db::name("sale")->save($order);
|
|
|
+ if ($uap == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, '销售单订单更新失败');
|
|
|
+ }
|
|
|
+ ActionLog::logAdd(["id"=>$this->uid,"nickname"=>$this->uname], [
|
|
|
+ "order_code" => $order["orderCode"],//出库单号
|
|
|
+ "status" => $lor,//这里的status是之前的值
|
|
|
+ "action_remark" => '',//备注
|
|
|
+ "action_type" => "status"//新建create,编辑edit,更改状态status
|
|
|
+ ], "XSQRD", $order['status'], $order);
|
|
|
+
|
|
|
+ ProcessOrder::AddProcess(["id"=>$this->uid,"nickname"=>$this->uname], [
|
|
|
+ "order_type" => 'XSQRD',
|
|
|
+ "order_code" =>$order["orderCode"],//出库单号
|
|
|
+ "order_id" => $order["id"],
|
|
|
+ "order_status" =>$order['status'],"before_status"=>$lor
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $ordernum['send_num'] -= $thnum;
|
|
|
+ $orderup = Db::name("order_num")->save($ordernum);
|
|
|
+ if ($orderup == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, '关联数据更新失败');
|
|
|
+ }
|
|
|
+ $cgd['th_fee'] += round($cgd['good_price'] * $thnum, 2);
|
|
|
+ $cgd['th_num'] += $thnum;
|
|
|
+ $cgd['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $cgdup = Db::name("purchease_order")->save($cgd);
|
|
|
+ if ($cgdup == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, '采购单数据更新失败');
|
|
|
+ }
|
|
|
+ if ($cgd['bkcode'] != "") {
|
|
|
+ $bk = Db::name("purchease_order")->where(["bkcode" => $cgd['bkcode'], "order_type" => 1, "order_source" =>0, "is_del" => 0])
|
|
|
+ ->find();
|
|
|
+ if ($bk == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, '未找到备库单数据');
|
|
|
+ }
|
|
|
+ $orderbk = Db::name("order_bk")->where(['cgdNo' => $bk['cgdNo'], "is_del" => 0])->find();
|
|
|
+ if ($orderbk == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, '备库单未完全入库');
|
|
|
+ }
|
|
|
+ $merge_num = Db::name("purchease_order")->where(["bkcode" => $bk['bkcode'], "order_type" =>1, "is_del" => 0])->where("order_source","<>",0)->field("sum(send_num)-sum(th_num) as num")
|
|
|
+ ->find();
|
|
|
+ $orderbk['balance_num'] = $orderbk['total_num'] - $merge_num['num'];
|
|
|
+ $orderbk['merge_num'] = $merge_num['num'];
|
|
|
+ $orderbk['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $orderbkup = Db::name("order_bk")->save($orderbk);
|
|
|
+ if ($orderbkup == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, '备库单库存数据释放失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'wsm_code' => $cgd['wsm_code']])
|
|
|
+ ->find();
|
|
|
+ if (empty($stock)) {
|
|
|
+ $stock = [
|
|
|
+ "spuCode" => $order['good_code'],
|
|
|
+ "wsm_code" => $cgd['wsm_code'],
|
|
|
+ "usable_stock" => 0,
|
|
|
+ "wait_out_stock" => 0,
|
|
|
+ "wait_in_stock" => 0,
|
|
|
+ "total_stock" => 0,
|
|
|
+ "addtime" => date("Y-m-d H:i:s"),
|
|
|
+ "updatetime" => date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $stock['usable_stock']+=$thnum;
|
|
|
+ $stock['wait_out_stock'] -= $thnum;
|
|
|
+ $stock['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $st_up = Db::name("good_stock")->save($stock);
|
|
|
+ if ($st_up == false) {
|
|
|
+ return error_show(1005, '可售商品入库失败');
|
|
|
+ }
|
|
|
+ $good_data[]= ['good_log_code' => $returnCode, "stock_id" => isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $thnum, "stock_name" => "usable_stock"];
|
|
|
+ $good_data[]= ['good_log_code' => $returnCode, "stock_id" => isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID(), "type" => 2, 'stock' => $thnum, "stock_name" => "wait_out_stock"];
|
|
|
+ GoodLog::LogAdd(["id"=>$this->uid,"nickname"=>$this->uname], $good_data, 'XSTHD');
|
|
|
+ $data=[
|
|
|
+ "orderCode"=>$orderCode,
|
|
|
+ "th_type"=>1,
|
|
|
+ "th_num"=>$thnum,
|
|
|
+ "th_fee"=>round($order['sale_price']*$thnum,2),
|
|
|
+ "thCode"=>$returnCode,
|
|
|
+ "spuCode"=>$order['good_code'],
|
|
|
+ "good_name"=>$order['good_name'],
|
|
|
+ "cat_id"=>$order['cat_id'],
|
|
|
+ "apply_id"=>$this->uid,
|
|
|
+ "apply_name"=>$this->uname,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "status"=>1,
|
|
|
+ "is_del"=>0
|
|
|
+ ];
|
|
|
+ $inse=Db::name("th_data")->insert($data);
|
|
|
+ if($inse==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"退货单更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,"退货单新建成功",["returnCode"=>$returnCode]);
|
|
|
+ }
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005,"退货单新建失败");
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, $e->getMessage());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ }
|
|
|
}
|