JutuikeUtil.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. namespace App\Http\Utils\Jutuike;
  3. use App\Exceptions\CommonException;
  4. use App\Http\Bean\Util\Jutuike\GetOrderListParamBean;
  5. use App\Http\Bean\Util\Jutuike\GoodsListParamBean;
  6. use App\Http\Bean\Util\Jutuike\GoodsSearchParamBean;
  7. use App\Http\Enum\ErrorEnum;
  8. use App\Http\Utils\BaseUtil;
  9. use App\Http\Utils\LoggerFactoryUtil;
  10. use function Complex\theta;
  11. use Tool\ShanTaoTool\HttpCurl;
  12. /**
  13. * jutuike工具类
  14. * Class JutuikeUtil
  15. * @package App\Http\Utils\Jutuike
  16. */
  17. class JutuikeUtil extends BaseUtil
  18. {
  19. /**
  20. * @var string 平台接口地址
  21. */
  22. static $baseUrl = "http://api.jutuike.com/";
  23. /**
  24. * @var string 电商聚合接口地址
  25. */
  26. static $baseJuheurl = "http://api.act.jutuike.com/";
  27. /**
  28. * 获取活动列表
  29. */
  30. public static function getActList($page=1)
  31. {
  32. $url = self::$baseUrl."union/act_list";
  33. $params = [
  34. "apikey"=>env("JU_TUI_KE_API_KEY"),
  35. "page"=>$page,
  36. "pageSize"=>100
  37. ];
  38. $res = HttpCurl::getCurl($url,$params);
  39. return $res;
  40. }
  41. /**
  42. * 获取订单列表
  43. * @param GetOrderListParamBean $getOrderListParamBean
  44. */
  45. public static function getOrderList(GetOrderListParamBean $getOrderListParamBean)
  46. {
  47. $url = self::$baseUrl."union/orders";
  48. $params = [
  49. "apikey"=>env("JU_TUI_KE_API_KEY")
  50. ];
  51. if ($getOrderListParamBean->getStartTime()){
  52. $params["start_time"] = $getOrderListParamBean->getStartTime();
  53. }
  54. if ($getOrderListParamBean->getEndTime()){
  55. $params["end_time"] = $getOrderListParamBean->getEndTime();
  56. }
  57. if ($getOrderListParamBean->getQueryType()){
  58. $params["query_type"] = $getOrderListParamBean->getQueryType();
  59. }
  60. if ($getOrderListParamBean->getStatus()){
  61. $params["status"] = $getOrderListParamBean->getStatus();
  62. }
  63. if ($getOrderListParamBean->getOrderSn()){
  64. $params["order_sn"] = $getOrderListParamBean->getOrderSn();
  65. }
  66. if ($getOrderListParamBean->getPage()){
  67. $params["page"] = $getOrderListParamBean->getPage();
  68. }
  69. if ($getOrderListParamBean->getPageSize()){
  70. $params["pageSize"] = $getOrderListParamBean->getPageSize();
  71. }
  72. $res = HttpCurl::getCurl($url,$params);
  73. return $res;
  74. }
  75. /**
  76. * 获取活动转链接口
  77. * @param $sid string 推广位
  78. * @param $actId int 活动ID
  79. */
  80. public static function transferAct($sid,$actId)
  81. {
  82. $instance = new LoggerFactoryUtil(JutuikeUtil::class);
  83. $key = "jutuikeTransferAct-".$sid."-".$actId;
  84. $val = self::getCacheFromRedis($key);
  85. if($val){
  86. $instance->info("缓存中获取:".$val);
  87. return json_decode($val,true);
  88. }
  89. $url = self::$baseUrl."union/act";
  90. $params = [
  91. "apikey"=>env("JU_TUI_KE_API_KEY"),
  92. "sid"=>$sid,
  93. "act_id"=>$actId
  94. ];
  95. $res = HttpCurl::getCurl($url,$params);
  96. $instance->info("上游发挥信息:".json_encode($res));
  97. if($res["code"]!=1){
  98. $instance = new LoggerFactoryUtil(JutuikeUtil::class);
  99. $instance->info("活动ID:".$actId);
  100. $instance->info("推广位ID:".$sid);
  101. $instance->info("上游返回数据:".json_encode($res));
  102. throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
  103. }
  104. $val = $res["data"];
  105. self::setRedisCache($key,json_encode($val),0);
  106. return $val;
  107. }
  108. /**
  109. * 获取转链的商品信息
  110. * @param $linkurl 转链url
  111. */
  112. public static function transferGoodsLink($linkurl)
  113. {
  114. $url = self::$baseJuheurl."union/wn_convert";
  115. $params = [
  116. "pub_id"=>env("JU_TUI_KE_PUB_ID"),
  117. "content"=>$linkurl,
  118. ];
  119. $res = HttpCurl::postCurl($url,$params);
  120. if($res["code"]!=1){
  121. $instance = new LoggerFactoryUtil(JutuikeUtil::class);
  122. $instance->info("上游返回数据:".json_encode($res));
  123. throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
  124. }
  125. return $res["data"];
  126. }
  127. /**
  128. * 转链API接口
  129. * @param $goodsId 商品ID
  130. * @param $sid 推广位ID
  131. * @param string $source 来源 jd-京东,vip-唯品会,pdd-拼多多,kaola-考拉,taobao-淘宝 默认vip
  132. */
  133. public static function convert($goodsId,$sid,$source="taobao")
  134. {
  135. $url = self::$baseJuheurl."union/convert";
  136. $params = [
  137. "pub_id"=>env("JU_TUI_KE_PUB_ID"),
  138. "goodsId"=>$goodsId,
  139. "sid"=>$sid,
  140. "source"=>$source,
  141. ];
  142. $res = HttpCurl::postCurl($url,$params);
  143. if($res["code"]!=1){
  144. $instance = new LoggerFactoryUtil(JutuikeUtil::class);
  145. $instance->info("上游返回数据:".json_encode($res));
  146. throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
  147. }
  148. return $res["data"];
  149. }
  150. /**
  151. * 获取平台分类接口
  152. * @param string $source
  153. */
  154. public static function goodsCategory($source)
  155. {
  156. $url = self::$baseJuheurl."union/goods_category";
  157. $params = [
  158. "pub_id"=>env("JU_TUI_KE_PUB_ID"),
  159. ];
  160. $params["source"] = $source;
  161. $res = HttpCurl::postCurl($url,$params);
  162. if($res["code"]!=1){
  163. $instance = new LoggerFactoryUtil(JutuikeUtil::class);
  164. $instance->info("上游返回数据:".json_encode($res));
  165. throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
  166. }
  167. return $res["data"];
  168. }
  169. /**
  170. * 获取商品列表
  171. * @param GoodsListParamBean $goodsListParamBean
  172. */
  173. public static function goodsList(GoodsListParamBean $goodsListParamBean)
  174. {
  175. $url = self::$baseJuheurl."union/query_goods";
  176. $params = [
  177. "pub_id"=>env("JU_TUI_KE_PUB_ID"),
  178. "source"=>$goodsListParamBean->getSource(),
  179. "cat"=>$goodsListParamBean->getCat(),
  180. "page"=>$goodsListParamBean->getPage(),
  181. "pageSize"=>$goodsListParamBean->getPageSize(),
  182. ];
  183. $res = HttpCurl::postCurl($url,$params);
  184. if($res["code"]!=1){
  185. $instance = new LoggerFactoryUtil(JutuikeUtil::class);
  186. $instance->info("上游返回数据:".json_encode($res));
  187. throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
  188. }
  189. return [
  190. "count"=>$res["total_results"],
  191. "list"=>$res["data"]
  192. ];
  193. }
  194. /**
  195. * 商品搜索接口
  196. * @param GoodsSearchParamBean $goodsSearchParamBean
  197. */
  198. public static function goodsSearch(GoodsSearchParamBean $goodsSearchParamBean)
  199. {
  200. $url = self::$baseJuheurl."union/search";
  201. $params = [
  202. "pub_id"=>env("JU_TUI_KE_PUB_ID"),
  203. "sid"=>$goodsSearchParamBean->getSource(),
  204. "source"=>$goodsSearchParamBean->getSource(),
  205. "keyword"=>$goodsSearchParamBean->getKeyword(),
  206. "sort"=>$goodsSearchParamBean->getSort(),
  207. "page"=>$goodsSearchParamBean->getPage(),
  208. "pageSize"=>$goodsSearchParamBean->getPageSize(),
  209. ];
  210. $res = HttpCurl::postCurl($url,$params);
  211. if($res["code"]!=1){
  212. $instance = new LoggerFactoryUtil(JutuikeUtil::class);
  213. $instance->info("上游返回数据:".json_encode($res));
  214. throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
  215. }
  216. return [
  217. "count"=>$res["total_results"],
  218. "list"=>$res["data"]
  219. ];
  220. }
  221. /**
  222. * 电商平台列表接口
  223. */
  224. public static function plateformList()
  225. {
  226. $url = self::$baseJuheurl."union/platform";
  227. $params = [
  228. "pub_id"=>env("JU_TUI_KE_PUB_ID")
  229. ];
  230. $res = HttpCurl::postCurl($url,$params);
  231. if($res["code"]!=1){
  232. $instance = new LoggerFactoryUtil(JutuikeUtil::class);
  233. $instance->info("上游返回数据:".json_encode($res));
  234. throw new CommonException(ErrorEnum::ERROR_TRANS_LINK);
  235. }
  236. return $res["data"];
  237. }
  238. }