Browse Source

Merge branch 'dev_wf' of wugg/phpstock into version1.5

wufeng 2 years ago
parent
commit
6139c4a754
2 changed files with 64 additions and 0 deletions
  1. 63 0
      app/admin/controller/Orderback.php
  2. 1 0
      app/admin/route/app.php

+ 63 - 0
app/admin/controller/Orderback.php

@@ -6,7 +6,9 @@ namespace app\Admin\controller;
 use app\admin\model\ActionLog;
 use app\admin\model\ProcessOrder;
 use think\App;
+use think\Exception;
 use think\facade\Db;
+use think\facade\Validate;
 
 //退货单
 class Orderback extends \app\BaseController
@@ -341,4 +343,65 @@ class Orderback extends \app\BaseController
             return error_show(1004,$e->getMessage());
         }
     }
+
+
+    //新写一个退货接口
+    public function ExamNew()
+    {
+        $param = $this->request->only(['thNo', 'status', 'remark', 'can_sell_wsm' => '', 'can_sell_num' => 0, 'defective_wsm' => '', 'defective_num' => 0, 'loss_num' => 0], 'post', 'trim');
+
+        $val = Validate::rule(['thNo|退货编码' => 'require', 'status|状态' => 'require|number|in:4,2,1', 'remark|备注' => 'checkRemark:']);
+
+        $val->extend('checkRemark', function ($val, $rule, $data) {
+            return $data['status'] == 4 ? true : (empty($val) ? '请填写备注' : true);
+        });
+
+        if (!$val->check($param)) return error_show(1004, $val->getError());
+
+        Db::startTrans();
+        try {
+
+            $info = Db::name("order_back")
+                ->field('id,order_type,status')
+                ->where(['thNo' => $param['thNo'], 'is_del' => 0])
+                ->find();
+
+            if (empty($info)) throw new Exception('未找到数据');
+
+            $update_data = ['status' => $param['status'], 'updatetime' => date('Y-m-d H:i:s')];
+
+            //status==4通过,其他值表示驳回
+            if ($param['status'] != 4) $update_data['remark'] = $param['remark'];
+            else {
+                $update_data['can_sell_wsm'] = $param['can_sell_wsm'];
+                $update_data['can_sell_num'] = $param['can_sell_num'];
+                $update_data['defective_wsm'] = $param['defective_wsm'];
+                $update_data['defective_num'] = $param['defective_num'];
+                $update_data['loss_num'] = $param['loss_num'];
+            }
+
+            $res = Db::name("order_back")
+                ->where(['id' => $info['id']])
+                ->update($update_data);
+
+            if ($res) {
+
+                $stn = ["order_code" => $param['thNo'], "status" => $param['status'], "action_remark" => '', "action_type" => "edit"];
+                ActionLog::logAdd($this->post['token'], $stn, $info['order_type'] == 2 ? "ZXCKTHD" : "CKTHD", $info['status'], $stn);
+                $process = ["order_code" => $param['thNo'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => $info['order_type'] == 2 ? "ZXCKTHD" : "CKTHD"];
+                ProcessOrder::AddProcess($this->post['token'], $process);
+
+                Db::commit();
+
+                return app_show(0, '操作成功');
+            } else throw new Exception('操作失败');
+
+        } catch (Exception $exception) {
+
+            Db::rollback();
+
+            return error_show(1005, $exception->getMessage());
+        }
+
+    }
 }

+ 1 - 0
app/admin/route/app.php

@@ -254,6 +254,7 @@ Route::rule('orderbackinfo','admin/Orderback/info');
 Route::rule('orderbackcheck','admin/Orderback/check');
 Route::rule('orderbce','admin/Orderback/CheckExam');
 Route::rule('orderbackexam','admin/Orderback/Exam');
+Route::rule('orderbackexamnew','admin/Orderback/ExamNew');//新写退货接口
 
 Route::rule('goldlist','admin/Gold/list');
 Route::rule('goldadd','admin/Gold/add');