Procházet zdrojové kódy

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

sunxbiao před 1 rokem
rodič
revize
56d1dc25a5

+ 25 - 0
app/common/dao/store/coupon/StoreCouponProductDao.php

@@ -14,6 +14,7 @@ namespace app\common\dao\store\coupon;
14 14
 use app\common\dao\BaseDao;
15 15
 use app\common\model\BaseModel;
16 16
 use app\common\model\store\coupon\StoreCouponProduct;
17
+use app\entity\data\store\StoreCouponProductEntity;
17 18
 use think\Collection;
18 19
 use think\db\exception\DataNotFoundException;
19 20
 use think\db\exception\DbException;
@@ -71,4 +72,28 @@ class StoreCouponProductDao extends BaseDao
71 72
     {
72 73
         return StoreCouponProduct::getDB()->whereIn('product_id', $productId)->column('coupon_id');
73 74
     }
75
+
76
+    /**
77
+     * @param int $couponId
78
+     * @return StoreCouponProductEntity[]
79
+     */
80
+    public function getStoreCouponProductEntityListByCouponId(int $couponId): array
81
+    {
82
+        $entityList = [];
83
+        try {
84
+            /** @var StoreCouponProduct $model */
85
+            $model = $this->getModel();
86
+            $dataListRes = $model::getDB()
87
+                ->where('coupon_id', '=', $couponId)
88
+                ->select()
89
+                ->toArray();
90
+            if (!empty($dataListRes)) {
91
+                foreach ($dataListRes as $data) {
92
+                    $entityList[] = StoreCouponProductEntity::newInstance($data);
93
+                }
94
+            }
95
+        } catch (\Exception $e) {
96
+        }
97
+        return $entityList;
98
+    }
74 99
 }

+ 10 - 0
app/common/repositories/store/coupon/StoreCouponProductRepository.php

@@ -13,6 +13,7 @@ namespace app\common\repositories\store\coupon;
13 13
 
14 14
 use app\common\dao\store\coupon\StoreCouponProductDao;
15 15
 use app\common\repositories\BaseRepository;
16
+use app\entity\data\store\StoreCouponProductEntity;
16 17
 
17 18
 /**
18 19
  * Class StoreCouponProductRepository
@@ -32,4 +33,13 @@ class StoreCouponProductRepository extends BaseRepository
32 33
     {
33 34
         $this->dao = $dao;
34 35
     }
36
+
37
+    /**
38
+     * @param int $couponId
39
+     * @return StoreCouponProductEntity[]
40
+     */
41
+    public function getStoreCouponProductEntityListByCouponId(int $couponId): array
42
+    {
43
+        return $this->dao->getStoreCouponProductEntityListByCouponId($couponId);
44
+    }
35 45
 }

+ 34 - 2
app/common/repositories/store/order/StoreOrderRepository.php

@@ -11594,6 +11594,8 @@ class StoreOrderRepository extends BaseRepository
11594 11594
         $yanglaojin = 0.00;
11595 11595
         $totalPrice = 0.00;
11596 11596
         $totalNum = 0;
11597
+        // 记录每类商品 在此笔订单中的金额
11598
+        // 商品 => 此笔订单内此商品总价
11597 11599
         $productPriceMap = [];
11598 11600
         $validTotalPrice = 0.00;
11599 11601
         $productCart = [];
@@ -11649,7 +11651,7 @@ class StoreOrderRepository extends BaseRepository
11649 11651
             // 计算养老金
11650 11652
             $yanglaojin = bcadd($yanglaojin, $productRepository->yanglaojin($cartEntity->getProductId()), 2);
11651 11653
 
11652
-            // 验证是否是秒杀产品
11654
+            // 验证是否是秒杀产品 如果是秒杀产品,并且设置了 大仓会员价 则将大仓会员价 设置为 商品价格
11653 11655
             if ($productEntity->getSeckill() == ProductEnum::SECKILL['Yes']['code'] && !is_null($productEntity->getDcPrice()) && $productEntity->getDcPrice() > 0.00) {
11654 11656
                 // 获取 在活动期间内的 秒杀活动记录
11655 11657
                 $seckillEntity = $seckillRepository->getSeckillEntityByProductId($cartEntity->getProductId());
@@ -11663,6 +11665,7 @@ class StoreOrderRepository extends BaseRepository
11663 11665
             // type => '商品类型:1:普通商品。2:爆款商品。3:消费积分商品 。5:会员专享商品(城中大仓)6:每日免费领商品 7:商户特殊商品 8:共富会员商品 9:共富高级会员商品 10:高级会员商品 11村代理商品(废弃) 12镇代理商品(废弃) 13县代理商品(废弃)  14- 合伙人商品 15 股权商品 16合伙人+股权商品',
11664 11666
             // ProductType => 0.普通商品 1.秒杀商品
11665 11667
             $productEntity->setProductType($productEntity->getType());
11668
+
11666 11669
             // 计算单价
11667 11670
             $price = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPrice(), 2);
