HomeLogic.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. namespace App\Http\Logic\Home;
  3. use App\Http\Bean\Util\Pdd\Ddk\ResourceUrlGenParamBean;
  4. use App\Http\Enum\CategoryTypeEnum;
  5. use App\Http\Enum\MeiTuanLinkTypeEnum;
  6. use App\Http\Enum\PlatformTypeEnum;
  7. use App\Http\Logic\BaseLogic;
  8. use App\Http\Utils\BaseUtil;
  9. use App\Http\Utils\Jutuike\JutuikeUtil;
  10. use App\Http\Utils\LoggerFactoryUtil;
  11. use App\Http\Utils\Meituan\MeituanLianmengUtil;
  12. use App\Http\Utils\Pdd\DuoDuoKeUtil;
  13. use App\Http\Utils\TaoBao\TaobaoLianMengUtil;
  14. use App\Models\CategoryModel;
  15. use App\Models\UserOrderCommissionModel;
  16. class HomeLogic extends BaseLogic
  17. {
  18. /**
  19. * 首页列表逻辑
  20. */
  21. public static function getHomeListLogic()
  22. {
  23. $recommends = CategoryModel::query()
  24. ->where("category_status",1)
  25. ->orderBy("category_sort_id","desc")
  26. ->get();
  27. $userId = BaseUtil::getUserId();
  28. $datas = [];
  29. $categoryMaps = CategoryTypeEnum::MAP;
  30. $instance = new LoggerFactoryUtil(HomeLogic::class);
  31. //加入缓存
  32. $memkey = "homeListKey:".$userId;
  33. $val = BaseUtil::getCacheFromRedis($memkey);
  34. $instance->info("键:".$memkey);
  35. $instance->info("缓存值:".$val);
  36. if (!$val){
  37. $instance->info("从数据库中获取");
  38. //临时组合数据
  39. $tmps = [];
  40. $linkUrl = "";
  41. foreach ($recommends as $recommend) {
  42. try{
  43. //判断列表数据
  44. switch ($recommend->category_type){
  45. case CategoryTypeEnum::WAIMAI:
  46. //外卖
  47. switch ($recommend->category_name){
  48. case "饿了么":
  49. $linkUrl = TaobaoLianMengUtil::getElmWaimaiSpreadUrl($userId,"20150318020002597","h5");
  50. break;
  51. case "美团外卖":
  52. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  53. $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$recommend->activity_id,MeiTuanLinkTypeEnum::H5);
  54. break;
  55. case "美团闪购":
  56. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  57. $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$recommend->activity_id,MeiTuanLinkTypeEnum::H5);
  58. break;
  59. case "美团优选":
  60. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  61. $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$recommend->activity_id,MeiTuanLinkTypeEnum::H5);
  62. break;
  63. case "美团酒店":
  64. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  65. $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$recommend->activity_id,MeiTuanLinkTypeEnum::H5);
  66. break;
  67. default:
  68. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
  69. $linkUrl = JutuikeUtil::transferAct($platformSid,$recommend->activity_id);
  70. break;
  71. }
  72. break;
  73. case CategoryTypeEnum::GOUWU:
  74. //购物(使用是聚推客)
  75. switch ($recommend->category_name){
  76. case "百亿补贴":
  77. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$userId);
  78. $bean = new ResourceUrlGenParamBean(
  79. [
  80. "pid"=>$platformSid,
  81. "resourceType"=>39996
  82. ]
  83. );
  84. $data = DuoDuoKeUtil::resourceUrlGen($bean);
  85. $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
  86. break;
  87. case "领券中心":
  88. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$userId);
  89. $bean = new ResourceUrlGenParamBean(
  90. [
  91. "pid"=>$platformSid,
  92. "resourceType"=>40000
  93. ]
  94. );
  95. $data = DuoDuoKeUtil::resourceUrlGen($bean);
  96. $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
  97. break;
  98. default:
  99. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
  100. $linkUrl = JutuikeUtil::transferAct($platformSid,$recommend->activity_id);
  101. break;
  102. }
  103. break;
  104. case CategoryTypeEnum::CHONGZHI:
  105. //充值(使用拼多多)
  106. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$userId);
  107. $bean = new ResourceUrlGenParamBean(
  108. [
  109. "pid"=>$platformSid,
  110. "resourceType"=>39997
  111. ]
  112. );
  113. $data = DuoDuoKeUtil::resourceUrlGen($bean);
  114. $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
  115. break;
  116. case CategoryTypeEnum::DAODIAN:
  117. //到店(使用聚推客)
  118. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
  119. $linkUrl = JutuikeUtil::transferAct($platformSid,$recommend->activity_id);
  120. break;
  121. case CategoryTypeEnum::CHUXING:
  122. //出行使用拼多多
  123. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$userId);
  124. $bean = new ResourceUrlGenParamBean(
  125. [
  126. "pid"=>$platformSid,
  127. "resourceType"=>50005
  128. ]
  129. );
  130. $data = DuoDuoKeUtil::resourceUrlGen($bean);
  131. $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
  132. break;
  133. }
  134. }catch (\Throwable $exception){}
  135. $recommend->link_url = $linkUrl;
  136. $tmps[$recommend->category_type][] = $recommend;
  137. }
  138. foreach ($tmps as $key=>$tmp){
  139. $datas[] = [
  140. "category_type_name"=>$categoryMaps[$key],
  141. "category_data"=>$tmp
  142. ];
  143. }
  144. $flag = BaseUtil::setRedisCache($memkey,json_encode($datas),0);
  145. $instance->info("写入缓存:".$flag);
  146. $val = json_encode($datas);
  147. }
  148. return json_decode($val,true);
  149. }
  150. /**
  151. * 反钱赚钱列表逻辑
  152. */
  153. public static function getCommissionListLogic()
  154. {
  155. $params = request()->all();
  156. $userId = BaseUtil::getUserId();
  157. $query = UserOrderCommissionModel::query()
  158. ->where("user_id",$userId);
  159. switch ($params["type"]){
  160. case 0:
  161. //赚钱
  162. $query->where("user_provider_id",0);
  163. break;
  164. case 1:
  165. //返钱
  166. $query->where("user_provider_id","<>",0);
  167. break;
  168. }
  169. $res = $query->select(
  170. [
  171. "order_commission",
  172. "commission_status",
  173. "commission_type",
  174. "created_at",
  175. "user_id",
  176. "user_provider_id",
  177. "user_head_img_url",
  178. "user_provider_head_img_url",
  179. "order_title",
  180. "user_nickname"
  181. ]
  182. )->orderBy("id","desc")
  183. ->paginate($params["page_size"]);
  184. return [
  185. "total"=>$res->total(),
  186. "list"=>$res->items()
  187. ];
  188. }
  189. }