sunhao 5 years ago
parent
commit
b328a78be3

+ 70 - 9
app/Http/Controllers/Admin/CustomerDepositController.php

@@ -114,9 +114,14 @@ class CustomerDepositController extends Controller
114 114
      */
115 115
     public function store(Request $request)
116 116
     {
117
+        $pay_money = $request->input('pay_money');
118
+        $pack_required = 'required';
119
+        if($pay_money>0){
120
+            $pack_required = '';
121
+        }
117 122
         $this->validate($request, [
118 123
             'phone' => 'required',   
119
-            'package_id' => 'required',        
124
+            'package_id' => $pack_required,        
120 125
             'pay_time' => 'required',        
121 126
                 
122 127
         ], [
@@ -126,18 +131,27 @@ class CustomerDepositController extends Controller
126 131
             
127 132
         ]);
128 133
         $admin_id = session('admin_id');
129
-        $package_id = (int)$request->input('package_id');
130
-        $package_info = CustomerDepositPackages::where('id', $package_id)->first();
131
-
134
+        
132 135
         $deposit = new CustomerDeposit();
133 136
         $deposit->phone = $request->input('phone');
134
-        $deposit->pay_amount = $package_info->pay_amount;
135
-        $deposit->discount = $package_info->discount;
136
-        $deposit->deposit_amount = $deposit->pay_amount + $deposit->discount;
137
-        $deposit->note = $package_info->note;
138 137
         $deposit->admin_id = $admin_id;
139 138
         $deposit->pay_time = $request->input('pay_time');
140
-    
139
+
140
+        if($pay_money>0){
141
+            //自定义充值
142
+            $deposit->pay_amount = $pay_money;
143
+            $deposit->discount = 0;
144
+            $deposit->deposit_amount = $pay_money;
145
+            $deposit->note = '自定义充值';
146
+        }else{
147
+            $package_id = (int)$request->input('package_id');
148
+            $package_info = CustomerDepositPackages::where('id', $package_id)->first();
149
+            $deposit->pay_amount = $package_info->pay_amount;
150
+            $deposit->discount = $package_info->discount;
151
+            $deposit->deposit_amount = $deposit->pay_amount + $deposit->discount;
152
+            $deposit->note = $package_info->note;
153
+        }
154
+        
141 155
         if($deposit->save()){
142 156
             //变更余额
143 157
             $name = trim( $request->input('name') );
@@ -207,4 +221,51 @@ class CustomerDepositController extends Controller
207 221
         return redirect('/admin/template/index')->with('info', '修改模板成功');
208 222
     }
209 223
 
224
+    //获余额
225
+    public function getBalance($phone){
226
+        $result = CustomerInfo::where('phone', $phone)->pluck('balance');
227
+        if(empty($result)){
228
+            exit('0');
229
+        }
230
+        exit($result);
231
+    }
232
+
233
+    /**
234
+     * @return \Illuminate\View\View
235
+     */
236
+    public function consumList(Request $request)
237
+    {
238
+        $phone = $request->input('phone');
239
+        $page = (int)$request->input('page');
240
+        $pageSize = 20;
241
+        if($page<=0){
242
+            $page = 1;
243
+        }
244
+
245
+        $offset = ($page-1) * $pageSize;
246
+
247
+        $count = CustomerConsum::where(function($query) use($phone){
248
+            if($phone) $query->where('phone', $phone);
249
+        })->where('is_del',0)->count();
250
+        if ($count > 1) {
251
+            // 总页数
252
+            $pages = ceil($count/$pageSize);
253
+        }else{
254
+            // 总页数
255
+            $pages = 1;
256
+        }
257
+
258
+        $result = CustomerConsum::where(function($query) use($phone){
259
+            if($phone) $query->where('phone', $phone);
260
+        })->where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
261
+        $result = json_decode(json_encode($result),true);
262
+
263
+        return view('deposit/consumList', ['result' =>$result,
264
+            'page'              =>$page,
265
+            'count'             =>$count,
266
+            'pages'             =>$pages,  
267
+            'phone'             =>$phone                 
268
+            ]);
269
+    }
270
+
210 271
 }