11668 11671
             // 计算总价
@@ -11776,14 +11779,43 @@ class StoreOrderRepository extends BaseRepository
11776 11779
 
11777 11780
 
11778 11781
             $merchantMap[$cartEntity->getMerId()]['merchantEntity'] = $merchantEntity;
11782
+            $merchantMap[$cartEntity->getMerId()]['productIdListByCart'][] = $cartEntity->getProductId();
11779 11783
         }
11780 11784
 
11781 11785
 
11782 11786
         foreach ($merchantMap as $merId => $item) {
11787
+            // 当前商户的实体信息
11783 11788
             /** @var MerchantEntity $merchantEntity */
11784 11789
             $merchantEntity = $item['merchantEntity'];
11785
-            // 计算优惠金额
11790
+            // 当前订单中 从当前商户中选择的商品列表
11791
+            $productIdListByCart = $item['productIdListByCart'];
11792
+
11793
+            // 查询 当前用户 在当前 店铺的 优惠券
11786 11794
             $storeCouponUserEntityList = $storeCouponUserRepository->getValidStoreCouponUserEntityListByMerIdAndUid($merchantEntity->getMerId(), $userEntity->getUid());
11795
+            foreach ($storeCouponUserEntityList as $storeCouponUserEntity) {
11796
+                // 如果不能明确当前优惠券的 获取方式 ,则忽略当前的优惠券的有效性
11797
+                if (empty($storeCouponUserEntity->getType())) {
11798
+                    continue;
11799
+                }
11800
+                // 优惠卷关联商品 辅助表
11801
+                $storeCouponProductEntityList = $storeCouponProductRepository->getStoreCouponProductEntityListByCouponId($storeCouponUserEntity->getCouponId());
11802
+
11803
+                foreach ($storeCouponProductEntityList as $storeCouponProductEntity) {
11804
+                    // 如果当前 优惠券 所关联的 此 商品 不在当前购买的商品列表中,则说明此条关联记录 无用
11805
+                    if (!in_array($storeCouponProductEntity->getProductId(), $productIdListByCart)) {
11806
+                        continue;
11807
+                    }
11808
+
11809
+                }
11810
+
11811
+                // 获取 当前消费者 有没有 从该商家发型的优惠券里 进行领取
11812
+                $couponCountByMerIdUid = $storeCouponRepository->validMerCouponExists($merchantEntity->getMerId(), $userEntity->getUid());
11813
+                if ($couponCountByMerIdUid > 0) {
11814
+
11815
+                }
11816
+
11817
+
11818
+            }
11787 11819
 
11788 11820
         }
11789 11821
 

+ 66 - 0
app/entity/data/store/StoreCouponProductEntity.php

@@ -0,0 +1,66 @@
1
+<?php
2
+
3
+namespace app\entity\data\store;
4
+
5
+use app\entity\data\DataEntity;
6
+
7
+class StoreCouponProductEntity extends DataEntity
8
+{
9
+    public $productId = 0;  // 产品id
10
+    public $couponId = 0;   // 优惠卷id
11
+    public $createTime = null;  // 添加时间
12
+
13
+    /**
14
+     * @return int
15
+     */
16
+    public function getProductId(): int
17
+    {
18
+        return $this->productId;
19
+    }
20
+
21
+    /**
22
+     * @param int $productId
23
+     * @return StoreCouponProductEntity
24
+     */
25
+    public function setProductId(int $productId): StoreCouponProductEntity
26
+    {
27
+        $this->productId = $productId;
28
+        return $this;
29
+    }
30
+
31
+    /**
32
+     * @return int
33
+     */
34
+    public function getCouponId(): int
35
+    {
36
+        return $this->couponId;
37
+    }
38
+
39
+    /**
40
+     * @param int $couponId
41
+     * @return StoreCouponProductEntity
42
+     */
43
+    public function setCouponId(int $couponId): StoreCouponProductEntity
44
+    {
45
+        $this->couponId = $couponId;
46
+        return $this;
47
+    }
48
+
49
+    /**
50
+     * @return null
51
+     */
52
+    public function getCreateTime()
53
+    {
54
+        return $this->createTime;
55
+    }
56
+
57
+    /**
58
+     * @param null $createTime
59
+     * @return StoreCouponProductEntity
60
+     */
61
+    public function setCreateTime($createTime)
62
+    {
63
+        $this->createTime = $createTime;
64
+        return $this;
65
+    }
66
+}