HomeLogic.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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\Meituan\MeituanLianmengUtilV1;
  13. use App\Http\Utils\Pdd\DuoDuoKeUtil;
  14. use App\Http\Utils\TaoBao\TaobaoLianMengUtil;
  15. use App\Models\CategoryModel;
  16. use App\Models\UserOrderCommissionModel;
  17. class HomeLogic extends BaseLogic
  18. {
  19. /**
  20. * 首页列表逻辑
  21. */
  22. public static function getHomeListLogic()
  23. {
  24. $recommends = CategoryModel::query()
  25. ->where("category_status",1)
  26. ->orderBy("category_sort_id","desc")
  27. ->get();
  28. $userId = BaseUtil::getUserId();
  29. $datas = [];
  30. $categoryMaps = CategoryTypeEnum::MAP;
  31. //临时组合数据
  32. $tmps = [];
  33. foreach ($recommends as $recommend) {
  34. $recommend->link_url = env("INDEX_BASE_URL")."/api/transfer/".$userId."/".$recommend->id;
  35. $tmps[$recommend->category_type][] = $recommend;
  36. }
  37. foreach ($tmps as $key=>$tmp){
  38. $datas[] = [
  39. "category_type_name"=>$categoryMaps[$key],
  40. "category_data"=>$tmp
  41. ];
  42. }
  43. return $datas;
  44. }
  45. /**
  46. * 反钱赚钱列表逻辑
  47. */
  48. public static function getCommissionListLogic()
  49. {
  50. $params = request()->all();
  51. $userId = BaseUtil::getUserId();
  52. $query = UserOrderCommissionModel::query()
  53. ->where("user_id",$userId);
  54. switch ($params["type"]){
  55. case 0:
  56. //赚钱
  57. $query->where("user_provider_id",0);
  58. break;
  59. case 1:
  60. //返钱
  61. $query->where("user_provider_id","<>",0);
  62. break;
  63. }
  64. $res = $query->select(
  65. [
  66. "order_commission",
  67. "commission_status",
  68. "commission_type",
  69. "created_at",
  70. "user_id",
  71. "user_provider_id",
  72. "user_head_img_url",
  73. "user_provider_head_img_url",
  74. "order_title",
  75. "user_nickname"
  76. ]
  77. )->orderBy("id","desc")
  78. ->paginate($params["page_size"]);
  79. return [
  80. "total"=>$res->total(),
  81. "list"=>$res->items()
  82. ];
  83. }
  84. /**
  85. * 根据活动和用户生成推广链接
  86. * @param $actId 活动ID
  87. * @param $userId 用户ID
  88. */
  89. public static function getTransferLink($actId, $userId)
  90. {
  91. $instance = new LoggerFactoryUtil(HomeLogic::class);
  92. $linkUrl = env("INDEX_BASE_URL");
  93. $data = [
  94. "type"=>1,
  95. "url"=>$linkUrl,
  96. "app_id"=>"",
  97. "page_path"=>""
  98. ];
  99. //获取活动
  100. $act = CategoryModel::query()->find($actId);
  101. if(!$act){
  102. return $data;
  103. }
  104. $instance->info("基础地址:".$linkUrl);
  105. try{
  106. //获取用户
  107. switch ($act["platform_type"]){
  108. case 1://淘宝
  109. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_TAOBAO,$userId);
  110. $response = TaobaoLianMengUtil::getActivityInfo($platformSid,$act->activity_id);
  111. $res = [
  112. "h5"=>$response["short_click_url"],
  113. ];
  114. break;
  115. case 2://拼多多
  116. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_PINGDUODUO,$userId);
  117. //判断类型
  118. switch ($act["category_name"]){
  119. case "话费充值":
  120. $bean = new ResourceUrlGenParamBean(
  121. [
  122. "pid"=>$platformSid,
  123. "resourceType"=>39997
  124. ]
  125. );
  126. $data = DuoDuoKeUtil::resourceUrlGen($bean);
  127. $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
  128. break;
  129. case "火车票":
  130. $bean = new ResourceUrlGenParamBean(
  131. [
  132. "pid"=>$platformSid,
  133. "resourceType"=>50005
  134. ]
  135. );
  136. $data = DuoDuoKeUtil::resourceUrlGen($bean);
  137. $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
  138. break;
  139. case "百亿补贴":
  140. $bean = new ResourceUrlGenParamBean(
  141. [
  142. "pid"=>$platformSid,
  143. "resourceType"=>39996
  144. ]
  145. );
  146. $data = DuoDuoKeUtil::resourceUrlGen($bean);
  147. $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
  148. break;
  149. case "领券中心":
  150. $bean = new ResourceUrlGenParamBean(
  151. [
  152. "pid"=>$platformSid,
  153. "resourceType"=>40000
  154. ]
  155. );
  156. $data = DuoDuoKeUtil::resourceUrlGen($bean);
  157. $linkUrl = $data["resource_url_response"]["single_url_list"]["short_url"];
  158. break;
  159. }
  160. $res["h5"] = $linkUrl;
  161. break;
  162. // case 3://京东
  163. //
  164. // break;
  165. case 4://美团
  166. switch ($act["category_name"]){
  167. case "美团外卖":
  168. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  169. $linkUrl = MeituanLianmengUtilV1::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
  170. break;
  171. case "美团闪购":
  172. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  173. $linkUrl = MeituanLianmengUtilV1::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
  174. break;
  175. case "美团优选":
  176. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  177. $linkUrl = MeituanLianmengUtilV1::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
  178. break;
  179. case "美团酒店":
  180. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  181. $linkUrl = MeituanLianmengUtilV1::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
  182. break;
  183. default:
  184. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
  185. $linkUrl = JutuikeUtil::transferAct($platformSid,$act["activity_id"]);
  186. break;
  187. }
  188. $res["h5"] = $linkUrl;
  189. break;
  190. // case 5://本平台
  191. break;
  192. case 6://聚推客
  193. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
  194. $res = JutuikeUtil::transferAct($platformSid,$act->activity_id);
  195. break;
  196. }
  197. switch ($act["url_type"]){
  198. case 1://h5链接
  199. $data = [
  200. "type"=>1,
  201. "url"=>$res["h5"],
  202. "app_id"=>$act["app_id"]??"",
  203. "page_path"=>$res["we_app_info"]["page_path"]??""
  204. ];
  205. break;
  206. case 2://小程序跳转
  207. $data = [
  208. "type"=>2,
  209. "url"=>$res["h5"],
  210. "app_id"=>$act["app_id"]??"",
  211. "page_path"=>"/pages".$res["we_app_info"]["page_path"]??""
  212. ];
  213. break;
  214. }
  215. }catch (\Throwable $exception){
  216. $instance->info("错误信息:".$exception->getMessage());
  217. }
  218. // $linkUrl = $linkUrl?$linkUrl:env("INDEX_BASE_URL");
  219. // $instance->info("回调地址:".$linkUrl);
  220. return $data;
  221. }
  222. }