+ 90 - 2
app/Http/Controllers/Admin/OrderController.php

@@ -15,6 +15,8 @@ use App\RedisModel;
15 15
 use App\Goods;
16 16
 use App\GoodsSkus;
17 17
 use App\OrderGoodsSkus;
18
+use App\CustomerInfo;
19
+use App\CustomerConsum;
18 20
 use Illuminate\Http\Request;
19 21
 use Illuminate\Support\Facades\DB;
20 22
 
@@ -535,7 +537,7 @@ class OrderController extends Controller
535 537
             return redirect('/admin/order/index')->with('info', $msg);
536 538
         }
537 539
         $res = RedisModel::expire( $redisKey, 60 );
538
-       
540
+        
539 541
         $skus = $request->input('skus');
540 542
         $warehouse = (int)$request->input('warehouse');
541 543
         if($warehouse == 3 && empty($skus)){
@@ -620,7 +622,17 @@ class OrderController extends Controller
620 622
         $order['delivery_date'] = !empty($request->input('delivery_date')) ? $request->input('delivery_date') : date('Y-m-d'); //发货日期
621 623
         $order['order_status'] = (int)$request->input('order_status');
622 624
         $order['payment_type'] = (int)$request->input('payment_type'); //支付方式
623
-
625
+       
626
+        //充值卡验证余额
627
+        if($order['payment_type'] == 4){
628
+            $deposit_phone = $request->input('deposit_phone');
629
+            $customerInfo = CustomerInfo::where('phone', $deposit_phone)->first();
630
+            $balance = $customerInfo->balance;
631
+            if($balance < $order['receivedAmount']){
632
+                //余额不足
633
+                return redirect('/admin/order/index')->with('info', '充值卡余额不足');
634
+            }
635
+        }
624 636
         DB::beginTransaction();
625 637
         try{      
626 638
 
@@ -682,6 +694,18 @@ class OrderController extends Controller
682 694
                     }
683 695
                     $order_skus_insert = DB::table('order_goods_skus')->insert($order_skus);
684 696
                 }
697
+
698
+                #新加逻辑,若付款方式为充值卡/消费记录
699
+                if($order['payment_type'] == 4){
700
+                    $consum = new CustomerConsum();
701
+                    $consum->phone = $deposit_phone;
702
+                    $consum->order_id = $res;
703
+                    $consum->money = $order['receivedAmount'];
704
+                    $consum->save();
705
+                    //更新余额                   
706
+                    $customerInfo->balance = $customerInfo->balance - $order['receivedAmount'];
707
+                    $customerInfo->save();
708
+                }
685 709
                 #记录操作日志
686 710
                 $self_id = session('admin_id');
687 711
                 $self_name = session('real_name');
@@ -745,6 +769,12 @@ class OrderController extends Controller
745 769
             }
746 770
             $order['goods'] = $goods;
747 771
         }
772
+
773
+        $deposit_phone = '';
774
+        if($order['payment_type'] == 4){
775
+            $consum = CustomerConsum::select('phone')->where('order_id', $id)->first();
776
+            $deposit_phone = isset($consum->phone) ? $consum->phone : '';
777
+        }
748 778
         return view('order/orderedit', [       
749 779
             'order' => $order,
750 780
             //'categorylist' => $catelist,
@@ -753,6 +783,7 @@ class OrderController extends Controller
753 783
             'self_role'=>$self_role,
754 784
             'str_query'=> 'page='.$page.'&admin_id='.$admin_id.'&stime='.$stime.'&etime='.$etime.'&receiverName='.$receiverName.'&receiverMobile='.$receiverMobile,
755 785
             'last_url' => $last_url,
786
+            'deposit_phone' => $deposit_phone,
756 787
         ]);
