Преглед изворни кода

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

sunxbiao пре 1 година
родитељ
комит
54696302ed

+ 12 - 0
app/common/enum/store/StoreOrderEnum.php

@@ -33,5 +33,17 @@ class StoreOrderEnum extends CommonEnum
33 33
         'NotSubmittedToWeiweiBao' => ['code' => 9, 'name' => '还未提交到微唯保']
34 34
     ];
35 35
 
36
+    // 组合支付类型 (考虑到这个区分 A或B 在此步骤毫无意义,划分混乱) A:会员专区 B:精彩生活区 C:复购区
37
+    const FZONE_PAY_TYPE = [
38
+        'B1-VR+Score' => ['code' => 'b1', 'name' => 'VR+积分'],
39
+        'B2-Cash+Score' => ['code' => 'b2', 'name' => '现金+积分'],
40
+        'B3-VR+Jingdou' => ['code' => 'b3', 'name' => 'VR+京豆'],
41
+        'B4-Cash+Jingdou' => ['code' => 'b4', 'name' => '现金+京豆'],
42
+        'B5-VR' => ['code' => 'b5', 'name' => 'VR'],
43
+        'A1-VR' => ['code' => 'a1', 'name' => 'VR'],
44
+        'A2-Cash' => ['code' => 'a2', 'name' => '现金'],
45
+        'A3-Cash+VR' => ['code' => 'a3', 'name' => '现金+VR'],
46
+        'C1-Fugou' => ['code' => 'c1', 'name' => '复购金'],
47
+    ];
36 48
 
37 49
 }

+ 39 - 15
app/common/repositories/store/order/StoreOrderRepository.php

@@ -58,6 +58,7 @@ use app\entity\data\store\StoreGroupOrderEntity;
58 58
 use app\entity\data\store\StoreOrderEntity;
59 59
 use app\entity\data\user\AddressEntity;
60 60
 use app\entity\data\user\UserEntity;
61
+use app\entity\monomer\store\FzonePayTypeEntity;
61 62
 use app\entity\request\api\store\order\StoreOrderCreateRequestEntity;
62 63
 use app\model\common\JdOrderModel;
63 64
 use app\model\common\TbOrderModel;
@@ -10690,6 +10691,8 @@ class StoreOrderRepository extends BaseRepository
10690 10691
         // 获取  商品 对应的 运费模板 de 配送区域表
10691 10692
         /** @var ShippingTemplateRegionRepository $shippingTemplateRegionRepository */
10692 10693
         $shippingTemplateRegionRepository = app()->make(ShippingTemplateRegionRepository::class);
10694
+        /** @var UserRepository $UserRepository */
10695
+        $UserRepository = app()->make(UserRepository::class);
10693 10696
 
10694 10697
         // 记录 用户 在指定商家的 优惠券
10695 10698
         $storeCouponUserEntityListByMerIdMap = [];
@@ -10713,6 +10716,8 @@ class StoreOrderRepository extends BaseRepository
10713 10716
         $totalNum = 0;
10714 10717
         // 此笔订单产生的总 邮费
10715 10718
         $totalPostage = 0.00;
10719
+        // 订单总成本价
10720
+        $totalCost = 0.00;
10716 10721
         // 订单实体表
10717 10722
         $storeOrderEntityList = [];
10718 10723
 
@@ -10828,12 +10833,17 @@ class StoreOrderRepository extends BaseRepository
10828 10833
             $price = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPrice(), 2);
10829 10834
             // 平台拿到的钱(商户分润)
10830 10835
             $serviceMoney = bcmul($cartEntity->getCartNum(), $productAttrValueEntity->getPlateMerProfit(), 2);
10836
+            // 商家获利部分(成本)
10837
+            $cost = bcsub($price, $serviceMoney, 2);
10831 10838
             // 计算养老金 注意 此步骤需要传入商品的价格,因为上述 可能对商品的价格发生了改变
10832 10839
             $yanglaojin = bcadd($yanglaojin, $productRepository->yanglaojin($cartEntity->getProductId(), $price), 2);
10840
+
10833 10841
             // 计算总价
10834 10842
             $totalPrice = bcadd($totalPrice, $price, 2);
10835 10843
             // 计算总数
10836 10844
             $totalNum = bcadd($totalNum, $cartEntity->getCartNum(), 2);
