123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <?php
- namespace App\Http\Utils\Jutuike;
- use App\Exceptions\CommonException;
- use App\Http\Bean\Util\Jutuike\GetOrderListParamBean;
- use App\Http\Bean\Util\Jutuike\GoodsListParamBean;
- use App\Http\Bean\Util\Jutuike\GoodsSearchParamBean;
- use App\Http\Enum\ErrorEnum;
- use App\Http\Utils\BaseUtil;
- use App\Http\Utils\LoggerFactoryUtil;
- use function Complex\theta;
- use Tool\ShanTaoTool\HttpCurl;
- /**
- * jutuike工具类
- * Class JutuikeUtil
- * @package App\Http\Utils\Jutuike
- */
- class JutuikeUtil extends BaseUtil
- {
- /**
- * @var string 平台接口地址
- */
- static $baseUrl = "http://api.jutuike.com/";
- /**
- * @var string 电商聚合接口地址
- */
- static $baseJuheurl = "http://api.act.jutuike.com/";
- /**
- * 获取活动列表
- */
- public static function getActList($page=1)
- {
- $url = self::$baseUrl."union/act_list";
- $params = [
- "apikey"=>env("JU_TUI_KE_API_KEY"),
- "page"=>$page,
- "pageSize"=>100
- ];
- $res = HttpCurl::getCurl($url,$params);
- return $res;
- }
- /**
- * 获取订单列表
- * @param GetOrderListParamBean $getOrderListParamBean
- */
- public static function getOrderList(GetOrderListParamBean $getOrderListParamBean)
- {
- $url = self::$baseUrl."union/orders";
- $params = [
- "apikey"=>env("JU_TUI_KE_API_KEY")
- ];
- if ($getOrderListParamBean->getStartTime()){
- $params["start_time"] = $getOrderListParamBean->getStartTime();
- }
- if ($getOrderListParamBean->getEndTime()){
- $params["end_time"] = $getOrderListParamBean->getEndTime();
- }
- if ($getOrderListParamBean->getQueryType()){
- $params["query_type"] = $getOrderListParamBean->getQueryType();
- }
- if ($getOrderListParamBean->getStatus()){
- $params["status"] = $getOrderListParamBean->getStatus();
- }
- if ($getOrderListParamBean->getOrderSn()){
- $params["order_sn"] = $getOrderListParamBean->getOrderSn();
- }
- if ($getOrderListParamBean->getPage()){
- $params["page"] = $getOrderListParamBean->getPage();
- }
- if ($getOrderListParamBean->getPageSize()){
- $params["pageSize"] = $getOrderListParamBean->getPageSize();
- }
- $res = HttpCurl::getCurl($url,$params);
- return $res;
- }
- /**
- * 获取活动转链接口
- * @param $sid string 推广位
- * @param $actId int 活动ID
- */
- public static function transferAct($sid,$actId)
- {
- $instance = new LoggerFactoryUtil(JutuikeUtil::class);
- $key = "jutuikeTransferAct-".$sid."-".$actId;
- $val = self::getCacheFromRedis($key);
- if($val){
- $instance->info("缓存中获取:".$val);
- return json_decode($val,true);
- }
- $url = self::$baseUrl."union/act";
- $params = [
- "apikey"=>env("JU_TUI_KE_API_KEY"),
- "sid"=>$sid,
- "act_id"=>$actId
- ];
- $res = HttpCurl::getCurl($url,$params);
- $instance->info("上游发挥信息:".json_encode($res));
- if($res["code"]!=1){
- $instance = new LoggerFactoryUtil(JutuikeUtil::class);
- $instance->info("活动ID:".$actId);
- $instance->info("推广位ID:".$sid);
- $instance->info("上游返回数据:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
- }
- $val = $res["data"];
- self::setRedisCache($key,json_encode($val),60*60*5);
- return $val;
- }
- /**
- * 获取转链的商品信息
- * @param $linkurl 转链url
- */
- public static function transferGoodsLink($linkurl)
- {
- $url = self::$baseJuheurl."union/wn_convert";
- $params = [
- "pub_id"=>env("JU_TUI_KE_PUB_ID"),
- "content"=>$linkurl,
- ];
- $res = HttpCurl::postCurl($url,$params);
- if($res["code"]!=1){
- $instance = new LoggerFactoryUtil(JutuikeUtil::class);
- $instance->info("上游返回数据:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
- }
- return $res["data"];
- }
- /**
- * 转链API接口
- * @param $goodsId 商品ID
- * @param $sid 推广位ID
- * @param string $source 来源 jd-京东,vip-唯品会,pdd-拼多多,kaola-考拉,taobao-淘宝 默认vip
- */
- public static function convert($goodsId,$sid,$source="taobao")
- {
- $url = self::$baseJuheurl."union/convert";
- $params = [
- "pub_id"=>env("JU_TUI_KE_PUB_ID"),
- "goodsId"=>$goodsId,
- "sid"=>$sid,
- "source"=>$source,
- ];
- $res = HttpCurl::postCurl($url,$params);
- if($res["code"]!=1){
- $instance = new LoggerFactoryUtil(JutuikeUtil::class);
- $instance->info("上游返回数据:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
- }
- return $res["data"];
- }
- /**
- * 获取平台分类接口
- * @param string $source
- */
- public static function goodsCategory($source)
- {
- $url = self::$baseJuheurl."union/goods_category";
- $params = [
- "pub_id"=>env("JU_TUI_KE_PUB_ID"),
- ];
- $params["source"] = $source;
- $res = HttpCurl::postCurl($url,$params);
- if($res["code"]!=1){
- $instance = new LoggerFactoryUtil(JutuikeUtil::class);
- $instance->info("上游返回数据:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
- }
- return $res["data"];
- }
- /**
- * 获取商品列表
- * @param GoodsListParamBean $goodsListParamBean
- */
- public static function goodsList(GoodsListParamBean $goodsListParamBean)
- {
- $url = self::$baseJuheurl."union/query_goods";
- $params = [
- "pub_id"=>env("JU_TUI_KE_PUB_ID"),
- "source"=>$goodsListParamBean->getSource(),
- "cat"=>$goodsListParamBean->getCat(),
- "page"=>$goodsListParamBean->getPage(),
- "pageSize"=>$goodsListParamBean->getPageSize(),
- ];
- $res = HttpCurl::postCurl($url,$params);
- if($res["code"]!=1){
- $instance = new LoggerFactoryUtil(JutuikeUtil::class);
- $instance->info("上游返回数据:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
- }
- return [
- "count"=>$res["total_results"],
- "list"=>$res["data"]
- ];
- }
- /**
- * 商品搜索接口
- * @param GoodsSearchParamBean $goodsSearchParamBean
- */
- public static function goodsSearch(GoodsSearchParamBean $goodsSearchParamBean)
- {
- $url = self::$baseJuheurl."union/search";
- $params = [
- "pub_id"=>env("JU_TUI_KE_PUB_ID"),
- "sid"=>$goodsSearchParamBean->getSource(),
- "source"=>$goodsSearchParamBean->getSource(),
- "keyword"=>$goodsSearchParamBean->getKeyword(),
- "sort"=>$goodsSearchParamBean->getSort(),
- "page"=>$goodsSearchParamBean->getPage(),
- "pageSize"=>$goodsSearchParamBean->getPageSize(),
- ];
- $res = HttpCurl::postCurl($url,$params);
- if($res["code"]!=1){
- $instance = new LoggerFactoryUtil(JutuikeUtil::class);
- $instance->info("上游返回数据:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
- }
- return [
- "count"=>$res["total_results"],
- "list"=>$res["data"]
- ];
- }
- /**
- * 电商平台列表接口
- */
- public static function plateformList()
- {
- $url = self::$baseJuheurl."union/platform";
- $params = [
- "pub_id"=>env("JU_TUI_KE_PUB_ID")
- ];
- $res = HttpCurl::postCurl($url,$params);
- if($res["code"]!=1){
- $instance = new LoggerFactoryUtil(JutuikeUtil::class);
- $instance->info("上游返回数据:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
- }
- return $res["data"];
- }
- }
|