全部
常见问题
产品动态
精选推荐

【pro】修复订单同步聚水潭出现偶尔丢单问题

管理 管理 编辑 删除

文件位置:app/services/erp/OrderServices.php

需要调整的方法:upload、getItems

替换下面对应方法:

    /**
     * 订单上传
     * @param int $oid
     * @return bool
     * @throws \Exception
     */
    public function upload(int $oid): bool
    {
        /** @var StoreOrderServices $orderServices */
        $orderServices = app()->make(StoreOrderServices::class);
        $order = $orderServices->get($oid, ['*'], ['store']);

        if ($order['id'] < 1) {
            throw new AdminException('订单信息不能为空!');
        }

        // 过滤已退款订单和虚拟商品
        if ($order['refund_status'] == 2 || $order['product_type'] > 0) {
            return true;
        }

        $biz = [
            'shop_id' => $this->getShopId($order->store->erp_shop_id ?? 0), // 店铺编号
            'so_id' => $this->getErpOrderId($order['order_id'], $order['erp_order_id']), // 线上订单号, 长度 <= 50
            'shop_status' => 'WAIT_SELLER_SEND_GOODS',   // 订单状态 待发货
            'buyer_message' => $order['mark'],           // 买家留言
            'shop_buyer_id' => (string)$order['uid'],    // 买家帐号
            'receiver_name' => $order['real_name'],      // 收件人
            'receiver_mobile' => $order['user_phone'],   // 联系手机
            'pay_amount' => (float)$order['pay_price'],  // 应付金额,保留两位小数,单位元)
            'freight' => (float)$order['freight_price'], // 运费
            'order_date' => date('Y-m-d H:i:s', $order['add_time']), // 订单日期
            'shop_modified' => date('Y-m-d H:i:s', $order['add_time']), // 订单修改日期
            'items' => $this->getItems($oid, (int)$order['uid'], $order['unique']),
            'pay' => [
                'outer_pay_id' => 'xxx', // 外部支付单号,最大50
                'pay_date' => date('Y-m-d H:i:s', $order['pay_time']),     // 支付日期
                'payment' => $order['pay_type'],        // 支付方式,最大20
                'seller_account' => 'seller',           // 卖家支付账号,最大 50
                'buyer_account' => 'buyer',             // 买家支付账号,最大 200
                'amount' => (float)$order['pay_price']  // 支付总额
            ]
        ];

        $biz = array_merge($biz, $this->getAddress($order['user_address']));

        $num = 3;
        for ($i = $num; $i >= 0; $i--) {
            if ($i <= 0) {
                Log::error(['msg' => 'ERP订单上传失败,调用均为异常', 'oid' => $oid]);
                return false;
            }

            try {
                $result = $this->services->serviceDriver('order')->ordersUpload([$biz]);
                if ($result['datas'][0]['issuccess'] && $order['erp_order_id'] != $biz['so_id']) {
                    $order->save(['erp_id' => $result['datas'][0]['o_id'], 'erp_order_id' => $biz['so_id']]);
                }
                break;
            } catch (\Exception $e) {
                usleep(1000 * 50);
                Log::error('ERP订单上传失败,原因:' . $e->getMessage());
            }
        }
        return true;
    }
    /**
     * 获取erp指定订单商品详情
     * @param int $oid
     * @param int $uid
     * @param string $unique
     * @return array
     */
    public function getItems(int $oid, int $uid, string $unique): array
    {
        /** @var StoreOrderCartInfoServices $storeOrderCartInfoServices */
        $storeOrderCartInfoServices = app()->make(StoreOrderCartInfoServices::class);
        $cartInfo = $storeOrderCartInfoServices->getOrderCartInfo($oid);

        if (empty($cartInfo)) {
            /** @var StoreOrderServices $orderServices */
            $orderServices = app()->make(StoreOrderServices::class);

            //同步查询订单商品为查询到 查询缓存信息
            $orderInfo = $orderServices->getCacheOrderInfo($uid, $unique);
            $cartInfo = $orderInfo['cartInfo'] ?? [];
        }

        $items = [];
        foreach ($cartInfo as $cart) {
            $cart = $cart['cart_info'] ?? $cart;
            $attrInfo = $cart['productInfo']['attrInfo'];
            $items[] = [
                'sku_id' => $attrInfo['code'],
                'shop_sku_id' => $attrInfo['code'],
                'base_price' => (float)bcdiv((string)$cart['truePrice'], (string)$cart['cart_num'], 2),
                'amount' => (float)$cart['truePrice'],
                'qty' => $cart['cart_num'],
                'pic' => $cart['productInfo']['image'],
                'name' => $cart['productInfo']['store_name'],
                'properties_value' => $attrInfo['suk'],
                'outer_oi_id' => $cart['product_attr_unique'],
            ];
        }
        return $items;
    }

然后重启Swoole!!!

神经蛙 最后编辑于2022-11-07 14:14:47

快捷回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
回复从新到旧

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest==1? '取消推荐': '推荐'}}
{{item.floor}}#
{{item.user_info.title}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

作者 管理员 企业

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}   {{itemc.ip_address}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
回复
回复
3693
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

管理员
暂无简介

回答

106

发布

9

经验

9690

快速安全登录

使用微信扫码登录
{{item.label}} {{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
加精
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 开源下载 CRMEB官方论坛 帮助文档
返回顶部 返回顶部
CRMEB客服