757 788
 
758 789
     }
@@ -830,6 +861,7 @@ class OrderController extends Controller
830 861
         //if(!empty($request->input('createTime'))) $order['createTime'] = $request->input('createTime'); // 订单创建时间
831 862
         $order['order_status'] = (int)$request->input('order_status');
832 863
         $order['payment_type'] = (int)$request->input('payment_type'); //支付方式
864
+
833 865
         //$order['status'] = (int)$request->input('status');
834 866
         $order['should_amount'] = $request->input('should_amount');
835 867
         if(!$order['should_amount']) $order['should_amount'] = null;
@@ -845,6 +877,27 @@ class OrderController extends Controller
845 877
         $id = (int)$request->input('id');
846 878
         //获取订单原信息
847 879
         $old_order = DB::table('order')->where('id', $id)->first();
880
+
881
+        // ++++++充值卡验证余额逻辑 +++++++ //
882
+        if($order['payment_type'] == 4){
883
+            $deposit_phone = $request->input('deposit_phone');
884
+            if($old_order->payment_type != 4){                            
885
+                $customerInfo = CustomerInfo::where('phone', $deposit_phone)->first();
886
+                $balance = $customerInfo->balance;
887
+                if($balance < $order['receivedAmount']){
888
+                    //余额不足
889
+                    return redirect('/admin/order/index')->with('info', '充值卡余额不足');
890
+                }               
891
+            }elseif($old_order->receivedAmount != $order['receivedAmount']){              
892
+                $customerInfo = CustomerInfo::where('phone', $deposit_phone)->first();
893
+                $balance = $customerInfo->balance;
894
+                if( $balance < $order['receivedAmount']-$old_order->receivedAmount ){
895
+                    //余额不足
896
+                    return redirect('/admin/order/index')->with('info', '充值卡余额不足');
897
+                }
898
+            }
899
+        }
900
+
848 901
         $today_date = date('Y-m-d');
849 902
         //是否同步卖家
850 903
         $mjFlag = 0;
@@ -983,6 +1036,28 @@ class OrderController extends Controller
983 1036
                     }
984 1037
                 }
985 1038
                
1039
+                #新加逻辑,若付款方式为充值卡/消费记录
1040
+                if($order['payment_type'] == 4 ){
1041
+                    if($old_order->payment_type != 4 ){
1042
+                        $consum = new CustomerConsum();
1043
+                        $consum->phone = $deposit_phone;
1044
+                        $consum->order_id = $id;
1045
+                        $consum->money = $order['receivedAmount'];
1046
+                        $consum->save();
1047
+                        //更新余额                   
1048
+                        $customerInfo->balance = $customerInfo->balance - $order['receivedAmount'];
1049
+                        $customerInfo->save();
1050
+                    }elseif($old_order->receivedAmount != $order['receivedAmount']){
1051
+                        $consum = CustomerConsum::where('order_id', $id)->first();                       
1052
+                        $consum->money = $order['receivedAmount'];
1053
+                        $consum->save();
1054
+                        //更新余额
1055
+                        $add_amount = $order['receivedAmount'] - $old_order->receivedAmount; //新增消费额,有可能为负数
1056
+                        $customerInfo->balance = $customerInfo->balance - $add_amount;
1057
+                        $customerInfo->save();
1058
+                    }
1059
+                }
1060
+
986 1061
                 #记录操作日志
987 1062
                 $self_id = session('admin_id');
988 1063
                 $self_name = session('real_name');            
@@ -1029,6 +1104,19 @@ class OrderController extends Controller
1029 1104
                         throw new Exception("订单同步到卖家云失败");
1030 1105
                     }
1031 1106
                 }
