zz 6 lat temu
rodzic
commit
cdabb36f4e

+ 18 - 3
app/Http/Controllers/Wap/Pay/OrdersController.php

@@ -10,6 +10,7 @@ use App\Modules\Subscribe\Services\OrderParamService;
 use App\Modules\Subscribe\Services\OrderParamWsoService;
 use App\Modules\Subscribe\Services\SubstituteOrderService;
 use App\Modules\User\Services\ReadRecordService;
+use App\Modules\User\Services\UserBindPhoneService;
 use App\Modules\User\Services\UserDivisionCpcPropertyService;
 use App\Modules\User\Services\UserGiftService;
 use Illuminate\Routing\Controller;
@@ -621,7 +622,15 @@ class OrdersController extends Controller
             $url = sprintf('%s://%s/recent', $url_info['scheme'], $url_info['host']);
             return redirect($url);
         }
-        return view('pay.order.wait', compact('order', 'url'));
+
+        $order_info = OrderService::getByTradeNo($order);
+        $uid = $order_info->uid;
+        $bind_info = UserBindPhoneService::bindInfo($uid);
+        $page = 'pay.order.wait';
+        if(!$bind_info){
+            $page = 'pay.order.bindPhone';
+        }
+        return view($page, compact('order', 'url'));
     }
 
     private function isNewUserSecondCharge($charge_type, $product_id, $uid)
@@ -744,12 +753,18 @@ class OrdersController extends Controller
 
     public function waitPage(Request $request)
     {
-
         $order = $request->input('order');
         //$order = "201712081711401585932843356442";
         $order = (string)$order;
+        $order_info = OrderService::getByTradeNo($order);
+        $uid = $order_info->uid;
+        $bind_info = UserBindPhoneService::bindInfo($uid);
+        $page = 'pay.order.wait';
+        if(!$bind_info){
+            $page = 'pay.order.bindPhone';
+        }
         $url = urldecode($request->input('redirect'));
-        return view('pay.order.wait', compact('order', 'url'));
+        return view($page, compact('order', 'url'));
         //return view('pay.order.wait');
     }
 

+ 26 - 2
app/Http/Controllers/Wap/User/UserController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Wap\User;
 
+use App\Libs\AliSMS;
 use App\Modules\Book\Services\BookConfigService;
 use App\Modules\Book\Services\BookUrgeUpdateService;
 use App\Modules\Book\Services\SignBookService;
@@ -9,6 +10,7 @@ use App\Modules\Statistic\Services\AdVisitStatService;
 use App\Modules\Subscribe\Services\OrderService;
 use App\Modules\User\Services\ForceGuidePersonAccountService;
 use App\Modules\User\Services\ReadRecordService;
+use App\Modules\User\Services\UserBindPhoneService;
 use App\Modules\User\Services\WapReaderPageFissionService;
 use Illuminate\Http\Request;
 use App\Http\Controllers\Wap\BaseController;
@@ -429,8 +431,30 @@ class UserController extends BaseController
         return view('wap.rand_sign',compact('hasSigned','fee'));
     }
 
