Просмотр исходного кода

优化用户下单方法-进行中

sunxbiao 1 год назад
Родитель
Сommit
9549400dc5

+ 29 - 1
app/common/dao/store/StoreSeckillActiveDao.php

@@ -5,12 +5,14 @@
5 5
  * @author Qinii
6 6
  * @day 2020-07-30
7 7
  *
8
- * 
8
+ *
9 9
  */
10 10
 namespace app\common\dao\store;
11 11
 
12
+use app\common\enum\store\SeckillActiveEnum;
12 13
 use app\common\model\store\StoreSeckillActive;
13 14
 use app\common\dao\BaseDao;
15
+use app\entity\data\store\SeckillActiveEntity;
14 16
 
15 17
 class StoreSeckillActiveDao extends BaseDao
16 18
 {
@@ -129,4 +131,30 @@ class StoreSeckillActiveDao extends BaseDao
129 131
             });
130 132
         return $query;
131 133
     }
134
+
135
+    /**
136
+     * 根据 商品ID 获取当前生效的 活动记录
137
+     * @param int $productId
138
+     * @return \app\entity\CommonEntity
139
+     */
140
+    public function getSeckillActiveEntityByProductIdInActive(int $productId): \app\entity\CommonEntity
141
+    {
142
+        $data = [];
143
+        try {
144
+            /** @var StoreSeckillActive $model */
145
+            $model = $this->getModel();
146
+            $dataRes = $model::getDB()
147
+                ->where('product_id', '=', $productId)
148
+                ->where("`start_time` <= '" . time() . "'")
149
+                ->where("`end_time` >= '" . time() . "'")
150
+                ->where("status", '=', SeckillActiveEnum::STATUS['Active']['code'])
151
+                ->find();
152
+            if (!empty($dataRes)) {
153
+                $data = $dataRes->toArray();
154
+            }
155
+        } catch (\Exception $e) {
156
+
157
+        }
158
+        return SeckillActiveEntity::newInstance($data);
159
+    }
132 160
 }

+ 24 - 0
app/common/dao/store/order/StoreCartDao.php

@@ -178,4 +178,28 @@ class StoreCartDao extends BaseDao
178 178
         }
179 179
         return CartEntity::newInstance($storeCartData);
180 180
     }
181
+
182
+    /**
183
+     * @param array $cartIdList
184
+     * @return CartEntity[]
185
+     */
186
+    public function getCartEntityListByCartIdList(array $cartIdList): array
187
+    {
188
+        $entityList = [];
189
+        try {
190
+            /** @var StoreCart  $model */
191
+            $model = $this->getModel();
192
+            $dataListRes = $model::getDB()
193
+                ->whereIn('cart_id', $cartIdList)
194
+                ->select()
195
+                ->toArray();
196
+            if (!empty($dataListRes)) {
197
+                foreach ($dataListRes as $data) {
198
+                    $entityList[] = CartEntity::newInstance($data);
199
+                }
200
+            }
201
+        } catch (\Exception $e) {
202
+        }
203
+        return $entityList;
204
+    }
181 205
 }

+ 26 - 0
app/common/dao/system/merchant/MerchantDao.php

@@ -12,8 +12,10 @@ namespace app\common\dao\system\merchant;
12 12
 
13 13
 
14 14
 use app\common\dao\BaseDao;
15
+use app\common\enum\merchant\MerchantEnum;
15 16
 use app\common\model\system\merchant\Merchant;
16 17
 use app\common\model\user\User;
18
+use app\entity\data\merchant\MerchantEntity;
17 19
 use think\db\BaseQuery;
18 20
 use think\db\exception\DataNotFoundException;
19 21
 use think\db\exception\DbException;
@@ -226,4 +228,28 @@ class MerchantDao extends BaseDao
226 228
     }
227 229
 
228 230
 
231
+    /**
232
+     * 根据 商户ID 获取 未删除的 商户信息
233
+     * @param int $merId
234
+     * @return \app\entity\CommonEntity
235
+     */
236
+    public function getMerchantEntityByMerchantId(int $merId): \app\entity\CommonEntity
237
+    {
238
+        $data = [];
239
+        try {
240
+            /** @var Merchant $model */
241
+            $model = $this->getModel();
242
+            $dataRes = $model::getDB()
243
+                ->where('mer_id', '=', $merId)
244
+                ->where('is_del', '=', MerchantEnum::IS_DEL['No']['code'])
245
+                ->find();
246
+            if (!empty($dataRes)) {
247
+                $data = $dataRes->toArray();
248
+            }
249
+        } catch (\Exception $e) {
250
+
251
+        }
252
+        return MerchantEntity::newInstance($data);
253
+    }
254
+
229 255
 }

+ 10 - 0
app/common/enum/merchant/MerchantEnum.php

@@ -0,0 +1,10 @@
1
+<?php
2
+
3
+namespace app\common\enum\merchant;
4
+
5
+use app\common\enum\CommonEnum;
6
+
7
+class MerchantEnum extends CommonEnum
8
+{
9
+
10
+}

+ 7 - 0
app/common/enum/store/ProductEnum.php

@@ -27,4 +27,11 @@ class ProductEnum extends CommonEnum
27 27
         'No' => ['code' => 0, 'name' => '非正常'],
28 28
         'Yes' => ['code' => 1, 'name' => '正常']
29 29
     ];
30
+
31
+
32
+    // 是否秒杀
33
+    const SECKILL = [
34
+        'No' => ['code' => 0, 'name' => '否'],
35
+        'Yes' => ['code' => 1, 'name' => '是']
36
+    ];
30 37
 }

