作者 李涵
1 个管道 的构建 通过 耗费 2 秒

合并分支 'li' 到 'master'

Li



查看合并请求 !505
@@ -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 }
@@ -410,12 +410,9 @@ @@ -410,12 +410,9 @@
410 dataType:"JSON", 410 dataType:"JSON",
411 411
412 success: function (data) { 412 success: function (data) {
413 - if(data.status === true) {  
414 - alert(data.msg);  
415 - window.location.reload();  
416 - }else {  
417 - alert(data.msg);  
418 - } 413 + alert(data.msg);
  414 + //清空数据
  415 +
419 } 416 }
420 }) 417 })
421 } 418 }