|
@@ -847,7 +847,8 @@ class User extends Api
|
|
|
$data = [];
|
|
|
$data['user_id'] = $user_id;
|
|
|
$data['fate_user_id'] = $fate_user_id;
|
|
|
- if(\app\common\model\UserFate::where($data)->find()) {
|
|
|
+ $user_fate = \app\common\model\UserFate::where($data)->find();
|
|
|
+ if($user_fate && $user_fate['createtime'] >= time() - 86400) {
|
|
|
$this->error("已经添加眼缘啦!");
|
|
|
}
|
|
|
|
|
@@ -862,31 +863,66 @@ class User extends Api
|
|
|
$user->view_count = $view_count - 1;
|
|
|
$res1 = $user->save();
|
|
|
// 添加眼缘记录
|
|
|
- $data['createtime'] = time();
|
|
|
- $res2 = \app\common\model\UserFate::insert($data);
|
|
|
-
|
|
|
- // 添加返利
|
|
|
- if($user->is_goddess == 1) {
|
|
|
- $memo = '被查看有眼缘获得收益!';
|
|
|
- $profit = config('site.fate') * config('site.goddessProfitRate') * 0.01;
|
|
|
+ if ($user_fate) {
|
|
|
+ $res2 = Db::name('user_fate')->where($data)->setField('createtime', time());
|
|
|
} else {
|
|
|
- $memo = '被查看有眼缘获得收益!';
|
|
|
- $profit = config('site.fate') * config('site.userProfitRate') * 0.01;
|
|
|
+ $data['createtime'] = time();
|
|
|
+ $res2 = \app\common\model\UserFate::insert($data);
|
|
|
}
|
|
|
- if($profit >= 0.01 && $fate_user_id > 0) {
|
|
|
- $res3 = \app\common\model\User::profit($profit,$fate_user_id,$memo);
|
|
|
- //给上级返利
|
|
|
- $fate_user_info = \app\common\model\User::where(['id'=>$fate_user_id])->find();
|
|
|
- $profit_last = $profit * config('site.SuperioruserProfitRate') * 0.01;
|
|
|
- if($profit_last >= 0.01 && $fate_user_info['pre_user_id'] > 0) {
|
|
|
- $res4 = \app\common\model\User::profit($profit_last,$fate_user_info['pre_user_id'],$fate_user_info['nickname'].'被查看有眼缘获得收益');
|
|
|
+
|
|
|
+ // 添加返利
|
|
|
+ if ($fate_user['gender'] == -1) {
|
|
|
+ //女的返钱
|
|
|
+ if ($user->is_goddess == 1) {
|
|
|
+ $memo = '被查看有眼缘获得收益!';
|
|
|
+ $profit = config('site.fate') * config('site.goddessProfitRate') * 0.01;
|
|
|
} else {
|
|
|
- $res4 = true;
|
|
|
+ $memo = '被查看有眼缘获得收益!';
|
|
|
+ $profit = config('site.fate') * config('site.userProfitRate') * 0.01;
|
|
|
}
|
|
|
+ if ($profit >= 0.01 && $fate_user_id > 0) {
|
|
|
+ $res3 = \app\common\model\User::profit($profit, $fate_user_id, $memo);
|
|
|
+ //给上级返利
|
|
|
+ $fate_user_info = \app\common\model\User::where(['id' => $fate_user_id])->find();
|
|
|
+ $profit_last = $profit * config('site.SuperioruserProfitRate') * 0.01;
|
|
|
+ if ($profit_last >= 0.01 && $fate_user_info['pre_user_id'] > 0) {
|
|
|
+ $res4 = \app\common\model\User::profit($profit_last, $fate_user_info['pre_user_id'], $fate_user_info['nickname'] . '被查看有眼缘获得收益');
|
|
|
+ } else {
|
|
|
+ $res4 = true;
|
|
|
+ }
|
|
|
|
|
|
+ } else {
|
|
|
+ $res3 = true;
|
|
|
+ $res4 = true;
|
|
|
+ }
|
|
|
} else {
|
|
|
- $res3 = true;
|
|
|
- $res4 = true;
|
|
|
+ //男的返钻石
|
|
|
+ $faterebate = (int)config('site.faterebate'); //男士被查看有眼缘可获得钻石数量
|
|
|
+ if ($faterebate > 0) {
|
|
|
+ //修改被查看用户钻石余额
|
|
|
+ $diamond = $fate_user['diamond'] + $faterebate;
|
|
|
+ $res3 = Db::name('user')->where(['id' => $fate_user_id, 'diamond' => $fate_user['diamond']])->setField('diamond', $diamond);
|
|
|
+ // 添加钻石明细
|
|
|
+ $diamond_log = Db::name('user_diamond_log')->where(['user_id' => $fate_user['id']])->order('id', 'desc')->find();
|
|
|
+ if (!$diamond_log && $fate_user['diamond'] > 0) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('钻石余额异常');
|
|
|
+ }
|
|
|
+ if ($diamond_log && $diamond_log['after'] != $fate_user['diamond']) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('钻石余额异常');
|
|
|
+ }
|
|
|
+ $_data['user_id'] = $fate_user_id;
|
|
|
+ $_data['diamond'] = $faterebate;
|
|
|
+ $_data['before'] = $fate_user['diamond'];
|
|
|
+ $_data['after'] = $diamond;
|
|
|
+ $_data['memo'] = '被查看有眼缘获得收益';
|
|
|
+ $_data['createtime'] = time();
|
|
|
+ $res4 = Db::name('user_diamond_log')->insertGetId($_data);
|
|
|
+ } else {
|
|
|
+ $res3 = true;
|
|
|
+ $res4 = true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if($res1 && $res2 && $res3 && $res4) {
|
|
@@ -919,6 +955,7 @@ class User extends Api
|
|
|
$user_id = $this->auth->id;
|
|
|
$where = [];
|
|
|
$where['a.user_id'] = $user_id;
|
|
|
+ $where['a.createtime'] = ['egt', time() - 86400];
|
|
|
$res = \app\common\model\UserFate::alias("a")
|
|
|
->field("a.id,u.id as user_id,u.avatar,u.nickname,u.age,u.constellation,u.hobby_ids,u.profession,u.wechat,u.copy_mobile,u.mobile")
|
|
|
->join("hx_user u","u.id = a.fate_user_id")
|
|
@@ -1556,7 +1593,8 @@ class User extends Api
|
|
|
$data = [];
|
|
|
$data['user_id'] = $user_id;
|
|
|
$data['fate_user_id'] = $fate_user_id;
|
|
|
- if(\app\common\model\UserFate::where($data)->find()) {
|
|
|
+ $user_fate = \app\common\model\UserFate::where($data)->find();
|
|
|
+ if($user_fate && $user_fate['createtime'] >= time() - 86400) {
|
|
|
$this->error("已经添加眼缘啦!");
|
|
|
}
|
|
|
|
|
@@ -1594,31 +1632,66 @@ class User extends Api
|
|
|
$res5 = Db::name('user_diamond_log')->insertGetId($_data);
|
|
|
|
|
|
// 添加眼缘记录
|
|
|
- $data['createtime'] = time();
|
|
|
- $res2 = \app\common\model\UserFate::insert($data);
|
|
|
-
|
|
|
- // 添加返利
|
|
|
- if($user->is_goddess == 1) {
|
|
|
- $memo = '被查看有眼缘获得收益!';
|
|
|
- $profit = config('site.fate') * config('site.goddessProfitRate') * 0.01;
|
|
|
+ if ($user_fate) {
|
|
|
+ $res2 = Db::name('user_fate')->where($data)->setField('createtime', time());
|
|
|
} else {
|
|
|
- $memo = '被查看有眼缘获得收益!';
|
|
|
- $profit = config('site.fate') * config('site.userProfitRate') * 0.01;
|
|
|
+ $data['createtime'] = time();
|
|
|
+ $res2 = \app\common\model\UserFate::insert($data);
|
|
|
}
|
|
|
- if($profit >= 0.01 && $fate_user_id > 0) {
|
|
|
- $res3 = \app\common\model\User::profit($profit,$fate_user_id,$memo);
|
|
|
- //给上级返利
|
|
|
- $fate_user_info = \app\common\model\User::where(['id'=>$fate_user_id])->find();
|
|
|
- $profit_last = $profit * config('site.SuperioruserProfitRate') * 0.01;
|
|
|
- if($profit_last >= 0.01 && $fate_user_info['pre_user_id'] > 0) {
|
|
|
- $res4 = \app\common\model\User::profit($profit_last,$fate_user_info['pre_user_id'],$fate_user_info['nickname'].'被查看有眼缘获得收益');
|
|
|
+
|
|
|
+ // 添加返利
|
|
|
+ if ($fate_user['gender'] == -1) {
|
|
|
+ //女的返钱
|
|
|
+ if ($user->is_goddess == 1) {
|
|
|
+ $memo = '被查看有眼缘获得收益!';
|
|
|
+ $profit = config('site.fate') * config('site.goddessProfitRate') * 0.01;
|
|
|
} else {
|
|
|
- $res4 = true;
|
|
|
+ $memo = '被查看有眼缘获得收益!';
|
|
|
+ $profit = config('site.fate') * config('site.userProfitRate') * 0.01;
|
|
|
}
|
|
|
+ if ($profit >= 0.01 && $fate_user_id > 0) {
|
|
|
+ $res3 = \app\common\model\User::profit($profit, $fate_user_id, $memo);
|
|
|
+ //给上级返利
|
|
|
+ $fate_user_info = \app\common\model\User::where(['id' => $fate_user_id])->find();
|
|
|
+ $profit_last = $profit * config('site.SuperioruserProfitRate') * 0.01;
|
|
|
+ if ($profit_last >= 0.01 && $fate_user_info['pre_user_id'] > 0) {
|
|
|
+ $res4 = \app\common\model\User::profit($profit_last, $fate_user_info['pre_user_id'], $fate_user_info['nickname'] . '被查看有眼缘获得收益');
|
|
|
+ } else {
|
|
|
+ $res4 = true;
|
|
|
+ }
|
|
|
|
|
|
+ } else {
|
|
|
+ $res3 = true;
|
|
|
+ $res4 = true;
|
|
|
+ }
|
|
|
} else {
|
|
|
- $res3 = true;
|
|
|
- $res4 = true;
|
|
|
+ //男的返钻石
|
|
|
+ $faterebate = (int)config('site.faterebate'); //男士被查看有眼缘可获得钻石数量
|
|
|
+ if ($faterebate > 0) {
|
|
|
+ //修改被查看用户钻石余额
|
|
|
+ $diamond = $fate_user['diamond'] + $faterebate;
|
|
|
+ $res3 = Db::name('user')->where(['id' => $fate_user_id, 'diamond' => $fate_user['diamond']])->setField('diamond', $diamond);
|
|
|
+ // 添加钻石明细
|
|
|
+ $diamond_log = Db::name('user_diamond_log')->where(['user_id' => $fate_user['id']])->order('id', 'desc')->find();
|
|
|
+ if (!$diamond_log && $fate_user['diamond'] > 0) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('钻石余额异常');
|
|
|
+ }
|
|
|
+ if ($diamond_log && $diamond_log['after'] != $fate_user['diamond']) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('钻石余额异常');
|
|
|
+ }
|
|
|
+ $_data['user_id'] = $fate_user_id;
|
|
|
+ $_data['diamond'] = $faterebate;
|
|
|
+ $_data['before'] = $fate_user['diamond'];
|
|
|
+ $_data['after'] = $diamond;
|
|
|
+ $_data['memo'] = '被查看有眼缘获得收益';
|
|
|
+ $_data['createtime'] = time();
|
|
|
+ $res4 = Db::name('user_diamond_log')->insertGetId($_data);
|
|
|
+ } else {
|
|
|
+ $res3 = true;
|
|
|
+ $res4 = true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if($res1 && $res2 && $res3 && $res4 && $res5) {
|