Browse Source

有赞订单生成、审核、发货等

wufeng 2 years ago
parent
commit
140294b05d

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

@@ -3559,16 +3559,22 @@ class Sale extends Base
         Db::startTrans();
         try{
             $up =Db::name("order_out")->save($outinfo);
+
+            $user_info = GetUserInfo($this->post['token']);
+            $uid = isset($user_info['data']['id'])?$user_info['data']['id']:0;
+            $uname = isset($user_info['data']['nickname'])?$user_info['data']['nickname']:'';
+
+
             if($up){
                 //修改状态,添加待办
-                ActionLog::logAdd($this->post['token'], [
+                ActionLog::logAdd(['id'=>$uid,'nickname'=>$uname], [
                     "order_code" => $outinfo['outCode'],//出库单号
                     "status" => $old_outinfo_status,//这里的status是之前的值
                     "action_remark" => '',//备注
                     "action_type" => "edit"//新建create,编辑edit,更改状态status
                 ], "CKD", $outinfo['status'], $outinfo);
 
-                ProcessOrder::AddProcess($this->post['token'], [
+                ProcessOrder::AddProcess(['id'=>$uid,'nickname'=>$uname], [
                     "order_type" => 'CKD',
                     "order_code" => $outinfo['outCode'],//出库单号
                     "order_id" => $outinfo['id'],
@@ -3587,14 +3593,14 @@ class Sale extends Base
                     }
 //                }
                 //修改状态,添加待办
-                ActionLog::logAdd($this->post['token'], [
+                ActionLog::logAdd(['id'=>$uid,'nickname'=>$uname], [
                     "order_code" => $einfo['orderCode'],//出库单号
                     "status" => $orderstatus,//这里的status是之前的值
                     "action_remark" => '',//备注
                     "action_type" => "edit"//新建create,编辑edit,更改状态status
                 ], "XSQRD", $einfo['status'], $einfo);
 
-                ProcessOrder::AddProcess($this->post['token'], [
+                ProcessOrder::AddProcess(['id'=>$uid,'nickname'=>$uname], [
                     "order_type" => 'XSQRD',
                     "order_code" =>$einfo['orderCode'],//出库单号
                     "order_id" => $einfo['id'],
@@ -3621,14 +3627,26 @@ class Sale extends Base
                     return error_show(1002, "库存更新失败");
                 }
                 $good_data[] = ['good_log_code' =>$outCode, "stock_id" =>$stokc['id'], "type" => 2,'stock'=>$outinfo['send_num'],"stock_name" => "wait_out_stock"];
-                GoodLog::LogAdd($this->post['token'],$good_data,"CKD");
+                GoodLog::LogAdd(['id'=>$uid,'nickname'=>$uname],$good_data,"CKD");
 //                Cache::store("redis")->handler()->lPush("SENDOUT",$outCode,1800);
+
                 Db::commit();
-                return app_show(0,"发货成功");
+
             }else{
                 Db::rollback();
                 return error_show(1004,"发货失败");
             }
+
+            //如果是有赞订单的话,将发货信息推到有赞
+            //有赞信息有可能推送失败(比如超过72小时,不允许多次修改等),所以不应该和这里的事务放到一起
+            if ($einfo['order_source'] == 5) {
+                $res = curl_request(config('app.yz_domain') . 'api/yz_out_send', ['orderCode' => $einfo['orderCode'], 'out_stype' => $post_name, 'post_code' => $post_code, 'uid' => $uid, 'uname' => $uname, 'order_out' => $outCode]);
+                $res = json_decode($res, true);
+                if ($res['code'] != 0) return app_show(0,'发货成功,'.$res['message']);
+            }
+
+            return app_show(0,"发货成功");
+
         }catch (\Exception $e){
             Db::rollback();
             return error_show(1004,$e->getMessage());

+ 750 - 0
app/command/handleYzOrderData.php

@@ -0,0 +1,750 @@
+<?php declare (strict_types=1);
+
+namespace app\command;
+
+use app\admin\model\ActionLog;
+use app\admin\model\GoodLog;
+use app\admin\model\ProcessOrder;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use think\Exception;
+use think\facade\Cache;
+use think\facade\Config;
+use think\facade\Db;
+
+//处理有赞订单数据
+class handleYzOrderData extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('handle_yz_order_data')->setDescription('处理有赞订单数据');
+    }
+
+    //处理有赞订单数据
+    protected function execute(Input $input, Output $output)
+    {
+
+        $c_data = Cache::store('redis')->handler()->rpop(Config::get('app.handle_queue_key'));
+
+        if ($c_data) {
+
+            $c_data = json_decode($c_data, true);
+
+            Db::startTrans();
+            try {
+
+                $standing_book_data = [];
+
+//                //先找用户确认信息
+//                $extend_data = Db::name('order_import_from_c_extend')
+//                    ->where(['order_import_from_c_id' => $c_data['id'], 'is_del' => 0, 'type' => 2])
+//                    ->find();
+//                if (empty($extend_data)) {
+//                    $extend_data = Db::name('order_import_from_c_extend')
+//                        ->where(['order_import_from_c_id' => $c_data['id'], 'is_del' => 0, 'type' => 1])
+//                        ->find();
+//                }
+//
+//                if (empty($extend_data)) throw new Exception('没有对应的解析数据');
+
+                //复用sale::create()方法 -- start
+
+                $orderCode = makeNo("QR");
+
+
+                //企业客户
+                $ct = Db::name('platform_youzan')
+                    ->alias('py')
+                    ->field('py.id,py.skuCode,py.spuCode,py.plat_code,co.id org1_id,co.name,py.sale_price,g.*,py.platform_id')
+                    ->leftJoin('platform p', 'p.id=py.platform_id AND p.is_del=0')
+                    ->leftJoin('customer_org1 co', 'co.name=p.platform_name AND co.is_del=0')
+                    ->leftJoin('good g', 'g.spuCode=py.spuCode AND g.is_del=0')
+                    ->where('py.skuCode', $c_data['skuCode'])
+                    ->where('py.exam_status', 6)//exam_status==6已上线
+                    ->find();
+
+                if ($ct) {
+                    $customer_code = Db::name('customer_info')
+                        ->where(['itemid' => $ct['org1_id'], 'companyName' => $ct['name'] . '客户', 'is_del' => 0])
+                        ->value('companyNo', '');
+
+                    if (!$customer_code) throw new Exception('在企业客户管理组织中找不到对应的企业');
+
+                } else throw new Exception('未找到商品数据');
+
+
+//                $customer_code = $customer_code = Db::name('customer_info')
+//                    ->where(['itemid' => $ct['id'], 'companyName' => $ct['name'] . '客户', 'is_del' => 0])
+//                    ->value('companyNo', '');
+//
+//                $customer = Db::name("customer_info")
+//                    ->where(["companyNo" => $customer_code])
+//                    ->find();
+
+//                if ($customer == false) throw new Exception('未找到客户数据');
+
+                $supplierNo = $ct['companyNo'];
+//                $supplier = Db::name("business")
+//                    ->where(["companyNo" => $supplierNo])
+//                    ->find();
+//                if ($supplier == false) throw new Exception('未找到平台供应商数据');
+
+                $goodtype = 1;//1正常商品
+
+                $sendtype = 1;//直接发货
+                $platform_id = $ct['platform_id'];
+
+                $platform_order = $c_data['tid'];
+                $good_num = $c_data['num'];
+                $arrtime = $paytime = $c_data['addtime'];
+//                $paytime = $c_data['addtime'];
+//                $workNo = $extend_data['po_code'];
+//                $ct = Db::name('good_platform')
+//                    ->alias('a')
+//                    ->join('good b', 'b.spuCode=a.spuCode', 'left')
+//                    ->where(['a.skuCode' => $extend_data['skuCode'], 'a.exam_status' => 6])//exam_status==6已上线
+//                    ->field("b.*,a.skuCode,a.spuCode,a.platform_code,a.plat_code")
+//                    ->find();
+//                if ($ct == false) throw new Exception('未找到商品数据');
+
+                $goodinfo = $ct;
+                $is_stock = $ct['is_stock'];
+                $order_type = $is_stock == 1 ? 1 : 2;//1备库(库存品)2非库存品
+                $order_source = 5;//有赞
+                $spuCode = $ct['spuCode'];
+                $skuCode = $ct['skuCode'];
+//                $is_activity = empty($extend_data['activity_name']) ? 0 : 1;
+
+                if ($is_stock == 1) {
+                    $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.wsm_type' => 5, "b.companyNo" => $supplierNo])
+                        ->field("a.id,a.usable_stock,a.wait_out_stock")
+                        ->find();
+
+                    if ($stock == false || $stock['usable_stock'] < $good_num) throw new Exception('库存数量不足');
+
+                    $origin_price = 0;
+
+                } else {
+
+                    $origin = Db::name("good_nake")
+                        ->where([["spuCode", "=", $spuCode], ["min_num", "<=", $good_num], ["is_del", "=", 0]])
+                        ->order("min_num desc")
+                        ->find();
+                    if ($origin == false) throw new Exception('未找到相关成本价格');
+
+                    $origin_price = $origin['nake_total'];
+
+                }
+
+
+                //活动相关信息
+                $act = Db::name('activity_info')
+                    ->alias('ai')
+                    ->field('ai.id,ai.activity_stock,ai.moq_num,ai.activity_stock')
+                    ->join('good_activity ga', 'ga.activity_code=ai.activity_code')
+                    ->where([
+                        'ai.skuCode' => $skuCode,
+                        'ai.spuCode' => $spuCode,
+                        'ai.is_del' => 0,
+                        'ai.status' => 1,
+                        'ga.status' => 6,
+                        'ga.is_del' => 0,
+                        'ga.platform_code' => $platform_id,
+                        'ga.is_stock' => $is_stock
+                    ])
+                    ->where(function ($query) {
+                        return $query->where('ga.start', '<=', date('Y-m-d H:i:s'))->where('ga.end', '>=', date('Y-m-d H:i:s'));
+                    })
+                    ->find();
+
+                $is_activity = 0;
+                if (!empty($act)) {
+                    $is_activity = 1;
+                    if ($act['moq_num'] > $good_num) throw new Exception('商品不满足活动价起订量' . $act['moq_num']);
+                    if ($act['activity_stock'] < $good_num) throw new Exception('商品活动库存剩余' . $act['activity_stock']);
+                }
+
+//                $is_activity = (int)(!empty($act));
+
+//                if ($is_activity == 1) {
+//                    $act = Db::name("activity_info")
+//                        ->alias("a")
+//                        ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
+//                        ->where(["a.skuCode" => $skuCode, "a.activity_code" => $extend_data['activity_code'], "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
+//                        ->find();
+//                    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'];//不能改动价格
+//                }
+
+
+                $sale_price = $c_data['discount_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('未找到相关阶梯价格');
+
+                    //$sale_price = $good['sale_price']; //不改动售价
+
+                    //理论上不会出现实时金价的订单
+//                    if ($ct['is_gold_price'] == 1 && $is_stock != 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);
+//                        $gold_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'];
+//                        if ($sale_price < $gold_sale_price) throw new Exception('价格不符合根据实时金价计算出的最终售价');
+//
+//                        $ct['cgd_gold_price'] = $gold['price'];
+//
+//                    }
+
+
+                }
+
+
+                $remark = $c_data['buyer_messages'];
+                $rm = 0;
+                $ri = 'youzan';
+                $data = [
+                    "orderCode" => $orderCode,
+                    "good_code" => $spuCode,
+                    "skuCode" => $skuCode,
+                    "customer_code" => $customer_code,
+                    "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
+                    "good_num" => $good_num,
+                    "cat_id" => $goodinfo['cat_id'],
+                    "apply_id" => $rm,
+                    "apply_name" => $ri,
+                    "origin_price" => $origin_price,
+                    "sale_price" => $sale_price,
+                    "post_fee" => 0,
+                    "status" => 0,
+                    "send_num" => 0,
+                    "wsend_num" => $good_num,
+                    "send_status" => 1,
+                    "good_type" => $goodtype,
+                    "send_type" => $sendtype,
+                    "supplierNo" => $goodinfo['companyNo'],
+                    "is_del" => 0,
+                    "zxNo" => "",
+                    "platform_order" => $platform_order,
+                    "platform_id" => $platform_id,
+                    "remark" => $remark,
+                    "is_stock" => $is_stock,
+                    "is_activity" => $is_activity,
+                    'activity_code' => $is_activity ? $act['activity_code'] : '',
+                    "order_type" => $order_type,
+                    "order_source" => $order_source,
+//                "poNo"=>$poNo,
+                    'good_weight' => $ct['weight'],
+                    'gold_price' => $ct['cgd_gold_price'],
+                    'cost_price' => $ct['cost_fee'],
+                    'diff_weight' => 0,
+                    'diff_fee' => 0,
+                    "workNo" => '',
+                    "addtime" => date("Y-m-d H:i:s"),
+                    "updatetime" => date("Y-m-d H:i:s"),
+                    'total_price' => bcmul((string)$sale_price, (string)$good_num, 2),
+                ];
+                $paytime == "" ? "" : $data['paytime'] = $paytime;
+                $datainfo = Db::name('sale')->insertGetId($data);
+
+                if ($datainfo > 0) {
+                    if ($is_activity == 1) {
+                        $actup = [
+                            "activity_stock" => $act['activity_stock'] - $good_num,
+                            "updatetime" => date("Y-m-d H:i:s")
+                        ];
+                        $actupp = Db::name("activity_info")
+                            ->where('id', $act['id'])
+                            ->save($actup);
+                        if ($actupp == false) throw new Exception('活动库存修改失败');
+
+                    }
+
+                    //补充台账数据
+                    $standing_book_data = array_merge($standing_book_data, [
+                        'orderCode' => $orderCode,
+                        'spuCode' => $data['good_code'],
+                        'skuCode' => $data['skuCode'],
+                        'order_type' => $data['order_type'],
+                        'order_source' => $data['order_source'],
+                        'supplierNo' => $data['supplierNo'],
+                        'companyNo' => $ct['companyNo'],
+                        'customer_code' => $data['customer_code'],
+                    ]);
+
+                    if ($is_stock == 0) {
+
+                        $cgd = [
+                            "supplierNo" => $ct['supplierNo'],
+                            "companyNo" => $supplierNo,
+                            "orderCode" => $orderCode,
+                            "spuCode" => $spuCode,
+                            "skuCode" => $skuCode,
+                            "good_name" => $ct['good_name'],
+                            "sale_price" => $origin_price,
+                            "total_fee" => $origin_price * $good_num,
+                            "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
+                            "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
+                            "open_fee" => $ct['open_fee'],
+                            "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
+                            "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
+                            "demo_fee" => $ct['demo_fee'],
+                            "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
+                            "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
+                            "good_num" => $good_num,
+                            "good_type" => $goodtype,
+                            "order_type" => $order_type,
+                            "order_source" => $order_source,
+                            "createrid" => $ct['createrid'],
+                            "creater" => $ct['creater'],
+                            'send_way' => 2,
+                            'gold_price' => $ct['cgd_gold_price'],
+                        ];
+
+                        //非库存品
+                        $bol = $this->createCgd($cgd, $rm, $ri, $standing_book_data);
+                        if ($bol == false) throw new Exception('订单创建失败');
+
+                    } else {
+                        //库存品
+                        $cgd = [
+                            'orderCode' => $orderCode,
+                            "good_num" => $good_num,
+                            "spuCode" => $spuCode,
+                            "companyNo" => $supplierNo,
+                            'order_type' => $order_type,
+                            'order_source' => $order_source
+                        ];
+                        $bol = $this->RelaCgd($cgd, $standing_book_data);
+                        if ($bol == false) throw new Exception('库存商品关联采购单失败');
+
+                        if (isset($stock)) {
+                            $stck = [
+                                "usable_stock" => $stock['usable_stock'] - $good_num,
+                                "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
+                                "updatetime" => date("Y-m-d H:i:s")
+                            ];
+                            $upad = Db::name("good_stock")
+                                ->where($stock)
+                                ->update($stck);
+                            if ($upad == false) throw new Exception('库存商品更新库存失败');
+
+                            //商品变动日志表,good_log_code字段存储采购单号
+                            $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
+                            $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
+                            GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
+                        }
+
+                    }
+                    if ($sendtype == 1) {
+
+                        $p_c_a = get_address($c_data['delivery_province'] . $c_data['delivery_city'] . $c_data['delivery_district']);
+
+                        $province = empty($p_c_a['province']) ? $p_c_a['province'] : Db::name('province')->whereLike('name', '%' . $p_c_a['province'] . '%')->value('province_code');
+                        $city = empty($p_c_a['city']) ? $p_c_a['city'] : Db::name('city')->whereLike('name', '%' . $p_c_a['city'] . '%')->value('city_code');
+                        $area = empty($p_c_a['district']) ? $p_c_a['district'] : Db::name('area')->whereLike('name', '%' . $p_c_a['district'] . '%')->value('area_code');
+
+                        $addr_code = implode([$province, $city, $area], ',');
+
+                        $temp = [
+                            'orderCode' => $orderCode,
+                            'contactor' => $c_data['receiver_name'],
+                            'mobile' => $c_data['receiver_tel'],
+                            'addr' => $c_data['delivery_address'],
+                            'addr_code' => $addr_code,
+                            'customer_code' => $customer_code,
+                            'receipt_quantity' => $c_data['num'],//收货数量,
+                            'post_fee' => $c_data['post_fee'],
+                            'is_del' => 0,
+                            'addtime' => date("Y-m-d H:i:s"),
+                            'updatetime' => date("Y-m-d H:i:s"),
+                            'arrive_time' => $arrtime,
+                        ];
+                        $vmp = Db::name('order_addr')->insertGetId($temp);
+                        if ($vmp > 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 = $c_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" => $order_type,
+                                "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,
+                                    "before_status" => 0
+                                ]);
+
+//                                $standing_book_data['outCode'] = $outCode;
+                            }
+                        } else throw new Exception('发货地址添加失败');
+                    }
+                }
+
+                //复用sale::create()方法 -- end
+
+                //处理完成
+//                $order_import_from_c_db
+//                    ->where('id', $c_data['id'])
+//                    ->where('is_del', OIFCModel::$is_del_normal)
+//                    ->save([
+//                        'status' => $order_import_from_c_db::$status_success,
+//                        'updatetime' => date('Y-m-d H:i:s'),
+//                        'remark' => '',
+//                        'updateid' => 0,
+//                        'updater' => 'system',
+//                        'orderCode' => $orderCode
+//                    ]);
+
+                //维护台账记录
+                if (isset($standing_book_data['bk_code'])) Db::name('standing_book')->where('bk_code', $standing_book_data['bk_code'])->update(array_merge($standing_book_data, ['updatetime' => date('Y-m-d H:i:s')]));
+                else Db::name('standing_book')->insert(array_merge($standing_book_data, ['addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo("IO")]));
+
+
+                //回调更新有赞订单数据
+                $callback_rs = $this->callbackYz(['status' => 6, 'id' => $c_data['id'], 'orderCode' => $orderCode]);
+                if ($callback_rs['code'] != 0) throw new Exception($callback_rs['message']);
+
+                Db::commit();
+
+                $output->writeln(date('Y-m-d H:i:s') . '|处理成功,orderCode:' . $orderCode);
+
+            } catch (\think\Exception $exception) {
+                Db::rollback();
+
+                $message[] = $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine();
+
+                //回调更新有赞订单数据
+                $callback_rs = $this->callbackYz(['status' => 2, 'id' => $c_data['id'], 'reason' => $exception->getMessage()]);
+                if ($callback_rs['code'] != 0) $message[] = $callback_rs['message'];
+
+                $output->writeln(date('Y-m-d H:i:s') . '|处理失败,' . implode(',', $message));
+            }
+
+        }
+
+        //没有需要处理的数据
+
+    }
+
+
+    //创建采购单
+    private function createCgd($data = [], $rm = '0', $ri = '', array &$standing_book_data = [])
+    {
+        $cgdCode = makeNo("CG");
+        $supplier = Db::name("supplier")->where(["code" => $data['supplierNo'], "is_del" => 0])->find();
+        if ($supplier == false) return false;
+
+        $wsm = Db::name("warehouse_info")
+            ->where(["supplierNo" => $data["supplierNo"], "companyNo" => $data['companyNo'], "is_del" => 0])
+            ->find();
+        if ($wsm == false) {
+            $wsm_code = makeNo("WSM");
+            $inwsm = [
+                "wsm_code" => $wsm_code,
+                "name" => $supplier['name'],
+                "wsm_type" => 2,
+                "supplierNo" => $supplier['code'],
+                "addr" => "",
+                "addrs_code" => "",
+                "contactor" => 0,
+                "contactor_name" => 0,
+                "mobile" => "",
+                "position" => "",
+                "companyNo" => $data['companyNo'],
+                "status" => 1,
+                "is_del" => 0,
+                "addtime" => date("Y-m-d H:i:s"),
+                "updatetime" => date("Y-m-d H:i:s")
+            ];
+            $in = Db::name("warehouse_info")->insert($inwsm);
+            if ($in == false) return false;
+
+        } else {
+            $wsm_code = $wsm['wsm_code'];
+        }
+
+        $cg = [
+            "cgdNo" => $cgdCode,
+            "bkcode" => "",
+            "wsm_code" => $wsm_code,
+            "cgder" => $data['creater'],
+            "cgder_id" => $data['createrid'],
+            "spuCode" => $data['spuCode'],
+            "skuCode" => $data['skuCode'],
+            "good_name" => $data['good_name'],
+            "good_num" => $data['good_num'],
+            "good_price" => $data['sale_price'],
+            "total_fee" => round($data['sale_price'] * $data['good_num'], 2),
+            "pakge_fee" => $data['pakge_fee'],
+            "cert_fee" => $data['cert_fee'],
+            "open_fee" => $data['open_fee'],
+            "teach_fee" => $data['cost_fee'],
+            "mark_fee" => $data['mark_fee'],
+            "demo_fee" => $data['demo_fee'],
+            "nake_fee" => $data['nake_fee'],
+            "delivery_fee" => $data['delivery_fee'],
+            #"weight"=>$data['weight'],
+            "diff_weight" => "0",
+            "diff_fee" => "0",
+            "gold_price" => $data['gold_price'],
+            "supplierNo" => $data['supplierNo'],
+            "supplier_name" => $supplier['name'],
+            "companyNo" => $data['companyNo'],
+            "send_status" => 1,
+            "send_num" => 0,
+            "wsend_num" => $data['good_num'],
+            "remark" => "",
+            "status" => 0,//0初始化
+            "lasttime" => date("Y-m-d H:i:s"),
+            "is_del" => 0,
+            "order_type" => $data['order_type'],
+            "order_source" => $data['order_source'],
+            "good_type" => $data['good_type'],
+            "addtime" => date("Y-m-d H:i:s"),
+            "updatetime" => date("Y-m-d H:i:s")
+        ];
+        $up = Db::name("purchease_order")->insert($cg, true);
+        if ($up) {
+
+            //修改状态,添加待办
+            ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
+                "order_code" => $cg['cgdNo'],//销售单code
+                "status" => 0,//这里的status是之前的值
+                "action_remark" => '',//备注
+                "action_type" => "create"//新建create,编辑edit,更改状态status
+            ], "CGD", $cg['status'], $cg);
+
+            ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
+                "order_type" => 'CGD',
+                "order_code" => $cg['cgdNo'],//销售单code
+                "order_id" => $up,
+                "order_status" => $cg['status'],
+                "before_status" => 0
+            ]);
+
+            $standing_book_data['cgdNo'] = $cgdCode;
+
+            $rela = [
+                "orderCode" => $data['orderCode'],
+                "cgdNo" => $cgdCode,
+                "spuCode" => $data['spuCode'],
+                "good_num" => $data['good_num'],
+                "wsend_num" => $data['good_num'],
+                "send_num" => 0,
+                "wait_num" => 0,
+                "status" => 1,
+                "source" => 2
+            ];
+            $re = Db::name("order_num")->save($rela);
+            if ($re == false) return false;
+            else {
+                $stokc = Db::name("good_stock")
+                    ->where(['spuCode' => $data['spuCode'], "wsm_code" => $wsm_code, "is_del" => 0])
+                    ->find();
+                if ($stokc == false) {
+                    $stokc = [
+                        "spuCode" => $data['spuCode'],
+                        "wsm_code" => $wsm_code,
+                        "wait_in_stock" => $data['good_num'],
+                        "wait_out_stock" => 0,
+                        "usable_stock" => 0,
+                        "intra_stock" => 0,
+                        "total_stock" => 0,
+                        "status" => 1,
+                        "addtime" => date("Y-m-d H:i:s"),
+                        "updatetime" => date("Y-m-d H:i:s")
+                    ];
+                } else {
+                    $stokc['wait_in_stock'] += $data['good_num'];
+                    $stokc['updatetime'] = date("Y-m-d H:i:s");
+                }
+                $stoc = Db::name("good_stock")->save($stokc);
+                if ($stoc == false) return false;
+
+                $good_data[] = ['good_log_code' => $cgdCode, "stock_id" => isset($stoc['id']) ? $stoc['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $data['good_num'], "stock_name" => "wait_in_stock"];
+                GoodLog::LogAdd(['id' => 0, 'nickname' => 'system'], $good_data, "CGD");
+
+                return true;
+            }
+        } else return false;
+
+    }
+
+
+    //创建.....
+    private function RelaCgd(array $outinfo = [], array &$standing_book_data = [])
+    {
+        //备库单
+        $cgd = Db::name("order_bk")
+            ->where([
+                ["spuCode", "=", $outinfo['spuCode']],
+                ["is_del", "=", 0],
+                ["balance_num", ">=", $outinfo['good_num']],
+                ['companyNo', "=", $outinfo['companyNo']]
+            ])
+            ->lock(true)
+            ->find();
+
+        if ($cgd == false) return false;
+
+        $cgdinfo = Db::name("purchease_order")->where(['cgdNo' => $cgd['cgdNo'], "is_del" => 0])->find();
+        if ($cgdinfo == false) return false;
+
+        $QrdCgd = [
+            "cgdNo" => makeNo("CG"),
+            "bkcode" => $cgdinfo['bkcode'],
+            'wsm_code' => $cgdinfo['wsm_code'],
+            "cgder_id" => $cgdinfo['cgder_id'],
+            "cgder" => $cgdinfo['cgder'],
+            "spuCode" => $cgdinfo['spuCode'],
+            "good_name" => $cgdinfo['good_name'],
+            "good_num" => $outinfo['good_num'],
+            "good_price" => $cgdinfo['good_price'],
+            "total_fee" => round($cgdinfo['good_price'] * $outinfo['good_num'], 2),
+            "pakge_fee" => $cgdinfo['pakge_fee'],
+            "cert_fee" => $cgdinfo['cert_fee'],
+            "open_fee" => $cgdinfo['open_fee'],
+            "delivery_fee" => $cgdinfo['delivery_fee'],
+            "mark_fee" => $cgdinfo['mark_fee'],
+            "teach_fee" => $cgdinfo['teach_fee'],
+            "nake_fee" => $cgdinfo['nake_fee'],
+            "demo_fee" => $cgdinfo['demo_fee'],
+            "weight" => $cgdinfo['weight'],
+            "diff_weight" => $cgdinfo['diff_weight'],
+            "diff_fee" => $cgdinfo['diff_fee'],
+            "gold_price" => $cgdinfo['gold_price'],
+            "supplierNo" => $cgdinfo['supplierNo'],
+            "supplier_name" => $cgdinfo['supplier_name'],
+            "companyNo" => $cgdinfo['companyNo'],
+            "send_status" => 3,
+            "send_num" => $outinfo['good_num'],
+            "wsend_num" => 0,
+            "remark" => $cgdinfo['remark'],
+            "status" => 3,//入库完成
+            "lasttime" => $cgdinfo['lasttime'],
+            "is_del" => 0,
+            "order_type" => $outinfo['order_type'],
+            "order_source" => $outinfo['order_source'],
+            "good_type" => $cgdinfo['good_type'],
+            "addtime" => date("Y-m-d H:i:s"),
+            "updatetime" => date("Y-m-d H:i:s")
+        ];
+        $insetrCgd = Db::name("purchease_order")->insert($QrdCgd);
+        if ($insetrCgd == false) return false;
+
+        $standing_book_data = array_merge($standing_book_data, [
+            'cgdNo' => $QrdCgd['cgdNo'],
+            'bk_code' => $QrdCgd['bkcode'],
+        ]);
+
+        $merge_num = Db::name("purchease_order")
+            ->where(["bkcode" => $cgdinfo['bkcode'], "order_type" => $outinfo['order_type'], "is_del" => 0])
+            ->where('order_source', '<>', 0)//0备库单不计算在内
+            ->field("sum(send_num)-sum(th_num) as num")
+            ->find();
+        $cgd['balance_num'] = $cgd['total_num'] - $merge_num['num'];
+        $cgd['merge_num'] = $merge_num['num'];
+        $cgd['updatetime'] = date("Y-m-d H:i:s");
+        $up = Db::name("order_bk")->save($cgd);
+        if ($up == false) return false;
+
+        $data = [
+            "orderCode" => $outinfo['orderCode'],
+            "cgdNo" => $QrdCgd['cgdNo'],
+            "spuCode" => $outinfo['spuCode'],
+            "companyNo" => $outinfo['companyNo'],
+            "good_num" => $outinfo['good_num'],
+            "wsend_num" => $outinfo['good_num'],
+            "send_num" => 0,
+            "wait_num" => $outinfo['good_num'],
+            "status" => 1,
+            "source" => 1,
+        ];
+        $order = Db::name("order_num")->save($data);
+        if ($order == false) return false;
+
+        return true;
+    }
+
+
+    //与有赞项目回调
+    private function callbackYz(array $data = [])
+    {
+        $host = Config::get('app.yz_domain');
+        $response = curl_request($host . 'api/callback_order_by_stock', $data);
+        return json_decode($response, true);
+    }
+
+
+}

+ 15 - 16
app/youzan/controller/Index.php

@@ -124,22 +124,6 @@ class Index extends Base
 
     }
 
-    //处理有赞订单(确认或取消)
-    public function checkHandleStatus()
-    {
-        $param = $this->request->filter('trim')->only(['token', 'good_info_id', 'handle_status'], 'post');
-
-        $val = Validate::rule([
-            'token' => 'require',
-            'good_info_id|订单id' => 'require|number|gt:0',
-            'handle_status|处理状态' => 'require|number|in:1,2',
-        ]);
-
-        if ($val->check($param)) return Order::checkHandleStatus($param);
-        else return error_show(1005, $val->getError());
-
-    }
-
     //获取有赞平台修改商品日志
     public function getYzUpdateLog()
     {
@@ -166,6 +150,21 @@ class Index extends Base
 
     }
 
+    //有赞订单审核
+    public function checkStatus()
+    {
+
+        $param = $this->request->filter('trim')->only(['id', 'status', 'token', 'reason' => '']);
+
+        $val = Validate::rule([
+            'id|订单ID' => 'require|number|gt:0',
+            'status|审核状态' => 'require|number|in:3,4,5,0', 'token' => 'require'
+        ]);
+
+        if ($val->check($param)) return Order::checkStatus($param);
+        else return error_show(1005, $val->getError());
+
+    }
 
 
 }

+ 15 - 422
app/youzan/logic/Order.php

@@ -18,437 +18,30 @@ class Order
     public static function getYzOrderList(array $data = [])
     {
 
-        $res= curl_request(config('app.yz_domain') . 'api/yz_order_list', $data);
-        $res = json_decode($res,true);
-        if($res['code']==0) return app_show(0,$res['message'],$res['data']);
-        else return error_show($res['code'],$res['message']);
+        $res = curl_request(config('app.yz_domain') . 'api/yz_order_list', $data);
+        $res = json_decode($res, true);
+        if ($res['code'] == 0) return app_show(0, $res['message'], $res['data']);
+        else return error_show($res['code'], $res['message']);
 
     }
 
-
-    //处理有赞订单(确认或取消)
-    public static function checkHandleStatus(array $data = [])
-    {
-        $user = GetUserInfo($data['token']);
-        $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
-        $uname = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
-
-        Db::startTrans();
-
-        try {
-
-            //有赞项目中,订单信息
-            $rs = Db::connect('mysql_yz')
-                ->table('yz_order_info')
-                ->alias('oi')
-                ->field('oi.id,oi.handle_status,oi.item_no,oi.num,oi.discount_price,oi.addtime,oi.buyer_messages,oa.receiver_name,oa.receiver_tel,oa.delivery_province,oa.delivery_city,oa.delivery_district,oa.delivery_address')
-                ->leftJoin('order_address oa', 'oa.tid=oi.tid')
-                ->where('oi.id', $data['good_info_id'])
-                ->findOrEmpty();
-
-            if (empty($rs)) throw new Exception('该订单记录不存在');
-            if ($rs['handle_status'] != 0) throw new Exception('该订单不是待确认状态');
-
-
-            //确认
-            if ($data['handle_status'] == 2) {
-
-                //组织数据
-                $extend_data = Db::name('platform_youzan')
-                    ->alias('pyz')
-                    ->field('pyz.id,ci.companyNo customer_code,g.companyNo,pyz.platform_id,p.platform_code')
-                    ->leftJoin('good g', 'g.spuCode=pyz.spuCode')
-                    ->leftJoin('platform p', 'p.id=pyz.platform_id AND p.is_del=0')
-                    ->leftJoin('customer_org1 co', 'co.name=p.platform_name AND co.is_del=0')
-                    ->leftJoin('customer_info ci', 'ci.itemid=co.id AND ci.companyName=co.name AND ci.is_del=0')
-                    ->where('pyz.skuCode', $rs['item_no'])
-                    ->findOrEmpty();
-
-                if (empty($temp)) throw new Exception('该商品的上架记录不存在');
-
-                $extend_data = array_merge($extend_data, [
-                    'num' => $rs['num'],
-                    'platform_time' => $rs['addtime'],
-                    'addtime' => $rs['addtime'],
-                    'po_code' => '',
-                    'skuCode' => $rs['item_no'],
-                    'activity_name' => '',//???????????????????? @todo 有赞商品和采销系统活动待关联
-                    'price' => $rs['discount_price'],
-                    'activity_code' => '',//???????????????????? @todo 有赞商品和采销系统活动待关联
-                    'order_remark' => $rs['buyer_messages'],
-                    'contactor' => $rs['receiver_name'],
-                    'mobile' => $rs['receiver_tel'],
-                    'addr' => $rs['delivery_province'] . $rs['delivery_city'] . $rs['delivery_district'] . $rs['delivery_address'],
-                ]);
-
-                $province = Db::name('province')->whereLike('name', '%' . $rs['delivery_province'] . '%')->value('province_code');
-                $city = Db::name('city')->whereLike('name', '%' . $rs['delivery_city'] . '%')->value('city_code');
-                $area = Db::name('area')->whereLike('name', '%' . $rs['delivery_district'] . '%')->value('area_code');
-
-                $extend_data['addr_code'] = implode([$province, $city, $area], ',');
-
-                //生成销售单和采购单
-                $orderCode = self::createOrderAndPurch($extend_data);
-
-            }
-
-
-            //更新有赞项目相关信息
-            $update_rs = Db::connect('mysql_yz')
-                ->table('yz_order_info')
-                ->where('oi.id', $data['good_info_id'])
-                ->update([
-                    'handle_status' => $data['handle_status'],
-                    'orderCode' => $orderCode,
-                    'updateid' => $uid,
-                    'updater' => $uname,
-                    'updatetime' => date('Y-m-d H:i:s'),
-                ]);
-
-            if (!$update_rs) throw new Exception('修改失败');
-
-            Db::commit();
-
-            return app_show(0, '操作成功');
-
-        } catch (Exception $exception) {
-
-            Db::rollback();
-
-            return error_show(1005, $exception->getMessage());
-        }
-    }
-
-
-    //
-    private static function createOrderAndPurch(array $extend_data = [])
+    //有赞订单审核
+    public static function checkStatus(array $data = [])
     {
-        $orderCode = makeNo("QR");
-        $customer_code = $extend_data['customer_code'];
-
-        $customer = Db::name("customer_info")
-            ->where(["companyNo" => $customer_code])
-            ->find();
-
-        if ($customer == false) throw new Exception('未找到客户数据');
-
-        $supplierNo = $extend_data['companyNo'];
-        $supplier = Db::name("business")
-            ->where(["companyNo" => $supplierNo])
-            ->find();
-        if ($supplier == false) throw new Exception('未找到平台供应商数据');
-
-        $goodtype = 1;//1正常商品
-
-        $sendtype = 1;//直接发货
-        $platform_id = $extend_data['platform_id'];
-
-        $platform_order = $extend_data['platform_code'];
-        $good_num = $extend_data['num'];
-        $arrtime = $extend_data['platform_time'];
-        $paytime = $extend_data['addtime'];
-        $workNo = $extend_data['po_code'];
-        $ct = Db::name('good_platform')
-            ->alias('a')
-            ->join('good b', 'b.spuCode=a.spuCode', 'left')
-            ->where(['a.skuCode' => $extend_data['skuCode'], 'a.exam_status' => 6])//exam_status==6已上线
-            ->field("b.*,a.skuCode,a.spuCode,a.platform_code,a.plat_code")
-            ->find();
-        if ($ct == false) throw new Exception('未找到商品数据');
-
-        $goodinfo = $ct;
-        $is_stock = $ct['is_stock'];
-        $order_type = $is_stock == 1 ? 1 : 2;//1备库(库存品)2非库存品
-        $order_source = 4;//4平台
-        $spuCode = $ct['spuCode'];
-        $skuCode = $ct['skuCode'];
-        $is_activity = empty($extend_data['activity_name']) ? 0 : 1;
-
-        if ($goodinfo['is_stock'] == 1) {
-            $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.wsm_type' => 5, "b.companyNo" => $supplierNo])
-                ->field("a.id,a.usable_stock,a.wait_out_stock")
-                ->find();
-
-            if ($stock == false || $stock['usable_stock'] < $good_num) throw new Exception('库存数量不足');
-
-            $origin_price = 0;
-
-        } else {
-
-            $origin = Db::name("good_nake")
-                ->where([["spuCode", "=", $spuCode], ["min_num", "<=", $good_num], ["is_del", "=", 0]])
-                ->order("min_num desc")
-                ->find();
-            if ($origin == false) throw new Exception('未找到相关成本价格');
-
-            $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('未找到相关阶梯价格');
-
-            //$sale_price = $good['sale_price']; //不改动售价
-
-            //理论上不会出现实时金价的订单
-            if ($ct['is_gold_price'] == 1 && $is_stock != 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);
-                $gold_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'];
-                if ($sale_price < $gold_sale_price) throw new Exception('价格不符合根据实时金价计算出的最终售价');
-
-                $ct['cgd_gold_price'] = $gold['price'];
-
-//                $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")
-                    ->alias("a")
-                    ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
-                    ->where(["a.skuCode" => $skuCode, "a.activity_code" => $extend_data['activity_code'], "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
-                    ->find();
-                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 = [
-            "supplierNo" => $ct['supplierNo'],
-            "companyNo" => $supplierNo,
-            "orderCode" => $orderCode,
-            "spuCode" => $ct['spuCode'],
-            "skuCode" => $ct['skuCode'],
-            "good_name" => $ct['good_name'],
-            "sale_price" => $origin_price,
-            "total_fee" => $origin_price * $good_num,
-            "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
-            "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
-            "open_fee" => $ct['open_fee'],
-            "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
-            "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
-            "demo_fee" => $ct['demo_fee'],
-            "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
-            "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
-            "good_num" => $good_num,
-            "good_type" => $goodtype,
-            "order_type" => $order_type,
-            "order_source" => $order_source,
-            "createrid" => $ct['createrid'],
-            "creater" => $ct['creater'],
-            'send_way' => 2,
-            'gold_price' => $ct['cgd_gold_price'],
-        ];
-
-        $send_num = $extend_data['num'];
-        $remark = $extend_data['order_remark'];
-        $rm = $c_data['createrid'];
-        $ri = $c_data['creater'];
-        $data = [
-            "orderCode" => $orderCode,
-            "good_code" => $spuCode,
-            "skuCode" => $skuCode,
-            "customer_code" => $customer_code,
-            "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
-            "good_num" => $good_num,
-            "cat_id" => $goodinfo['cat_id'],
-            "apply_id" => $rm,
-            "apply_name" => $ri,
-            "origin_price" => $origin_price,
-            "sale_price" => $sale_price,
-            "post_fee" => 0,
-            "status" => 0,
-            "send_num" => 0,
-            "wsend_num" => $good_num,
-            "send_status" => 1,
-            "good_type" => $goodtype,
-            "send_type" => $sendtype,
-            "supplierNo" => $extend_data['companyNo'],
-            "is_del" => 0,
-            "zxNo" => "",
-            "platform_order" => $platform_order,
-            "platform_id" => $platform_id,
-            "remark" => $remark,
-            "is_stock" => $is_stock,
-            "is_activity" => $is_activity === "" ? 0 : $is_activity,
-            'activity_code' => $extend_data['activity_code'],
-            "order_type" => $order_type,
-            "order_source" => $order_source,
-//                "poNo"=>$poNo,
-            'good_weight' => $ct['weight'],
-            'gold_price' => $ct['cgd_gold_price'],
-            'cost_price' => $ct['cost_fee'],
-            'diff_weight' => 0,
-            'diff_fee' => 0,
-            "workNo" => $workNo,
-            "addtime" => date("Y-m-d H:i:s"),
-            "updatetime" => date("Y-m-d H:i:s"),
-            'total_price' => round($sale_price * $good_num, 2),
-        ];
-        $paytime == "" ? "" : $data['paytime'] = $paytime;
-        $datainfo = Db::name('sale')->insert($data, true);
-        if ($datainfo > 0) {
-            if ($is_activity == 1) {
-                $actup = [
-                    "activity_stock" => $act['activity_stock'] - $good_num,
-                    "updatetime" => date("Y-m-d H:i:s")
-                ];
-                $actupp = Db::name("activity_info")
-                    ->where(["skuCode" => $skuCode, "activity_code" => $extend_data['activity_code'], "is_del" => 0, "status" => 1])
-                    ->save($actup);
-                if ($actupp == false) throw new Exception('活动库存修改失败');
-
-            }
-
-            //补充台账数据
-            $standing_book_data = array_merge($standing_book_data, [
-                'orderCode' => $orderCode,
-                'spuCode' => $data['good_code'],
-                'skuCode' => $data['skuCode'],
-                'order_type' => $data['order_type'],
-                'order_source' => $data['order_source'],
-                'supplierNo' => $extend_data['supplierNo'],
-                'companyNo' => $extend_data['companyNo'],
-                'customer_code' => $data['customer_code'],
-            ]);
-            if ($is_stock == 0) {
-
-                //非库存品
-                $bol = $this->createCgd($cgd, $rm, $ri, $standing_book_data);
-                if ($bol == false) throw new Exception('订单创建失败');
-
-            } else {
-                //库存品
-                $bol = $this->RelaCgd(['orderCode' => $orderCode, "good_num" => $good_num, "spuCode" => $spuCode, "companyNo" => $supplierNo, 'order_type' => $order_type, 'order_source' => $order_source], $standing_book_data);
-                if ($bol == false) throw new Exception('库存商品关联采购单失败');
-
-                if (isset($stock)) {
-                    $stck = [
-                        "usable_stock" => $stock['usable_stock'] - $good_num,
-                        "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
-                        "updatetime" => date("Y-m-d H:i:s")
-                    ];
-                    $upad = Db::name("good_stock")
-                        ->where($stock)
-                        ->update($stck);
-                    if ($upad == false) throw new Exception('库存商品更新库存失败');
-
-                    //商品变动日志表,good_log_code字段存储采购单号
-                    $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
-                    $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
-                    GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
-                }
-
-            }
-            if ($sendtype == 1) {
-                $temp = [
-                    'orderCode' => $orderCode,
-                    'contactor' => $extend_data['contactor'],
-                    'mobile' => $extend_data['mobile'],
-                    'addr' => $extend_data['addr'],
-                    'addr_code' => $extend_data['addr_code'],
-                    'customer_code' => $customer_code,
-                    'receipt_quantity' => $extend_data['num'],//收货数量,
-                    'post_fee' => 0,
-                    'is_del' => 0,
-                    'addtime' => date("Y-m-d H:i:s"),
-                    'updatetime' => date("Y-m-d H:i:s"),
-                    'arrive_time' => $arrtime,
-                ];
-                $vmp = Db::name('order_addr')->insert($temp, true);
-                if ($vmp > 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('未匹配到采购数据');
+        if (in_array($data['status'], [3, 5]) && $data['reason'] == '') return error_show(1005, '请填写驳回原因');
 
-                    $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" => $order_type,
-                        "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);
+        //用户信息
+        $userinfo = GetUserInfo($data['token']);
 
-                        ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
-                            "order_type" => 'CKD',
-                            "order_code" => $outCode,//出库单号
-                            "order_id" => 0,
-                            "order_status" => 0,
-                            "before_status" => 0
-                        ]);
+        $uid = isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0;
+        $uname = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '';
 
-                        $standing_book_data['outCode'] = $outCode;
-                    }
-                } else throw new Exception('发货地址添加失败');
-            }
-        }
+        $res = curl_request(config('app.yz_domain') . 'api/yz_check_status', array_merge($data, ['uid' => $uid, 'uname' => $uname]));
+        $res = json_decode($res, true);
+        if ($res['code'] == 0) return app_show(0, '操作成功', $res['data']);
+        else return error_show(1005, $res['message']);
 
-        //复用sale::create()方法 -- end
     }
 
 

+ 2 - 1
app/youzan/route/app.php

@@ -12,9 +12,10 @@ route::rule('yz_goodoff', 'youzan/Index/youzanOffline');//将商品从有赞平
 route::rule('yz_goodoff_list', 'youzan/Index/youzanOfflineList');//有赞下线商品列表
 route::rule('yz_goodoff_detail', 'youzan/Index/youzanOfflineDetail');//有赞下线商品详情
 route::rule('yz_order_list', 'youzan/Index/getYzOrderList');//获取有赞订单列表
-route::rule('yz_check_handle_status', 'youzan/Index/checkHandleStatus');//处理有赞订单(确认或取消)
+//route::rule('yz_check_handle_status', 'youzan/Index/checkHandleStatus');//处理有赞订单(确认或取消)
 route::rule('yz_get_update_good_log_by_yz', 'youzan/Index/getYzUpdateLog');//获取有赞平台修改商品日志,有赞平台
 route::rule('yz_get_update_good_log_by_caixiao', 'youzan/Index/getUpdateGoodLog');//获取修改商品日志,采销系统
+route::rule('yz_check_status', 'youzan/Index/checkStatus');//有赞订单审核
 
 route::rule('good_off_line', 'youzan/Other/goodOffLineByYouzan');//商品下架(有赞平台操作)
 route::rule('good_delete_by_yz', 'youzan/Other/goodDeleteByYouzan');//商品删除(有赞平台操作)