+ 13 - 0
app/common/enum/store/SeckillActiveEnum.php

@@ -0,0 +1,13 @@
1
+<?php
2
+
3
+namespace app\common\enum\store;
4
+
5
+use app\common\enum\CommonEnum;
6
+
7
+class SeckillActiveEnum extends CommonEnum
8
+{
9
+    const STATUS = [
10
+        'Active' => ['code' => 0, 'name' => '进行中'],
11
+        'Finish' => ['code' => 1, 'name' => '已结束']
12
+    ];
13
+}

+ 13 - 2
app/common/repositories/store/StoreSeckillActiveRepository.php

@@ -11,8 +11,7 @@ namespace app\common\repositories\store;
11 11
 
12 12
 use app\common\dao\store\StoreSeckillActiveDao;
13 13
 use app\common\repositories\BaseRepository;
14
-use FormBuilder\Factory\Elm;
15
-use think\facade\Route;
14
+use app\entity\data\store\SeckillActiveEntity;
16 15
 
17 16
 class StoreSeckillActiveRepository extends BaseRepository
18 17
 {
@@ -30,4 +29,16 @@ class StoreSeckillActiveRepository extends BaseRepository
30 29
     {
31 30
         $this->dao = $dao;
32 31
     }
32
+
33
+    /**
34
+     * 根据 商品ID 获取当前生效的 活动记录
35
+     * @param int $productId
36
+     * @return SeckillActiveEntity
37
+     */
38
+    public function getSeckillActiveEntityByProductIdInActive(int $productId): SeckillActiveEntity
39
+    {
40
+        /** @var SeckillActiveEntity $seckillActiveEntity */
41
+        $seckillActiveEntity = $this->dao->getSeckillActiveEntityByProductIdInActive($productId);
42
+        return $seckillActiveEntity;
43
+    }
33 44
 }

+ 10 - 0
app/common/repositories/store/order/StoreCartRepository.php

@@ -133,4 +133,14 @@ class StoreCartRepository extends BaseRepository
133 133
         $cartEntity = $this->dao->getCartEntityByCartId($cartId);
134 134
         return $cartEntity;
135 135
     }
136
+
137
+    /**
138
+     * 根据 购物车 ID 获取购物车实体
139
+     * @param array $cartIdList
140
+     * @return CartEntity[]
141
+     */
142
+    public function getCartEntityListByCartIdList(array $cartIdList): array
143
+    {
144
+        return $this->dao->getCartEntityListByCartIdList($cartIdList);
145
+    }
136 146
 }

+ 79 - 46
app/common/repositories/store/order/StoreOrderRepository.php

@@ -13,6 +13,7 @@ namespace app\common\repositories\store\order;
13 13
 
14 14
 use app\common\dao\store\order\StoreOrderDao;
15 15
 use app\common\enum\store\CartEnum;
16
+use app\common\enum\store\ProductEnum;
16 17
 use app\common\model\store\order\StoreGroupOrder;
17 18
 use app\common\model\store\order\StoreOrder;
18 19
 use app\common\model\store\order\StoreRefundOrder;
@@ -10622,10 +10623,10 @@ class StoreOrderRepository extends BaseRepository
10622 10623
         return isset($group_rate[$user_group]) ? round($group_rate[$user_group] / 100, 2) : 0.00;
10623 10624
     }
10624 10625
 
10625
-    public function createOrderNew(StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity, UserEntity $userEntity, CartEntity $cartEntity, AddressEntity $addressEntity, ShareEntity $shareEntity)
10626
+    public function createOrderNew(StoreOrderCreateRequestEntity $storeOrderCreateRequestEntity, UserEntity $userEntity, array $cartEntityList, AddressEntity $addressEntity, ShareEntity $shareEntity)
10626 10627
     {
10627 10628
 
10628
-        $order = $this->cartIdByOrderInfoNew($userEntity->getUid(), [$cartEntity->getCartId()], $addressEntity->getAddressId(), false, 0, 0, 0);
10629
+        $order = $this->cartIdByOrderInfoNew($userEntity->getUid(), [$cartEntityList->getCartId()], $addressEntity->getAddressId(), false, 0, 0, 0);
10629 10630
         return $order;
10630 10631
         $isTest = $userEntity->getTestUser();
10631 10632
 
@@ -11533,53 +11534,87 @@ class StoreOrderRepository extends BaseRepository
11533 11534
     }
11534 11535
 
11535 11536
     /**
11536
-     * @param $uid
11537
-     * @param array $cartId
11538
-     * @param int|null $addressId
11539
-     * @param $confirm
11540
-     * @param $psType
11541
-     * @param $payType
11542
-     * @param $youhui_price_key
11543
-     * @param CartEntity $cartEntity
11544
-     * @return mixed
11545
-     * @throws DataNotFoundException
11546
-     * @throws DbException
11547
-     * @throws ModelNotFoundException
11537
+     * @param CartEntity[] $cartEntityList
11538
+     * @return array
11548 11539
      */