1107
+
1108
+                //假如删除订单为充值卡订单,返还余额
1109
+                if($order->payment_type == 4){
1110
+                    //查询消费记录/卡号
1111
+                    $consum = CustomerConsum::where('order_id', $id)->where('is_del', 0)->first();
1112
+                    //消费记录设为删除
1113
+                    CustomerConsum::where('order_id', $id)->update(['is_del'=>1]);
1114
+                    //余额返还
1115
+                    $cust = CustomerInfo::select('balance')->where('phone', $consum->phone)->first();
1116
+                    $balance = $cust->balance + $order->receivedAmount;
1117
+                    CustomerInfo::where('phone', $consum->phone)->update(['balance'=>$balance]);
1118
+                }
1119
+
1032 1120
                 #记录操作日志
1033 1121
                 $self_id = session('admin_id');
1034 1122
                 $self_name = session('real_name');            

+ 4 - 1
app/Http/routes.php

@@ -242,13 +242,16 @@ Route::group(['prefix' => 'admin'], function(){
242 242
         Route::get('statistics/dayGrandTeamTotal_export',   'Admin\StatisticsController@dayGrandTeamTotal_export');
243 243
 
244 244
         //充值
245
-        Route::get('deposit/index', 'Admin\CustomerDepositController@index');
245
+        Route::get('deposit/index', 'Admin\CustomerDepositController@index');  //充值记录
246
+        Route::get('deposit/consumList', 'Admin\CustomerDepositController@consumList'); //消费记录
246 247
         Route::get('deposit/customerList', 'Admin\CustomerDepositController@customerList');
247 248
         Route::get('deposit/create', 'Admin\CustomerDepositController@create');
248 249
         Route::post('deposit/store', 'Admin\CustomerDepositController@store');
249 250
         Route::get('deposit/edit', 'Admin\CustomerDepositController@edit');
250 251
         Route::post('deposit/update', 'Admin\CustomerDepositController@update');
251 252
         Route::get('deposit/del/{id}', 'Admin\CustomerDepositController@delete');
253
+        //获取余额
254
+        Route::get('cust/getBalance/{phone}', 'Admin\CustomerDepositController@getBalance');
252 255
 
253 256
     });
254 257
     

+ 1 - 1
resources/views/admin/index.blade.php

@@ -104,7 +104,7 @@
104 104
             </dl>
105 105
 
106 106
              <dl id="menu-deposit">
107
-                <dt @if(!isset($res['deposit/manage'])) style="display:none;list-style-type:none;" @endif><i class="Hui-iconfont">&#xe634;</i> 充值管理<i class="Hui-iconfont menu_dropdown-arrow">&#xe6d5;</i></dt>
107
+                <dt @if(!isset($res['deposit/manage'])) style="display:none;list-style-type:none;" @endif><i class="Hui-iconfont">&#xe692;</i> 充值管理<i class="Hui-iconfont menu_dropdown-arrow">&#xe6d5;</i></dt>
108 108
                 <dd>
109 109
                     <ul>                       
