123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?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\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;
- $instance = new LoggerFactoryUtil(HomeLogic::class);
- //加入缓存
- $memkey = "homeListKey:".$userId;
- $val = BaseUtil::getCacheFromRedis($memkey);
- $instance->info("键:".$memkey);
- $instance->info("缓存值:".$val);
- if (!$val){
- $instance->info("从数据库中获取");
- //临时组合数据
- $tmps = [];
- $linkUrl = "";
- foreach ($recommends as $recommend) {
- try{
- //判断列表数据
- switch ($recommend->category_type){
- case CategoryTypeEnum::WAIMAI:
- //外卖
- switch ($recommend->category_name){
- case "饿了么":
- $linkUrl = TaobaoLianMengUtil::getElmWaimaiSpreadUrl($userId,"20150318020002597","h5");
- break;
- case "美团外卖":
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
- $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$recommend->activity_id,MeiTuanLinkTypeEnum::H5);
- break;
- case "美团闪购":
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
- $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$recommend->activity_id,MeiTuanLinkTypeEnum::H5);
- break;
- case "美团优选":
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
- $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$recommend->activity_id,MeiTuanLinkTypeEnum::H5);
- break;
- case "美团酒店":
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
- $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$recommend->activity_id,MeiTuanLinkTypeEnum::H5);
- break;
- default:
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
- $linkUrl = JutuikeUtil::transferAct($platformSid,$recommend->activity_id);
- break;
- }
- break;
- case CategoryTypeEnum::GOUWU:
- //购物(使用是聚推客)
- switch ($recommend->category_name){
- case "百亿补贴":
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$userId);
- $bean = new ResourceUrlGenParamBean(
- [
- "pid"=>$platformSid,
- "resourceType"=>39996
- ]
- );
- $data = DuoDuoKeUtil::resourceUrlGen($bean);
- $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
- break;
- case "领券中心":
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$userId);
- $bean = new ResourceUrlGenParamBean(
- [
- "pid"=>$platformSid,
- "resourceType"=>40000
- ]
- );
- $data = DuoDuoKeUtil::resourceUrlGen($bean);
- $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
- break;
- default:
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
- $linkUrl = JutuikeUtil::transferAct($platformSid,$recommend->activity_id);
- break;
- }
- break;
- case CategoryTypeEnum::CHONGZHI:
- //充值(使用拼多多)
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$userId);
- $bean = new ResourceUrlGenParamBean(
- [
- "pid"=>$platformSid,
- "resourceType"=>39997
- ]
- );
- $data = DuoDuoKeUtil::resourceUrlGen($bean);
- $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
- break;
- case CategoryTypeEnum::DAODIAN:
- //到店(使用聚推客)
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
- $linkUrl = JutuikeUtil::transferAct($platformSid,$recommend->activity_id);
- break;
- case CategoryTypeEnum::CHUXING:
- //出行使用拼多多
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$userId);
- $bean = new ResourceUrlGenParamBean(
- [
- "pid"=>$platformSid,
- "resourceType"=>50005
- ]
- );
- $data = DuoDuoKeUtil::resourceUrlGen($bean);
- $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
- break;
- }
- }catch (\Throwable $exception){}
- $recommend->link_url = $linkUrl;
- $tmps[$recommend->category_type][] = $recommend;
- }
- foreach ($tmps as $key=>$tmp){
- $datas[] = [
- "category_type_name"=>$categoryMaps[$key],
- "category_data"=>$tmp
- ];
- }
- $flag = BaseUtil::setRedisCache($memkey,json_encode($datas),0);
- $instance->info("写入缓存:".$flag);
- $val = json_encode($datas);
- }
- return json_decode($val,true);
- }
- /**
- * 反钱赚钱列表逻辑
- */
- 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()
- ];
- }
- }
|