11549
-    public function cartIdByOrderInfoNew(CartEntity $cartEntity)
11540
+    public function cartIdByOrderInfoNew(array $cartEntityList)
11550 11541
     {
11551
-        // 获取购物车商品信息
11542
+        // 商户
11543
+        /** @var MerchantRepository $merchantRepository */
11544
+        $merchantRepository = app()->make(MerchantRepository::class);
11545
+        // 商品
11552 11546
         /** @var ProductRepository $productRepository */
11553 11547
         $productRepository = app()->make(ProductRepository::class);
11554
-        $productEntity = $productRepository->getProductEntityByProductId($cartEntity->getProductId());
11555
-        if (empty($productEntity->getProductId())) {
11556
-            throw new ValidateException('未查询到商品信息');
11557
-        }
11558
-
11559
-        // 获取购物车商品属性信息
11548
+        // 商品属性
11560 11549
         /** @var ProductAttrValueRepository $productAttrValueRepository */
11561 11550
         $productAttrValueRepository = app()->make(ProductAttrValueRepository::class);
11562
-        $productAttrValueEntity = $productAttrValueRepository->getProductAttrValueEntityByUnique($cartEntity->getProductAttrUnique());
11563
-        if (empty($productAttrValueEntity->getProductId())) {
11564
-            throw new ValidateException('未查询到商品属性信息');
11565
-        }
11551
+        // 目前还未搞清这个表的意义
11552
+        /** @var SeckillRepository $seckillRepository */
11553
+        $seckillRepository = app()->make(SeckillRepository::class);
11554
+        // 商户设置秒杀商品关联表
11555
+        /** @var StoreSeckillActiveRepository $storeSeckillActiveRepository */
11556
+        $storeSeckillActiveRepository = app()->make(StoreSeckillActiveRepository::class);
11566 11557
 
11567
-        // 判断订单是否已失效
11568
-        if ($cartEntity->getIsFail() == CartEnum::IS_FAIL['Yes']['code']) {
11569
-            throw new ValidateException($productEntity->getStoreName() . ' 已失效');
11570
-        }
11571
-        // 如果商品类型是 普通商品 ,则判断库存是否充足
11572
-        if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
11573
-            if ($productAttrValueEntity->getStock() < $cartEntity->getCartNum()) {
11574
-                throw new ValidateException($productEntity->getStoreName() . ' 库存不足--' . $cartEntity->getCartNum());
11558
+        foreach ($cartEntityList as $cartEntity) {
11559
+            // 验证商户
11560
+            $merchantEntity = $merchantRepository->getMerchantEntityByMerchantId($cartEntity->getMerId());
11561
+            if (empty($merchantEntity->getMerId())) {
11562
+                throw new ValidateException('未查询到商户信息');
11575 11563
             }
11576
-        } else {
11577
-            // 如果不是普通商品 则是否秒杀产品,如果是秒杀产品则判断是否超卖
11578
-            if (!$this->getDayPayCount($cartEntity->getUid(), $cartEntity->getProductId()) || !$this->getPayCount($cartEntity->getUid(), $cartEntity->getProductId())) {
11579
-                throw new ValidateException($productEntity->getStoreName() . ' 已超出购买限制');
11564
+
11565
+            // 获取购物车商品信息
11566
+            $productEntity = $productRepository->getProductEntityByProductId($cartEntity->getProductId());
11567
+            if (empty($productEntity->getProductId())) {
11568
+                throw new ValidateException('未查询到商品信息');
11569
+            }
11570
+
11571
+            // 获取购物车商品属性信息
11572
+            $productAttrValueEntity = $productAttrValueRepository->getProductAttrValueEntityByUnique($cartEntity->getProductAttrUnique());
11573
+            if (empty($productAttrValueEntity->getProductId())) {
11574
+                throw new ValidateException('未查询到商品属性信息');
11580 11575
             }
11576
+
11577
+            // 判断订单是否已失效
11578
+            if ($cartEntity->getIsFail() == CartEnum::IS_FAIL['Yes']['code']) {
11579
+                throw new ValidateException($productEntity->getStoreName() . ' 已失效');
11580
+            }
11581
+
11582
+            // 如果商品类型是 普通商品 ,则判断库存是否充足
11583
+            if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
11584
+                if ($productAttrValueEntity->getStock() < $cartEntity->getCartNum()) {
11585
+                    throw new ValidateException($productEntity->getStoreName() . ' 库存不足--' . $cartEntity->getCartNum());
11586
+                }
11587
+            } else {
11588
+                // 如果是秒杀商品 应该首先判断是否还在活动期间内(rrx_store_seckill_active 商户设置秒杀商品关联表)
11589
+                $seckillActiveEntity = $storeSeckillActiveRepository->getSeckillActiveEntityByProductIdInActive($cartEntity->getProductId());
11590
+                if (empty($seckillActiveEntity->getSeckillActiveId())) {
11591
+                    throw new ValidateException($productEntity->getStoreName() . ' 秒杀活动已失效');
11592
+                }
11593
+
11594
+                // 如果不是普通商品 则是否秒杀产品,如果是秒杀产品则判断是否超卖
11595
+                if (!$this->getDayPayCount($cartEntity->getUid(), $cartEntity->getProductId()) || !$this->getPayCount($cartEntity->getUid(), $cartEntity->getProductId())) {
11596
+                    throw new ValidateException($productEntity->getStoreName() . ' 已超出购买限制');
11597
+                }
11598
+            }
11599
+
11600
+            // 计算养老金
11601
+            $yanglaojin = $productRepository->yanglaojin($cartEntity->getProductId());
11602
+
11603
+            if ($productEntity->getSeckill() == ProductEnum::SECKILL['Yes']['code'] && !is_null($productEntity->getDcPrice()) && $productEntity->getDcPrice() > 0.00) {
11604
+                // 获取 在活动期间内的 秒杀活动记录
11605
+                $seckillEntity = $seckillRepository->getSeckillEntityByProductId($cartEntity->getProductId());
11606
+                if (!empty($seckillEntity->getId())) {
11607
+                    // 把 商品属性的 价格 改成 大仓会员价
11608
+                    $productAttrValueEntity->setPrice($productEntity->getDcPrice());
11609
+                }
11610
+            }
11611
+
11612
+            // TODO 写到这了,对应 StoreCartRepository.php 的 70 的else 内
11613
+
11581 11614
         }
11582 11615
 
11616
+
11617
+
11583 11618
         // 计算 邮费
11584 11619
         $postage_price = 0.00;
11585 11620
         $product_price = [];
@@ -11591,9 +11626,7 @@ class StoreOrderRepository extends BaseRepository
11591 11626
         // ProductType => 0.普通商品 1.秒杀商品
11592 11627
         $productEntity->setProductType($productEntity->getType());
11593 11628
 
11594
-        /** @var SeckillRepository $seckillRepository */
11595
-        $seckillRepository = app()->make(SeckillRepository ::class);
11596
-        $seckillEntity = $seckillRepository->getSeckillEntityByProductId($cartEntity->getProductId());
11629
+        $seckillEntity = $seckillRepository->getSeckillEntityByProductId($cartEntityList->getProductId());
11597 11630
         // ??? 暂时不理解这一步
11598 11631
         if (!empty($seckillEntity->getId())) {
11599 11632
             // 把 商品属性的 价格 改成 大仓会员价
@@ -11601,15 +11634,15 @@ class StoreOrderRepository extends BaseRepository
11601 11634
         }
11602 11635
 
11603 11636
         // 计算 订单价格 总价 单价 (目前一笔订单只能有一个购物车 购物车内 只能有一件商品)
11604
-        $total_price = $price = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPrice(), 2);
11605
-        $total_num = $cartEntity->getCartNum();
11637
+        $total_price = $price = bcmul($cartEntityList->getCartNum(), $productAttrValueEntity->getPrice(), 2);
11638
+        $total_num = $cartEntityList->getCartNum();
11606 11639
 
11607 11640
         // 如果是 普通商品 product_type 类型 0=普通产品
11608
-        if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
11609
-            $valid_total_price = $product_price[$cartEntity->getProductId()] = $price;
11641
+        if ($cartEntityList->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
11642
+            $valid_total_price = $product_price[$cartEntityList->getProductId()] = $price;
11610 11643
         }
11611 11644
 
11612
-        $product_cart[$cartEntity->getProductId()] = [$cartEntity->getCartId()];
11645
+        $product_cart[$cartEntityList->getProductId()] = [$cartEntityList->getCartId()];
11613 11646
 
11614 11647
         // unset($cartInfo['list'][$_k]['product']['temp']);
11615 11648
         // $cartInfo['list'][$_k] = $cart;

+ 12 - 1
app/common/repositories/system/merchant/MerchantRepository.php

@@ -24,6 +24,7 @@ use app\common\repositories\user\UserVisitRepository;
24 24
 use app\common\repositories\wechat\RoutineQrcodeRepository;
25 25
 use app\controller\admin\system\merchant\MerchantIntention;
26 26
 use app\controller\merchant\gong\Goods;
27
+use app\entity\data\merchant\MerchantEntity;
27 28
 use app\traits\HaikeApiRequest;
28 29
 use crmeb\services\QrcodeService;
29 30
 use crmeb\services\UploadService;
@@ -1008,6 +1009,16 @@ class MerchantRepository extends BaseRepository
1008 1009
 
1009 1010
     }
