123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- <?php
- namespace App\Http\Utils\Wechat\Miniprograme;
- use App\Exceptions\CommonException;
- use App\Http\Bean\Util\Wechat\Miniprograme\GetOrderSearchParamBean;
- use App\Http\Bean\Util\Wechat\Miniprograme\GetProductGenerateParamBean;
- use App\Http\Bean\Util\Wechat\Miniprograme\GetProductListParamBean;
- use App\Http\Enum\ErrorEnum;
- use App\Http\Utils\BaseUtil;
- use App\Http\Utils\LoggerFactoryUtil;
- use Tool\ShanTaoTool\HttpCurl;
- /**
- * 小程序联盟推客
- * Class MiniprogrameLianMengUtil
- * @package App\Http\Utils\Wechat\Miniprograme
- */
- class MiniprogrameLianMengUtil extends BaseUtil
- {
- /**
- * 获取接口密钥
- * @return bool|string|void
- */
- public static function getMiniLianMengAccessToken()
- {
- return parent::getAccessToken(env("WECHAT_MINIPROGRAME_LIANMENG_APP_ID"),env("WECHAT_MINIPROGRAME_LIANMENG_APP_SECRET"));
- }
- /**
- * 获取联盟商品类目列表及类目ID
- */
- public static function getProductCategory()
- {
- $url = "https://api.weixin.qq.com/union/promoter/product/category";
- $params = [
- "access_token"=>self::getMiniLianMengAccessToken()
- ];
- $res = HttpCurl::getCurl($url,$params);
- if($res["errcode"]!=0){
- $instance = new LoggerFactoryUtil(MiniprogrameLianMengUtil::class);
- $instance->info("微信信息:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- return $res["productCats"];
- }
- /**
- * 查询全量商品
- * @param GetProductListParamBean $getProductListParamBean
- */
- public static function getProductList(GetProductListParamBean $getProductListParamBean)
- {
- $url = "https://api.weixin.qq.com/union/promoter/product/list";
- $params = [
- "access_token"=>self::getMiniLianMengAccessToken(),
- "from"=>$getProductListParamBean->getFrom(),
- "limit"=>$getProductListParamBean->getLimit()
- ];
- //搜索关键词
- if($getProductListParamBean->getQuery()){
- $params["query"] = $getProductListParamBean->getQuery();
- }
- //搜索类型
- if($getProductListParamBean->getQueryType()){
- $params["queryType"] = $getProductListParamBean->getQueryType();
- }
- //商品最高价格
- if($getProductListParamBean->getMaxPrice()){
- $params["maxPrice"] = $getProductListParamBean->getMaxPrice();
- }
- //商品最低价格
- if($getProductListParamBean->getMinPrice()){
- $params["minPrice"] = $getProductListParamBean->getMinPrice();
- }
- //佣金金额下限
- if($getProductListParamBean->getMinCommissionValue()){
- $params["minCommissionValue"] = $getProductListParamBean->getMinCommissionValue();
- }
- //佣金比例下限
- if($getProductListParamBean->getMinCommissionRatio()){
- $params["minCommissionRatio"] = $getProductListParamBean->getMinCommissionRatio();
- }
- //排序
- if($getProductListParamBean->getSortType()){
- $params["sortType"] = $getProductListParamBean->getSortType();
- }
- //单个类目
- if($getProductListParamBean->getCategoryId()){
- $params["categoryId"] = $getProductListParamBean->getCategoryId();
- }
- //小商店appId列表
- if($getProductListParamBean->getShopAppIds()){
- $params["shopAppIds"] = $getProductListParamBean->getShopAppIds();
- }
- //是否有联盟全
- if($getProductListParamBean->getHasCoupon()){
- $params["hasCoupon"] = $getProductListParamBean->getHasCoupon();
- }
- //多个类目ID
- if($getProductListParamBean->getCategory()){
- $params["category"] = $getProductListParamBean->getCategory();
- }
- //黑名单类目ID
- if($getProductListParamBean->getNoCategory()){
- $params["noCategory"] = $getProductListParamBean->getNoCategory();
- }
- //商品ID
- if($getProductListParamBean->getProductId()){
- $params["productId"] = $getProductListParamBean->getProductId();
- }
- //配送方式
- if($getProductListParamBean->getShippingMethods()){
- $params["shippingMethods"] = $getProductListParamBean->getShippingMethods();
- }
- //发货地址
- if($getProductListParamBean->getAddressList()){
- $params["addressList"] = $getProductListParamBean->getAddressList();
- }
- $res = HttpCurl::getCurl($url,$params);
- if($res["errcode"]!=0){
- $instance = new LoggerFactoryUtil(MiniprogrameLianMengUtil::class);
- $instance->info("微信信息:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- return [
- "total"=>$res["total"],
- "product_list"=>$res["productList"]
- ];
- }
- /**
- * 查询联盟精选商品
- * @param GetProductListParamBean $getProductListParamBean
- */
- public static function getProductSelect(GetProductListParamBean $getProductListParamBean)
- {
- $url = "https://api.weixin.qq.com/union/promoter/product/select";
- $params = [
- "access_token"=>self::getMiniLianMengAccessToken(),
- "from"=>$getProductListParamBean->getFrom(),
- "limit"=>$getProductListParamBean->getLimit()
- ];
- //商品最高价格
- if($getProductListParamBean->getMaxPrice()){
- $params["maxPrice"] = $getProductListParamBean->getMaxPrice();
- }
- //商品最低价格
- if($getProductListParamBean->getMinPrice()){
- $params["minPrice"] = $getProductListParamBean->getMinPrice();
- }
- //佣金金额下限
- if($getProductListParamBean->getMinCommissionValue()){
- $params["minCommissionValue"] = $getProductListParamBean->getMinCommissionValue();
- }
- //佣金比例下限
- if($getProductListParamBean->getMinCommissionRatio()){
- $params["minCommissionRatio"] = $getProductListParamBean->getMinCommissionRatio();
- }
- //排序
- if($getProductListParamBean->getSortType()){
- $params["sortType"] = $getProductListParamBean->getSortType();
- }
- //单个类目
- if($getProductListParamBean->getCategoryId()){
- $params["categoryId"] = $getProductListParamBean->getCategoryId();
- }
- //小商店appId列表
- if($getProductListParamBean->getShopAppIds()){
- $params["shopAppIds"] = $getProductListParamBean->getShopAppIds();
- }
- //是否有联盟全
- if($getProductListParamBean->getHasCoupon()){
- $params["hasCoupon"] = $getProductListParamBean->getHasCoupon();
- }
- //多个类目ID
- if($getProductListParamBean->getCategory()){
- $params["category"] = $getProductListParamBean->getCategory();
- }
- //黑名单类目ID
- if($getProductListParamBean->getNoCategory()){
- $params["noCategory"] = $getProductListParamBean->getNoCategory();
- }
- //商品ID
- if($getProductListParamBean->getProductId()){
- $params["productId"] = $getProductListParamBean->getProductId();
- }
- //配送方式
- if($getProductListParamBean->getShippingMethods()){
- $params["shippingMethods"] = $getProductListParamBean->getShippingMethods();
- }
- //发货地址
- if($getProductListParamBean->getAddressList()){
- $params["addressList"] = $getProductListParamBean->getAddressList();
- }
- $res = HttpCurl::getCurl($url,$params);
- if($res["errcode"]!=0){
- $instance = new LoggerFactoryUtil(MiniprogrameLianMengUtil::class);
- $instance->info("微信信息:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- return [
- "total"=>$res["total"],
- "product_list"=>$res["productList"]
- ];
- }
- /**
- * 获取商品推广素材
- * @param GetProductGenerateParamBean $getProductGenerateParamBean
- */
- public static function getProductGenerate(GetProductGenerateParamBean $getProductGenerateParamBean)
- {
- $url = "https://api.weixin.qq.com/union/promoter/product/generate?access_token=".self::getMiniLianMengAccessToken();
- $params = [
- "pid"=>$getProductGenerateParamBean->getPid(),
- "productList"=>$getProductGenerateParamBean->getProductList()
- ];
- // dd(json_encode($params));
- $res = HttpCurl::postCurl($url,$params);
- if($res["errcode"]!=0){
- $instance = new LoggerFactoryUtil(MiniprogrameLianMengUtil::class);
- $instance->info("微信信息:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- return $res["list"];
- }
- /**
- * 添加推广位
- * @param $promotionSourceName string 推广位名称
- */
- public static function addPromotion($promotionSourceName)
- {
- $url = "https://api.weixin.qq.com/union/promoter/promotion/add?access_token=".self::getMiniLianMengAccessToken();
- $params = [
- "promotionSourceName"=>$promotionSourceName
- ];
- $res = HttpCurl::postCurl($url,$params);
- if($res["errcode"]!=0){
- $instance = new LoggerFactoryUtil(MiniprogrameLianMengUtil::class);
- $instance->info("微信信息:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- return $res["pid"];
- }
- /**
- * 删除推广位
- * @param $promotionSourcePid string 推广位pid
- * @param $promotionSourceName string 推广位名称
- * @throws CommonException
- */
- public static function deletePromotion($promotionSourcePid, $promotionSourceName)
- {
- $url = "https://api.weixin.qq.com/union/promoter/promotion/del?access_token=".self::getMiniLianMengAccessToken();
- $params = [
- "promotionSourceName"=>$promotionSourceName,
- "promotionSourcePid"=>$promotionSourcePid
- ];
- $res = HttpCurl::postCurl($url,$params);
- if($res["errcode"]!=0){
- $instance = new LoggerFactoryUtil(MiniprogrameLianMengUtil::class);
- $instance->info("微信信息:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- }
- /**
- * 修改推广位
- * @param $previousPromotionInfo array 修改钱推广位信息
- * @param $promotionInfo array 修改后推广位信息
- */
- public static function modifyPromotion($previousPromotionInfo, $promotionInfo)
- {
- $url = "https://api.weixin.qq.com/union/promoter/promotion/upd?access_token=".self::getMiniLianMengAccessToken();
- $params = [
- "previousPromotionInfo"=>$previousPromotionInfo,
- "promotionInfo"=>$promotionInfo
- ];
- $res = HttpCurl::postCurl($url,$params);
- if($res["errcode"]!=0){
- $instance = new LoggerFactoryUtil(MiniprogrameLianMengUtil::class);
- $instance->info("微信信息:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- }
- /**
- * 获取推广位列表
- * @param $start int 偏移
- * @param $limit int 每页数据
- */
- public static function getPromotionList($start, $limit)
- {
- $url = "https://api.weixin.qq.com/union/promoter/promotion/list";
- $params = [
- "access_token"=>self::getMiniLianMengAccessToken(),
- "start"=>$start,
- "limit"=>$limit
- ];
- $res = HttpCurl::getCurl($url,$params);
- if($res["errcode"]!=0){
- $instance = new LoggerFactoryUtil(MiniprogrameLianMengUtil::class);
- $instance->info("微信信息:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- return [
- "total"=>$res["total"],
- "promotion_max_cnt"=>$res["promotionMaxCnt"],
- "promotion_source_list"=>$res["promotionSourceList"]
- ];
- }
- /**
- * 根据订单ID查询订单详情
- * @param $orderList array 订单id列表
- */
- public static function getOrderDetail($orderIdList)
- {
- $url = "https://api.weixin.qq.com/union/promoter/order/info?access_token=".self::getMiniLianMengAccessToken();
- $params = [
- "orderIdList"=>$orderIdList
- ];
- $res = HttpCurl::postCurl($url,$params);
- if($res["errcode"]!=0){
- $instance = new LoggerFactoryUtil(MiniprogrameLianMengUtil::class);
- $instance->info("微信信息:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- return $res["orderList"];
- }
- /**
- * 根据订单支付时间、订单分佣状态拉取订单详情
- * @param GetOrderSearchParamBean $getOrderSearchParamBean
- */
- public static function getOrderSearch(GetOrderSearchParamBean $getOrderSearchParamBean)
- {
- $url = "https://api.weixin.qq.com/union/promoter/order/search";
- $params = [
- "access_token"=>self::getMiniLianMengAccessToken()
- ];
- //页码
- if($getOrderSearchParamBean->getPage()){
- $params["page"] = $getOrderSearchParamBean->getPage();
- }
- //起始时间戳
- if($getOrderSearchParamBean->getStartTimestamp()){
- $params["startTimestamp"] = $getOrderSearchParamBean->getStartTimestamp();
- }
- //结束时间戳
- if($getOrderSearchParamBean->getEndTimestamp()){
- $params["endTimestamp"] = $getOrderSearchParamBean->getEndTimestamp();
- }
- $res = HttpCurl::getCurl($url,$params);
- if($res["errcode"]!=0){
- $instance = new LoggerFactoryUtil(MiniprogrameLianMengUtil::class);
- $instance->info("微信信息:".json_encode($res));
- throw new CommonException(ErrorEnum::ERROR_SYSTEM);
- }
- return $res["orderList"];
- }
- }
|