Browse Source

售后申请单,客户发货时优化

wufeng 2 years ago
parent
commit
0777d9d261
2 changed files with 44 additions and 1 deletions
  1. 42 1
      app/admin/controller/After.php
  2. 2 0
      app/admin/controller/Sale.php

+ 42 - 1
app/admin/controller/After.php

@@ -1358,13 +1358,54 @@ class After extends Base
                         "before_status" => $old_info_status,
                         'holder_id' => $info['apply_id']
                     ]);
+
+
+                    //如果售后已完成,维护销售单、发货单和采购单
+                    if ($info['status'] == 5) {
+                        $sale['th_num'] += $info['error_num'];
+                        if ($sale['th_num'] == $sale['send_num'] && $sale['wsend_num'] == 0) {
+                            $sale['status'] = 3;
+                        }
+                        $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
+                        $sale['updatetime'] = date("Y-m-d H:i:s");
+                        Db::name("sale")->save($sale);
+
+                        if ($info['error_num'] >= $out['send_num']) $out['status'] = 4;
+                        $out['send_num'] -= $info['error_num'];
+                        $out['error_num'] += $info['error_num'];
+                        $out['updatetime'] = date("Y-m-d H:i:s");
+                        $upout = Db::name("order_out")->save($out);
+                        if ($upout == false) throw new Exception('出库单数据更新失败');
+
+                        //发货工单
+                        Db::name('order_out_child')
+                            ->where(['is_del' => 0, 'outCode' => $info["outCode"]])
+                            ->dec('num', $info['error_num'])
+                            ->update(['updatetime' => date("Y-m-d H:i:s")]);
+
+                        //如果供应商承担,维护采购单
+                        if ($info['is_th'] == 1) {
+                            $cgdNo = Db::name('order_num')
+                                ->where(['orderCode' => $info['orderCode']])
+                                ->value('cgdNo', '');
+                            if ($cgdNo != '') {
+                                Db::name('purchease_order')
+                                    ->where(['is_del' => 0, 'cgdNo' => $cgdNo])
+                                    ->dec('th_num', $info['error_num'])
+                                    ->dec('th_fee', round($sale['sale_price'] * $info['error_num'], 2))
+                                    ->update(['updatetime' => date("Y-m-d H:i:s")]);
+                            }
+                        }
+
+                    }
+
                     Db::commit();
                     return json_show(0, '退货成功');
                 } else throw new Exception('修改售后申请单状态失败');
 
             } else throw new Exception('退货失败');
 
-                    //售后退货单数据
+            //售后退货单数据
 //                    $thNo = makeNo("ST");
 //                    $thdata = [
 //                        "thNo" => $thNo,

+ 2 - 0
app/admin/controller/Sale.php

@@ -4703,6 +4703,8 @@ class Sale extends Base
                 ->where(['id' => $rs['id'], 'status' => 2, "is_del" => 0])
                 ->update(['status' => 3, 'updatetime' => date('Y-m-d H:i:s')]);
 
+            //发货工单不做更新,发货工单只给库管人员看,不关心是否收货,只保留 待发货/已发货/已取消 这几个状态就可以了
+
             //查询该发货单所属的销售单,是否还有未收货的其他发货单
             $other_res_sale = Db::name('order_out')
                 ->where(['orderCode' => $rs['orderCode'], 'status' => 2, "is_del" => 0])