Browse Source

细节优化

萤火科技 1 năm trước cách đây
mục cha
commit
48a8359fd4

+ 1 - 1
app/api/model/Goods.php

@@ -178,7 +178,7 @@ class Goods extends GoodsModel
         if (empty($goodsInfo) || $goodsInfo['is_delete']) {
             throwError('很抱歉,商品信息不存在');
         }
-        // 判断商品状态(上架)
+        // 判断商品状态 (上架)
         if ($verifyStatus && $goodsInfo['status'] == GoodsStatusEnum::OFF_SALE) {
             throwError('很抱歉,当前商品已下架');
         }

+ 1 - 1
app/api/model/article/Category.php

@@ -33,7 +33,7 @@ class Category extends CategoryModel
     ];
 
     /**
-     * 获取分类列表
+     * 获取显示的分类列表
      * @return \think\Collection
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException

+ 1 - 1
app/api/service/Order.php

@@ -78,7 +78,7 @@ class Order extends OrderService
      * 获取某商品的购买件数
      * @param int $userId 用户ID
      * @param int $goodsId 商品ID
-     * @param int $orderSource
+     * @param int $orderSource 商品来源
      * @return int
      */
     public static function getGoodsBuyNum(int $userId, int $goodsId, int $orderSource): int

+ 7 - 4
app/api/service/order/Checkout.php

@@ -66,9 +66,12 @@ class Checkout extends BaseService
      * @var array
      */
     private array $checkoutRule = [
-        'isUserGrade' => true,          // 会员等级折扣
-        'isCoupon' => true,             // 优惠券折扣
-        'isUsePoints' => true,          // 积分抵扣
+        'isUserGrade' => true,            // 会员等级折扣
+        'isCoupon' => true,               // 优惠券折扣
+        'isUsePoints' => true,            // 积分抵扣
+        'isUseFullDiscount' => true,      // 满额立减
+        'isUseFullFree' => true,          // 满额包邮
+        'isDealer' => true,               // 开启分销
     ];
 
     /**
@@ -127,7 +130,7 @@ class Checkout extends BaseService
      */
     public function setCheckoutRule($data): Checkout
     {
-        $this->checkoutRule = array_merge($this->checkoutRule, $data);
+        $this->checkoutRule = \array_merge($this->checkoutRule, $data);
         return $this;
     }
 

+ 39 - 0
app/api/service/order/source/checkout/Basics.php

@@ -14,6 +14,7 @@ namespace app\api\service\order\source\checkout;
 
 use app\common\service\BaseService;
 use app\api\model\User as UserModel;
+use app\api\service\Order as OrderService;
 
 /**
  * 订单结算台扩展基类
@@ -46,4 +47,42 @@ abstract class Basics extends BaseService
      * @return mixed
      */
     abstract public function validateGoodsList();
+
+
+    /**
+     * 验证商品限购
+     * @param int $orderSource 商品来源
+     * @return bool
+     */
+    public function validateRestrict(int $orderSource): bool
+    {
+        foreach ($this->goodsList as $goods) {
+            // 不限购
+            if (!$goods['is_restrict']) return true;
+            // 拼团商品单次限购数量
+            if ($goods['total_num'] > $goods['restrict_single']) {
+                $this->error = "很抱歉,该商品限购{$goods['restrict_single']}件,请修改购买数量";
+                return false;
+            }
+            // 获取用户已下单的件数(未取消 订单来源)
+            $alreadyBuyNum = OrderService::getGoodsBuyNum($this->user['user_id'], $goods['goods_id'], $orderSource);
+            // 情况1: 已购买0件, 实际想购买5件
+            if ($alreadyBuyNum == 0 && $goods['total_num'] > $goods['restrict_total']) {
+                $this->error = "很抱歉,该商品限购{$goods['restrict_total']}件,请修改购买数量";
+                return false;
+            }
+            // 情况2: 已购买3件, 实际想购买1件
+            if ($alreadyBuyNum >= $goods['restrict_total']) {
+                $this->error = "很抱歉,该商品限购{$goods['restrict_total']}件,您当前已下单{$alreadyBuyNum}件,无法购买";
+                return false;
+            }
+            // 情况3: 已购买2件, 实际想购买2件
+            if (($alreadyBuyNum + $goods['total_num']) > $goods['restrict_total']) {
+                $diffNum = ($alreadyBuyNum + $goods['total_num']) - $goods['restrict_total'];
+                $this->error = "很抱歉,该商品限购{$goods['restrict_total']}件,您最多能再购买{$diffNum}件";
+                return false;
+            }
+        }
+        return true;
+    }
 }

+ 3 - 39
app/api/service/order/source/checkout/Main.php

@@ -34,11 +34,11 @@ class Main extends Basics
             return false;
         }
         // 判断商品库存