110 110
                         <li @if(!isset($res['deposit/manage'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/deposit/customerList')}}" data-title="客户充值信息" href="javascript:void(0)">客户充值信息</a></li>                        

+ 81 - 0
resources/views/deposit/consumList.blade.php

@@ -0,0 +1,81 @@
1
+@extends('admin/master')
2
+@section('content')
3
+    <body>
4
+    @if(session('info'))
5
+        <div class="Huialert Huialert-info" onclick="$(this).remove()" id="info">
6
+            {{session('info')}}
7
+        </div>
8
+    @endif
9
+    <div class="page-container">
10
+        <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"> <a class="btn btn-primary radius" href="/admin/deposit/customerList"> 返回</a></span> </div>
11
+        <div class="mt-20">
12
+            <table class="table table-border table-bordered table-bg table-hover table-sort">
13
+                <thead>
14
+                <tr class="text-c">
15
+                    {{--<th width="25"><input type="checkbox" name="" value=""></th>--}}
16
+                    <th width="10%">账号</th>                   
17
+                    <th width="10%">消费金额</th>
18
+                    <th width="10%">订单ID</th>
19
+                    <th width="10%">时间</th>
20
+                </tr>
21
+                </thead>
22
+                <tbody>
23
+                @if($result)
24
+                @foreach($result as $a)
25
+                    <tr class="text-c">
26
+                        {{--<td><input name="" type="checkbox" value=""></td>--}}
27
+                        <td class="text-c">{{$a['phone']}}</td>
28
+                        <td class="text-c">{{$a['money']}}</td>
29
+                        <td class="text-c">{{$a['order_id']}}</td>
30
+                        <td class="text-c">{{$a['create_time']}}</td>
31
+                        
32
+                    </tr>
33
+                @endforeach
34
+                @endif
35
+                </tbody>
36
+            </table>
37
+        </div>
38
+        <div id="page" class="page_div"></div>
39
+    </div>
40
+
41
+    <!--_footer 作为公共模版分离出去-->
42
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
43
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
44
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
45
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
46
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
47
+    <!--/_footer 作为公共模版分离出去-->
48
+    <!--/_footer 作为公共模版分离出去-->
49
+
50
+    <script type="text/javascript">
51
+        $(function(){
52
+            setTimeout("$('#info').hide()",3000);
53
+        });
54
+        /*管理员-添加*/
55
+        function admin_add(title, phone){
56
+            location.href = '/admin/deposit/create?phone='+phone;
57
+        }
58
+        /*管理员-编辑*/
59
+        function admin_edit(title,id){
60
+            location.href = "/admin/admin/teamedit/"+id;
61
+        }
62
+
63
+        function depositlist(title,phone){
64
+            location.href = '/admin/deposit/index?phone='+phone;
65
+        }
66
+
67
+
68
+        $("#page").paging({ 
69
+            pageNo:{{$page}},
70
+            totalPage: {{$pages}},
71
+            totalSize: {{$count}},
72
+            callback: function(num) {
73
+                var phone = '{{$phone}}'
74
+                location.href='consumList?page='+num+'&phone='+phone;
75
+            }
76
+        })
77
+
78
+    </script>
79
+    </body>
80
+
81
+@endsection

+ 8 - 0
resources/views/deposit/create.blade.php

@@ -55,6 +55,14 @@
55 55
             </div>
56 56
             <div class="row cl">
57 57
                 <label class="form-label col-xs-4 col-sm-2">
58
+                    自定义金额:</label>
59
+                <div class="formControls col-xs-6 col-sm-6">
60
+                    <input type="text" class="input-text" value="{{old('pay_money')}}" placeholder="填写自定义金额套餐将不会生效" name="pay_money">
61
+                    
62
+                </div>
63
+            </div>
64
+            <div class="row cl">
65
+                <label class="form-label col-xs-4 col-sm-2">
58 66
                     <font color='red'>* </font>充值时间:</label>
59 67
                 <div class="formControls col-xs-6 col-sm-6">
60 68
                     <input id="pay_time" type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd HH:mm:ss' })" autocomplete="off"  class="input-text Wdate" style="width:30%;text-align:center;" name="pay_time" value="{{old('pay_time')}}"> <font color='red'>  </font>                  

+ 6 - 0
resources/views/deposit/customerList.blade.php

@@ -40,6 +40,7 @@
40 40
                         <td class="text-c">{{$a['balance']}}</td>
41 41
                         <td class="f-14 product-brand-manage"><!--a style="text-decoration:none" onClick='admin_edit("编辑团队","{{$a['id']}}")' href="javascript:;" title="编辑团队"><span class="btn btn-primary radius">编辑</span></a> <a style="text-decoration:none" class="ml-5" onClick="admin_del(this, '{{$a['id']}}')" href="javascript:;" title="删除"><span class="btn btn-danger radius">删除</span></a-->
42 42
                             <a style="text-decoration:none" onClick='depositlist("查看充值记录","{{$a['phone']}}")' href="javascript:;" title="查看充值记录"><span class="btn btn-primary radius">查看充值记录</span></a>
43
+                            <a style="text-decoration:none" onClick='consumlist("查看充值记录","{{$a['phone']}}")' href="javascript:;" title="查看消费记录"><span class="btn btn-warning radius">查看消费记录</span></a>
43 44
                         </td>
44 45
                     </tr>
45 46
                 @endforeach
@@ -75,6 +76,11 @@
75 76
         function depositlist(title,phone){
76 77
             location.href = '/admin/deposit/index?phone='+phone;
77 78
         }
79
+
80
+        function consumlist(title,phone){
81
+            location.href = '/admin/deposit/consumList?phone='+phone;
82
+        }
83
+
78 84
         function user_search(){
79 85
             var phone = $('#phone').val();
80 86
             var name = $('#name').val();

+ 84 - 1
resources/views/order/ordercreate.blade.php

@@ -201,10 +201,21 @@
201 201
                     <!--input type="radio" name="payment_type" value="2" @if(old('payment_type')==='2') checked @endif>
202 202
                     <label for="status-0">付款码支付</label-->
203 203
                     <input type="radio" name="payment_type" value="3" @if(old('payment_type')==='3') checked @endif>
204
-                    <label for="status-0">个体户支付</label>
204
+                    <label for="status-0" style="margin-right: 27px;">个体户支付</label>
205
+                    <input type="radio" name="payment_type" value="4" @if(old('payment_type')==='4') checked @endif>
206
+                    <label for="status-0">充值卡支付</label>
207
+                </div>
208
+            </div>
209
+            <div class="row cl" style="display: none" id='deposit_div'>
210
+                <label class="form-label col-xs-4 col-sm-2">
211
+                    <font color='red'> </font>充值卡号:</label>
212
+                <div class="formControls col-xs-6 col-sm-6">
213
+                    <input id='deposit_phone' type="text" class="input-text" onkeyup="getBalance()" value="{{old('deposit_phone')}}" placeholder="" name="deposit_phone">
214
+                    <font color='red' id='vip_pay'></font>
205 215
                 </div>
206 216
             </div>
207 217
 
218
+
208 219
             <div class="row cl">
209 220
                 <label class="form-label col-xs-4 col-sm-2">
210 221
                     <font color='red'>* </font>是否退补单:</label>
@@ -350,8 +361,50 @@
350 361
                     }
351 362
                 });
352 363
             })
