Browse Source

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

wufeng 2 years ago
parent
commit
ffa8826906
2 changed files with 120 additions and 80 deletions
  1. 30 6
      app/admin/controller/Sale.php
  2. 90 74
      app/command/ImportOrderFromCHandleData.php

+ 30 - 6
app/admin/controller/Sale.php

@@ -3550,13 +3550,37 @@ class Sale extends Base
 
         if (empty($outCode)) return error_show(1004, '发货申请单编号不能为为空');
 
-        $rs = Db::name('order_out')
-            ->field('id')
-            ->where(['outCode' => $outCode, 'status' => 2])
-            ->find();
+        Db::startTrans();
+
+        try {
+
+            $rs = Db::name('order_out')
+                ->field('id,orderCode')
+                ->where(['outCode' => $outCode, 'status' => 2])
+                ->find();
+
+            if (empty($rs)) throw new Exception('该出库单不存在或不允许确认收货');
+
+            $res_order_out = Db::name('order_out')
+                ->where(['id' => $rs['id'], 'status' => 2])
+                ->update(['status' => 3, 'updatetime' => date('Y-m-d H:i:s')]);
+
+            $res_sale = Db::name('sale')
+                ->where(['orderCode' => $rs['orderCode'], 'status' => 0])
+                ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
+
+            if ($res_order_out && $res_sale) {
+                Db::commit();
+                return app_show(0, '收货完成');
+            } else {
+                Db::rollback();
+                error_show(1005, '收货失败');
+            }
+        } catch (\Exception $e) {
+            Db::rollback();
+            return error_show(1005, $e->getMessage());
+        }
 
-        if (empty($rs)) return error_show(1005, '该出库单不存在或不允许确认收货');
-        else return Db::name('order_out')->where(['id' => $rs['id'], 'status' => 2])->update(['status' => 3, 'updatetime' => date('Y-m-d H:i:s')]) ? app_show(0, '收货完成') : error_show(1005, '收货失败');
     }
 
 

+ 90 - 74
app/command/ImportOrderFromCHandleData.php

@@ -101,7 +101,7 @@ class ImportOrderFromCHandleData extends Command
                     $stock = Db::name("good_stock")
                         ->alias("a")
                         ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
-                        ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.companyNo" => $supplierNo])
+                        ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1,'b.wsm_type'=>5, "b.companyNo" => $supplierNo])
                         ->field("a.id,a.usable_stock,a.wait_out_stock")
                         ->find();
 
