123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <?php
- namespace App\Http\Logic\Home;
- use App\Http\Bean\Util\Pdd\Ddk\ResourceUrlGenParamBean;
- use App\Http\Enum\CategoryTypeEnum;
- use App\Http\Enum\MeiTuanLinkTypeEnum;
- use App\Http\Enum\PlatformTypeEnum;
- use App\Http\Logic\BaseLogic;
- use App\Http\Utils\BaseUtil;
- use App\Http\Utils\Jutuike\JutuikeUtil;
- use App\Http\Utils\LoggerFactoryUtil;
- use App\Http\Utils\Meituan\MeituanLianmengUtil;
- use App\Http\Utils\Meituan\MeituanLianmengUtilV1;
- use App\Http\Utils\Pdd\DuoDuoKeUtil;
- use App\Http\Utils\TaoBao\TaobaoLianMengUtil;
- use App\Models\CategoryModel;
- use App\Models\UserOrderCommissionModel;
- class HomeLogic extends BaseLogic
- {
- /**
- * 首页列表逻辑
- */
- public static function getHomeListLogic()
- {
- $recommends = CategoryModel::query()
- ->where("category_status",1)
- ->orderBy("category_sort_id","desc")
- ->get();
- $userId = BaseUtil::getUserId();
- $datas = [];
- $categoryMaps = CategoryTypeEnum::MAP;
- //临时组合数据
- $tmps = [];
- foreach ($recommends as $recommend) {
- $recommend->link_url = env("INDEX_BASE_URL")."/api/transfer/".$userId."/".$recommend->id;
- $tmps[$recommend->category_type][] = $recommend;
- }
- foreach ($tmps as $key=>$tmp){
- $datas[] = [
- "category_type_name"=>$categoryMaps[$key],
- "category_data"=>$tmp
- ];
- }
- return $datas;
- }
- /**
- * 反钱赚钱列表逻辑
- */
- public static function getCommissionListLogic()
- {
- $params = request()->all();
- $userId = BaseUtil::getUserId();
- $query = UserOrderCommissionModel::query()
- ->where("user_id",$userId);
- switch ($params["type"]){
- case 0:
- //赚钱
- $query->where("user_provider_id",0);
- break;
- case 1:
- //返钱
- $query->where("user_provider_id","<>",0);
- break;
- }
- $res = $query->select(
- [
- "order_commission",
- "commission_status",
- "commission_type",
- "created_at",
- "user_id",
- "user_provider_id",
- "user_head_img_url",
- "user_provider_head_img_url",
- "order_title",
- "user_nickname"
- ]
- )->orderBy("id","desc")
- ->paginate($params["page_size"]);
- return [
- "total"=>$res->total(),
- "list"=>$res->items()
- ];
- }
- /**
- * 根据活动和用户生成推广链接
- * @param $actId 活动ID
- * @param $userId 用户ID
- */
- public static function getTransferLink($actId, $userId)
- {
- $instance = new LoggerFactoryUtil(HomeLogic::class);
- $linkUrl = env("INDEX_BASE_URL");
- $data = [
- "type"=>1,
- "url"=>$linkUrl,
- "app_id"=>"",
- "page_path"=>""
- ];
- //获取活动
- $act = CategoryModel::query()->find($actId);
- if(!$act){
- return $data;
- }
- $instance->info("基础地址:".$linkUrl);
- try{
- //获取用户
- switch ($act["platform_type"]){
- case 1://淘宝
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_TAOBAO,$userId);
- $response = TaobaoLianMengUtil::getActivityInfo($platformSid,$act->activity_id);
- $res = [
- "h5"=>$response["short_click_url"],
- ];
- break;
- case 2://拼多多
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$userId);
- //判断类型
- switch ($act["category_name"]){
- case "话费充值":
- $bean = new ResourceUrlGenParamBean(
- [
- "pid"=>$platformSid,
- "resourceType"=>39997
- ]
- );
- $data = DuoDuoKeUtil::resourceUrlGen($bean);
- $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
- break;
- case "火车票":
- $bean = new ResourceUrlGenParamBean(
- [
- "pid"=>$platformSid,
- "resourceType"=>50005
- ]
- );
- $data = DuoDuoKeUtil::resourceUrlGen($bean);
- $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
- break;
- case "百亿补贴":
- $bean = new ResourceUrlGenParamBean(
- [
- "pid"=>$platformSid,
- "resourceType"=>39996
- ]
- );
- $data = DuoDuoKeUtil::resourceUrlGen($bean);
- $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
- break;
- case "领券中心":
- $bean = new ResourceUrlGenParamBean(
- [
- "pid"=>$platformSid,
- "resourceType"=>40000
- ]
- );
- $data = DuoDuoKeUtil::resourceUrlGen($bean);
- $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
- break;
- }
- $res["h5"] = $linkUrl;
- break;
- // case 3://京东
- //
- // break;
- case 4://美团
- switch ($act["category_name"]){
- case "美团外卖":
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
- $linkUrl = MeituanLianmengUtilV1::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
- break;
- case "美团闪购":
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
- $linkUrl = MeituanLianmengUtilV1::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
- break;
- case "美团优选":
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
- $linkUrl = MeituanLianmengUtilV1::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
- break;
- case "美团酒店":
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
- $linkUrl = MeituanLianmengUtilV1::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
- break;
- default:
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
- $linkUrl = JutuikeUtil::transferAct($platformSid,$act["activity_id"]);
- break;
- }
- $res["h5"] = $linkUrl;
- break;
- // case 5://本平台
- break;
- case 6://聚推客
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
- $res = JutuikeUtil::transferAct($platformSid,$act->activity_id);
- break;
- }
- switch ($act["url_type"]){
- case 1://h5链接
- $data = [
- "type"=>1,
- "url"=>$res["h5"],
- "app_id"=>$act["app_id"]??"",
- "page_path"=>$res["we_app_info"]["page_path"]??""
- ];
- break;
- case 2://小程序跳转
- $data = [
- "type"=>2,
- "url"=>$res["h5"],
- "app_id"=>$act["app_id"]??"",
- "page_path"=>"/pages".$res["we_app_info"]["page_path"]??""
- ];
- break;
- }
- }catch (\Throwable $exception){
- $instance->info("错误信息:".$exception->getMessage());
- }
- // $linkUrl = $linkUrl?$linkUrl:env("INDEX_BASE_URL");
- // $instance->info("回调地址:".$linkUrl);
- return $data;
- }
- }
|