364
+
365
+            $('input[type=radio][name=payment_type]').change(function () {
366
+                var payment_type = $("input[type='radio'][name='payment_type']:checked").val();
367
+                if(payment_type==4){
368
+                    var phone = $("input[name=receiverMobile]").val();
369
+                    $("#deposit_phone").val(phone);
370
+                    $("#deposit_div").show();
371
+                    //获取充值卡余额
372
+                    var reg = /^1\d{10}$/
373
+                    if(!reg.test(phone)){
374
+                        return false;
375
+                    }
376
+                    $.ajax({
377
+                        'url':'/admin/cust/getBalance/'+phone,
378
+                        'type': 'get',
379
+                        'success' : function(data){
380
+                            var str = '【充值卡余额为:'+data+'元】';
381
+                            $("#vip_pay").html(str);
382
+                        }
383
+                    });
384
+                }else{
385
+                    $("#deposit_div").hide();
386
+                }
387
+            })
353 388
             
354 389
         });
390
+
391
+        function getBalance(){
392
+            var phone = $("input[name=deposit_phone]").val();
393
+            var reg = /^1\d{10}$/
394
+            if(!reg.test(phone)){
395
+                $("#vip_pay").html('【充值卡余额为:0元】');
396
+                return false;
397
+            }
398
+            //获取充值卡余额
399
+            $.ajax({
400
+                'url':'/admin/cust/getBalance/'+phone,
401
+                'type': 'get',
402
+                'success' : function(data){
403
+                    var str = '【充值卡余额为:'+data+'元】';
404
+                    $("#vip_pay").html(str);
405
+                }
406
+            });
407
+        }
355 408
         /*返回*/