1010 1011
 
1011
-
1012
+    /**
1013
+     * 根据 商户ID 获取 未删除的 商户信息
1014
+     * @param int $merchantId
1015
+     * @return MerchantEntity
1016
+     */
1017
+    public function getMerchantEntityByMerchantId(int $merchantId): MerchantEntity
1018
+    {
1019
+        /** @var MerchantEntity $entity */
1020
+        $entity = $this->dao->getMerchantEntityByMerchantId($merchantId);
1021
+        return $entity;
1022
+    }
1012 1023
 
1013 1024
 }

+ 25 - 17
app/controller/api/store/order/StoreOrder.php

@@ -42,7 +42,7 @@ use think\facade\Request;
42 42
  * @author xaboy
43 43
  * @day 2020/6/10
44 44
  */
45
-class StoreOrder extends BaseController
45
+class StoreOrder
46 46
 {
47 47
     /**
48 48
      * @var StoreOrderRepository
@@ -58,7 +58,7 @@ class StoreOrder extends BaseController
58 58
      */
59 59
     public function __construct(App $app, StoreOrderRepository $repository)
60 60
     {
61
-        parent::__construct($app);
61
+        // parent::__construct($app);
62 62
         $this->repository = $repository;
63 63
 
64 64
         $this->source = request()->header('source');
@@ -697,6 +697,8 @@ class StoreOrder extends BaseController
697 697
     }
698 698
 
699 699
     /**
700
+     * 理解注释
701
+     * store_cart 购物车表,每个人购物车里 有多件商品,每个商品在这张表里 都是一条记录
700 702
      * @param StoreOrderCreateValidate $storeOrderCreateValidate
701 703
      * @return false|string|\think\response\Json
702 704
      * @throws DataNotFoundException
@@ -721,11 +723,13 @@ class StoreOrder extends BaseController
721 723
 
722 724
         // 2、加锁,他之前加的锁好像在锁狗屎,毛线都没锁住, 而且为什么要锁用户
723 725
         // 增加锁,防止同一用户重读点击
724
-        // $redisHandler = Cache::store('redis')->handler();
725
-        // $isSet = $redisHandler->set('createOrder' . $uid . '-' . $storeOrderCreateRequestEntity->getCartId(), 1, ['nx', 'ex' => 30]);
726
-        // if ($isSet) {
727
-        //     return app('json')->fail('请勿重复下单');
728
-        // }
726
+        $redisHandler = Cache::store('redis')->handler();
727
+        $cartIdList = $storeOrderCreateRequestEntity->getCartIdList();
728
+        sort($cartIdList);
729
+        $isSet = $redisHandler->set('createOrder' . $uid . '-' . implode('-', $cartIdList), 1, ['nx', 'ex' => 30]);
730
+        if (!$isSet) {
731
+            return app('json')->fail('请勿重复下单');
732
+        }
729 733
 
730 734
         /** @var UserRepository $userRepository */
731 735
         $userRepository = app()->make(UserRepository::class);
@@ -737,18 +741,20 @@ class StoreOrder extends BaseController
737 741
         // 目前购物车只能添加一件商品,据了解之前 写的购物车,添加多件商品组合支付时计算的 金额和 VR 积分之类的会有问题
738 742
         /** @var StoreCartRepository $storeCartRepository */
739 743
         $storeCartRepository = app()->make(StoreCartRepository::class);
740
-        $cartEntity = $storeCartRepository->getCartEntityByCartId($storeOrderCreateRequestEntity->getCartId());
741
-        if (empty($cartEntity->getCartId())) {
744
+        $cartEntityList = $storeCartRepository->getCartEntityListByCartIdList($storeOrderCreateRequestEntity->getCartIdList());
745
+        if (empty($cartEntityList) || count($storeOrderCreateRequestEntity->getCartIdList()) != count($cartEntityList)) {
742 746
             return app('json')->fail('获取购物车内容失败');
743 747
         }
744 748
         // 确认购物车内 微唯宝 的商品 是否满足发货
745
-        /** @var ProductAttrValueRepository $productAttrValueRepository */
746
-        $productAttrValueRepository = app()->make(ProductAttrValueRepository::class);
747
-        // 检查库存 查看 此商品已下架 此商品规格无货 此商品不支持该地区
748
-        // (按照代码中所写的逻辑来推理:从微唯宝拉取过来,从而上架到商品表的商品,都有SPUId,所以去走微唯宝提供的接口验证,而会员专区和商贸区的商品可能是商户自己加的,没有SPUId,所以也就不用走微唯宝的验证)
749
-        $checkGong = $productAttrValueRepository->checkGong($cartEntity->getProductId(), $cartEntity->getProductAttrUnique(), $cartEntity->getCartNum(), $uid, $storeOrderCreateRequestEntity->getAddressId());
750
-        if (isset($checkGong['code']) && $checkGong['code'] == -1) {
751
-            return app('json')->fail($checkGong['message']);
749
+        foreach ($cartEntityList as $cartEntity) {
750
+            /** @var ProductAttrValueRepository $productAttrValueRepository */
751
+            $productAttrValueRepository = app()->make(ProductAttrValueRepository::class);
752
+            // 检查库存 查看 此商品已下架 此商品规格无货 此商品不支持该地区
753
+            // (按照代码中所写的逻辑来推理:从微唯宝拉取过来,从而上架到商品表的商品,都有SPUId,所以去走微唯宝提供的接口验证,而会员专区和商贸区的商品可能是商户自己加的,没有SPUId,所以也就不用走微唯宝的验证)
754
+            $checkGong = $productAttrValueRepository->checkGong($cartEntity->getProductId(), $cartEntity->getProductAttrUnique(), $cartEntity->getCartNum(), $uid, $storeOrderCreateRequestEntity->getAddressId());
755
+            if (isset($checkGong['code']) && $checkGong['code'] == -1) {
756
+                return app('json')->fail($checkGong['message']);
757
+            }
752 758
         }
753 759
 
754 760
         // 获取 用户收货地址
@@ -768,7 +774,9 @@ class StoreOrder extends BaseController
768 774
         $shareEntity = $shareRepository->getShareEntityByShareId($storeOrderCreateRequestEntity->getShareId());
769 775
 
770 776
 
771
-        $result = $this->repository->createOrderNew($storeOrderCreateRequestEntity, $userEntity, $cartEntity, $addressEntity, $shareEntity);
777
+
778
+
779
+        $result = $this->repository->createOrderNew($storeOrderCreateRequestEntity, $userEntity, $cartEntityList, $addressEntity, $shareEntity);
772 780
         
773 781
         
774 782
         return app('json')->success('aaa', $result);

Разница между файлами не показана из-за своего большого размера
+ 1757 - 0
app/entity/data/merchant/MerchantEntity.php


+ 32 - 32
app/entity/data/store/ProductEntity.php

@@ -158,7 +158,7 @@ class ProductEntity extends DataEntity
158 158
     }
159 159
 
160 160
     /**
161
-     * @return null
161
+     * @return mixed
162 162
      */
163 163
     public function getBrandId()
164 164
     {
@@ -166,7 +166,7 @@ class ProductEntity extends DataEntity
166 166
     }
167 167
 
168 168
     /**
169
-     * @param null $brandId
169
+     * @param mixed $brandId
170 170
      * @return ProductEntity
171 171
      */
172 172
     public function setBrandId($brandId)
@@ -264,7 +264,7 @@ class ProductEntity extends DataEntity
264 264
     }
265 265
 
266 266
     /**
267
-     * @return null
267
+     * @return mixed
268 268
      */
269 269
     public function getPrice()
270 270
     {
@@ -272,7 +272,7 @@ class ProductEntity extends DataEntity
272 272
     }
273 273
 
274 274
     /**
275
-     * @param null $price
275
+     * @param mixed $price
276 276
      * @return ProductEntity
277 277
      */
278 278
     public function setPrice($price)
@@ -282,7 +282,7 @@ class ProductEntity extends DataEntity
282 282
     }
