123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- namespace App\Http\Logic\Buy;
- use App\Http\Bean\Util\Jutuike\GoodsListParamBean;
- use App\Http\Bean\Util\Jutuike\GoodsSearchParamBean;
- use App\Http\Enum\PlatformTypeEnum;
- use App\Http\Logic\BaseLogic;
- use App\Http\Utils\BaseUtil;
- use App\Http\Utils\Jutuike\JutuikeUtil;
- use App\Http\Utils\LoggerFactoryUtil;
- use App\Models\UserModel;
- class BuyLogic extends BaseLogic
- {
- /**
- * 电商平台分类逻辑
- */
- public static function getCateListLogic()
- {
- $params = request()->all();
- $lists = JutuikeUtil::goodsCategory($params["source"]);
- $datas = [];
- foreach ($lists as $key=>$list){
- $datas[] = [
- "id"=>$key,
- "name"=>$list
- ];
- }
- return $datas;
- }
- /**
- * 获取商品列表逻辑
- */
- public static function getGoodsListLogic()
- {
- $params = request()->all();
- $arr = [
- "source"=>$params["source"],
- "cat"=>$params["cat_id"],
- "page"=>$params["page"],
- "pageSize"=>$params["page_size"],
- ];
- $user = UserModel::findById(BaseUtil::getUserId());
- $bean = new GoodsListParamBean($arr);
- $lists = JutuikeUtil::goodsList($bean);
- $instance = new LoggerFactoryUtil(BuyLogic::class);
- $instance->info("上游返回数据:".json_encode($lists));
- $datas = [];
- foreach ($lists["list"] as $list){
- $datas[] = [
- "sales_tip"=>$list["sales_tip"]??0,
- "shop_name"=>$list["shopName"]??"",
- "goods_name"=>$list["goodsName"],
- "goods_thumb_url"=>$list["goodsThumbUrl"],
- "market_price"=>$list["marketPrice"],
- "price"=>$list["price"],
- "goods_id"=>$list["goodsId"],
- "discount"=>$list["discount"],
- "commission"=>round($list["commission"]*$user["user_commission_rate"]/100,2),
- ];
- }
- return [
- "total"=>$lists["count"],
- "list"=>$datas
- ];
- }
- /**
- * 商品详情页逻辑
- */
- public static function getGoodsDetailLogic()
- {
- $params = request()->all();
- $userId = BaseUtil::getUserId();
- $user = UserModel::findById($userId);
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
- $res = JutuikeUtil::convert($params["goods_id"],$platformSid,$params["source"]);
- $coupon_info = [];
- if(isset($res["couponInfo"]["fav"])){
- $coupon_info = [
- "fav"=>$res["couponInfo"]["fav"],
- "use_end_time"=>$res["couponInfo"]["useEndTime"],
- "use_begin_time"=>$res["couponInfo"]["useBeginTime"],
- ];
- }
- $data = [
- "goods_name"=>$res["goodsName"],
- "price"=>$res["price"],
- "market_price"=>$res["marketPrice"],
- "discount"=>$res["discount"],
- "commission"=>round($res["commission"]*$user["user_commission_rate"]/100,2),
- "url"=>$res["url"],
- "goods_carousel_pictures"=>$res["goodsCarouselPictures"],
- "goods_detail_pictures"=>$res["goodsDetailPictures"],
- "coupon_info"=>$coupon_info
- ];
- return $data;
- }
- /**
- * 商品搜索逻辑
- */
- public static function getGoodsSearchLogic()
- {
- $params = request()->all();
- $userId = BaseUtil::getUserId();
- $user = UserModel::findById($userId);
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
- $arr = [
- "sid"=>$platformSid,
- "keyword"=>$params["keyword"],
- "sort"=>1,
- "source"=>$params["source"],
- "page"=>$params["page"],
- "pageSize"=>$params["page_size"],
- ];
- if(isset($params["sort"])){
- $arr["sort"] = $params["sort"];
- }
- $bean = new GoodsSearchParamBean($arr);
- $res = JutuikeUtil::goodsSearch($bean);
- $instance = new LoggerFactoryUtil(BuyLogic::class);
- $instance->info("上游返回数据:".json_encode($res));
- $datas = [];
- foreach ($res["list"] as $list){
- $datas[] = [
- "shop_name"=>$list["shopName"]??"",
- "sales_tip"=>$list["sales_tip"]??0,
- "goods_name"=>$list["goodsName"],
- "goods_thumb_url"=>$list["goodsThumbUrl"],
- "market_price"=>$list["marketPrice"],
- "price"=>$list["price"],
- "goods_id"=>$list["goodsId"],
- "discount"=>$list["discount"],
- "commission"=>round($list["commission"]*$user["user_commission_rate"]/100,2),
- ];
- }
- return [
- "total"=>$res["count"],
- "list"=>$datas
- ];
- }
- /**
- * 获取淘宝商品的转链逻辑
- */
- public static function transferGoodsLogic()
- {
- $params = request()->all();
- $userId = $params["user_id"];
- $user = UserModel::findById($userId);
- $platformSid = BaseUtil::getPlatformUserSpreadId(PlatformTypeEnum::PLATFORM_JUTUIKE,$userId);
- $res = JutuikeUtil::convert($params["goods_id"],$platformSid);
- $coupon_info = [];
- if(isset($res["couponInfo"]["fav"])){
- $coupon_info = [
- "fav"=>$res["couponInfo"]["fav"],
- "use_end_time"=>$res["couponInfo"]["useEndTime"],
- "use_begin_time"=>$res["couponInfo"]["useBeginTime"],
- ];
- }
- $data = [
- "goods_name"=>$res["goodsName"],
- "price"=>$res["price"],
- "market_price"=>$res["marketPrice"],
- "discount"=>$res["discount"],
- "commission"=>round($res["commission"]*$user["user_commission_rate"]/100,2),
- "url"=>$res["url"],
- "goods_carousel_pictures"=>$res["goodsCarouselPictures"],
- "goods_detail_pictures"=>$res["goodsDetailPictures"],
- "coupon_info"=>$coupon_info
- ];
- return $data;
- }
- }
|