Skip to content

Commit

Permalink
邀请链接定制&付费定制功能
Browse files Browse the repository at this point in the history
  • Loading branch information
laurieryayoi committed Nov 30, 2018
1 parent 9fc7b61 commit 6e10203
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
36 changes: 35 additions & 1 deletion app/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ public function buyInvite($request, $response, $args)
$num = $request->getParam('num');
$num = trim($num);

if (Tools::isInt($num) == false || $price < 0 || $num <= 0) {
if (!Tools::isInt($num) || $price < 0 || $num <= 0) {
$res['ret'] = 0;
$res['msg'] = "非法请求";
return $response->getBody()->write(json_encode($res));
Expand All @@ -913,6 +913,40 @@ public function buyInvite($request, $response, $args)
return $response->getBody()->write(json_encode($res));
}

public function customInvite($request, $response, $args)
{
$price = Config::get('custom_invite_price');
$customcode = $request->getParam('customcode');
$customcode = trim($customcode);

if (!Tools::is_validate($customcode) || $price < 0 || strlen($customcode)<1 || strlen($customcode)>32) {
$res['ret'] = 0;
$res['msg'] = "非法请求,邀请链接后缀不能包含特殊符号且长度不能大于32字符";
return $response->getBody()->write(json_encode($res));
}

if (InviteCode::where('code', $customcode)->count()!=0) {
$res['ret'] = 0;
$res['msg'] = "此后缀名被抢注了";
return $response->getBody()->write(json_encode($res));
}

$user = $this->user;
if ($user->money < $price) {
$res['ret'] = 0;
$res['msg'] = "余额不足,总价为" . $price . "元。";
return $response->getBody()->write(json_encode($res));
}
$code = InviteCode::where('user_id', $user->id)->first();
$code->code = $customcode;
$user->money -= $price;
$user->save();
$code->save();
$res['ret'] = 1;
$res['msg'] = "定制成功";
return $response->getBody()->write(json_encode($res));
}

public function sys()
{
return $this->view()->assign('ana', "")->display('user/sys.tpl');
Expand Down
5 changes: 1 addition & 4 deletions app/Utils/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ public static function getDir($dir)
public static function is_validate($str)
{
$pattern = "/[^A-Za-z0-9\-_\.]/";
if (preg_match($pattern, $str)) {
return false;
}
return true;
return !preg_match($pattern, $str);
}

public static function is_relay_rule_avaliable($rule, $ruleset, $node_id)
Expand Down
1 change: 1 addition & 0 deletions config/.config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ $System_Config['mu_regex']='%5m%id.%suffix'; //单端口多用户混淆参数
$System_Config['inviteNum'] = '10'; //注册后的邀请链接可用次数
$System_Config['invite_get_money']='1'; //新用户通过私人邀请链接注册时,获得奖励金额(作为初始资金)
$System_Config['invite_price']='-1'; //用户购买邀请码所需要的价格,价格小于0时视为不开放购买
$System_Config['custom_invite_price']='-1'; //用户定制邀请码所需要的价格,价格小于0时视为不开放购买

#邮箱验证
$System_Config['enable_email_verify']='false'; //是否启用注册邮箱验证码
Expand Down
1 change: 1 addition & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
$this->put('/ticket/{id}', 'App\Controllers\UserController:ticket_update');

$this->post('/buy_invite', 'App\Controllers\UserController:buyInvite');
$this->post('/custom_invite', 'App\Controllers\UserController:customInvite');
$this->get('/edit', 'App\Controllers\UserController:edit');
$this->post('/password', 'App\Controllers\UserController:updatePassword');
$this->post('/wechat', 'App\Controllers\UserController:updateWechat');
Expand Down
12 changes: 6 additions & 6 deletions resources/views/material/user/invite.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
<div class="card-inner margin-bottom-no">
<div class="card-inner margin-bottom-no">
<div class="cardbtn-edit">
<div class="card-heading">定制链接后缀</div>
<div class="card-heading">定制链接后缀 <code class="card-tag tag-green">{$config['custom_invite_price']}RMB/次</code></div>
<button class="btn btn-flat waves-attach" id="custom-invite-confirm"><span class="icon">check</span>&nbsp;</button>
</div>
<p>在下方输入自定义的链接后缀,定制个性邀请链接~</p>
<p>例:输入<code>vip</code>则链接变为<code>{$config["baseUrl"]}/auth/register?code=vip</code></p>
<div class="form-group form-group-label">
<label class="floating-label" for="custom-invite-link">输入链接后缀</label>
<input class="form-control maxwidth-edit" id="custom-invite-link" type="num">
Expand All @@ -79,12 +79,12 @@
<div class="card-inner">
<div class="card-inner">
<div class="cardbtn-edit">
<div class="card-heading">购买邀请次数</div>
<div class="card-heading">购买邀请次数 <code class="card-tag tag-green">{$config['invite_price']}RMB/个</code></div>
<button class="btn btn-flat waves-attach" id="buy-invite"><span class="material-icons">shopping_cart</span></button>
</div>
<p>邀请次数价格:<code>{$config['invite_price']}</code>元/个</p>
<p>在下方输入需要购买的邀请次数</p>
<div class="form-group form-group-label">
<label class="floating-label" for="buy-invite-num">在这输入购买次数</label>
<label class="floating-label" for="buy-invite-num">输入购买次数</label>
<input class="form-control maxwidth-edit" id="buy-invite-num" type="num">
</div>
</div>
Expand Down Expand Up @@ -213,7 +213,7 @@ $("#custom-invite-confirm").click(function () {
url: "/user/custom_invite",
dataType: "json",
data: {
text: $("#custom-invite-link").val(),
customcode: $("#custom-invite-link").val(),
},
success: function (data) {
if (data.ret) {
Expand Down

0 comments on commit 6e10203

Please sign in to comment.