HomeLogic.php 8.8 KB

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