Yahoo 4 lat temu
rodzic
commit
d2b7413cf4

+ 20 - 20
app/api/controller/Order.php

@@ -16,7 +16,8 @@ use app\api\model\Order as OrderModel;
 use app\api\model\Setting as SettingModel;
 use app\store\model\Express as ExpressModel;
 use app\common\enum\order\PayType as OrderPayTypeEnum;
-use app\common\exception\BaseException;
+use cores\exception\BaseException;
+use think\response\Json;
 
 /**
  * 我的订单控制器
@@ -27,10 +28,10 @@ class Order extends Controller
 {
     /**
      * 获取当前用户待处理的订单数量
-     * @return array|\think\response\Json
+     * @return Json
      * @throws BaseException
      */
-    public function todoCounts()
+    public function todoCounts(): Json
     {
         $model = new OrderModel;
         $counts = $model->getTodoCounts();
@@ -40,11 +41,11 @@ class Order extends Controller
     /**
      * 我的订单列表
      * @param string $dataType 订单类型 (all全部 payment待付款 received待发货 deliver待收货 comment待评价)
-     * @return array|\think\response\Json
-     * @throws BaseException
+     * @return Json
      * @throws \think\db\exception\DbException
+     * @throws BaseException
      */
-    public function list(string $dataType)
+    public function list(string $dataType): Json
     {
         $model = new OrderModel;
         $list = $model->getList($dataType);
@@ -54,13 +55,13 @@ class Order extends Controller
     /**
      * 订单详情信息
      * @param int $orderId 订单ID
-     * @return array|\think\response\Json
-     * @throws BaseException
+     * @return Json
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
+     * @throws BaseException
      */
-    public function detail(int $orderId)
+    public function detail(int $orderId): Json
     {
         // 订单详情
         $model = OrderModel::getUserOrderDetail($orderId);
@@ -76,13 +77,13 @@ class Order extends Controller
     /**
      * 获取物流信息
      * @param int $orderId 订单ID
-     * @return array|\think\response\Json
-     * @throws BaseException
+     * @return Json
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
+     * @throws BaseException
      */
-    public function express(int $orderId)
+    public function express(int $orderId): Json
     {
         // 订单信息
         $order = OrderModel::getDetail($orderId);
@@ -101,10 +102,10 @@ class Order extends Controller
     /**
      * 取消订单
      * @param int $orderId
-     * @return array|\think\response\Json
+     * @return Json
      * @throws BaseException
      */
-    public function cancel(int $orderId)
+    public function cancel(int $orderId): Json
     {
         $model = OrderModel::getDetail($orderId);
         if ($model->cancel()) {
@@ -116,10 +117,10 @@ class Order extends Controller
     /**
      * 确认收货
      * @param int $orderId
-     * @return array|\think\response\Json
+     * @return Json
      * @throws BaseException
      */
-    public function receipt(int $orderId)
+    public function receipt(int $orderId): Json
     {
         $model = OrderModel::getDetail($orderId);
         if ($model->receipt()) {
@@ -132,13 +133,13 @@ class Order extends Controller
      * 立即支付
      * @param int $orderId 订单ID
      * @param int $payType 支付方式
-     * @return array|\think\response\Json
-     * @throws BaseException
+     * @return Json
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
+     * @throws BaseException
      */
-    public function pay(int $orderId, int $payType = OrderPayTypeEnum::WECHAT)
+    public function pay(int $orderId, int $payType = OrderPayTypeEnum::WECHAT): Json
     {
         // 获取订单详情
         $model = OrderModel::getUserOrderDetail($orderId);
@@ -155,5 +156,4 @@ class Order extends Controller
             'payment' => $payment               // 微信支付参数
         ]);
     }
-
 }

+ 15 - 18
app/api/model/Order.php

@@ -12,24 +12,21 @@ declare (strict_types=1);
 
 namespace app\api\model;
 
-use app\api\model\Goods as GoodsModel;
-use app\api\model\Setting as SettingModel;
-use app\api\model\GoodsSku as GoodsSkuModel;
-use app\api\service\User as UserService;
-use app\api\service\Payment as PaymentService;
-use app\api\service\order\PaySuccess as OrderPaySuccesService;
-use app\api\service\order\source\Factory as OrderSourceFactory;
+use app\api\model\{Goods as GoodsModel, 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;
-use app\common\service\Order as OrderService;
-use app\common\service\order\Complete as OrderCompleteService;
-use app\common\enum\Setting as SettingEnum;
-use app\common\enum\OrderType as OrderTypeEnum;
-use app\common\enum\order\PayType as OrderPayTypeEnum;
-use app\common\enum\order\PayStatus as PayStatusEnum;
-use app\common\enum\order\OrderStatus as OrderStatusEnum;
-use app\common\enum\order\DeliveryType as DeliveryTypeEnum;
-use app\common\enum\order\ReceiptStatus as ReceiptStatusEnum;
-use app\common\enum\order\DeliveryStatus as DeliveryStatusEnum;
+use app\common\service\{Order as OrderService, order\Complete as OrderCompleteService};
+use app\common\enum\{
+    Setting as SettingEnum,
+    OrderType as OrderTypeEnum,
+    order\PayType as OrderPayTypeEnum,
+    order\PayStatus as PayStatusEnum,
+    order\OrderStatus as OrderStatusEnum,
+    order\DeliveryType as DeliveryTypeEnum,
+    order\ReceiptStatus as ReceiptStatusEnum,
+    order\DeliveryStatus as DeliveryStatusEnum
+};
 use app\common\library\helper;
 use cores\exception\BaseException;
 
@@ -170,8 +167,8 @@ class Order extends OrderModel
      * 获取用户订单列表
      * @param string $type 订单类型 (all全部 payment待付款 received待发货 deliver待收货 comment待评价)
      * @return \think\Paginator
-     * @throws BaseException
      * @throws \think\db\exception\DbException
+     * @throws BaseException
      */
     public function getList(string $type = 'all'): \think\Paginator
     {

+ 17 - 15
app/api/model/UserCoupon.php

@@ -33,7 +33,7 @@ class UserCoupon extends UserCouponModel
      * @return \think\Paginator
      * @throws \think\db\exception\DbException
      */
-    public function getList(int $userId, array $param)
+    public function getList(int $userId, array $param): \think\Paginator
     {
         $filter = $this->getFilter($param);
         return $this->where($filter)
@@ -44,9 +44,9 @@ class UserCoupon extends UserCouponModel
     /**
      * 检索查询条件
      * @param array $param
-     * @return array|mixed
+     * @return array
      */
-    private function getFilter(array $param = [])
+    private function getFilter(array $param = []): array
     {
         // 设置默认查询参数
         $params = $this->setQueryDefaultValue($param, [
@@ -80,20 +80,22 @@ class UserCoupon extends UserCouponModel
      * @param int $userId
      * @return int
      */
-    public function getCount(int $userId)
+    public function getCount(int $userId): int
     {
         return $this->where('user_id', '=', $userId)
             ->where('is_use', '=', 0)
             ->where('is_expire', '=', 0)
+            ->where('start_time', '<=', time())
+            ->where('end_time', '>', time())
             ->count();
     }
 
     /**
      * 获取用户优惠券ID集
-     * @param $userId
+     * @param int $userId
      * @return array
      */
-    public function getUserCouponIds(int $userId)
+    public function getUserCouponIds(int $userId): array
     {
         return $this->where('user_id', '=', $userId)->column('coupon_id');
     }
@@ -104,7 +106,7 @@ class UserCoupon extends UserCouponModel
      * @return bool
      * @throws BaseException
      */
-    public function receive(int $couponId)
+    public function receive(int $couponId): bool
     {
         // 当前用户信息
         $userInfo = UserService::getCurrentLoginUser(true);
@@ -124,7 +126,7 @@ class UserCoupon extends UserCouponModel
      * @param Coupon $coupon
      * @return bool
      */
-    private function add($user, Coupon $coupon)
+    private function add($user, Coupon $coupon): bool
     {
         // 计算有效期
         if ($coupon['expire_type'] == ExpireTypeEnum::RECEIVE) {
@@ -169,9 +171,9 @@ class UserCoupon extends UserCouponModel
      * @param Coupon $coupon 优惠券详情
      * @return bool
      */
-    private function checkReceive($userInfo, Coupon $coupon)
+    private function checkReceive($userInfo, Coupon $coupon): bool
     {
-        if (!$coupon) {
+        if (empty($coupon)) {
             $this->error = '优惠券不存在';
             return false;
         }
@@ -192,10 +194,10 @@ class UserCoupon extends UserCouponModel
      * 订单结算优惠券列表
      * @param int $userId 用户id
      * @param float $orderPayPrice 订单商品总金额
-     * @return array|mixed
+     * @return array
      * @throws \think\db\exception\DbException
      */
-    public static function getUserCouponList(int $userId, float $orderPayPrice)
+    public static function getUserCouponList(int $userId, float $orderPayPrice): array
     {
         // 获取用户可用的优惠券列表
         $list = (new static)->getList($userId, ['dataType' => 'isUsable', 'amount' => $orderPayPrice]);
@@ -230,11 +232,11 @@ class UserCoupon extends UserCouponModel
 
     /**
      * 判断当前优惠券是否满足订单使用条件
-     * @param $couponList
+     * @param array $couponList
      * @param array $orderGoodsIds 订单商品ID集
-     * @return mixed
+     * @return array
      */
-    public static function couponListApplyRange(array $couponList, array $orderGoodsIds)
+    public static function couponListApplyRange(array $couponList, array $orderGoodsIds): array
     {
         // 名词解释(is_apply):允许用于抵扣当前订单
         foreach ($couponList as &$item) {

+ 1 - 1
app/common/enum/order/PayType.php

@@ -31,7 +31,7 @@ class PayType extends EnumBasics
      * 获取枚举数据
      * @return array
      */
-    public static function data()
+    public static function data(): array
     {
         return [
             self::BALANCE => [

+ 3 - 3
app/common/service/Message.php

@@ -8,7 +8,7 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\common\service;
 
@@ -40,9 +40,9 @@ class Message extends BaseService
      * @param string $sceneName 场景名称
      * @param array $param 参数
      * @param int $storeId 商城ID
-     * @return bool
+     * @return mixed
      */
-    public static function send(string $sceneName, array $param, int $storeId): bool
+    public static function send(string $sceneName, array $param, int $storeId)
     {
         if (!isset(self::$sceneList[$sceneName])) return false;
         $class = self::$sceneList[$sceneName];