Bläddra i källkod

1.注册发激活邮件
2.返利链接

zhangjiangbin 8 år sedan
förälder
incheckning
d3724feb90

+ 30 - 12
app/Http/Controllers/RegisterController.php

@@ -4,9 +4,12 @@ namespace App\Http\Controllers;
 
 use App\Http\Models\Invite;
 use App\Http\Models\User;
+use App\Http\Models\Verify;
 use Illuminate\Http\Request;
+use App\Mail\activeUser;
 use Response;
 use Redirect;
+use Mail;
 
 /**
  * 注册控制器
@@ -90,20 +93,35 @@ class RegisterController extends BaseController
             $port = self::$config['is_rand_port'] ? $this->getRandPort() : $last_user->port + 1;
 
             // 创建新用户
-            $obj = new User();
-            $obj->username = $username;
-            $obj->password = md5($password);
-            $obj->port = $port;
-            $obj->passwd = $this->makeRandStr();
-            $obj->transfer_enable = $this->toGB(1);
-            $obj->enable_time = date('Y-m-d H:i:s');
-            $obj->expire_time = date('Y-m-d H:i:s', strtotime("+30 days"));
-            $obj->reg_ip = $request->getClientIp();
-            $obj->save();
+            $user = new User();
+            $user->username = $username;
+            $user->password = md5($password);
+            $user->port = $port;
+            $user->passwd = $this->makeRandStr();
+            $user->transfer_enable = $this->toGB(1);
+            $user->enable_time = date('Y-m-d H:i:s');
+            $user->expire_time = date('Y-m-d H:i:s', strtotime("+30 days"));
+            $user->reg_ip = $request->getClientIp();
+            $user->save();
 
             // 更新邀请码
-            if (self::$config['is_invite_register'] && $obj->id) {
-                Invite::where('id', $code->id)->update(['fuid' => $obj->id,'status' => 1]);
+            if (self::$config['is_invite_register'] && $user->id) {
+                Invite::where('id', $code->id)->update(['fuid' => $user->id,'status' => 1]);
+
+                // 生成激活账号的地址
+                $token = md5(self::$config['website_name'] . $username . microtime());
+                $verify = new Verify();
+                $verify->user_id = $user->id;
+                $verify->username = $username;
+                $verify->token = $token;
+                $verify->status = 0;
+                $verify->save();
+
+                // 发送邮件
+                $activeUserUrl = self::$config['website_url'] . '/active/' . $token;
+                Mail::to($username)->send(new activeUser(self::$config['website_name'], $activeUserUrl));
+
+                $request->session()->flash('regSuccessMsg', '注册成功:激活邮件已发送,请查看邮箱');
             }
 
             return Redirect::to('login');

+ 5 - 1
app/Http/Controllers/ShopController.php

@@ -34,6 +34,7 @@ class ShopController extends BaseController
     {
         if ($request->method() == 'POST') {
             $name = $request->get('name');
+            $desc = $request->get('desc');
             $traffic = $request->get('traffic');
             $price = $request->get('price');
             $score = $request->get('score');
@@ -57,6 +58,7 @@ class ShopController extends BaseController
 
             $obj = new Goods();
             $obj->name = $name;
+            $obj->desc = $desc;
             $obj->logo = $logo;
             $obj->traffic = $traffic;
             $obj->price = $price;
@@ -83,6 +85,7 @@ class ShopController extends BaseController
 
         if ($request->method() == 'POST') {
             $name = $request->get('name');
+            $desc = $request->get('desc');
             $traffic = $request->get('traffic');
             $price = $request->get('price');
             $score = $request->get('score');
@@ -106,11 +109,12 @@ class ShopController extends BaseController
 
             $data = [
                 'name'    => $name,
+                'desc'    => $desc,
                 'logo'    => $logo,
                 'traffic' => $traffic,
                 'price'   => $price,
                 'score'   => $score,
-                'status'  => $status,
+                'status'  => $status
             ];
             $ret = Goods::where('id', $id)->update($data);
             if ($ret) {

+ 54 - 4
app/Http/Controllers/UserController.php

@@ -9,6 +9,7 @@ use App\Http\Models\Goods;
 use App\Http\Models\Invite;
 use App\Http\Models\Order;
 use App\Http\Models\OrderGoods;
+use App\Http\Models\ReferralApply;
 use App\Http\Models\ReferralLog;
 use App\Http\Models\SsNode;
 use App\Http\Models\SsNodeInfo;
@@ -734,7 +735,6 @@ TXT;
                 $userBalanceLogObj->created_at = date('Y-m-d H:i:s');
                 $userBalanceLogObj->save();
 
-
                 // 优惠券置为已使用
                 if (!empty($coupon)) {
                     if ($coupon->usage == 1) {
@@ -753,6 +753,16 @@ TXT;
                 // 把流量包内的流量加到账号上
                 User::where('id', $user['id'])->increment('transfer_enable', $goods->traffic);
 
+                // 写入返利日志
+                $referralLog = new ReferralLog();
+                $referralLog->user_id = $user['id'];
+                $referralLog->ref_user_id = $user['referral_uid'];
+                $referralLog->order_id = $order->oid;
+                $referralLog->amount = $totalPrice;
+                $referralLog->ref_amount = $totalPrice * static::$config['referral_percent'];
+                $referralLog->status = 0;
+                $referralLog->save();
+
                 DB::commit();
 
                 return Response::json(['status' => 'success', 'data' => '', 'message' => '支付成功']);
@@ -818,13 +828,53 @@ TXT;
     {
         // 生成个人推广链接
         $user = $request->session()->get('user');
+
         $view['referral_traffic'] = static::$config['referral_traffic'];
         $view['referral_percent'] = static::$config['referral_percent'];
         $view['referral_money'] = static::$config['referral_money'];
-        $view['referralLogList'] = ReferralLog::where('ref_user_id', $user['id'])->paginate();
-        $view['totalAmount'] = ReferralLog::where('ref_user_id', $user['id'])->where('status', 0)->sum('ref_amount');
-        $view['link'] = static::$config['website_url'] . '/?ref=' . $user['id'];
+        $view['referralLogList'] = ReferralLog::where('ref_user_id', $user['id'])->with('user')->paginate();
+        $view['totalAmount'] = ReferralLog::where('ref_user_id', $user['id'])->sum('ref_amount');
+        $view['canAmount'] = ReferralLog::where('ref_user_id', $user['id'])->where('status', 0)->sum('ref_amount');
+        $view['link'] = static::$config['website_url'] . '/?aff=' . $user['id'];
 
         return Response::view('user/referral', $view);
     }
+
+    // 申请提现
+    public function extractMoney(Request $request)
+    {
+        $user = $request->session()->get('user');
+
+        // 校验可以提现金额是否超过系统设置的阀值
+        $ref_amount = ReferralLog::where('ref_user_id', $user['id'])->where('status', 0)->sum('ref_amount');
+        if ($ref_amount < static::$config['referral_money']) {
+            return Response::json(['status' => 'fail', 'data' => '', 'message' => '申请失败:满' . static::$config['referral_money'] . '元才可以提现,继续努力吧']);
+        }
+
+        // 判断是否已存在申请
+        $referralApply = ReferralApply::where('user_id', $user['id'])->where('status', 0)->first();
+        if ($referralApply) {
+            return Response::json(['status' => 'fail', 'data' => '', 'message' => '申请失败:已存在申请,请等待之前的申请处理完']);
+        }
+
+        // 取出本次申请关联返利日志ID
+        $link_logs = '';
+        $referralLog = ReferralLog::where('ref_user_id', $user['id'])->where('status', 0)->get();
+        foreach ($referralLog as $log) {
+            $link_logs .= $log->id . ',';
+        }
+        $link_logs = rtrim($link_logs, ',');
+
+        $obj = new ReferralApply();
+        $obj->user_id = $user['id'];
+        $obj->before = $ref_amount;
+        $obj->after = 0;
+        $obj->amount = $ref_amount;
+        $obj->link_logs = $link_logs;
+        $obj->status = 0;
+        $obj->created_at = date('Y-m-d H:i:s');
+        $obj->save();
+
+        return Response::json(['status' => 'success', 'data' => '', 'message' => '申请成功,请等待管理员审核']);
+    }
 }

+ 1 - 0
app/Http/Models/ReferralApply.php

@@ -18,6 +18,7 @@ class ReferralApply extends Model
         'before',
         'after',
         'amount',
+        'link_logs',
         'status',
         'created_at'
     ];

+ 4 - 0
app/Http/Models/ReferralLog.php

@@ -23,4 +23,8 @@ class ReferralLog extends Model
         'created_at'
     ];
 
+    function user() {
+        return $this->hasOne(User::class, 'id', 'user_id');
+    }
+
 }

+ 0 - 1
readme.md

@@ -29,7 +29,6 @@ telegram群组:https://t.me/chatssrpanel
 | Law-杰   | ¥10 | 
 | Err      | ¥51 | 
 | 緃噺開始 |  ¥5 | 
-|良心***| ¥67 |
 |、无奈|¥5|
 |Sunny Woon| ¥10|
 

+ 6 - 0
resources/views/login.blade.php

@@ -49,6 +49,12 @@
                 <span> {!! Session::get('errorMsg') !!} </span>
             </div>
         @endif
+        @if (Session::get('regSuccessMsg'))
+            <div class="alert alert-success">
+                <button class="close" data-close="alert"></button>
+                <span> {{Session::get('regSuccessMsg')}} </span>
+            </div>
+        @endif
         <div class="form-group">
             <!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
             <label class="control-label visible-ie8 visible-ie9">用户名</label>

+ 7 - 1
resources/views/shop/addGoods.blade.php

@@ -46,7 +46,7 @@
                         <form action="{{url('shop/addGoods')}}" method="post" enctype="multipart/form-data" class="form-horizontal form-bordered">
                             <div class="form-body">
                                 <div class="form-group">
-                                    <label class="control-label col-md-3">商品名称</label>
+                                    <label class="control-label col-md-3">名称</label>
                                     <div class="col-md-6">
                                         <input type="text" class="form-control" name="name" value="" id="name" placeholder="" required>
                                         <input type="hidden" name="_token" value="{{csrf_token()}}" />
@@ -70,6 +70,12 @@
                                         </div>
                                     </div>
                                 </div>
+                                <div class="form-group">
+                                    <label class="control-label col-md-3">描述</label>
+                                    <div class="col-md-6">
+                                        <textarea class="form-control" rows="3" name="desc" id="desc" placeholder="商品的简单描述"></textarea>
+                                    </div>
+                                </div>
                                 <div class="form-group">
                                     <label class="control-label col-md-3">内含流量</label>
                                     <div class="col-md-6">

+ 6 - 0
resources/views/shop/editGoods.blade.php

@@ -76,6 +76,12 @@
                                         </div>
                                     </div>
                                 </div>
+                                <div class="form-group">
+                                    <label class="control-label col-md-3">描述</label>
+                                    <div class="col-md-6">
+                                        <textarea class="form-control" rows="3" name="desc" id="desc" placeholder="商品的简单描述">{{$goods->desc}}</textarea>
+                                    </div>
+                                </div>
                                 <div class="form-group">
                                     <label class="control-label col-md-3">内含流量</label>
                                     <div class="col-md-6">

+ 33 - 8
resources/views/user/referral.blade.php

@@ -24,9 +24,25 @@
         <!-- BEGIN PAGE BASE CONTENT -->
         <div class="row">
             <div class="col-md-12">
-                <div class="alert alert-success">
+                <div class="alert alert-danger">
                     通过您的推广链接注册的账号可以获得 <code>{{$referral_traffic}}MiB流量</code> 奖励。您可以获得他们每笔消费的<code>{{$referral_percent * 100}}%现金返利</code>。累计满 <code>{{$referral_money}}元</code>,就可以申请提现至微信或者支付宝。
                 </div>
+                <div class="portlet light form-fit bordered">
+                    <div class="portlet-title">
+                        <div class="caption">
+                            <i class="icon-link font-blue"></i>
+                            <span class="caption-subject font-blue bold uppercase">我的推广链接</span>
+                        </div>
+                    </div>
+                    <div class="portlet-body form">
+                        <div class="mt-clipboard-container">
+                            <input type="text" id="mt-target-1" class="form-control" value="{{$link}}" />
+                            <a href="javascript:;" class="btn blue mt-clipboard" data-clipboard-action="copy" data-clipboard-target="#mt-target-1">
+                                <i class="icon-note"></i> 复制链接
+                            </a>
+                        </div>
+                    </div>
+                </div>
                 <!-- BEGIN EXAMPLE TABLE PORTLET-->
                 <div class="portlet light bordered">
                     <div class="portlet-title">
@@ -35,9 +51,7 @@
                             <span class="caption-subject bold uppercase"> 推广返利 </span>
                         </div>
                         <div class="actions">
-                            <div class="btn-group btn-group-devided" data-toggle="buttons" onclick="extractMoney()">
-                                <a href="javascript:;" class="btn btn-danger"><i class="fa fa-money"></i> 申请提现 </a>
-                            </div>
+                            <button type="submit" class="btn red" onclick="extractMoney()"><i class="fa fa-money"></i> 申请提现</button>
                         </div>
                     </div>
                     <div class="portlet-body">
@@ -49,7 +63,8 @@
                                     <th> 消费者 </th>
                                     <th> 消费金额 </th>
                                     <th> 返利金额 </th>
-                                    <th> 日期 </th>
+                                    <th> 状态 </th>
+                                    <th> 返利时间 </th>
                                 </tr>
                                 </thead>
                                 <tbody>
@@ -61,9 +76,15 @@
                                     @foreach($referralLogList as $key => $referralLog)
                                         <tr class="odd gradeX">
                                             <td> {{$key + 1}} </td>
-                                            <td> {{$referralLog->user_id}} </td>
+                                            <td> {{$referralLog->user->username}} </td>
                                             <td> {{$referralLog->amount}} </td>
                                             <td> {{$referralLog->ref_amount}} </td>
+                                            <td>
+                                                @if ($referralLog->status)
+                                                    <span class="label label-sm label-default">已提现</span>
+                                                @else
+                                                    <span class="label label-sm label-info">未提现</span>
+                                                @endif
                                             <td> {{$referralLog->created_at}} </td>
                                         </tr>
                                     @endforeach
@@ -73,7 +94,7 @@
                         </div>
                         <div class="row">
                             <div class="col-md-4 col-sm-4">
-                                <div class="dataTables_info" role="status" aria-live="polite">共 {{$referralLogList->total()}} 条记录,合计可提现金额 <code>{{$totalAmount}}元</code></div>
+                                <div class="dataTables_info" role="status" aria-live="polite">共 {{$referralLogList->total()}} 条记录,合计返利<code>{{$canAmount}}元</code></div>
                             </div>
                             <div class="col-md-8 col-sm-8">
                                 <div class="dataTables_paginate paging_bootstrap_full_number pull-right">
@@ -92,11 +113,15 @@
 @endsection
 @section('script')
     <script src="/assets/global/plugins/bootbox/bootbox.min.js" type="text/javascript"></script>
+    <script src="/assets/global/plugins/clipboardjs/clipboard.min.js" type="text/javascript"></script>
+    <script src="/assets/pages/scripts/components-clipboard.min.js" type="text/javascript"></script>
 
     <script type="text/javascript">
         // 申请提现
         function extractMoney() {
-            bootbox.alert('开发中');
+            $.post("{{url('user/extractMoney')}}", {_token:'{{csrf_token()}}'}, function (ret) {
+                bootbox.alert(ret.message);
+            });
         }
     </script>
 @endsection

+ 1 - 0
routes/web.php

@@ -84,4 +84,5 @@ Route::group(['middleware' => ['user']], function(){
     Route::any('user/profile', 'UserController@profile'); // 修改个人信息
     Route::post('user/exchange', 'UserController@exchange'); // 积分兑换流量
     Route::get('user/referral', 'UserController@referral'); // 推广返利
+    Route::post('user/extractMoney', 'UserController@extractMoney'); // 申请提现
 });

+ 39 - 2
sql/db.sql

@@ -87,7 +87,7 @@ CREATE TABLE `user` (
   `username` varchar(128) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '用户名',
   `password` varchar(64) NOT NULL DEFAULT '' COMMENT '密码',
   `port` int(11) NOT NULL DEFAULT '0' COMMENT 'SS端口',
-  `passwd` varchar(32) NOT NULL DEFAULT '' COMMENT 'SS密码',
+  `passwd` varchar(16) NOT NULL DEFAULT '' COMMENT 'SS密码',
   `transfer_enable` bigint(20) NOT NULL DEFAULT '1073741824000' COMMENT '可用流量,单位字节,默认1TiB',
   `u` bigint(20) NOT NULL DEFAULT '0' COMMENT '已上传流量,单位字节',
   `d` bigint(20) NOT NULL DEFAULT '0' COMMENT '已下载流量,单位字节',
@@ -114,7 +114,8 @@ CREATE TABLE `user` (
   `is_admin` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否管理员:0-否、1-是',
   `reg_ip` varchar(20) NOT NULL DEFAULT '127.0.0.1' COMMENT '注册IP',
   `last_login` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次登录时间',
-  `status` tinyint(11) DEFAULT '0' COMMENT '状态:-1-禁止登陆、0-未激活、1-正常',
+  `referral_uid` int(11) NOT NULL DEFAULT '0' COMMENT '邀请人',
+  `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态:-1-禁用、0-未激活、1-正常',
   `created_at` datetime DEFAULT NULL,
   `updated_at` datetime DEFAULT NULL,
   PRIMARY KEY (`id`),
@@ -315,6 +316,7 @@ CREATE TABLE `goods` (
   `traffic` bigint(20) NOT NULL DEFAULT '0' COMMENT '商品内含多少流量',
   `score` int(11) NOT NULL DEFAULT '0' COMMENT '商品价值多少积分',
   `price` int(11) NOT NULL DEFAULT '0' COMMENT '商品售价,单位分',
+  `desc` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '商品描述',
   `is_del` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否已删除:0-否、1-是',
   `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态:0-下架、1-上架',
   `created_at` datetime DEFAULT NULL COMMENT '创建时间',
@@ -452,6 +454,41 @@ CREATE TABLE `user_balance_log` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
 
+-- ----------------------------
+-- Table structure for `referral_apply`
+-- ----------------------------
+CREATE TABLE `referral_apply` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
+  `before` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '操作前可提现金额',
+  `after` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '操作后可提现金额',
+  `amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '本次提现金额',
+  `link_logs` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '关联返利日志ID,例如:1,3,4',
+  `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态:-1-驳回、0-待审核、1-审核通过待打款、2-已打款',
+  `created_at` datetime DEFAULT NULL COMMENT '创建时间',
+  `updated_at` datetime DEFAULT NULL COMMENT '最后一次更新时间',
+  PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='提现申请';
+
+
+-- ----------------------------
+-- Table structure for `referral_log`
+-- ----------------------------
+CREATE TABLE `referral_log` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
+  `ref_user_id` int(11) NOT NULL DEFAULT '0' COMMENT '推广人ID',
+  `order_id` int(11) NOT NULL DEFAULT '0' COMMENT '关联订单ID',
+  `amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '消费金额',
+  `ref_amount` int(11) NOT NULL DEFAULT '0' COMMENT '返利金额',
+  `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '状态:0-未提现、1-已提现',
+  `created_at` datetime DEFAULT NULL COMMENT '创建时间',
+  `updated_at` datetime DEFAULT NULL COMMENT '最后一次更新时间',
+  PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='消费返利日志';
+
+
+
 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
 /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;