1557492053 1 yıl önce
ebeveyn
işleme
4a6b088674
1 değiştirilmiş dosya ile 12 ekleme ve 5 silme
  1. 12 5
      application/api/model/user/Voucher.php

+ 12 - 5
application/api/model/user/Voucher.php

@@ -53,6 +53,11 @@ class Voucher extends BaseModel
         return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
     }
 
+    public function voucherinfo()
+    {
+        return $this->belongsTo(\app\admin\model\Voucher::class, 'voucher_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
     /**
      * 过期
      * @param $user_id
@@ -68,11 +73,13 @@ class Voucher extends BaseModel
 
     public function fetchVoucher($user_id, $status, $page = 1, $size = 10)
     {
-        return $this->where([
-            "user_id" => $user_id,
-        ])
-            ->where("status", "<>", \E_VOUCHER_STATUS::Use)
-            ->where("status", "in", $status)
+        return $this->alias("uv")
+            ->with("voucherinfo")
+            ->where([
+                "uv.user_id" => $user_id,
+            ])
+            ->where("uv.status", "<>", \E_VOUCHER_STATUS::Use)
+            ->where("uv.status", "in", $status)
             ->page($page)
             ->paginate($size);
     }