283 283
 
284 284
     /**
285
-     * @return null
285
+     * @return mixed
286 286
      */
287 287
     public function getCost()
288 288
     {
@@ -290,7 +290,7 @@ class ProductEntity extends DataEntity
290 290
     }
291 291
 
292 292
     /**
293
-     * @param null $cost
293
+     * @param mixed $cost
294 294
      * @return ProductEntity
295 295
      */
296 296
     public function setCost($cost)
@@ -300,7 +300,7 @@ class ProductEntity extends DataEntity
300 300
     }
301 301
 
302 302
     /**
303
-     * @return null
303
+     * @return mixed
304 304
      */
305 305
     public function getOtPrice()
306 306
     {
@@ -308,7 +308,7 @@ class ProductEntity extends DataEntity
308 308
     }
309 309
 
310 310
     /**
311
-     * @param null $otPrice
311
+     * @param mixed $otPrice
312 312
      * @return ProductEntity
313 313
      */
314 314
     public function setOtPrice($otPrice)
@@ -472,7 +472,7 @@ class ProductEntity extends DataEntity
472 472
     }
473 473
 
474 474
     /**
475
-     * @return null
475
+     * @return mixed
476 476
      */
477 477
     public function getRefusal()
478 478
     {
@@ -480,7 +480,7 @@ class ProductEntity extends DataEntity
480 480
     }