356 409
         function return_index(){
357 410
             location.href='/admin/order/index';
@@ -706,6 +759,36 @@
706 759
             return false;
707 760
         }
708 761
 
762
+        //验证充值卡
763
+        var is_ok = 1;
764
+        var payment_type = $("input[type='radio'][name='payment_type']:checked").val();
765
+        if(payment_type==4){
766
+            var phone = $("input[name=deposit_phone]").val();
767
+            if(!phone){
768
+                is_ok = 0;
769
+            }
770
+            //获取充值卡余额
771
+            $.ajax({
772
+                url:'/admin/cust/getBalance/'+phone,
773
+                type: 'get',
774
+                async:false,
775
+                success : function(data){
776
+                    data=parseFloat(data);
777
+                    receivedAmount=parseFloat(receivedAmount);
778
+                    if(data<receivedAmount){
779
+                        is_ok = 0;
780
+                    }else{
781
+                        is_ok = 1;
782
+                    } 
783
+                }
784
+            });
785
+
786
+            if(is_ok==0){
787
+                layer.msg('充值卡余额不足,请充值或选择其他付款方式!',{icon:2,time:1500});
788
+                return false;
789
+            }
790
+        }
791
+
709 792
         return true;
710 793
 
711 794
      }

+ 130 - 0
resources/views/order/orderedit.blade.php

@@ -226,6 +226,16 @@
226 226
             </div>
227 227
             @endif
228 228
 
229
+            @if($order['payment_type']=='4')
230
+            <div class="row cl">
231
+                <label class="form-label col-xs-4 col-sm-2">
232
+                    <font color='red'>* </font>支付方式:</label>
233
+                <div class="formControls col-xs-6 col-sm-6">
234
+                    <input type="radio" name="payment_type" value="4" checked >
235
+                    <label for="status-0" style="margin-right: 27px;">充值卡支付</label>
236
+                </div>
237
+            </div>
238
+            @else
229 239
             <div class="row cl">
230 240
                 <label class="form-label col-xs-4 col-sm-2">
231 241
                     <font color='red'>* </font>支付方式:</label>
@@ -238,8 +248,33 @@
238 248
                     @endif
239 249
                     <input type="radio" name="payment_type" value="3" @if($order['payment_type']=='3') checked @endif>
240 250
                     <label for="status-0" style="margin-right: 27px;">个体户支付</label>
251
+
252
+                    <input type="radio" name="payment_type" value="4" @if($order['payment_type']=='4') checked @endif>
253
+                    <label for="status-0" style="margin-right: 27px;">充值卡支付</label>
241 254
                 </div>
242 255
             </div>
256
+            @endif
257
+
258
+            @if($order['payment_type'] != 4)
259
+            <div class="row cl"  style="display: none" id='deposit_div'>
260
+                <label class="form-label col-xs-4 col-sm-2">
261
+                    <font color='red'> </font>充值卡号:</label>
262
+                <div class="formControls col-xs-6 col-sm-6">
263
+                    <input id='deposit_phone' type="text" class="input-text" onkeyup="getBalance()" value="{{old('deposit_phone')}}" placeholder="" name="deposit_phone">
264
+                    <font color='red' id='vip_pay'></font>
265
+                </div>
266
+            </div>
267
+            @else
268
+            <div class="row cl" id='deposit_div'>
269
+                <label class="form-label col-xs-4 col-sm-2">
270
+                    <font color='red'> </font>充值卡号:</label>
271
+                <div class="formControls col-xs-6 col-sm-6">
272
+                    {{$deposit_phone}}
273
+                    <input type="hidden" name='deposit_phone' value="{{$deposit_phone}}" />
274
+                    <font color='red' id='vip_pay'></font>
275
+                </div>
276
+            </div>
277
+            @endif
243 278
 
244 279
             <div class="row cl">
