作者 李洪娟

Merge branch 'master' of http://114.215.101.231:8099/lihan/integral into juan

... ... @@ -45,7 +45,7 @@ class FriendController extends HomeBaseController
return $this->fetch(':friend_list', [
'keyword' => $keyword,
'list' => $list,
'balance' => Db::name('user')->where(['id'=>session('user.id')])->value('balance')
'balance' => Db::name('user')->where(['id' => session('user.id')])->value('balance')
]);
} else {
$this->error('查无此人');
... ... @@ -60,73 +60,83 @@ class FriendController extends HomeBaseController
Db::startTrans();
$uid = session('user.id');
$total = $request->param('total');
//获取赠送者角色、父级和当前积分
$info = Db::name('user')->field('role,parent_id,balance')->where(['id' => $uid])->find();
//判断此人积分是否足够赠送,且是否能被500整除
if ($info['balance'] < $total && $total >= 0) {
echo json_encode(['msg' => '您的积分不足', 'status' => false]);
//获取赠送者角色、父级、当前积分和赠送密码
$info = Db::name('user')->field('role,parent_id,balance,integral_pwd')->where(['id' => $uid])->find();
$integral_pwd = $request->param('integral_pwd');
//判断密码是否正确
if (md5($integral_pwd) != $info['integral_pwd']) {
echo json_encode(['msg' => '密码错误', 'status' => false]);
exit();
} else {
if ($total % 500 != 0) {
echo json_encode(['msg' => '赠送积分必须是500积分的整数倍', 'status' => false]);
//判断此人积分是否足够赠送,且是否能被500整除
if ($info['balance'] < $total && $total >= 0) {
echo json_encode(['msg' => '您的积分不足', '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;
}
}
}
//判断两人是否首次赠送
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 ($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;
}
}
}
//好友表建立后赠送者减积分,被赠送者加积分
//判断两人是否首次赠送
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;
$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;
}
} else {
Db::rollback();
$tag = false;
... ... @@ -135,36 +145,33 @@ class FriendController extends HomeBaseController
Db::rollback();
$tag = false;
}
} else {
Db::rollback();
$tag = false;
} //只加好友
else {
Db::commit();
$tag = true;
}
} //只加好友
else {
Db::commit();
$tag = true;
} else {
Db::rollback();
$tag = false;
}
} else {
Db::rollback();
$tag = false;
}
} else {
Db::rollback();
$tag = false;
}
if ($tag) {
if ($total == 0) {
$msg = '添加好友成功';
if ($tag) {
if ($total == 0) {
$msg = '添加好友成功';
} else {
$msg = '赠送积分成功';
}
} else {
$msg = '赠送积分成功';
$msg = '未知错误';
}
} else {
$msg = '未知错误';
}
echo json_encode(['msg' => $msg, 'status' => $tag]);
exit();
echo json_encode(['msg' => $msg, 'status' => $tag]);
exit();
}
}
}
}
... ...
... ... @@ -361,7 +361,7 @@
}
})
var arr=[];
var str=""
var txts = wrap.getElementsByClassName("entercode");
//输入的密码自动输入到下一个
... ... @@ -370,22 +370,26 @@
for(var i=0;i<txts.length;i++){
$(txts[i]).val("")
}
for(var i = 0; i<txts.length;i++){
var t = txts[i];
t.index = i;
if(t.index>0){
t.setAttribute("readonly", true);
}
t.onkeyup=function(){
var arr=[];
var regular = /\s+/g;
if(regular.test(this.value)){
$(this).focus();
}else if($(this).val()==""){
$(this).focus();
}else{
console.log($(this).val());
arr.push($(this).val());
console.log(arr)
var next = this.index + 1;
if(next > txts.length - 1) return;
txts[next].removeAttribute("readonly");
... ... @@ -399,6 +403,8 @@
str=arr[0]+arr[1]+arr[2]+arr[3]+arr[4]+arr[5];
console.log(str)
$.ajax({
url:"{:url('friendship/Friend/donateIntegral')}",
data:{
... ... @@ -411,11 +417,16 @@
success: function (data) {
if(data.status === true) {
window.event.stopPropagation()
$(".passwordwrap").css("display","none")
alert(data.msg);
window.location.reload();
}else {
alert(data.msg);
}
//清空数据
for (var i = 0; i < txts.length; i++) {
$(txts[i]).val("")
}
}
})
}
... ...