481 481
 
482 482
     /**
483
-     * @param null $refusal
483
+     * @param mixed $refusal
484 484
      * @return ProductEntity
485 485
      */
486 486
     public function setRefusal($refusal)
@@ -523,7 +523,7 @@ class ProductEntity extends DataEntity
523 523
     }
524 524
 
525 525
     /**
526
-     * @return null
526
+     * @return mixed
527 527
      */
528 528
     public function getGiveCouponIds()
529 529
     {
@@ -531,7 +531,7 @@ class ProductEntity extends DataEntity
531 531
     }
532 532
 
533 533
     /**
534
-     * @param null $giveCouponIds
534
+     * @param mixed $giveCouponIds
535 535
      * @return ProductEntity
536 536
      */
537 537
     public function setGiveCouponIds($giveCouponIds)
@@ -552,7 +552,7 @@ class ProductEntity extends DataEntity
552 552
     }
553 553
 
554 554
     /**
555
-     * @return null
555
+     * @return mixed
556 556
      */
557 557
     public function getCreateTime()
558 558
     {
@@ -560,7 +560,7 @@ class ProductEntity extends DataEntity
560 560
     }
561 561
 
562 562
     /**
563
-     * @param null $createTime
563
+     * @param mixed $createTime
564 564
      * @return ProductEntity
565 565
      */
566 566
     public function setCreateTime($createTime)
@@ -570,7 +570,7 @@ class ProductEntity extends DataEntity
570 570
     }
571 571
 
572 572
     /**
573
-     * @return null
573
+     * @return mixed
574 574
      */
575 575
     public function getCareCount()
576 576
     {
@@ -578,7 +578,7 @@ class ProductEntity extends DataEntity
578 578
     }
579 579
 
580 580
     /**
581
-     * @param null $careCount
581
+     * @param mixed $careCount
582 582
      * @return ProductEntity
583 583
      */
584 584
     public function setCareCount($careCount)
@@ -632,7 +632,7 @@ class ProductEntity extends DataEntity
632 632
     }
633 633
 
634 634
     /**
635
-     * @return null
635
+     * @return mixed
636 636
      */
637 637
     public function getPension()
638 638
     {
@@ -640,7 +640,7 @@ class ProductEntity extends DataEntity
640 640
     }
641 641
 
642 642
     /**
643
-     * @param null $pension
643
+     * @param mixed $pension
644 644
      * @return ProductEntity
645 645
      */
646 646
     public function setPension($pension)
@@ -672,7 +672,7 @@ class ProductEntity extends DataEntity
672 672
     }
673 673
 
674 674
     /**
675
-     * @return null
675
+     * @return mixed
676 676
      */
677 677
     public function getDcPrice()
678 678
     {
@@ -680,7 +680,7 @@ class ProductEntity extends DataEntity
680 680
     }
681 681
 
682 682
     /**
683
-     * @param null $dcPrice
683
+     * @param mixed $dcPrice
684 684
      * @return ProductEntity
685 685
      */
686 686
     public function setDcPrice($dcPrice)
@@ -712,7 +712,7 @@ class ProductEntity extends DataEntity
712 712
     }
713 713
 
714 714
     /**
715
-     * @return null
715
+     * @return mixed
716 716
      */
717 717
     public function getSpuId()
718 718
     {
@@ -720,7 +720,7 @@ class ProductEntity extends DataEntity
720 720
     }
721 721
 
