二开(1)——CRMEB的一元抢购


前端的路径 /pages/activity/goods_one/index (一元抢购)
后端对应的API相关路径:
/api/store/product/one/lst (API路径是由route统一处理)
从路由映射里面检查
route/api.php (前端API的路径集合)
Route::group(‘store/product’, function () {Route::get(‘one/lst’, ‘StoreProductOne/lst’); 可以看到指向的是
app/controller/api/store/product/StoreProductOne.php 文件里面lst方法

跳转到 $data = t h i s − > r e p o s i t o r y − > g e t A p i O n e P r o d u c t ( this->repository->getApiOneProduct( this>repository>getApiOneProduct(where,$page, $limit); 然后是一个读取联表的方法
联表数据是:eb_store_product(系统商品表) 和 eb_store_spu(搜索信息表)

        return model::alias('Product')->where([
            'Product.is_show' => 1,  //商品需要展示
            'Product.status' => 1,  //有效的商品
            'Product.is_used' => 1, //显示的隐藏的
            'Product.mer_status' => 1,//店铺的状态
            'Product.product_type' => 5,// 5表示是一元购商品  6表示抽奖商品
            'Product.is_gift_bag' => 0, //是否是礼包
        ])->where('stock', '>', 0) //库存
            ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
                $query->where('Product.mer_id', $where['mer_id']);
            }) //是不是查询了商家
            ->when(isset($where['star']), function ($query) use ($where) {
                //商品的搜索信息和商品构成一组完整信息返回
                $query->Join('StoreSpu U', 'Product.product_id = U.product_id')->where('U.product_type', 5);
                $query->when($where['star'] !== '', function ($query) use ($where) {
                    $query->where('U.star', $where['star']);
                });
                $query->order('U.star DESC,U.rank DESC');
            });

这段代码逻辑 主要是读取系统里面的正常的一元购商品,同时会判断商户信息,同时会把相关搜索信息组装成一个完整的一元购商品表返回出来。一元购后台商品的添加: (普通商品添加 添加的时候会读取该字段)。

商品搜索信息表+商品表 俩者组合返回正常的商品数据。eb_store_product+eb_store_spu 前者主要商品详情和设置,后者模板星级和其他附加信息存储。

主要用来的相关开发: 一元购商品是否经过特殊校验(比如只有限定店铺能开启一元购)是否对商品进行数量虚拟。返回到前端的相关字段注解:
如果只是一元抢购商品页面,输出的字段偏多,有些暂时没用到。当前页面主要用的是 背景图+名字+售价+库存+进度百分比(需要前端根据已售/已售+库存计算对应百分比)

        {
            "product_id": 371, // 产品ID
            "mer_id": 101, //商户编号
            "is_new": 0,
            "keyword": "",  //搜索关键字的显示
            "brand_id": 116,  //品牌
            "image": "http:\/\/jingyuntg.com\/uploads\/copy\/75d1dc7f76e94e6c95416e4142df02e8.jpg", //底图
            "product_type": 5,  //类型相关
            "store_name": "抢购测试2", //一元购列表页面的名字
            "sort": 0,  //排序字段
            "rank": 0, //排名
            "star": 1, //后台对商品打的星星
            "rate": "5.0",
            "reply_count": 0,
            "sales": 1,  //已经卖的数量
            "price": "0.00",  //前端的售价,理论上这里的抢购可以是任意价格比如999买苹果手机
            "cost": "1.20",
            "ot_price": "2.20", //显示的价格
            "stock": 99, //当前系统的库存数据
            "extension_type": 0, //拓展
            "care_count": 0,  //关注人数
            "unit_name": "个",//商品单位
            "create_time": "2024-05-07 16:05:20" //商品添加的时间
        }

该页面已经缓存了商品详情的一些数据,展示商品其他数据的时候,就无需再次请求
api/store/product/show/382
主要获取商品相关的详情(额外新增售后相关+店铺的信息,基础商品信息已经在商品列表里面显示出来)因为这部分仅仅是数据展示,这部分逻辑其实有问题,当前库存数据没有显示出来,直接导致显示的售后是跟不进去的,此处需要对系统进行额外的开发改动。

相关数据:
api/user/cart/count 可通过该接口实时获取购物车的商品数量,一元购商品是跳过了购物车的。

​ (2)一元购商品购买
请求的API api/user/cart/create
Route::group(‘user/cart’, function () { Route::post(‘/create’, ‘StoreCart/create’);}
这里的路由->prefix(‘api.store.order.’) 通过这个可以定位到 app/controller/api/store/order/StoreCart.php

默认情况下 检测用户VIP等级情况(如要放开,可以导致新用户直接抽奖)
r e s u l t = a p p ( ) − > m a k e ( P r o d u c t R e p o s i t o r y : : c l a s s ) − > c a r t O n e P r o d u c t C h e c k ( result = app()->make(ProductRepository::class)->cartOneProductCheck( result=app()>make(ProductRepository::class)>cartOneProductCheck(data,$this->request->userInfo());
发起购买之前,我们会对当前商品进行一次身份和商品的检测,一元购商品的核心方法:

        // 这里修改为只要购买过就不能再次购买 还有检测是否是付费VIP 否则也不能购买 明天继续
        $storeOrderRepository = app()->make(StoreOrderRepository::class);
        if ($storeOrderRepository->getUserOneProductPayCount($userInfo->uid, $product['product_id'])) {
            throw new ValidateException('本次活动您该商品购买数量已达到上限');
        }

       //下单检测 SKU的情况
        $value_make = app()->make(ProductAttrValueRepository::class);
        $sku = $value_make->getOptionByUnique($data['product_attr_unique']);

        $_sku = $value_make->getWhere(['sku' => $sku['sku'], 'product_id' => $product['product_id']]);
        if (!$_sku) {
            throw new ValidateException('原商品SKU不存在');
        }
        if ($_sku['stock'] <= 0) {
            throw new ValidateException('原库存不足');
        }
        $cart = null;
        return compact('product', 'sku', 'cart');

这里主要涉及的二开点,下单一元购用户身份修改

订单查看:

api/order/group_one_order_list
app/controller/api/store/order/StoreOrder.php 文件对应

//一元购的入口比较隐晦,前端 我的——我的抽奖——一元抢购(该段代码对应了一元抢购的列表逻辑)        
$list = $groupOrderRepository->getList(['uid' => $this->request->uid(), 'activity_type' => 5],
            $page,
            $limit,
            true);

//这里使用了foreach里面嵌套了数据库查询循环 应用了&取址直接修改
        foreach ($list['list'] as &$item) {
            //奖票
            $item['lottery'] = ProductOneRecords::where([
                'user_id' => $item->uid,
                'order_id' => $item->group_order_id
            ])->find();
            $item['lottery_records'] = [];
            if (!empty($item['lottery'])) {
                $item['lottery_records'] = ProductOneRecords::where([
                    'product_id' => $item['lottery']['product_id'],
//                    'round' => $item['lottery']['round'],
                ])->field(['id', 'number', 'round', 'status', 'user_id', 'create_time'])->with('user')->order('create_time', 'desc')->select();
            }
        }
   //一元购的功能可以看到列表
        return app('json')->success($list);

这里是抽奖的二开核心。

商家店铺里面查看一元购活动:(商品搜索逻辑通用,这里加了个action参数)
https://jingyuntg.com/api/product/spu/merchant/101?order=&keyword=&page=1&limit=30&action=1
//商户商品 product/spu/merchant/:id
Route::get(‘/merchant/:id’, ‘StoreSpu/merProductLst’);

  • 24
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大梁来了

千山万水总是情,打赏一块行不行

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值