<?php


namespace App\Services\common;

use App\Models\goods\mysql\GoodsSkuSubShop;
use App\Models\shop\mysql\Shop;
use App\Models\shop\mysql\SubShop;
use Api\PhpUtils\Validate\Validate;
use Api\PhpServices\Idgen\Idgen;

// use Validate\ShopValidate;
use App\Exception\custom\ShopException;
use Api\PhpServices\Sensitive\Sensitive;
use App\Exception\custom\InterfaceException;
use Api\PhpUtils\Http\Request;
use Helpers\Aes;
use Api\PhpServices\Ksy\Ksyun;

class CommonService
{


    public static function isNewUser($params)
    {
        $url = config('interface','order.user.is_new_user');
        if(empty($url)){
            throw new InterfaceException(['cus'=>0]);
        }
        $res = (new Request())->get($url, $params);
        if ($res['code'] == 0 && isset($res['response'])) {  
            return !empty($res['response']['result']) ? $res['response']['result'] : [];
        }
        return [];
    }
   
    /**
     * 通过生活号id获取生活号信息
     * life_account_id = [] 数组形式传递
     *
     */
    public static function getlifeAccountList($params)
    {
        $lifeAccountId = !empty($params['life_account_id']) ? $params['life_account_id'] : '';
        $url = config('interface', 'merchant.lifeaccount.get_life_account_by_ids');
        if (empty($url)) {
            throw new InterfaceException(['cus' => 1]);
        }
        if (empty( $lifeAccountId )) {
           return [];
        }
        $params['life_account_ids'] = implode(',', $lifeAccountId);
        $res = (new Request())->get($url, $params);
        if ($res['code'] == 0 && isset($res['response'])) {  
            return !empty($res['response']['result']) ? $res['response']['result'] : [];
        }
        return [];
    }
    
    /**
     * 获取分享码code
     *
     */
    public static function getGoodsShareId($params)
    {
        $userId = !empty($params['user_id']) ? $params['user_id'] : 0;
        $marketingId = !empty($params['marketing_id']) ? $params['marketing_id'] : 0;
        $goodsSkuId = !empty($params['goods_sku_id']) ? $params['goods_sku_id'] : 0;
        $content = $userId .'_' .$marketingId;
        $goodsShareId = Aes::encrypt($content);
        return $goodsShareId;
    }

}