722 722
     /**
723
-     * @param null $spuId
723
+     * @param mixed $spuId
724 724
      * @return ProductEntity
725 725
      */
726 726
     public function setSpuId($spuId)
@@ -730,7 +730,7 @@ class ProductEntity extends DataEntity
730 730
     }
731 731
 
732 732
     /**
733
-     * @return null
733
+     * @return mixed
734 734
      */
735 735
     public function getCostPrice()
736 736
     {
@@ -738,7 +738,7 @@ class ProductEntity extends DataEntity
738 738
     }
739 739
 
740 740
     /**
741
-     * @param null $costPrice
741
+     * @param mixed $costPrice
742 742
      * @return ProductEntity
743 743
      */
744 744
     public function setCostPrice($costPrice)
@@ -748,7 +748,7 @@ class ProductEntity extends DataEntity
748 748
     }
749 749
 
750 750
     /**
751
-     * @return null
751
+     * @return mixed
752 752
      */
753 753
     public function getGongSkuId()
754 754
     {
@@ -756,7 +756,7 @@ class ProductEntity extends DataEntity
756 756
     }
757 757
 
758 758
     /**
759
-     * @param null $gongSkuId
759
+     * @param mixed $gongSkuId
760 760
      * @return ProductEntity
761 761
      */
762 762
     public function setGongSkuId($gongSkuId)
@@ -766,7 +766,7 @@ class ProductEntity extends DataEntity
766 766
     }
767 767
 
768 768
     /**
769
-     * @return null
769
+     * @return mixed
770 770
      */
771 771
     public function getPlateMerProfit()
772 772
     {
@@ -774,7 +774,7 @@ class ProductEntity extends DataEntity
774 774
     }
775 775
 
776 776
     /**
777
-     * @param null $plateMerProfit
777
+     * @param mixed $plateMerProfit
778 778
      * @return ProductEntity
779 779
      */
780 780
     public function setPlateMerProfit($plateMerProfit)
@@ -784,7 +784,7 @@ class ProductEntity extends DataEntity
784 784
     }
785 785
 
786 786
     /**
787
-     * @return null
787
+     * @return mixed
788 788
      */
789 789
     public function getYanglaojinScale()
790 790
     {
@@ -792,7 +792,7 @@ class ProductEntity extends DataEntity
792 792
     }
793 793
 
794 794
     /**
795
-     * @param null $yanglaojinScale
795
+     * @param mixed $yanglaojinScale
796 796
      * @return ProductEntity
797 797
      */
798 798
     public function setYanglaojinScale($yanglaojinScale)
@@ -835,7 +835,7 @@ class ProductEntity extends DataEntity
835 835
     }
836 836
 
837 837
     /**
838
-     * @return null
838
+     * @return mixed
839 839
      */
840 840
     public function getArgument()
841 841
     {
@@ -843,7 +843,7 @@ class ProductEntity extends DataEntity
843 843
     }
844 844
 
845 845
     /**
846
-     * @param null $argument
846
+     * @param mixed $argument
847 847
      * @return ProductEntity
848 848
      */
849 849
     public function setArgument($argument)

+ 199 - 0
app/entity/data/store/SeckillActiveEntity.php

