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 extends BaseUtil
- {
-
- public static function getMiniLianMengAccessToken()
- {
- return parent::getAccessToken(env("WECHAT_MINIPROGRAME_LIANMENG_APP_ID"),env("WECHAT_MINIPROGRAME_LIANMENG_APP_SECRET"));
- }
-
- 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"];
- }
-
- 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();
- }
-
- if($getProductListParamBean->getShopAppIds()){
- $params["shopAppIds"] = $getProductListParamBean->getShopAppIds();
- }
-
- if($getProductListParamBean->getHasCoupon()){
- $params["hasCoupon"] = $getProductListParamBean->getHasCoupon();
- }
-
- if($getProductListParamBean->getCategory()){
- $params["category"] = $getProductListParamBean->getCategory();
- }
-
- if($getProductListParamBean->getNoCategory()){
- $params["noCategory"] = $getProductListParamBean->getNoCategory();
- }
-
- 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"]
- ];
- }
-
- 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();
- }
-
- if($getProductListParamBean->getShopAppIds()){
- $params["shopAppIds"] = $getProductListParamBean->getShopAppIds();
- }
-
- if($getProductListParamBean->getHasCoupon()){
- $params["hasCoupon"] = $getProductListParamBean->getHasCoupon();
- }
-
- if($getProductListParamBean->getCategory()){
- $params["category"] = $getProductListParamBean->getCategory();
- }
-
- if($getProductListParamBean->getNoCategory()){
- $params["noCategory"] = $getProductListParamBean->getNoCategory();
- }
-
- 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"]
- ];
- }
-
- 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()
- ];
- $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"];
- }
-
- 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"];
- }
-
- 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);
- }
- }
-
- 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);
- }
- }
-
- 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"]
- ];
- }
-
- 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"];
- }
-
- 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"];
- }
- }
|