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

合并分支 'li' 到 'master'

赠送积分和角色管理



查看合并请求 !532
@@ -63,81 +63,80 @@ class FriendController extends HomeBaseController @@ -63,81 +63,80 @@ class FriendController extends HomeBaseController
63 $total = $request->param('total'); 63 $total = $request->param('total');
64 //获取赠送者角色、父级、当前积分和赠送密码 64 //获取赠送者角色、父级、当前积分和赠送密码
65 $info = Db::name('user')->field('role,parent_id,balance,integral_pwd')->where(['id' => $uid])->find(); 65 $info = Db::name('user')->field('role,parent_id,balance,integral_pwd')->where(['id' => $uid])->find();
66 - $integral_pwd = (empty($request->param('integral_pwd'))) ? $info['integral_pwd'] : $request->param('integral_pwd');  
67 - //判断密码是否正确  
68 - if (md5($integral_pwd) != $info['integral_pwd']) {  
69 - echo json_encode(['msg' => '密码错误', 'status' => false]); 66 + $integral_pwd = $request->param('integral_pwd');
  67 + //判断密码是否正确(加好友时不用验证密码)
  68 + if ($total > 0) {
  69 + if (md5($integral_pwd) != $info['integral_pwd']) {
  70 + echo json_encode(['msg' => '密码错误', 'status' => false]);
  71 + exit();
  72 + }
  73 + }
  74 +
  75 + //判断此人积分是否足够赠送,且是否能被500整除
  76 + if ($info['balance'] < $total && $total >= 0) {
  77 + echo json_encode(['msg' => '您的积分不足', 'status' => false]);
70 exit(); 78 exit();
71 } else { 79 } else {
72 - //判断此人积分是否足够赠送,且是否能被500整除  
73 - if ($info['balance'] < $total && $total >= 0) {  
74 - echo json_encode(['msg' => '您的积分不足', 'status' => false]); 80 + if ($total % 500 != 0) {
  81 + echo json_encode(['msg' => '赠送积分必须是500积分的整数倍', 'status' => false]);
75 exit(); 82 exit();
76 } else { 83 } else {
77 - if ($total % 500 != 0) {  
78 - echo json_encode(['msg' => '赠送积分必须是500积分的整数倍', 'status' => false]);  
79 - exit();  
80 - } else {  
81 - $parent_id = ($info['role'] == 2) ? $uid : $info['parent_id'];  
82 - $tag = true;  
83 - $friend_id = $request->param('friend_id');  
84 - $friend_parent_id = Db::name('user')->where(['id' => $friend_id])->value('parent_id');  
85 - //如果此人有父级id或本身就是代理员,检测被分享人是否有父级id,若没有则绑定关系  
86 - if (!empty($parent_id)) {  
87 - if (empty($friend_parent_id)) {  
88 - $bind = [  
89 - 'id' => $friend_id,  
90 - 'parent_id' => $parent_id  
91 - ];  
92 - if (Db::name('user')->update($bind)) {  
93 - $tag = true;  
94 - } else {  
95 - $tag = false;  
96 - } 84 + $parent_id = ($info['role'] == 2) ? $uid : $info['parent_id'];
  85 + $tag = true;
  86 + $friend_id = $request->param('friend_id');
  87 + $friend_parent_id = Db::name('user')->where(['id' => $friend_id])->value('parent_id');
  88 + //如果此人有父级id或本身就是代理员,检测被分享人是否有父级id,若没有则绑定关系
  89 + if (!empty($parent_id)) {
  90 + if (empty($friend_parent_id)) {
  91 + $bind = [
  92 + 'id' => $friend_id,
  93 + 'parent_id' => $parent_id
  94 + ];
  95 + if (Db::name('user')->update($bind)) {
  96 + $tag = true;
  97 + } else {
  98 + $tag = false;
97 } 99 }
98 } 100 }
99 - //判断两人是否首次赠送  
100 - if ($tag) {  
101 - $ship = [  
102 - 'uid' => $uid,  
103 - 'friend_uid' => $friend_id,  
104 - ];  
105 - //非首次赠送,积分叠加  
106 - if (Db::name('friendship')->where($ship)->count()) {  
107 - if (Db::name('friendship')->where($ship)->setInc('total', $total)) {  
108 - $tag = true;  
109 - } else {  
110 - $tag = false;  
111 - }  
112 - } //首次赠送,插入好友表  
113 - else {  
114 - $ship['total'] = $total;  
115 - if (Db::name('friendship')->insert($ship)) {  
116 - $tag = true;  
117 - } else {  
118 - $tag = false;  
119 - } 101 + }
  102 + //判断两人是否首次赠送
  103 + if ($tag) {
  104 + $ship = [
  105 + 'uid' => $uid,
  106 + 'friend_uid' => $friend_id,
  107 + ];
  108 + //非首次赠送,积分叠加
  109 + if (Db::name('friendship')->where($ship)->count()) {
  110 + if (Db::name('friendship')->where($ship)->setInc('total', $total)) {
  111 + $tag = true;
  112 + } else {
  113 + $tag = false;
  114 + }
  115 + } //首次赠送,插入好友表
  116 + else {
  117 + $ship['total'] = $total;
  118 + if (Db::name('friendship')->insert($ship)) {
  119 + $tag = true;
  120 + } else {
  121 + $tag = false;
120 } 122 }
121 - //好友表建立后赠送者减积分,被赠送者加积分  
122 - if ($tag) {  
123 - //赠送时  
124 - if ($total > 0) {  
125 - if (Db::name('user')->where(['id' => $uid])->setDec('balance', $total)) {  
126 - if (Db::name('user')->where(['id' => $friend_id])->setInc('balance', $total)) {  
127 - //插入赠送记录日志log  
128 - $log = [  
129 - 'uid' => $friend_id,  
130 - 'create_time' => time(),  
131 - 'balance' => $total,  
132 - 'type' => 3  
133 - ];  
134 - if (Db::name('zj_integral_log')->insert($log)) {  
135 - Db::commit();  
136 - $tag = true;  
137 - } else {  
138 - Db::rollback();  
139 - $tag = false;  
140 - } 123 + }
  124 + //好友表建立后赠送者减积分,被赠送者加积分
  125 + if ($tag) {
  126 + //赠送时
  127 + if ($total > 0) {
  128 + if (Db::name('user')->where(['id' => $uid])->setDec('balance', $total)) {
  129 + if (Db::name('user')->where(['id' => $friend_id])->setInc('balance', $total)) {
  130 + //插入赠送记录日志log
  131 + $log = [
  132 + 'uid' => $friend_id,
  133 + 'create_time' => time(),
  134 + 'balance' => $total,
  135 + 'type' => 3
  136 + ];
  137 + if (Db::name('zj_integral_log')->insert($log)) {
  138 + Db::commit();
  139 + $tag = true;
141 } else { 140 } else {
142 Db::rollback(); 141 Db::rollback();
143 $tag = false; 142 $tag = false;
@@ -146,33 +145,36 @@ class FriendController extends HomeBaseController @@ -146,33 +145,36 @@ class FriendController extends HomeBaseController
146 Db::rollback(); 145 Db::rollback();
147 $tag = false; 146 $tag = false;
148 } 147 }
149 - } //只加好友  
150 - else {  
151 - Db::commit();  
152 - $tag = true; 148 + } else {
  149 + Db::rollback();
  150 + $tag = false;
153 } 151 }
154 - } else {  
155 - Db::rollback();  
156 - $tag = false; 152 + } //只加好友
  153 + else {
  154 + Db::commit();
  155 + $tag = true;
157 } 156 }
158 } else { 157 } else {
159 Db::rollback(); 158 Db::rollback();
160 $tag = false; 159 $tag = false;
161 } 160 }
  161 + } else {
  162 + Db::rollback();
  163 + $tag = false;
  164 + }
162 165
163 - if ($tag) {  
164 - if ($total == 0) {  
165 - $msg = '添加好友成功';  
166 - } else {  
167 - $msg = '赠送积分成功';  
168 - } 166 + if ($tag) {
  167 + if ($total == 0) {
  168 + $msg = '添加好友成功';
169 } else { 169 } else {
170 - $msg = '未知错误'; 170 + $msg = '赠送积分成功';
171 } 171 }
172 -  
173 - echo json_encode(['msg' => $msg, 'status' => $tag, 'data' => Db::name('user')->where(['id' => session('user.id')])->value('balance')]);  
174 - exit(); 172 + } else {
  173 + $msg = '未知错误';
175 } 174 }
  175 +
  176 + echo json_encode(['msg' => $msg, 'status' => $tag, 'data' => Db::name('user')->where(['id' => session('user.id')])->value('balance')]);
  177 + exit();
176 } 178 }
177 } 179 }
178 } 180 }