Explorar o código

add - 权益卡列表

liugc hai 1 ano
pai
achega
ba8ebb2a1f

+ 12 - 0
app/api/controller/UserEquityController.php

@@ -0,0 +1,12 @@
+<?php
+namespace app\api\controller;
+
+use app\api\lists\UserEquityLists;
+
+class UserEquityController extends BaseApiController
+{
+    public function lists()
+    {
+        return $this->dataLists(new UserEquityLists());
+    }
+}

+ 34 - 0
app/api/lists/UserEquityLists.php

@@ -0,0 +1,34 @@
+<?php
+namespace app\api\lists;
+
+use app\common\model\equity\UserEquity;
+
+class UserEquityLists  extends BaseApiDataLists
+{
+   public function queryWhere()
+   {
+       $where = [];
+       $where[] = ['user_id','=',$this->userId];
+       $where[] = ['number','>',0];
+       $where[] = ['end_time','>=',time()];
+
+       if(isset($this->params['goods_id']) && !empty($this->params['goods_id'])){
+           $where[] = ['goods_id','=',$this->params['goods_id']];
+       }
+       return $where;
+   }
+
+   public function  lists():array
+   {
+       return UserEquity::with(['equityConfig'])->where($this->queryWhere())
+           ->limit($this->limitOffset, $this->limitLength)
+           ->order('create_time desc')
+           ->select()
+           ->toArray();
+   }
+
+    public function count(): int
+    {
+        return UserEquity::where($this->queryWhere())->count();
+    }
+}

+ 4 - 1
app/common/model/equity/UserEquity.php

@@ -7,5 +7,8 @@ class UserEquity extends BaseModel
 {
 
     protected $name = 'user_equity';
-
+    public function equityConfig()
+    {
+        return $this->hasOne(EquityConfig::class, 'id', 'equity_id');
+    }
 }