-    private function bindTelephoneStatus(){
-
+    public function sendCode(Request $request){
+        $phone = $request->post('phone');
+        $code = random_int(1000,9999);
+        Redis::setex('code:'.$phone,'120',$code);
+        AliSMS::send($phone, 'paid_user_bind_phone', ['code'=>$code]);
+        return response()->success();
+    }
+    public function bindPhone(Request $request){
+        $code = $request->post('code');
+        $phone = $request->post('phone');
+        $old = Redis::get('code:'.$phone);
+        if($old && $old == $code){
+            $user_info  = UserService::getById($this->uid);
+            if(!$user_info){
+                return response()->error();
+            }
+            try{
+                UserBindPhoneService::bind($this->uid,$user_info->openid,$phone);
+                UserService::addBalance($this->uid,100,0,100);
+            }catch (\Exception $e){}
+            return response()->success();
+        }else{
+            return response()->error();
+        }
     }
 
     public function guidePersonalAccount(Request $request){

+ 3 - 0
app/Http/Routes/Wap/WapRoutes.php

@@ -143,6 +143,9 @@ Route::group(['domain'=>env('WAP_DOMAIN'),'namespace'=>'App\Http\Controllers\Wap
         //催更
         Route::get('user/urgeUpdate','User\UserController@urgeUpdate');
 
+        Route::post('bindphone/sendcode','User\UserController@sendCode');
+        Route::post('bindphone/bind','User\UserController@bindPhone');
+
         // 测试登录
 //         Route::any('user/test_add_user_login_cookie','User\UserController@test_add_user_login_cookie');
         

+ 12 - 0
app/Modules/User/Models/UserBindPhone.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Modules\User\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class UserBindPhone extends Model
+{
+    protected $table = 'user_bind_phone';
+
+    protected $fillable = ['uid','openid','phone'];
+}

+ 31 - 0
app/Modules/User/Services/UserBindPhoneService.php

@@ -0,0 +1,31 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2019/7/4
+ * Time: 16:52
+ */
+
+namespace App\Modules\User\Services;
+
+use App\Modules\User\Models\UserBindPhone;
+
+class UserBindPhoneService
+{
+    public static function bindInfo($uid)
+    {
+        $model = new UserBindPhone();
+        return $model->join('users','users.openid','=','user_bind_phone.openid')
+            ->select('user_bind_phone.uid','user_bind_phone.phone')
+            ->where('users.id',$uid)
+            ->first();
+    }
+
+    public static function bind($uid,$openid,$phone){
+        $model = new UserBindPhone();
+        $model->uid = $uid;
+        $model->openid = $openid;
+        $model->phone = $phone;
+        $model->save();
+    }
+}

+ 354 - 0
resources/views/pay/order/bindPhone.blade.php

@@ -0,0 +1,354 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8" />
+    <meta
+            name="viewport"
+            content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
+    />
+    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
+    <title>绑定手机</title>
+    <style>
+        html,
+        body,
+        p {
+            padding: 0;
+            margin: 0;
+        }
+
+        html {
+            background: #f7f7f7;
+        }
+
+        img {
+            width: 100%;
+        }
+
+        i {
+            font-style: normal;
+        }
+
+        .page-banner {
+            position: absolute;
+            top: 0;
+            left: 0;
+            width: 100%;
+            z-index: 9;
+        }
+
+        .bind-phone__wrap {
+            position: relative;
+            z-index: 99;
+            border-radius: 6px;
+            background: #fff;
+            padding: 20px;
+            margin: 125px 13px 0;
+            text-align: center;
+            font-size: 0;
+        }
+
+        .bind-phone__wrap .wrap-banner {
+            width: 90%;
+        }
+
+        .bind-form {
+            margin-top: 35px;
+        }
+
+        .bind-form .form-item {
+            display: -webkit-box;
+            display: -ms-flexbox;
+            display: flex;
+            -webkit-box-pack: start;
+            -ms-flex-pack: start;
+            justify-content: flex-start;
+            -webkit-box-align: center;
+            -ms-flex-align: center;
+            align-items: center;
+            margin: 0 12px;
+            border-bottom: 1px solid #f7f7f7;
+        }
+
+        .bind-form .form-item input {
+            -webkit-box-flex: 1;
+            -ms-flex: 1;
+            flex: 1;
+            padding: 10px 0;
+            font-size: 14px;
+            color: #333;
+            outline: none;
+            border: none;
+        }
+
+        .bind-form .form-item input::-webkit-input-placeholder {
+            color: #999;
+            font-size: 14px;
+        }
+
+        .bind-form .form-item .get-code {
+            font-size: 13px;
+            color: #ff7130;
+        }
+
+        .bind-form .form-item:not(:last-child) {
+            margin-bottom: 17px;
+        }
+
+        .bind-form .submit-wrap {
+            margin-top: 69px;
+            margin-bottom: 18px;
+            display: -webkit-box;
+            display: -ms-flexbox;
+            display: flex;
+            -webkit-box-pack: justify;
+            -ms-flex-pack: justify;
+            justify-content: space-between;
+            -webkit-box-align: center;
+            -ms-flex-align: center;
+            align-items: center;
+        }
+
+        .bind-form .submit-wrap button {
+            -webkit-box-flex: 1;
+            -ms-flex: 1;
+            flex: 1;
+            outline: none;
+            border-radius: 6px;
+            font-size: 15px;
+            color: #fff;
+            text-align: center;
+            border: 1px solid transparent;
+            line-height: 45px;
+            background: #ff7130;
+            display: inline-block;
+        }
+
+        .bind-form .submit-wrap button.to-refuse {
+            color: #b3b3b3;
+            background: #ecf2f7;
+        }
+
+        .bind-form .submit-wrap button.to-refuse__enable {
+            border-color: #ff7130;
+            color: #ff7130;
+            background: #fff;
+        }
+
+        .bind-form .submit-wrap button:not(:last-child) {
+            margin-right: 11px;
+        }
+
+        .dialog-wrap {
+            position: fixed;
+            top: 0;
+            bottom: 0;
+            left: 0;
+            right: 0;
+            background: rgba(0, 0, 0, 0.2);
+            z-index: 999;
+        }
+
+        .dialog-wrap .dialog-content {
+            position: absolute;
+            width: 90%;
+            top: 50%;
+            left: 50%;
+            -webkit-transform: translate(-50%, -50%);
+            transform: translate(-50%, -50%);
+            background: #fff;
+            border-radius: 2px;
+            font-size: 0;
+            text-align: center;
+        }
+
+        .dialog-wrap .dialog-content .dialog-img {
+            position: relative;
+            width: 80px;
+            top: 50%;
+            -webkit-transform: translate(0%, -50%);
+            transform: translate(0%, -50%);
+        }
+
+        .dialog-wrap .dialog-content .content-info {
+            text-align: center;
+            font-size: 16px;
+            color: #666;
+            line-height: 1;
+            margin-bottom: 40px;
+        }
+
+        .dialog-wrap .dialog-content .content-info .bind-title {
+            font-size: 30px;
+            font-weight: bold;
+            margin-bottom: 15px;
+        }
+
+        .dialog-wrap .dialog-content .content-info i {
+            color: #ff7130;
+            font-weight: bold;
+            font-size: 20px;
+        }
+
+        .dialog-wrap .dialog-content .close {
+            outline: none;
+            border: none;
+            width: 175px;
+            line-height: 40px;
+            font-size: 15px;
+            color: #fff;
+            background: #ff7130;
+            border-radius: 6px;
+            margin: 0 auto 26px;
+            text-align: center;
+        }
+    </style>
+</head>
+<body>
+<main>
+    <img src="https://cdn-novel.iycdm.com/h5/bind-phone/doing.jpg" alt="" class="page-banner" />
+    <div class="bind-phone__wrap">
+        <img src="https://cdn-novel.iycdm.com/h5/bind-phone/title.jpg" alt="" class="wrap-banner" />
+        <div class="bind-form">
+            <form action="">
+                <div class="form-item">
+                    <input
+                            type="phone"
+                            name="phone"
+                            id="phone"
+                            placeholder="请输入手机号"
+                    />
+                </div>
+                <div class="form-item">
+                    <input
+                            type="text"
+                            name="code"
+                            id="code"
+                            placeholder="请输入手机验证码"
+                    />
+                    <span class="get-code">获取验证码</span>
+                </div>
+            </form>
+            <div class="submit-wrap">
+                <button class="to-bind" id="bind">立即绑定</button>
+                <!-- 可以点击的时候 多加一个class->to-refuse__enable -->
+                <button class="to-refuse" id="refuse" disabled>残忍拒绝</button>
+            </div>
+        </div>
+    </div>
+</main>
+<div class="dialog-wrap" style="display: none">
+    <div class="dialog-content">
+        <img src="https://cdn-novel.iycdm.com/h5/bind-phone/success.png" alt="" class="dialog-img" />
+        <div class="content-info">
+            <p class="bind-title">绑定成功</p>
+            <p class="bind-text">手机号绑定成功,赠送您<i>100</i>书币</p>
+        </div>
+        <button class="close" id="close">知道了</button>
+    </div>
+</div>
+</body>
+<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
+<script>
+    var reg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57]|19[0-9])[0-9]{8}$/;
+    var refuseNumber = 10;
+    var getPhoneCodeNumber = 60;
+
+    // 倒计时
+    function countDown(time, cb) {
+        var timer = null
+        timer = setInterval(function() {
+            $.ajax({
+                url:"/api/order/issuccess",
+                data:{
+                    order:"{{ $order }}"
+                },
+                success:function(res){
+                    if(res['code'] == 0){
+                        time = 1;
+                    }
+                }
+            });
+            if (time === 1) clearInterval(timer);
+            time--;
+            if (cb) cb(time);
+        }, 1000);
+    }
+
+    // 残忍拒绝事件
+    $("#refuse").on("click", function() {
+        if(!$(this).attr('disabled')){
+            location.href = "{!! $url !!}";
+        }
+    });
+
+    // 残忍拒绝倒计时
+    countDown(refuseNumber, function(time) {
+        if (time === 0) {
+            $("#refuse").text("残忍拒绝");
+            $("#refuse").attr("disabled", false);
+            $("#refuse").addClass("to-refuse__enable");
+        } else $("#refuse").text("残忍拒绝(" + time + "s)");
+    });
+
+    // 获取验证码
+    var code_getting = false;
+    $(".get-code").on("click", function() {
+        var phone = $("#phone").val();
+        if (!phone) {
+            alert("请输入手机号!");
+            return;
+        } else if (!reg.test(phone)) {
+            alert("手机号不合法!");
+            return;
+        }
+        $.ajax({
+            url:'/api/bindphone/sendcode',
+            type:'post',
+            data:{phone:phone},
+            success:function () {
+
+            }
+        });
+        if (!code_getting) {
+            code_getting = true;
+            countDown(getPhoneCodeNumber, function(time) {
+                if (time === 0) {
+                    $(".get-code").text("获取验证码");
+                    code_getting = false;
+                } else $(".get-code").text(time + "s");
+            });
+        }
+    });
+
+    // 立即绑定事件
+    $("#bind").on("click", function() {
+        var phone = $("#phone").val();
+        var code = $("#code").val();
+        if (!phone || !code) alert("手机号或验证码不能为空");
+        else {
+            // 绑定逻辑
+            $.ajax({
+                url:'/api/bindphone/bind',
+                type:'post',
+                data:{phone:phone,code:code},
+                success:function ($res) {
+                    if($res.code == 0){
+                        $(".dialog-wrap").fadeIn();
+                    }
+                }
+            })
+        }
+    });
+
+    // 关闭弹窗
+    $(".dialog-content").delegate(".close", "click", function(e) {
+        e.stopPropagation();
+        $(".dialog-wrap").fadeOut();
+        setTimeout(function(){
+            location.href = "{!! $url !!}";
+        },50);
+    })
+
+
+</script>
+</html>