Răsfoiți Sursa

新增:进行中的售后单数量

Yahoo 4 ani în urmă
părinte
comite
83c3d36b72
2 a modificat fișierele cu 23 adăugiri și 9 ștergeri
  1. 5 4
      app/api/model/Order.php
  2. 18 5
      app/api/model/OrderRefund.php

+ 5 - 4
app/api/model/Order.php

@@ -12,7 +12,7 @@ declare (strict_types=1);
 
 namespace app\api\model;
 
-use app\api\model\{Goods as GoodsModel, Setting as SettingModel};
+use app\api\model\{Goods as GoodsModel, OrderRefund as OrderRefundModel, Setting as SettingModel};
 use app\api\service\{User as UserService, Goods as GoodsService, Payment as PaymentService};
 use app\api\service\order\{PaySuccess as OrderPaySuccesService, source\Factory as OrderSourceFactory};
 use app\common\model\Order as OrderModel;
@@ -353,9 +353,10 @@ class Order extends OrderModel
     public function getTodoCounts(): array
     {
         return [
-            'payment' => $this->getCount('payment'),
-            'delivery' => $this->getCount('delivery'),
-            'received' => $this->getCount('received')
+            'payment' => $this->getCount('payment'),    // 待付款的订单
+            'delivery' => $this->getCount('delivery'),  // 待发货的订单
+            'received' => $this->getCount('received'),  // 待收货的订单
+            'refund' => OrderRefundModel::getCountByUnderway(),  // 进行中的售后单
         ];
     }
 

+ 18 - 5
app/api/model/OrderRefund.php

@@ -18,7 +18,7 @@ use app\common\model\OrderRefund as OrderRefundModel;
 use app\common\enum\order\refund\RefundType as RefundTypeEnum;
 use app\common\enum\order\refund\AuditStatus as AuditStatusEnum;
 use app\common\enum\order\refund\RefundStatus as RefundStatusEnum;
-use app\common\exception\BaseException;
+use cores\exception\BaseException;
 
 /**
  * 售后单模型
@@ -50,7 +50,7 @@ class OrderRefund extends OrderRefundModel
      * @param $data
      * @return string
      */
-    public function getStateTextAttr($value, $data)
+    public function getStateTextAttr($value, $data): string
     {
         // 已完成
         if ($data['status'] == RefundStatusEnum::COMPLETED) {
@@ -84,8 +84,9 @@ class OrderRefund extends OrderRefundModel
      * @return \think\Paginator
      * @throws \app\common\exception\BaseException
      * @throws \think\db\exception\DbException
+     * @throws BaseException
      */
-    public function getList(int $state = -1)
+    public function getList(int $state = -1): \think\Paginator
     {
         // 检索查询条件
         $filter = [];
@@ -108,7 +109,7 @@ class OrderRefund extends OrderRefundModel
      * @return static|null
      * @throws BaseException
      */
-    public static function getDetail(int $orderRefundId, $isWith = false)
+    public static function getDetail(int $orderRefundId, bool $isWith = false): ?OrderRefund
     {
         // 关联查询
         $with = $isWith ? ['orderGoods' => ['image'], 'images.file', 'address'] : [];
@@ -121,6 +122,19 @@ class OrderRefund extends OrderRefundModel
         return $detail;
     }
 
+    /**
+     * 获取当前用户的售后单数量(进行中的)
+     * @return int
+     * @throws BaseException
+     */
+    public static function getCountByUnderway(): int
+    {
+        $userId = UserService::getCurrentLoginUserId();
+        return (new static)->where('user_id', '=', $userId)
+            ->where('status', '=', 0)
+            ->count();
+    }
+
     /**
      * 订单商品详情
      * @param int $orderGoodsId 订单商品ID
@@ -217,5 +231,4 @@ class OrderRefund extends OrderRefundModel
         }
         return !empty($data) && (new OrderRefundImage)->addAll($data) !== false;
     }
-
 }