Merge branch 'master' of http://114.215.101.231:8099/lihan/integral into juan
正在显示
2 个修改的文件
包含
102 行增加
和
84 行删除
@@ -45,7 +45,7 @@ class FriendController extends HomeBaseController | @@ -45,7 +45,7 @@ class FriendController extends HomeBaseController | ||
45 | return $this->fetch(':friend_list', [ | 45 | return $this->fetch(':friend_list', [ |
46 | 'keyword' => $keyword, | 46 | 'keyword' => $keyword, |
47 | 'list' => $list, | 47 | 'list' => $list, |
48 | - 'balance' => Db::name('user')->where(['id'=>session('user.id')])->value('balance') | 48 | + 'balance' => Db::name('user')->where(['id' => session('user.id')])->value('balance') |
49 | ]); | 49 | ]); |
50 | } else { | 50 | } else { |
51 | $this->error('查无此人'); | 51 | $this->error('查无此人'); |
@@ -60,73 +60,83 @@ class FriendController extends HomeBaseController | @@ -60,73 +60,83 @@ class FriendController extends HomeBaseController | ||
60 | Db::startTrans(); | 60 | Db::startTrans(); |
61 | $uid = session('user.id'); | 61 | $uid = session('user.id'); |
62 | $total = $request->param('total'); | 62 | $total = $request->param('total'); |
63 | - //获取赠送者角色、父级和当前积分 | ||
64 | - $info = Db::name('user')->field('role,parent_id,balance')->where(['id' => $uid])->find(); | ||
65 | - //判断此人积分是否足够赠送,且是否能被500整除 | ||
66 | - if ($info['balance'] < $total && $total >= 0) { | ||
67 | - echo json_encode(['msg' => '您的积分不足', 'status' => false]); | 63 | + //获取赠送者角色、父级、当前积分和赠送密码 |
64 | + $info = Db::name('user')->field('role,parent_id,balance,integral_pwd')->where(['id' => $uid])->find(); | ||
65 | + $integral_pwd = $request->param('integral_pwd'); | ||
66 | + //判断密码是否正确 | ||
67 | + if (md5($integral_pwd) != $info['integral_pwd']) { | ||
68 | + echo json_encode(['msg' => '密码错误', 'status' => false]); | ||
68 | exit(); | 69 | exit(); |
69 | } else { | 70 | } else { |
70 | - if ($total % 500 != 0) { | ||
71 | - echo json_encode(['msg' => '赠送积分必须是500积分的整数倍', 'status' => false]); | 71 | + //判断此人积分是否足够赠送,且是否能被500整除 |
72 | + if ($info['balance'] < $total && $total >= 0) { | ||
73 | + echo json_encode(['msg' => '您的积分不足', 'status' => false]); | ||
72 | exit(); | 74 | exit(); |
73 | } else { | 75 | } else { |
74 | - $parent_id = ($info['role'] == 2) ? $uid : $info['parent_id']; | ||
75 | - $tag = true; | ||
76 | - $friend_id = $request->param('friend_id'); | ||
77 | - $friend_parent_id = Db::name('user')->where(['id' => $friend_id])->value('parent_id'); | ||
78 | - //如果此人有父级id或本身就是代理员,检测被分享人是否有父级id,若没有则绑定关系 | ||
79 | - if (!empty($parent_id)) { | ||
80 | - if (empty($friend_parent_id)) { | ||
81 | - $bind = [ | ||
82 | - 'id' => $friend_id, | ||
83 | - 'parent_id' => $parent_id | ||
84 | - ]; | ||
85 | - if (Db::name('user')->update($bind)) { | ||
86 | - $tag = true; | ||
87 | - } else { | ||
88 | - $tag = false; | ||
89 | - } | ||
90 | - } | ||
91 | - } | ||
92 | - //判断两人是否首次赠送 | ||
93 | - if ($tag) { | ||
94 | - $ship = [ | ||
95 | - 'uid' => $uid, | ||
96 | - 'friend_uid' => $friend_id, | ||
97 | - ]; | ||
98 | - //非首次赠送,积分叠加 | ||
99 | - if (Db::name('friendship')->where($ship)->count()) { | ||
100 | - if (Db::name('friendship')->where($ship)->setInc('total', $total)) { | ||
101 | - $tag = true; | ||
102 | - } else { | ||
103 | - $tag = false; | ||
104 | - } | ||
105 | - } //首次赠送,插入好友表 | ||
106 | - else { | ||
107 | - $ship['total'] = $total; | ||
108 | - if (Db::name('friendship')->insert($ship)) { | ||
109 | - $tag = true; | ||
110 | - } else { | ||
111 | - $tag = false; | 76 | + if ($total % 500 != 0) { |
77 | + echo json_encode(['msg' => '赠送积分必须是500积分的整数倍', 'status' => false]); | ||
78 | + exit(); | ||
79 | + } else { | ||
80 | + $parent_id = ($info['role'] == 2) ? $uid : $info['parent_id']; | ||
81 | + $tag = true; | ||
82 | + $friend_id = $request->param('friend_id'); | ||
83 | + $friend_parent_id = Db::name('user')->where(['id' => $friend_id])->value('parent_id'); | ||
84 | + //如果此人有父级id或本身就是代理员,检测被分享人是否有父级id,若没有则绑定关系 | ||
85 | + if (!empty($parent_id)) { | ||
86 | + if (empty($friend_parent_id)) { | ||
87 | + $bind = [ | ||
88 | + 'id' => $friend_id, | ||
89 | + 'parent_id' => $parent_id | ||
90 | + ]; | ||
91 | + if (Db::name('user')->update($bind)) { | ||
92 | + $tag = true; | ||
93 | + } else { | ||
94 | + $tag = false; | ||
95 | + } | ||
112 | } | 96 | } |
113 | } | 97 | } |
114 | - //好友表建立后赠送者减积分,被赠送者加积分 | 98 | + //判断两人是否首次赠送 |
115 | if ($tag) { | 99 | if ($tag) { |
116 | - //赠送时 | ||
117 | - if ($total > 0) { | ||
118 | - if (Db::name('user')->where(['id' => $uid])->setDec('balance', $total)) { | ||
119 | - if (Db::name('user')->where(['id' => $friend_id])->setInc('balance', $total)) { | ||
120 | - //插入赠送记录日志log | ||
121 | - $log = [ | ||
122 | - 'uid' => $friend_id, | ||
123 | - 'create_time' => time(), | ||
124 | - 'balance' => $total, | ||
125 | - 'type' => 3 | ||
126 | - ]; | ||
127 | - if (Db::name('zj_integral_log')->insert($log)) { | ||
128 | - Db::commit(); | ||
129 | - $tag = true; | 100 | + $ship = [ |
101 | + 'uid' => $uid, | ||
102 | + 'friend_uid' => $friend_id, | ||
103 | + ]; | ||
104 | + //非首次赠送,积分叠加 | ||
105 | + if (Db::name('friendship')->where($ship)->count()) { | ||
106 | + if (Db::name('friendship')->where($ship)->setInc('total', $total)) { | ||
107 | + $tag = true; | ||
108 | + } else { | ||
109 | + $tag = false; | ||
110 | + } | ||
111 | + } //首次赠送,插入好友表 | ||
112 | + else { | ||
113 | + $ship['total'] = $total; | ||
114 | + if (Db::name('friendship')->insert($ship)) { | ||
115 | + $tag = true; | ||
116 | + } else { | ||
117 | + $tag = false; | ||
118 | + } | ||
119 | + } | ||
120 | + //好友表建立后赠送者减积分,被赠送者加积分 | ||
121 | + if ($tag) { | ||
122 | + //赠送时 | ||
123 | + if ($total > 0) { | ||
124 | + if (Db::name('user')->where(['id' => $uid])->setDec('balance', $total)) { | ||
125 | + if (Db::name('user')->where(['id' => $friend_id])->setInc('balance', $total)) { | ||
126 | + //插入赠送记录日志log | ||
127 | + $log = [ | ||
128 | + 'uid' => $friend_id, | ||
129 | + 'create_time' => time(), | ||
130 | + 'balance' => $total, | ||
131 | + 'type' => 3 | ||
132 | + ]; | ||
133 | + if (Db::name('zj_integral_log')->insert($log)) { | ||
134 | + Db::commit(); | ||
135 | + $tag = true; | ||
136 | + } else { | ||
137 | + Db::rollback(); | ||
138 | + $tag = false; | ||
139 | + } | ||
130 | } else { | 140 | } else { |
131 | Db::rollback(); | 141 | Db::rollback(); |
132 | $tag = false; | 142 | $tag = false; |
@@ -135,36 +145,33 @@ class FriendController extends HomeBaseController | @@ -135,36 +145,33 @@ class FriendController extends HomeBaseController | ||
135 | Db::rollback(); | 145 | Db::rollback(); |
136 | $tag = false; | 146 | $tag = false; |
137 | } | 147 | } |
138 | - } else { | ||
139 | - Db::rollback(); | ||
140 | - $tag = false; | 148 | + } //只加好友 |
149 | + else { | ||
150 | + Db::commit(); | ||
151 | + $tag = true; | ||
141 | } | 152 | } |
142 | - } //只加好友 | ||
143 | - else { | ||
144 | - Db::commit(); | ||
145 | - $tag = true; | 153 | + } else { |
154 | + Db::rollback(); | ||
155 | + $tag = false; | ||
146 | } | 156 | } |
147 | } else { | 157 | } else { |
148 | Db::rollback(); | 158 | Db::rollback(); |
149 | $tag = false; | 159 | $tag = false; |
150 | } | 160 | } |
151 | - } else { | ||
152 | - Db::rollback(); | ||
153 | - $tag = false; | ||
154 | - } | ||
155 | 161 | ||
156 | - if ($tag) { | ||
157 | - if ($total == 0) { | ||
158 | - $msg = '添加好友成功'; | 162 | + if ($tag) { |
163 | + if ($total == 0) { | ||
164 | + $msg = '添加好友成功'; | ||
165 | + } else { | ||
166 | + $msg = '赠送积分成功'; | ||
167 | + } | ||
159 | } else { | 168 | } else { |
160 | - $msg = '赠送积分成功'; | 169 | + $msg = '未知错误'; |
161 | } | 170 | } |
162 | - } else { | ||
163 | - $msg = '未知错误'; | ||
164 | - } | ||
165 | 171 | ||
166 | - echo json_encode(['msg' => $msg, 'status' => $tag]); | ||
167 | - exit(); | 172 | + echo json_encode(['msg' => $msg, 'status' => $tag]); |
173 | + exit(); | ||
174 | + } | ||
168 | } | 175 | } |
169 | } | 176 | } |
170 | } | 177 | } |
@@ -361,7 +361,7 @@ | @@ -361,7 +361,7 @@ | ||
361 | } | 361 | } |
362 | }) | 362 | }) |
363 | 363 | ||
364 | - var arr=[]; | 364 | + |
365 | var str="" | 365 | var str="" |
366 | var txts = wrap.getElementsByClassName("entercode"); | 366 | var txts = wrap.getElementsByClassName("entercode"); |
367 | //输入的密码自动输入到下一个 | 367 | //输入的密码自动输入到下一个 |
@@ -370,22 +370,26 @@ | @@ -370,22 +370,26 @@ | ||
370 | for(var i=0;i<txts.length;i++){ | 370 | for(var i=0;i<txts.length;i++){ |
371 | $(txts[i]).val("") | 371 | $(txts[i]).val("") |
372 | } | 372 | } |
373 | + | ||
373 | for(var i = 0; i<txts.length;i++){ | 374 | for(var i = 0; i<txts.length;i++){ |
375 | + | ||
374 | var t = txts[i]; | 376 | var t = txts[i]; |
375 | t.index = i; | 377 | t.index = i; |
376 | if(t.index>0){ | 378 | if(t.index>0){ |
377 | t.setAttribute("readonly", true); | 379 | t.setAttribute("readonly", true); |
378 | } | 380 | } |
379 | t.onkeyup=function(){ | 381 | t.onkeyup=function(){ |
380 | - | 382 | + var arr=[]; |
381 | var regular = /\s+/g; | 383 | var regular = /\s+/g; |
382 | if(regular.test(this.value)){ | 384 | if(regular.test(this.value)){ |
383 | $(this).focus(); | 385 | $(this).focus(); |
384 | }else if($(this).val()==""){ | 386 | }else if($(this).val()==""){ |
385 | $(this).focus(); | 387 | $(this).focus(); |
386 | }else{ | 388 | }else{ |
389 | + | ||
387 | console.log($(this).val()); | 390 | console.log($(this).val()); |
388 | arr.push($(this).val()); | 391 | arr.push($(this).val()); |
392 | + console.log(arr) | ||
389 | var next = this.index + 1; | 393 | var next = this.index + 1; |
390 | if(next > txts.length - 1) return; | 394 | if(next > txts.length - 1) return; |
391 | txts[next].removeAttribute("readonly"); | 395 | txts[next].removeAttribute("readonly"); |
@@ -399,6 +403,8 @@ | @@ -399,6 +403,8 @@ | ||
399 | str=arr[0]+arr[1]+arr[2]+arr[3]+arr[4]+arr[5]; | 403 | str=arr[0]+arr[1]+arr[2]+arr[3]+arr[4]+arr[5]; |
400 | console.log(str) | 404 | console.log(str) |
401 | 405 | ||
406 | + | ||
407 | + | ||
402 | $.ajax({ | 408 | $.ajax({ |
403 | url:"{:url('friendship/Friend/donateIntegral')}", | 409 | url:"{:url('friendship/Friend/donateIntegral')}", |
404 | data:{ | 410 | data:{ |
@@ -411,11 +417,16 @@ | @@ -411,11 +417,16 @@ | ||
411 | 417 | ||
412 | success: function (data) { | 418 | success: function (data) { |
413 | if(data.status === true) { | 419 | if(data.status === true) { |
420 | + window.event.stopPropagation() | ||
421 | + $(".passwordwrap").css("display","none") | ||
414 | alert(data.msg); | 422 | alert(data.msg); |
415 | - window.location.reload(); | ||
416 | }else { | 423 | }else { |
417 | alert(data.msg); | 424 | alert(data.msg); |
418 | } | 425 | } |
426 | + //清空数据 | ||
427 | + for (var i = 0; i < txts.length; i++) { | ||
428 | + $(txts[i]).val("") | ||
429 | + } | ||
419 | } | 430 | } |
420 | }) | 431 | }) |
421 | } | 432 | } |
-
请 注册 或 登录 后发表评论