10845
+            // 计算总成本
10846
+            $totalCost = bcadd($totalCost, $cost, 2);
10837 10847
 
10838 10848
             // 如果是 普通商品 product_type 类型 0=普通产品
10839 10849
             if ($cartEntity->getProductType() == CartEnum::PRODUCT_TYPE['Ordinary']['code']) {
@@ -10951,7 +10961,7 @@ class StoreOrderRepository extends BaseRepository
10951 10961
                 ->setPayPostage($postage)
10952 10962
                 ->setPayPrice($price)
10953 10963
                 ->setMerId($cartEntity->getMerId())
10954
-                ->setCost(bcsub($price, $serviceMoney, 2))
10964
+                ->setCost($cost)
10955 10965
                 ->setPayType($storeOrderCreateRequestEntity->getPayType())
10956 10966
                 ->setShareId($storeOrderCreateRequestEntity->getShareId())
10957 10967
                 ->setShareUid($shareEntity->getUid())
@@ -10966,25 +10976,39 @@ class StoreOrderRepository extends BaseRepository
10966 10976
                 ->setDouhuomallStatus(StoreOrderEnum::DOHUOMALL_STATUS['NotSubmittedToWeiweiBao']['code'])
10967 10977
                 ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType())
10968 10978
                 ->setConPri($serviceMoney);
10979
+        }
10969 10980
 
10981
+        /** @var FzonePayTypeEntity $fzonePayTypeEntity */
10982
+        $fzonePayTypeEntity = FzonePayTypeEntity::newInstance($storeOrderCreateRequestEntity->getFzonePayType());
10983
+        if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B1-VR+Score']['code']) {
10984
+            if ($fzonePayTypeEntity->getPrice() > $userEntity->getVr() || $fzonePayTypeEntity->getOther() > $userEntity->getScore()) {
10985
+                throw new ValidateException('支付失败,VR或积分不足!');
10986
+            }
10987
+        } else if ($fzonePayTypeEntity->getType() == StoreOrderEnum::FZONE_PAY_TYPE['B2-Cash+Score']['code']) {
10970 10988
 
10989
+        }
10971 10990
 
10991
+        /** @var StoreGroupOrderEntity $storeGroupOrderEntity */
10992
+        $storeGroupOrderEntity = StoreGroupOrderEntity::newInstance();
10993
+        $storeGroupOrderEntity->setUid($userEntity->getUid())
10994
+            ->setGroupOrderSn($this->getNewOrderId() . '0')
10995
+            ->setTotalPostage($totalPostage)
10996
+            ->setTotalPrice($totalPrice)
10997
+            ->setTotalNum($totalNum)
10998
+            ->setRealName($addressEntity->getRealName())
10999
+            ->setUserPhone($addressEntity->getPhone())
11000
+            ->setUserAddress($addressEntity->getProvince() . $addressEntity->getCity() . $addressEntity->getDistrict() . $addressEntity->getDetail())
11001
+            ->setPayPrice($totalPrice)
11002
+            ->setPayPostage($totalPostage)
11003
+            ->setCost($totalCost)
11004
+            ->setPayType($storeOrderCreateRequestEntity->getPayType())
11005
+            ->setFzonePaytype($storeOrderCreateRequestEntity->getFzonePayType());
10972 11006
 
10973
-            // // 修改优惠券状态
10974
-            // // $storeCouponUserRepository->updates([], []);
10975
-            // /** @var StoreGroupOrderEntity $storeGroupOrderEntity */
10976
-            // $storeGroupOrderEntity = StoreGroupOrderEntity::newInstance();
10977
-            // $storeGroupOrderEntity->setUid($cartEntity->getUid())
10978
-            //     ->setGroupOrderSn($this->getNewOrderId() . '0')
10979
-            //     ->setTotalPostage($postage)
10980
-            //     ->setTotalPrice($price)
10981
-            //     ->setTotalNum($cartEntity->getCartNum())
10982
-            //     ->setRealName($addressEntity->getRealName())
10983
-            //     ->setUserPhone($addressEntity->getPhone())
10984
-            //     ->setUserAddress($addressEntity->getProvince() . $addressEntity->getCity() . $addressEntity->getDistrict() . $addressEntity->getDetail())
10985
-            //     ->setPayPrice()
11007
+        // TODO 保存后 将保存后的ID 存入到订单表中
11008
+        // foreach ($storeOrderEntityList as $storeOrderEntity) {
11009
+        //     $storeOrderEntity->setGroupOrderId();
11010
+        // }
10986 11011
 