@@ -0,0 +1,199 @@
1
+<?php
2
+
3
+namespace app\entity\data\store;
4
+
5
+use app\entity\data\DataEntity;
6
+
7
+class SeckillActiveEntity extends DataEntity
8
+{
9
+    public $seckillActiveId = 0;  // 活动ID
10
+    public $startDay = null;  // 开始日期
11
+    public $endDay = null;  // 结束日期
12
+    public $startTime = 0;  // 开始时间
13
+    public $endTime = 0;  // 结束时间
14
+    public $merId = 0;  // 商户ID
15
+    public $productId = 0;  // 商品ID
16
+    public $oncePayCount = 0;  // 每人每日购买数量限制
17
+    public $allPayCount = 0;  // 总购买数量限制
18
+    public $status = 0;  // 活动状态(0: 进行中, -1: 过时)
19
+
20
+    /**
21
+     * @return int
22
+     */
23
+    public function getSeckillActiveId(): int
24
+    {
25
+        return $this->seckillActiveId;
26
+    }
27
+
28
+    /**
29
+     * @param int $seckillActiveId
30
+     * @return SeckillActiveEntity
31
+     */
32
+    public function setSeckillActiveId(int $seckillActiveId): SeckillActiveEntity
33
+    {
34
+        $this->seckillActiveId = $seckillActiveId;
35
+        return $this;
36
+    }
37
+
38
+    /**
39
+     * @return mixed
40
+     */
41
+    public function getStartDay()
42
+    {
43
+        return $this->startDay;
44
+    }
45
+
46
+    /**
47
+     * @param mixed $startDay
48
+     * @return SeckillActiveEntity
49
+     */
50
+    public function setStartDay($startDay)
51
+    {
52
+        $this->startDay = $startDay;
53
+        return $this;
54
+    }
55
+
56
+    /**
57
+     * @return mixed
58
+     */
59
+    public function getEndDay()
60
+    {
61
+        return $this->endDay;
62
+    }
63
+
64
+    /**
65
+     * @param mixed $endDay
66
+     * @return SeckillActiveEntity
67
+     */
68
+    public function setEndDay($endDay)
69
+    {
70
+        $this->endDay = $endDay;
71
+        return $this;
72
+    }
73
+
74
+    /**
75
+     * @return int
76
+     */
77
+    public function getStartTime(): int
78
+    {
79
+        return $this->startTime;
80
+    }
81
+
82
+    /**
83
+     * @param int $startTime
84
+     * @return SeckillActiveEntity
85
+     */
86
+    public function setStartTime(int $startTime): SeckillActiveEntity
87
+    {
88
+        $this->startTime = $startTime;
89
+        return $this;
90
+    }
91
+
92
+    /**
93
+     * @return int
94
+     */
95
+    public function getEndTime(): int
96
+    {
97
+        return $this->endTime;
98
+    }
99
+
100
+    /**
101
+     * @param int $endTime
102
+     * @return SeckillActiveEntity
103
+     */
104
+    public function setEndTime(int $endTime): SeckillActiveEntity
105
+    {
106
+        $this->endTime = $endTime;
107
+        return $this;
108
+    }
109
+
110
+    /**
111
+     * @return int
112
+     */
113
+    public function getMerId(): int
114
+    {
115
+        return $this->merId;
116
+    }
117
+
118
+    /**
119
+     * @param int $merId
120
+     * @return SeckillActiveEntity
121
+     */
122
+    public function setMerId(int $merId): SeckillActiveEntity
123
+    {
124
+        $this->merId = $merId;
125
+        return $this;
126
+    }
127
+
128
+    /**
129
+     * @return int
130
+     */
131
+    public function getProductId(): int
132
+    {
133
+        return $this->productId;
134
+    }
135
+
136
+    /**
137
+     * @param int $productId
138
+     * @return SeckillActiveEntity
139
+     */
140
+    public function setProductId(int $productId): SeckillActiveEntity
141
+    {
142
+        $this->productId = $productId;
143
+        return $this;
144
+    }
145
+
146
+    /**
147
+     * @return int
148
+     */
149
+    public function getOncePayCount(): int
150
+    {
151
+        return $this->oncePayCount;
152
+    }
153
+
154
+    /**
155
+     * @param int $oncePayCount
156
+     * @return SeckillActiveEntity
157
+     */
158
+    public function setOncePayCount(int $oncePayCount): SeckillActiveEntity
159
+    {
160
+        $this->oncePayCount = $oncePayCount;
161
+        return $this;
162
+    }
163
+
164
+    /**
165
+     * @return int
166
+     */
167
+    public function getAllPayCount(): int
168
+    {
169
+        return $this->allPayCount;
170
+    }
171
+
172
+    /**
173
+     * @param int $allPayCount
174
+     * @return SeckillActiveEntity
175
+     */
176
+    public function setAllPayCount(int $allPayCount): SeckillActiveEntity
177
+    {
178
+        $this->allPayCount = $allPayCount;
179
+        return $this;
180
+    }
181
+
182
+    /**
183
+     * @return int
184
+     */
185
+    public function getStatus(): int
186
+    {
187
+        return $this->status;
188
+    }
189
+
190
+    /**
191
+     * @param int $status
192
+     * @return SeckillActiveEntity
193
+     */
194
+    public function setStatus(int $status): SeckillActiveEntity
195
+    {
196
+        $this->status = $status;
197
+        return $this;
198
+    }
199
+}

+ 15 - 0
app/entity/request/api/store/order/StoreOrderCreateRequestEntity.php

@@ -7,6 +7,7 @@ use app\entity\request\RequestCommonEntity;
7 7
 class StoreOrderCreateRequestEntity extends RequestCommonEntity
8 8
 {
9 9
     public $cartId = 0;
10
+    public $cartIdList = [];
10 11
     public $addressId = 0;
11 12
     public $payType = 0;
12 13
     public $mark = '';
@@ -21,10 +22,24 @@ class StoreOrderCreateRequestEntity extends RequestCommonEntity
21 22
 
22 23
     public function setCartId(int $cartId): StoreOrderCreateRequestEntity
23 24
     {
25
+        if(empty($this->getCartIdList())) {
26
+            $this->setCartIdList([$cartId]);
27
+        }
24 28
         $this->cartId = $cartId;
25 29
         return $this;
26 30
     }
27 31
 
32
+    public function getCartIdList(): array
33
+    {
34
+        return $this->cartIdList;
35
+    }
36
+
37
+    public function setCartIdList(array $cartIdList): StoreOrderCreateRequestEntity
38
+    {
39
+        $this->cartIdList = $cartIdList;
40
+        return $this;
41
+    }
42
+
28 43
     public function getAddressId(): int
29 44
     {
30 45
         return $this->addressId;

+ 2 - 0
app/validate/api/store/order/StoreOrderCreateValidate.php

@@ -12,6 +12,7 @@ class StoreOrderCreateValidate extends CommonValidate
12 12
 
13 13
     protected $rule = [
14 14
         'cart_id' => 'require|integer',
15
+        'cart_id_list' => 'array',
15 16
         'fzone_paytype' => 'require',
16 17
         'address_id' => 'require|integer|gt:0',
17 18
         'pay_type' => 'require|integer',
@@ -22,6 +23,7 @@ class StoreOrderCreateValidate extends CommonValidate
22 23
     protected $message = [
23 24
         'cart_id.require' => '缺少购物车ID参数!',
24 25
         'cart_id.integer' => '购物车ID必须是整数!',
26
+        'cart_id_list.array' => '购物车ID列表必须是一个数组!',
25 27
         'fzone_paytype.require' => '支付方式不能为空!',
26 28
         // 'fzone_paytype.string' => '支付方式必须是字符串!',
27 29
         'address_id.require' => '地址ID不能为空!',