BuyLogic.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace App\Http\Logic\Buy;
  3. use App\Http\Bean\Util\Jutuike\GoodsListParamBean;
  4. use App\Http\Bean\Util\Jutuike\GoodsSearchParamBean;
  5. use App\Http\Enum\PlatformTypeEnum;
  6. use App\Http\Logic\BaseLogic;
  7. use App\Http\Utils\BaseUtil;
  8. use App\Http\Utils\Jutuike\JutuikeUtil;
  9. use App\Http\Utils\LoggerFactoryUtil;
  10. use App\Models\UserModel;
  11. class BuyLogic extends BaseLogic
  12. {
  13. /**
  14. * 电商平台分类逻辑
  15. */
  16. public static function getCateListLogic()
  17. {
  18. $params = request()->all();
  19. $lists = JutuikeUtil::goodsCategory($params["source"]);
  20. $datas = [];
  21. foreach ($lists as $key=>$list){
  22. $datas[] = [
  23. "id"=>$key,
  24. "name"=>$list
  25. ];
  26. }
  27. return $datas;
  28. }
  29. /**
  30. * 获取商品列表逻辑
  31. */
  32. public static function getGoodsListLogic()
  33. {
  34. $params = request()->all();
  35. $arr = [
  36. "source"=>$params["source"],
  37. "cat"=>$params["cat_id"],
  38. "page"=>$params["page"],
  39. "pageSize"=>$params["page_size"],
  40. ];
  41. $user = UserModel::findById(BaseUtil::getUserId());
  42. $bean = new GoodsListParamBean($arr);
  43. $lists = JutuikeUtil::goodsList($bean);
  44. $instance = new LoggerFactoryUtil(BuyLogic::class);
  45. $instance->info("上游返回数据:".json_encode($lists));
  46. $datas = [];
  47. foreach ($lists["list"] as $list){
  48. $datas[] = [
  49. "sales_tip"=>$list["sales_tip"]??0,
  50. "shop_name"=>$list["shopName"]??"",
  51. "goods_name"=>$list["goodsName"],
  52. "goods_thumb_url"=>$list["goodsThumbUrl"],
  53. "market_price"=>$list["marketPrice"],
  54. "price"=>$list["price"],
  55. "goods_id"=>$list["goodsId"],
  56. "discount"=>$list["discount"],
  57. "commission"=>round($list["commission"]*$user["user_commission_rate"]/100,2),
  58. ];
  59. }
  60. return [
  61. "total"=>$lists["count"],
  62. "list"=>$datas
  63. ];
  64. }
  65. /**
  66. * 商品详情页逻辑
  67. */
  68. public static function getGoodsDetailLogic()
  69. {
  70. $params = request()->all();
  71. $userId = BaseUtil::getUserId();
  72. $user = UserModel::findById($userId);
  73. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
  74. $res = JutuikeUtil::convert($params["goods_id"],$platformSid,$params["source"]);
  75. $coupon_info = [];
  76. if(isset($res["couponInfo"]["fav"])){
  77. $coupon_info = [
  78. "fav"=>$res["couponInfo"]["fav"],
  79. "use_end_time"=>$res["couponInfo"]["useEndTime"],
  80. "use_begin_time"=>$res["couponInfo"]["useBeginTime"],
  81. ];
  82. }
  83. $data = [
  84. "goods_name"=>$res["goodsName"],
  85. "price"=>$res["price"],
  86. "market_price"=>$res["marketPrice"],
  87. "discount"=>$res["discount"],
  88. "commission"=>round($res["commission"]*$user["user_commission_rate"]/100,2),
  89. "url"=>$res["url"],
  90. "goods_carousel_pictures"=>$res["goodsCarouselPictures"],
  91. "goods_detail_pictures"=>$res["goodsDetailPictures"],
  92. "coupon_info"=>$coupon_info
  93. ];
  94. return $data;
  95. }
  96. /**
  97. * 商品搜索逻辑
  98. */
  99. public static function getGoodsSearchLogic()
  100. {
  101. $params = request()->all();
  102. $userId = BaseUtil::getUserId();
  103. $user = UserModel::findById($userId);
  104. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
  105. $arr = [
  106. "sid"=>$platformSid,
  107. "keyword"=>$params["keyword"],
  108. "sort"=>1,
  109. "source"=>$params["source"],
  110. "page"=>$params["page"],
  111. "pageSize"=>$params["page_size"],
  112. ];
  113. if(isset($params["sort"])){
  114. $arr["sort"] = $params["sort"];
  115. }
  116. $bean = new GoodsSearchParamBean($arr);
  117. $res = JutuikeUtil::goodsSearch($bean);
  118. $instance = new LoggerFactoryUtil(BuyLogic::class);
  119. $instance->info("上游返回数据:".json_encode($res));
  120. $datas = [];
  121. foreach ($res["list"] as $list){
  122. $datas[] = [
  123. "shop_name"=>$list["shopName"]??"",
  124. "sales_tip"=>$list["sales_tip"]??0,
  125. "goods_name"=>$list["goodsName"],
  126. "goods_thumb_url"=>$list["goodsThumbUrl"],
  127. "market_price"=>$list["marketPrice"],
  128. "price"=>$list["price"],
  129. "goods_id"=>$list["goodsId"],
  130. "discount"=>$list["discount"],
  131. "commission"=>round($list["commission"]*$user["user_commission_rate"]/100,2),
  132. ];
  133. }
  134. return [
  135. "total"=>$res["count"],
  136. "list"=>$datas
  137. ];
  138. }
  139. /**
  140. * 获取淘宝商品的转链逻辑
  141. */
  142. public static function transferGoodsLogic()
  143. {
  144. $params = request()->all();
  145. $userId = $params["user_id"];
  146. $user = UserModel::findById($userId);
  147. $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
  148. $res = JutuikeUtil::convert($params["goods_id"],$platformSid);
  149. $coupon_info = [];
  150. if(isset($res["couponInfo"]["fav"])){
  151. $coupon_info = [
  152. "fav"=>$res["couponInfo"]["fav"],
  153. "use_end_time"=>$res["couponInfo"]["useEndTime"],
  154. "use_begin_time"=>$res["couponInfo"]["useBeginTime"],
  155. ];
  156. }
  157. $data = [
  158. "goods_name"=>$res["goodsName"],
  159. "price"=>$res["price"],
  160. "market_price"=>$res["marketPrice"],
  161. "discount"=>$res["discount"],
  162. "commission"=>round($res["commission"]*$user["user_commission_rate"]/100,2),
  163. "url"=>$res["url"],
  164. "goods_carousel_pictures"=>$res["goodsCarouselPictures"],
  165. "goods_detail_pictures"=>$res["goodsDetailPictures"],
  166. "coupon_info"=>$coupon_info
  167. ];
  168. return $data;
  169. }
  170. }