-        if (!$this->validateGoodsSeckillStock()) {
+        if (!$this->validateGoodsStock()) {
             return false;
         }
         // 验证商品限购
-        if (!$this->validateLimitNum()) {
+        if (!$this->validateRestrict(OrderSourceEnum::MAIN)) {
             return false;
         }
         return true;
@@ -63,7 +63,7 @@ class Main extends Basics
      * 判断商品库存数量
      * @return bool
      */
-    private function validateGoodsSeckillStock(): bool
+    private function validateGoodsStock(): bool
     {
         foreach ($this->goodsList as $goods) {
             if ($goods['total_num'] > $goods['skuInfo']['stock_num']) {
@@ -73,40 +73,4 @@ class Main extends Basics
         }
         return true;
     }
-
-    /**
-     * 验证商品限购
-     * @return bool
-     */
-    public function validateLimitNum(): bool
-    {
-        foreach ($this->goodsList as $goods) {
-            // 不限购
-            if (!$goods['is_restrict']) return true;
-            // 商品单次限购数量
-            if ($goods['total_num'] > $goods['restrict_single']) {
-                $this->error = "很抱歉,商品 [{$goods['goods_name']}] 限购{$goods['restrict_single']}件,请修改购买数量";
-                return false;
-            }
-            // 获取用户已下单的件数(未取消 订单来源)
-            $alreadyBuyNum = OrderService::getGoodsBuyNum($this->user['user_id'], $goods['goods_id'], OrderSourceEnum::MAIN);
-            // 情况1: 已购买0件, 实际想购买5件
-            if ($alreadyBuyNum == 0 && $goods['total_num'] > $goods['restrict_total']) {
-                $this->error = "很抱歉,商品 [{$goods['goods_name']}] 限购{$goods['restrict_total']}件,请修改购买数量";
-                return false;
-            }
-            // 情况2: 已购买3件, 实际想购买1件
-            if ($alreadyBuyNum >= $goods['restrict_total']) {
-                $this->error = "很抱歉,商品 [{$goods['goods_name']}] 限购{$goods['restrict_total']}件,您已购买过{$alreadyBuyNum}件";
-                return false;
-            }
-            // 情况3: 已购买2件, 实际想购买2件
-            if (($alreadyBuyNum + $goods['total_num']) > $goods['restrict_total']) {
-                $diffNum = ($alreadyBuyNum + $goods['total_num']) - $goods['restrict_total'];
-                $this->error = "很抱歉,商品 [{$goods['goods_name']}] 限购{$goods['restrict_total']}件,您最多能再购买{$diffNum}件";
-                return false;
-            }
-        }
-        return true;
-    }
 }

+ 1 - 1
app/common/model/Goods.php

@@ -65,7 +65,7 @@ class Goods extends BaseModel
      */
     public function getGoodsSalesAttr($value, $data)
     {
-        return $data['sales_initial'] + $data['sales_actual'];
+        return is_null($value) ? $data['sales_initial'] + $data['sales_actual'] : $value;
     }
 
     /**

+ 4 - 4
app/common/model/store/Setting.php

@@ -324,10 +324,10 @@ class Setting extends BaseModel
                         'max_money_ratio' => '10',            // 最高可抵扣订单额百分比
                     ],
                     // 积分说明
-                    'describe' => "a) 积分不可兑现、不可转让,仅可在本平台使用;\n" .
-                        "b) 您在本平台参加特定活动也可使用积分,详细使用规则以具体活动时的规则为准;\n" .
-                        "c) 积分的数值精确到个位(小数点后全部舍弃,不进行四舍五入)\n" .
-                        "d) 买家在完成该笔交易(订单状态为“已签收”)后才能得到此笔交易的相应积分,如购买商品参加店铺其他优惠,则优惠的金额部分不享受积分获取;",
+                    'describe' => "1. 积分不可兑现、不可转让, 仅可在本平台使用。\n" .
+                        "2. 您在本平台参加特定活动也可使用积分, 详细使用规则以具体活动时的规则为准。\n" .
+                        "3. 积分的数值精确到个位(小数点后全部舍弃, 不进行四舍五入)。\n" .
+                        "4. 每次购物赠送的积分将在订单完成后(包括退换货流程完成)到账。\n",
                 ],
             ],
             // 店铺页面风格设置

+ 2 - 1
app/common/service/Goods.php

@@ -33,7 +33,8 @@ class Goods extends BaseService
      */
     public static function setGoodsData($data, bool $isMultiple = true, array $hidden = [], string $goodsIndex = 'goods_id')
     {
-        if (!$isMultiple) $dataSource = [$data]; else $dataSource = $data;
+        // 数据来源
+        $dataSource = !$isMultiple ? [$data] : $data;
         // 获取商品列表
         $model = new GoodsModel;
         $goodsData = $model->getListByIds(helper::getArrayColumn($dataSource, $goodsIndex));

+ 2 - 2
app/store/model/User.php

@@ -185,7 +185,7 @@ class User extends UserModel
             BalanceLogModel::add(SceneEnum::ADMIN, [
                 'user_id' => $this['user_id'],
                 'money' => (float)$diffMoney,
-                'remark' => $data['remark'],
+                'remark' => $data['remark'] ?? '',
             ], [$storeUserName]);
         });
         return true;
@@ -245,7 +245,7 @@ class User extends UserModel
                     'old_grade_id' => $oldGradeId,
                     'new_grade_id' => $data['grade_id'],
                     'change_type' => ChangeTypeEnum::ADMIN_USER,
-                    'remark' => $data['remark']
+                    'remark' => $data['remark']?? ''
                 ]);
             }
             return $status !== false;

+ 2 - 4
app/store/model/article/Category.php

@@ -29,7 +29,6 @@ class Category extends CategoryModel
      */
     public function add(array $data): bool
     {
-        // 保存记录
         $data['store_id'] = self::$storeId;
         return $this->save($data);
     }
@@ -41,12 +40,11 @@ class Category extends CategoryModel
      */
     public function edit(array $data): bool
     {
-        // 保存记录
         return $this->save($data);
     }
 
     /**
-     * 删除商品分类
+     * 删除文章分类
      * @param int $categoryId
      * @return bool
      */
@@ -55,7 +53,7 @@ class Category extends CategoryModel
         // 判断是否存在文章
         $articleCount = ArticleModel::getArticleTotal(['category_id' => $categoryId]);
         if ($articleCount > 0) {
-            $this->error = '该分类下存在' . $articleCount . '个文章,不允许删除';
+            $this->error = "该分类下存在{$articleCount}个文章,不允许删除";
             return false;
         }
         // 删除记录