10987
-        }
10988 11012
 
10989 11013
 
10990 11014
         return [];

+ 12 - 2
app/entity/data/store/StoreGroupOrderEntity.php

@@ -511,11 +511,21 @@ class StoreGroupOrderEntity extends DataEntity
511 511
     }
512 512
 
513 513
     /**
514
-     * @param string $fzonePaytype
514
+     * @param mixed $fzonePaytype
515 515
      * @return StoreGroupOrderEntity
516 516
      */
517
-    public function setFzonePaytype(string $fzonePaytype): StoreGroupOrderEntity
517
+    public function setFzonePaytype($fzonePaytype): StoreGroupOrderEntity
518 518
     {
519
+        if (!is_string($fzonePaytype)) {
520
+            $fzonePaytypePre = $fzonePaytype;
521
+            $fzonePaytype = '';
522
+
523
+            if (is_array($fzonePaytypePre)) {
524
+                $fzonePaytype = json_encode($fzonePaytypePre);
525
+            }
526
+
527
+            unset($fzonePaytypePre);
528
+        }
519 529
         $this->fzonePaytype = $fzonePaytype;
520 530
         return $this;
521 531
     }

+ 10 - 0
app/entity/monomer/MonomerEntity.php

@@ -0,0 +1,10 @@
1
+<?php
2
+
3
+namespace app\entity\monomer;
4
+
5
+use app\entity\CommonEntity;
6
+
7
+class MonomerEntity extends CommonEntity
8
+{
9
+
10
+}

+ 104 - 0
app/entity/monomer/store/FzonePayTypeEntity.php

@@ -0,0 +1,104 @@
1
+<?php
2
+
3
+namespace app\entity\monomer\store;
4
+
5
+use app\entity\data\DataEntity;
6
+
7
+class FzonePayTypeEntity extends DataEntity
8
+{
9
+    public $type = '';
10
+    public $price = 0.00;
11
+    public $other = 0.00;
12
+    public $note = '';
13
+    public $checked = false;
14
+
15
+    /**
16
+     * @return string
17
+     */
18
+    public function getType(): string
19
+    {
20
+        return $this->type;
21
+    }
22
+
23
+    /**
24
+     * @param string $type
25
+     * @return FzonePayTypeEntity
26
+     */
27
+    public function setType(string $type): FzonePayTypeEntity
28
+    {
29
+        $this->type = $type;
30
+        return $this;
31
+    }
32
+
33
+    /**
34
+     * @return float
35
+     */
36
+    public function getPrice(): float
37
+    {
38
+        return $this->price;
39
+    }
40
+
41
+    /**
42
+     * @param float $price
43
+     * @return FzonePayTypeEntity
44
+     */
45
+    public function setPrice(float $price): FzonePayTypeEntity
46
+    {
47
+        $this->price = $price;
48
+        return $this;
49
+    }
50
+
51
+    /**
52
+     * @return float
53
+     */
54
+    public function getOther(): float
55
+    {
56
+        return $this->other;
57
+    }
58
+
59
+    /**
60
+     * @param float $other
61
+     * @return FzonePayTypeEntity
62
+     */
63
+    public function setOther(float $other): FzonePayTypeEntity
64
+    {
65
+        $this->other = $other;
66
+        return $this;
67
+    }
68
+
69
+    /**
70
+     * @return string
71
+     */
72
+    public function getNote(): string
73
+    {
74
+        return $this->note;
75
+    }
76
+
77
+    /**
78
+     * @param string $note
79
+     * @return FzonePayTypeEntity
80
+     */
81
+    public function setNote(string $note): FzonePayTypeEntity
82
+    {
83
+        $this->note = $note;
84
+        return $this;
85
+    }
86
+
87
+    /**
88
+     * @return bool
89
+     */
90
+    public function isChecked(): bool
91
+    {
92
+        return $this->checked;
93
+    }
94
+
95
+    /**
96
+     * @param bool $checked
97
+     * @return FzonePayTypeEntity
98
+     */
99
+    public function setChecked(bool $checked): FzonePayTypeEntity
100
+    {
101
+        $this->checked = $checked;
102
+        return $this;
103
+    }
104
+}