作者 lihan
1 个管道 的构建 通过 耗费 3 秒

赠送积分和角色管理

... ... @@ -63,81 +63,80 @@ class FriendController extends HomeBaseController
$total = $request->param('total');
//获取赠送者角色、父级、当前积分和赠送密码
$info = Db::name('user')->field('role,parent_id,balance,integral_pwd')->where(['id' => $uid])->find();
$integral_pwd = (empty($request->param('integral_pwd'))) ? $info['integral_pwd'] : $request->param('integral_pwd');
//判断密码是否正确
if (md5($integral_pwd) != $info['integral_pwd']) {
echo json_encode(['msg' => '密码错误', 'status' => false]);
$integral_pwd = $request->param('integral_pwd');
//判断密码是否正确(加好友时不用验证密码)
if ($total > 0) {
if (md5($integral_pwd) != $info['integral_pwd']) {
echo json_encode(['msg' => '密码错误', 'status' => false]);
exit();
}
}
//判断此人积分是否足够赠送,且是否能被500整除
if ($info['balance'] < $total && $total >= 0) {
echo json_encode(['msg' => '您的积分不足', 'status' => false]);
exit();
} else {
//判断此人积分是否足够赠送,且是否能被500整除
if ($info['balance'] < $total && $total >= 0) {
echo json_encode(['msg' => '您的积分不足', 'status' => false]);
if ($total % 500 != 0) {
echo json_encode(['msg' => '赠送积分必须是500积分的整数倍', 'status' => false]);
exit();
} else {
if ($total % 500 != 0) {
echo json_encode(['msg' => '赠送积分必须是500积分的整数倍', 'status' => false]);
exit();
} else {
$parent_id = ($info['role'] == 2) ? $uid : $info['parent_id'];
$tag = true;
$friend_id = $request->param('friend_id');
$friend_parent_id = Db::name('user')->where(['id' => $friend_id])->value('parent_id');
//如果此人有父级id或本身就是代理员,检测被分享人是否有父级id,若没有则绑定关系
if (!empty($parent_id)) {
if (empty($friend_parent_id)) {
$bind = [
'id' => $friend_id,
'parent_id' => $parent_id
];
if (Db::name('user')->update($bind)) {
$tag = true;
} else {
$tag = false;
}
$parent_id = ($info['role'] == 2) ? $uid : $info['parent_id'];
$tag = true;
$friend_id = $request->param('friend_id');
$friend_parent_id = Db::name('user')->where(['id' => $friend_id])->value('parent_id');
//如果此人有父级id或本身就是代理员,检测被分享人是否有父级id,若没有则绑定关系
if (!empty($parent_id)) {
if (empty($friend_parent_id)) {
$bind = [
'id' => $friend_id,
'parent_id' => $parent_id
];
if (Db::name('user')->update($bind)) {
$tag = true;
} else {
$tag = false;
}
}
//判断两人是否首次赠送
if ($tag) {
$ship = [
'uid' => $uid,
'friend_uid' => $friend_id,
];
//非首次赠送,积分叠加
if (Db::name('friendship')->where($ship)->count()) {
if (Db::name('friendship')->where($ship)->setInc('total', $total)) {
$tag = true;
} else {
$tag = false;
}
} //首次赠送,插入好友表
else {
$ship['total'] = $total;
if (Db::name('friendship')->insert($ship)) {
$tag = true;
} else {
$tag = false;
}
}
//判断两人是否首次赠送
if ($tag) {
$ship = [
'uid' => $uid,
'friend_uid' => $friend_id,
];
//非首次赠送,积分叠加
if (Db::name('friendship')->where($ship)->count()) {
if (Db::name('friendship')->where($ship)->setInc('total', $total)) {
$tag = true;
} else {
$tag = false;
}
} //首次赠送,插入好友表
else {
$ship['total'] = $total;
if (Db::name('friendship')->insert($ship)) {
$tag = true;
} else {
$tag = false;
}
//好友表建立后赠送者减积分,被赠送者加积分
if ($tag) {
//赠送时
if ($total > 0) {
if (Db::name('user')->where(['id' => $uid])->setDec('balance', $total)) {
if (Db::name('user')->where(['id' => $friend_id])->setInc('balance', $total)) {
//插入赠送记录日志log
$log = [
'uid' => $friend_id,
'create_time' => time(),
'balance' => $total,
'type' => 3
];
if (Db::name('zj_integral_log')->insert($log)) {
Db::commit();
$tag = true;
} else {
Db::rollback();
$tag = false;
}
}
//好友表建立后赠送者减积分,被赠送者加积分
if ($tag) {
//赠送时
if ($total > 0) {
if (Db::name('user')->where(['id' => $uid])->setDec('balance', $total)) {
if (Db::name('user')->where(['id' => $friend_id])->setInc('balance', $total)) {
//插入赠送记录日志log
$log = [
'uid' => $friend_id,
'create_time' => time(),
'balance' => $total,
'type' => 3
];
if (Db::name('zj_integral_log')->insert($log)) {
Db::commit();
$tag = true;
} else {
Db::rollback();
$tag = false;
... ... @@ -146,33 +145,36 @@ class FriendController extends HomeBaseController
Db::rollback();
$tag = false;
}
} //只加好友
else {
Db::commit();
$tag = true;
} else {
Db::rollback();
$tag = false;
}
} else {
Db::rollback();
$tag = false;
} //只加好友
else {
Db::commit();
$tag = true;
}
} else {
Db::rollback();
$tag = false;
}
} else {
Db::rollback();
$tag = false;
}
if ($tag) {
if ($total == 0) {
$msg = '添加好友成功';
} else {
$msg = '赠送积分成功';
}
if ($tag) {
if ($total == 0) {
$msg = '添加好友成功';
} else {
$msg = '未知错误';
$msg = '赠送积分成功';
}
echo json_encode(['msg' => $msg, 'status' => $tag, 'data' => Db::name('user')->where(['id' => session('user.id')])->value('balance')]);
exit();
} else {
$msg = '未知错误';
}
echo json_encode(['msg' => $msg, 'status' => $tag, 'data' => Db::name('user')->where(['id' => session('user.id')])->value('balance')]);
exit();
}
}
}
... ...