@@ -117,12 +117,29 @@ class ImportOrderFromCHandleData extends Command
                 $origin_price = $origin['nake_total'];
                 $sale_price = $extend_data['price'];
                 if ($goodtype == 1) {
-//                    $good = Db::name("good_ladder")
-//                        ->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])
-//                        ->where([["min_num", "<=", $good_num]])
-//                        ->order("min_num desc")
-//                        ->find();
-////                    if ($good == false) throw new Exception('未找到相关阶梯价格');
+                    $good = Db::name("good_ladder")
+                        ->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])
+                        ->where([["min_num", "<=", $good_num]])
+                        ->order("min_num desc")
+                        ->find();
+                    if ($good == false) throw new Exception('未找到相关阶梯价格');
+
+                    $sale_price = $good['sale_price'];
+                    if ($ct['is_gold_price'] == 1) {
+                        $gold = Db::name("gold_price1")
+                            ->field('id,price')
+                            ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
+                            ->order("addtime desc")
+                            ->find();
+
+                        //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
+                        $sale_price = $ct['demo_fee'] / $good_num + $ct['open_fee'] / $good_num + $ct['noble_weight'] * $gold["price"] + $good['cost_fee'] * $ct['noble_weight'] + $origin['package_fee'] + $origin['mark_fee'] + $origin['cert_fee'] + $origin['nake_fee'] + $origin['delivery_fee'];
+
+//                $order_rate = Db::name("cat")->where(["id" => $ct['cat_id']])->value('order_rate');
+//                $budget = isset($order_rate) ? $order_rate / 100 : 0;
+
+                        // $saleprice = $total_fee / (1 - $budget);
+                    }
 
                     if ($is_activity == 1) {
                         $act = Db::name("activity_info")
@@ -133,6 +150,7 @@ class ImportOrderFromCHandleData extends Command
                         if ($act == false) throw new Exception('未找到相关活动价');
                         if ($act['moq_num'] > $good_num) throw new Exception('商品不满足活动价起订量' . $act['moq_num']);
                         if ($act['activity_stock'] < $good_num) throw new Exception('商品活动库存剩余' . $act['activity_stock']);
+                        $sale_price = $act['activity_price'];
                     }
                 }
                 $cgd = [
@@ -265,73 +283,71 @@ class ImportOrderFromCHandleData extends Command
                         ];
                         $vmp = Db::name('order_addr')->insert($temp, true);
                         if ($vmp > 0) {
-                            if ($is_stock == 1) {
-                                $order = Db::name("order_num")
-                                    ->where(["orderCode" => $orderCode, "status" => 1])
-                                    ->where([["wsend_num", ">=", 0]])
-                                    ->lock(true)
-                                    ->find();
-                                if ($order == false) throw new Exception('未找到可以发货得采购单数据');
-
-
-                                $num = $extend_data['num'];
-                                $outCode = makeNo("DF");
-                                $order['wsend_num'] -= $num;
-                                $order['send_num'] += $num;
-                                $or = Db::name("order_num")->save($order);
-                                if ($or == false) throw new Exception('发货地址更新失败');
-
-                                $tep = [
-                                    "cgdNo" => $order['cgdNo'],
-                                    "outCode" => $outCode,
-                                    "send_num" => $num,
-                                    "status" => 1,
-                                    "addtime" => date("Y-m-d H:i:s"),
-                                    "updatetime" => date("Y-m-d H:i:s")
-                                ];
-                                $sen = Db::name("order_send")->save($tep);
-                                if ($sen == false) throw new Exception('发货地址添加创建失败');
-
-                                $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
-                                if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
-
-                                $out = [
-                                    "orderCode" => $orderCode,
-                                    "outCode" => $outCode,
-                                    "apply_id" => $rm,
-                                    "apply_name" => $ri,
-                                    "addrid" => $vmp,
-                                    "post_name" => "",
-                                    "post_code" => "",
-                                    "post_fee" => 0,
-                                    "sendtime" => date("Y-m-d H:i:s"),
-                                    "send_num" => $num,
-                                    "check_num" => 0,
-                                    "error_num" => 0,
-                                    "wsm_code" => $cgdinfo['wsm_code'],
-                                    "order_type" => 1,
-                                    "status" => 1,
-                                    "addtime" => date("Y-m-d H:i:s"),
-                                    "updatetime" => date("Y-m-d H:i:s")
-                                ];
-                                $ou = Db::name("order_out")->insert($out);
-                                if ($ou == false) throw new Exception('发货地址添加创建失败');
-                                else {
-                                    //修改状态,添加待办
-                                    ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
-                                        "order_code" => $outCode,//出库单号
-                                        "status" => 0,//这里的status是之前的值
-                                        "action_remark" => '',//备注
-                                        "action_type" => "create"//新建create,编辑edit,更改状态status
-                                    ], "CKD", 0, $out);
-
-                                    ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
-                                        "order_type" => 'CKD',
-                                        "order_code" => $outCode,//出库单号
-                                        "order_id" => 0,
-                                        "order_status" => 0
-                                    ]);
-                                }
+                            $order = Db::name("order_num")
+                                ->where(["orderCode" => $orderCode, "status" => 1])
+                                ->where([["wsend_num", ">=", 0]])
+                                ->lock(true)
+                                ->find();
+                            if ($order == false) throw new Exception('未找到可以发货得采购单数据');
+
+
+                            $num = $extend_data['num'];
+                            $outCode = makeNo("DF");
+                            $order['wsend_num'] -= $num;
+                            $order['send_num'] += $num;
+                            $or = Db::name("order_num")->save($order);
+                            if ($or == false) throw new Exception('发货地址更新失败');
+
+                            $tep = [
+                                "cgdNo" => $order['cgdNo'],
+                                "outCode" => $outCode,
+                                "send_num" => $num,
+                                "status" => 1,
+                                "addtime" => date("Y-m-d H:i:s"),
+                                "updatetime" => date("Y-m-d H:i:s")
+                            ];
+                            $sen = Db::name("order_send")->save($tep);
+                            if ($sen == false) throw new Exception('发货地址添加创建失败');
+
+                            $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
+                            if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
+
+                            $out = [
+                                "orderCode" => $orderCode,
+                                "outCode" => $outCode,
+                                "apply_id" => $rm,
+                                "apply_name" => $ri,
+                                "addrid" => $vmp,
+                                "post_name" => "",
+                                "post_code" => "",
+                                "post_fee" => 0,
+                                "sendtime" => date("Y-m-d H:i:s"),
+                                "send_num" => $num,
+                                "check_num" => 0,
+                                "error_num" => 0,
+                                "wsm_code" => $cgdinfo['wsm_code'],
+                                "order_type" => 1,
+                                "status" => $is_stock == 1 ? 1 : 0,
+                                "addtime" => date("Y-m-d H:i:s"),
+                                "updatetime" => date("Y-m-d H:i:s")
+                            ];
+                            $ou = Db::name("order_out")->insert($out);
+                            if ($ou == false) throw new Exception('发货地址添加创建失败');
+                            else {
+                                //修改状态,添加待办
+                                ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
+                                    "order_code" => $outCode,//出库单号
+                                    "status" => 0,//这里的status是之前的值
+                                    "action_remark" => '',//备注
+                                    "action_type" => "create"//新建create,编辑edit,更改状态status
+                                ], "CKD", 0, $out);
+
+                                ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
+                                    "order_type" => 'CKD',
+                                    "order_code" => $outCode,//出库单号
+                                    "order_id" => 0,
+                                    "order_status" => 0
+                                ]);
                             }
                         } else throw new Exception('发货地址添加失败');
                     }