HomeLogic.php 8.9 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. //
  155. //
  156. // break;
  157. // case 3://京东
  158. //
  159. // break;
  160. // case 4://美团
  161. // switch ($act["category_name"]){
  162. // case "美团外卖":
  163. // $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  164. // $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
  165. // break;
  166. // case "美团闪购":
  167. // $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  168. // $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
  169. // break;
  170. // case "美团优选":
  171. // $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  172. // $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
  173. // break;
  174. // case "美团酒店":
  175. // $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_MEITUAN,$userId);
  176. // $linkUrl = MeituanLianmengUtil::getMeituanWaimaiUrl($userId,$platformSid,$act["activity_id"],MeiTuanLinkTypeEnum::H5);
  177. // break;
  178. // default:
  179. // $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
  180. // $linkUrl = JutuikeUtil::transferAct($platformSid,$act["activity_id"]);
  181. // break;
  182. // }
  183. // break;
  184. // case 5://本平台
  185. break;
  186. case 6://聚推客
  187. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
  188. $res = JutuikeUtil::transferAct($platformSid,$act->activity_id);
  189. break;
  190. }
  191. switch ($act["url_type"]){
  192. case 1://h5链接
  193. $data = [
  194. "type"=>1,
  195. "url"=>$res["h5"],
  196. "app_id"=>$act["app_id"]??"",
  197. "page_path"=>$res["we_app_info"]["page_path"]??""
  198. ];
  199. break;
  200. case 2://小程序跳转
  201. $data = [
  202. "type"=>2,
  203. "url"=>$res["h5"],
  204. "app_id"=>$act["app_id"]??"",
  205. "page_path"=>"/pages".$res["we_app_info"]["page_path"]??""
  206. ];
  207. break;
  208. }
  209. }catch (\Throwable $exception){
  210. }
  211. // $linkUrl = $linkUrl?$linkUrl:env("INDEX_BASE_URL");
  212. // $instance->info("回调地址:".$linkUrl);
  213. return $data;
  214. }
  215. }