Ver Fonte

新增 用户积分记录接口

phperli há 3 anos atrás
pai
commit
e376221513

+ 11 - 1
app/Http/Controllers/V1/UserController.php

xqd xqd
@@ -515,7 +515,6 @@ class UserController extends Controller
         } catch (\Exception $exception) {
             return $this->error($exception->getMessage());
         }
-
     }
 
     //切换声音 极光推送声音
@@ -528,4 +527,15 @@ class UserController extends Controller
         return $this->success();
     }
 
+    //用户积分
+    public function integral(Request $request)
+    {
+        $userId = $request->input('user_id');
+        $page = $request->input('page', 1);
+
+        $list = $this->UserService->getIntegrals($userId, $page);
+
+        return $this->success($list);
+    }
+
 }

+ 21 - 0
app/Models/UserIntegral.php

xqd
@@ -8,4 +8,25 @@ use Illuminate\Database\Eloquent\Model;
 class UserIntegral extends Model
 {
     use HasFactory;
+
+    const UPDATED_AT = null;
+
+    const TYPE = [
+        0 => '未知',
+        1 => '个人新开户',
+        2 => '企业新开户',
+        3 => '球队新开户',
+        4 => '球场会员认证',
+        5 => '粉丝',
+        6 => '一杆进洞',
+        7 => '总场次奖励',
+        8 => '打卡',
+        9 => '点赞',
+    ];
+
+    public static function getTypeName($type=0)
+    {
+        return self::TYPE[$type];
+    }
+
 }

+ 31 - 9
app/Services/Api/UserService.php

xqd xqd xqd xqd xqd xqd
@@ -220,7 +220,7 @@ class UserService
             ->limit($limit)
             ->get();
 
-        if($list->isEmpty()){
+        if ($list->isEmpty()) {
             return [];
         }
         $list = $list->toArray();
@@ -330,7 +330,7 @@ class UserService
             ->orderBy('user_follows.updated_at', 'desc')
             ->get();
 
-        if($list->isEmpty()){
+        if ($list->isEmpty()) {
             return [];
         }
         $list = $list->toArray();
@@ -352,7 +352,7 @@ class UserService
             ->orderBy('user_follows.updated_at', 'desc')
             ->get();
 
-        if($list->isEmpty()){
+        if ($list->isEmpty()) {
             return [];
         }
         $list = $list->toArray();
@@ -401,7 +401,7 @@ class UserService
             ->orderBy('id', 'desc')
             ->get();
 
-        if($list->isEmpty()){
+        if ($list->isEmpty()) {
             return [];
         }
         $list = $list->toArray();
@@ -533,13 +533,13 @@ class UserService
     }
 
     //用户积分变化
-    public function changeIntegral($userId, $amount=0, $type=1)
+    public function changeIntegral($userId, $amount = 0, $type = 1)
     {
         DB::beginTransaction();
-        try{
-            if($type == '+'){
+        try {
+            if ($type == '+') {
                 UserExtra::query()->where('user_id', $userId)->increment('integral', $amount);
-            }else{
+            } else {
                 UserExtra::query()->where('user_id', $userId)->decrement('integral', $amount);
             }
 
@@ -554,10 +554,32 @@ class UserService
             $userIntegral->save();
 
             DB::commit();
-        }catch (Exception $exception){
+        } catch (Exception $exception) {
             ErrorMsgServive::write($exception, request()->url());
             DB::rollBack();
         }
     }
 
+    //积分变化记录
+    public function getIntegrals($userId, $page)
+    {
+        $limit = 20;
+        $offset = ($page - 1) * $offset;
+        $list = UserIntegral::query()
+            ->where('user_id', $userId)
+            ->limit($limit)
+            ->offset($offset)
+            ->get();
+
+        if ($list->isEmpty()) {
+            return [];
+        }
+        $list = $list->toArray();
+        foreach ($list as $key => &$val) {
+            $val['type_name'] = UserIntegral::getTypeName($val['type']);
+        }
+
+        return $list;
+    }
+
 }

+ 2 - 0
routes/api.php

xqd
@@ -366,6 +366,8 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api)
             $api->any('del_account', 'UserController@delAccount')->name('user.del_account');
             //提示音选择
             $api->any('jpush_voice', 'UserController@chooseJpushVoice');
+            //用户积分记录
+            $api->any('integral', 'UserController@integral');
 
         });