<?php


namespace App\Services\order;



class OrderService
{
    public static function get_idgen_id($number, $count=1){
        $res = Idgen::get(appConfig('idgen.partner'),appConfig('idgen.key'), [], [[
            "type" => "merchant_shop_id",
            'number'=>$number,
            "count"=> $count]]);
        $id = $res['id_datetime']['merchant_shop_id'] ?? [];
        return $id;
    }

    /**
     * @param $orderId
     * @param $userId
     * 调用内部服务获取用户订单、子单、分润信息
     */
    public static function getOrderData($orderId, $userId) {
        return self::getDemoData($orderId, $userId);
    }

    public static function getDemoData($orderId, $userId) {
        $order = [
            'order_id'=>$orderId,
            'user_id'=>$userId,
            'life_account_id'=>2312, //'生活号id',
            'shop_id'=>2312, //'店铺shop_id',
            'order_type'=>1, //'1虚拟商品，2实体商品',
            'payment'=>1, //'1虚拟商品，2实体商品',
            'order_status'=>100, //'100 待付款',
        ];

        $order_items = [
            [
                'order_item_id'=>$orderId . rand(100, 999),
                'order_id'=>$orderId,
                'user_id'=>$userId,
                'goods_spu_id'=>$orderId . rand(100, 999),
                'goods_sku_id'=>$orderId . rand(100, 999),
                'marketing_type'=>1,
            ],
            [
                'order_item_id'=>$orderId . rand(100, 999),
                'order_id'=>$orderId,
                'user_id'=>$userId,
                'goods_spu_id'=>$orderId . rand(100, 999),
                'goods_sku_id'=>$orderId . rand(100, 999),
                'marketing_type'=>1,
            ]
        ];

        foreach ($order_items as $r) {
            $order_distribution[] = [
                'commission_mode'=>1,
                'distributor_user_id'=>122234,
                'distributor_commission_value'=>60,
                'parent_user_id'=>122234 . rand(111, 999),
                'parent_commission_value'=>60,
            ];
        }

        return [
            'order'=> $order,
            'order_items'=> $order_items,
            'order_distribution'=> $order_distribution,
        ];
    }
}