245 280
                 <label class="form-label col-xs-4 col-sm-2">
@@ -374,7 +409,37 @@
374 409
                     }
375 410
                 });
376 411
             })
412
+
413
+            $('input[type=radio][name=payment_type]').change(function () {
414
+                var payment_type = $("input[type='radio'][name='payment_type']:checked").val();
415
+                if(payment_type==4){
416
+                    var phone = $("input[name=receiverMobile]").val();
417
+                    $("#deposit_div").show();
418
+                }else{
419
+                    $("#deposit_div").hide();
420
+                }
421
+            })
422
+
377 423
         });
424
+
425
+        function getBalance(){
426
+            var phone = $("input[name=deposit_phone]").val();
427
+            var reg = /^1\d{10}$/
428
+            if(!reg.test(phone)){
429
+                $("#vip_pay").html('【充值卡余额为:0元】');
430
+                return false;
431
+            }
432
+            //获取充值卡余额
433
+            $.ajax({
434
+                'url':'/admin/cust/getBalance/'+phone,
435
+                'type': 'get',
436
+                'success' : function(data){
437
+                    var str = '【充值卡余额为:'+data+'元】';
438
+                    $("#vip_pay").html(str);
439
+                }
440
+            });
441
+        }
442
+
378 443
         /*返回*/
379 444
         function return_index(){
380 445
             location.href='/admin/order/index';
@@ -578,6 +643,71 @@
578 643
             return false;
579 644
         }
580 645
 
646
+        //验证充值卡
647
+        var old_payment_type = "{{$order['payment_type']}}";
648
+        var old_receivedAmount = "{{$order['receivedAmount']}}";
649
+        old_receivedAmount = parseFloat(old_receivedAmount);
650
+        var is_ok = 1;
651
+        var receivedAmount = $("input[name=receivedAmount]").val();
652
+        var payment_type = $("input[type='radio'][name='payment_type']:checked").val();
653
+
654
+
655
+        if( payment_type==4 && old_payment_type != 4 ){
656
+            var phone = $("input[name=deposit_phone]").val();
657
+            if(!phone){
658
+                is_ok = 0;
659
+            }
660
+            //获取充值卡余额
661
+            $.ajax({
662
+                url:'/admin/cust/getBalance/'+phone,
663
+                type: 'get',
664
+                async:false,
665
+                success : function(data){
666
+                    data=parseFloat(data);
667
+                    receivedAmount=parseFloat(receivedAmount);
668
+                    if(data<receivedAmount){
669
+                        is_ok = 0;
670
+                    }else{
671
+                        is_ok = 1;
672
+                    } 
673
+                }
674
+            });
675
+
676
+            if(is_ok==0){
677
+                layer.msg('充值卡余额不足,请充值后再进行该操作!',{icon:2,time:1500});
678
+                return false;
679
+            }
680
+        }
681
+
682
+        if( payment_type==4 && old_payment_type==4 && old_receivedAmount != receivedAmount ){
683
+            var phone = "{{$deposit_phone}}"
684
+            if(old_receivedAmount < receivedAmount){
685
+                //金额增加,判断余额
686
+                var money = receivedAmount - old_receivedAmount;
687
+                //获取充值卡余额
688
+                $.ajax({
689
+                    url:'/admin/cust/getBalance/'+phone,
690
+                    type: 'get',
691
+                    async:false,
692
+                    success : function(data){
693
+                        data=parseFloat(data);
694
+                        money=parseFloat(money);
695
+                        if(data<money){
696
+                            is_ok = 0;
697
+                        }else{
698
+                            is_ok = 1;
699
+                        } 
700
+                    }
701
+                });
702
+
703
+            }
704
+
705
+            if(is_ok==0){
706
+                layer.msg('充值卡余额不足,请充值后再进行该操作!',{icon:2,time:1500});
707
+                return false;
708
+            }
709
+        }
710
+
581 711
         return true;
582 712
 
583 713
      }