浏览代码

贵族调整和邀请送金额

zhangxiaobin 1 年之前
父节点
当前提交
b458a960c3

+ 21 - 0
application/api/controller/Guild.php

@@ -733,4 +733,25 @@ class Guild extends Api
             $this->error($e->getMessage());
         }
     }
+
+    /**
+     * 获取家族状态
+     * @return void
+     */
+    public function getStatus()
+    {
+        try {
+            $id = $this->request->param('guild_id',0);
+            if (!empty($id)) {
+                $where['id'] = $id;
+            } else {
+                $where['user_id'] = $this->auth->id;
+            }
+            $field = 'id,status';
+            $guild = model('Guild')->field($field)->where($where)->find();
+            $this->success('获取成功', $guild);
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
 }

+ 1 - 1
application/api/controller/Noble.php

@@ -240,7 +240,7 @@ class Noble extends Api
             'partyNotice' => $partyNotice,
         ];
         $tcpJson = json_encode($tcpArr);
-        Gateway::sendToAll($tcpJson);
+        //Gateway::sendToAll($tcpJson);//暂时注释
 
     }
 

+ 5 - 0
application/api/controller/Notify.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
+use app\common\service\UserService;
 use kjpay\kjpay;
 use think\Request;
 use think\Db;
@@ -53,6 +54,8 @@ class Notify extends Api
                     $userInfo->chargecount = $userInfo->chargecount + $payamount;
                     $userInfo->chargetime = time();
                     $userInfo->save();
+                    $userService = new UserService();
+                    $userService->inviteMoney(['user_id'=>$orderInfo["user_id"]]);
                     Db::commit();
                 }
             } catch (ValidateException $e) {
@@ -109,6 +112,8 @@ class Notify extends Api
                     $userInfo->chargecount = $userInfo->chargecount + $payamount;
                     $userInfo->chargetime = time();
                     $userInfo->save();
+                    $userService = new UserService();
+                    $userService->inviteMoney(['user_id'=>$orderInfo["user_id"]]);
                     Db::commit();
                 }
             } catch (ValidateException $e) {

+ 43 - 0
application/api/controller/Usercenter.php

@@ -972,4 +972,47 @@ class UserCenter extends Common
         $this->success("获取成功!",$res);
     }
 
+    /**
+     * 邀请
+     * @return void
+     */
+    public function addInvite()
+    {
+        try {
+            $inviteNo = $this->request->param('invite_no','');
+            $userId = $this->auth->id;
+            if (empty($inviteNo)) {
+                throw new Exception('参数错误');
+            }
+            $where['invite_no'] = $inviteNo;
+            $userField = 'id,invite_no';
+            $user = model('User')->field($userField)->where($where)->find();
+            if (empty($user)) {
+                throw new Exception('无效的邀请码');
+            }
+            $userInviteWhere['invite_user_id'] = $userId;
+            $userInvite = model('UserInvite')->where($userInviteWhere)->find();
+            if (!empty($userInvite)) {
+                throw new Exception('您已经被邀请过');
+            }
+            $userInviteData = [
+                'user_id' => $user['id'],
+                'invite_user_id' => $userId,
+                'createtime' => time(),
+            ];
+            $userInviteRes = model('UserInvite')->insertGetId($userInviteData);
+            if (!$userInviteRes) {
+                throw new Exception('邀请失败');
+            }
+            $userUpWhere['id'] = $userId;
+            $userUpdate = ['pre_userid'=>$user['id']];
+            $userUpdateRes = model('User')->where($userUpWhere)->update($userUpdate);
+            if (!$userUpdateRes) {
+                throw new Exception('更新邀请人失败');
+            }
+            $this->success('邀请成功');
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
 }

+ 14 - 0
application/common/model/UserInvite.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+class UserInvite extends Model
+{
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+}

+ 45 - 0
application/common/service/UserService.php

@@ -139,4 +139,49 @@ class UserService
         }
         return $result;
     }
+
+    /**
+     * 邀请赠送金额
+     * @return void
+     */
+    public function inviteMoney($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '',
+            'data' => [],
+        ];
+        try {
+            $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+            if (!empty($userId)) {
+                $field = 'id,pre_user_id,money';
+                $where['id'] = $userId;
+                $user = model('User')->field($field)->where($where)->find();
+                if (!empty($user)) {
+                    if (!empty($user['pre_user_id'])) {
+                        $preWhere['id'] = $user['pre_user_id'];
+                        $preUser = model('User')->field($field)->where($preWhere)->find();
+                        if (!empty($preUser)) {
+                            //查看是否赠送过金额
+                            $moneyLogWhere['invite_user_id'] = $userId;
+                            $moneyLogWhere['type'] = 15;
+                            $moneyLog = model('UserMoneyLog')->where($moneyLogWhere)->find();
+                            if (empty($moneyLogWhere)) {
+                                $money = config('site.invite_money');
+                                $remark = '邀请用户充值赠送金额';
+                                $res = model('Wallet')->lockChangeAccountRemain($preUser['id'],$money,'+',$preUser['money'],$remark,15);
+                                if (!$res['status']) {
+                                    throw new Exception($res['msg']);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
 }

文件差异内容过多而无法显示
+ 1 - 0
application/extra/site.php


+ 1 - 0
application/extra/wallet.php

@@ -19,6 +19,7 @@ return [
         12 => '私聊到账',  //增加
         13 => '抽奖箱子和转盘', //减少
         14 => '余额兑换钻石', //增加
+        15 => '邀请用户充值赠送金额', //增加
         //money
         101 => '获赠礼物', //增加
         102 => '房间礼物抽成', //增加

部分文件因为文件数量过多而无法显示