Browse Source

商品成本复制接口复用

wufeng 2 years ago
parent
commit
80759f9888
2 changed files with 120 additions and 3 deletions
  1. 119 3
      app/abutment/controller/Good.php
  2. 1 0
      app/abutment/route/app.php

+ 119 - 3
app/abutment/controller/Good.php

@@ -22,7 +22,7 @@ class Good extends BaseController
 
         $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 = [["gb.is_del", "=", 0],['gb.is_stock', '=', 0]];
+        $where = [["gb.is_del", "=", 0], ['gb.is_stock', '=', 0]];
         $condit = [["a.is_del", "=", 0]];
         $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !== "" ? intval($this->post['cat_id']) : "";
         if ($cat_id !== "") {
@@ -1518,7 +1518,7 @@ class Good extends BaseController
         $this->post = $this->request->filter('trim')->post();
         $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],['level',"=",3]];
+        $where = [["is_del", "=", 0], ['level', "=", 3]];
         $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== "" ? trim($this->post['cat_name']) : "";
         if ($cat_name !== "") {
             $where[] = ['cat_name', "like", "%$cat_name%"];
@@ -1590,7 +1590,7 @@ class Good extends BaseController
 
             $rs = PlatformYouzan::field('id')
                 ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal])
-                ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8,PlatformYouzan::$exam_status_2])
+                ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8, PlatformYouzan::$exam_status_2])
                 ->findOrEmpty()
                 ->isEmpty();
             if (!$rs) $is_allow_update = 0;
@@ -1600,5 +1600,121 @@ class Good extends BaseController
 
     }
 
+    //上线商品复制
+    public function copy()
+    {
+        $this->post = $this->request->filter('trim')->post();
+        $supcode = isset($this->post['spuCode']) && $this->post['spuCode'] != "" ? trim($this->post['spuCode']) : "";
+        if ($supcode == "") {
+            return json_show(1004, "参数spuCode不能为空");
+        }
+        $data = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->find();
+        if ($data == false) {
+            return json_show(1004, "未找到商品数据");
+        }
+        $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
+        if ($token == '') {
+            return json_show(105, "参数token不能为空");
+        }
+//        $user =GetUserInfo($token);
+//        if(empty($user)||$user['code']!=0){
+//            return json_show(102,"用户数据不存在");
+//        }
+        $createrid = $this->request->user['uid'];
+        $creater = $this->request->user['nickname'];
+        $nake = Db::name("good_nake")->where(["spuCode" => $supcode, "is_del" => 0])->select()->toArray();
+        $ladd = [];
+        $newCode = makeNo("SKU");
+        if (!empty($nake)) {
+            foreach ($nake as $value) {
+                $tmp = [];
+                $tmp['spuCode'] = $newCode;
+                $tmp['min_num'] = $value['min_num'];
+                $tmp['nake_fee'] = $value['nake_fee'];
+                $tmp['cost_fee'] = $value['cost_fee'];
+                $tmp['delivery_fee'] = $value['delivery_fee'];
+                $tmp['cert_fee'] = $value['cert_fee'];
+                $tmp['mark_fee'] = $value['mark_fee'];
+                $tmp['package_fee'] = $value['package_fee'];
+                $tmp['other_fee'] = $value['other_fee'];
+                $tmp['nake_total'] = $value['nake_total'];
+                $tmp['creater_id'] = $createrid;
+                $tmp['creater'] = $creater;
+                $tmp['is_del'] = $value['is_del'];
+                $tmp['addtime'] = date("Y-m-d H:i:s");
+                $tmp['updatetime'] = date("Y-m-d H:i:s");
+                $ladd[] = $tmp;
+            }
+        }
+        $spec = Db::name("good_spec")
+            ->where(["spuCode" => $supcode, "is_del" => 0])
+            ->select()
+            ->toArray();
+        $specArr = [];
+        if (!empty($spec)) {
+            foreach ($spec as $value) {
+                $tmp = [];
+                $tmp['spuCode'] = $newCode;
+                $tmp['spec_id'] = $value['spec_id'];
+                $tmp['spec_value_id'] = $value['spec_value_id'];
+                $tmp['is_del'] = $value['is_del'];
+                $tmp['addtime'] = date("Y-m-d H:i:s");
+                $tmp['updatetime'] = date("Y-m-d H:i:s");
+                $specArr[] = $tmp;
+            }
+        }
+        Db::startTrans();
+        try {
+            unset($data['id']);
+            $data['spuCode'] = $newCode;
+            $data['createrid'] = $createrid;
+            $data['creater'] = $creater;
+            $data['status'] = 7;
+            $data['addtime'] = date("Y-m-d H:i:s");
+            $data['updatetime'] = date("Y-m-d H:i:s");
+            $cre = Db::name("good_basic")->insert($data);
+            if ($cre) {
+                //修改状态,添加待办
+                ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
+                    "order_code" => $newCode,//咨询单详情编号
+                    "status" => 0,//这里的status是之前的值
+                    "action_remark" => '',//备注
+                    "action_type" => "create"//新建create,编辑edit,更改状态status
+                ], "SPCB", 7, $data);
+
+                ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
+                    "order_type" => 'SPCB',
+                    "order_code" => $newCode,//咨询单详情编号
+                    "order_id" => Db::name("good_basic")->getLastInsID(),
+                    "order_status" => 7, "before_status" => 0
+                ]);
+                if (!empty($ladd)) {
+                    $na = Db::name("good_nake")->insertAll($ladd);
+                    if ($na == 0) {
+                        Db::rollback();
+                        return json_show(1005, "成本数据复制失败");
+                    }
+                }
+                if (!empty($specArr)) {
+                    $sp = Db::name("good_spec")->insertAll($specArr);
+                    if ($sp == 0) {
+                        Db::rollback();
+                        return json_show(1005, "规格数据复制失败");
+                    }
+                }
+                Db::commit();
+                return json_show(0, "复制数据成功", ["spuCode" => $newCode]);
+            } else {
+                Db::rollback();
+                return json_show(1005, "数据复制失败");
+            }
+
+        } catch (\Exception $e) {
+            Db::rollback();
+            return json_show(1004, $e->getMessage());
+        }
+
+    }
+
 
 }

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

@@ -37,6 +37,7 @@ route::rule('goldLinst', 'abutment/Good/linst');//贵金属种类列表
 route::rule('catList', 'abutment/Good/wlist');//分类列表
 route::rule('catListTitle', 'abutment/Good/title');//分类列表-全部
 route::rule('checkIsUpdate', 'abutment/Good/checkIsUpdate');//判断是否允许修改成本信息和基础信息
+route::rule('goodCopy', 'abutment/Good/copy');//上线商品复制
 
 //销售订单(采销的采购单)
 route::rule('getOrderList', 'abutment/Order/getList');//列表