|
@@ -823,6 +823,17 @@ class User extends Api
|
|
|
if($fate_user_id == $user_id) {
|
|
|
$this->error("不需要添加自己为有眼缘哦!");
|
|
|
}
|
|
|
+ $fate_user = Db::name('user')->find($fate_user_id);
|
|
|
+ if (!$fate_user) {
|
|
|
+ $this->error('用户不存在');
|
|
|
+ }
|
|
|
+ $data = [];
|
|
|
+ $data['user_id'] = $user_id;
|
|
|
+ $data['fate_user_id'] = $fate_user_id;
|
|
|
+ if(\app\common\model\UserFate::where($data)->find()) {
|
|
|
+ $this->error("已经添加眼缘啦!");
|
|
|
+ }
|
|
|
+
|
|
|
$user = \app\common\model\User::get($user_id);
|
|
|
// 查看当前用户剩余次数
|
|
|
$view_count = \app\common\model\User::getViewCount($user_id);
|
|
@@ -834,12 +845,6 @@ class User extends Api
|
|
|
$user->view_count = $user->view_count - 1;
|
|
|
$res1 = $user->save();
|
|
|
// 添加眼缘记录
|
|
|
- $data = [];
|
|
|
- $data['user_id'] = $user_id;
|
|
|
- $data['fate_user_id'] = $fate_user_id;
|
|
|
- if(\app\common\model\UserFate::where($data)->find()) {
|
|
|
- $this->error("已经添加眼缘啦!");
|
|
|
- }
|
|
|
$data['createtime'] = time();
|
|
|
$res2 = \app\common\model\UserFate::insert($data);
|
|
|
|
|
@@ -1496,4 +1501,105 @@ class User extends Api
|
|
|
$this->success('钻石', $list);
|
|
|
}
|
|
|
|
|
|
+ //钻石支付有眼缘
|
|
|
+ public function diamondpayfate() {
|
|
|
+ $fate_user_id = $this->request->request('fate_user_id'); // 被眼缘用户ID
|
|
|
+ if (!$fate_user_id) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+
|
|
|
+ if($fate_user_id == $user_id) {
|
|
|
+ $this->error("不需要添加自己为有眼缘哦!");
|
|
|
+ }
|
|
|
+
|
|
|
+ $fate_user = Db::name('user')->find($fate_user_id);
|
|
|
+ if (!$fate_user) {
|
|
|
+ $this->error('用户不存在');
|
|
|
+ }
|
|
|
+ $data = [];
|
|
|
+ $data['user_id'] = $user_id;
|
|
|
+ $data['fate_user_id'] = $fate_user_id;
|
|
|
+ if(\app\common\model\UserFate::where($data)->find()) {
|
|
|
+ $this->error("已经添加眼缘啦!");
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = \app\common\model\User::get($user_id);
|
|
|
+ // 查看当前用户钻石余额是否充足
|
|
|
+ $diamondpayfate = (int)config('site.diamondpayfate');
|
|
|
+ if ($diamondpayfate <= 0) {
|
|
|
+ $this->error('钻石配置错误,请联系管理员');
|
|
|
+ }
|
|
|
+
|
|
|
+ if($user['diamond'] < $diamondpayfate) {
|
|
|
+ $this->error(__('钻石余额不足,请先充值!',[],100));
|
|
|
+ } else {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ //修改用户钻石余额
|
|
|
+ $diamond = $user['diamond'] - $diamondpayfate;
|
|
|
+ $res1 = Db::name('user')->where(['id' => $user_id, 'diamond' => $user['diamond']])->setField('diamond', $diamond);
|
|
|
+ // 添加钻石明细
|
|
|
+ $diamond_log = Db::name('user_diamond_log')->where(['user_id' => $user['id']])->order('id', 'desc')->find();
|
|
|
+ if (!$diamond_log && $user['diamond'] > 0) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('钻石余额异常');
|
|
|
+ }
|
|
|
+ if ($diamond_log && $diamond_log['after'] != $user['diamond']) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('钻石余额异常');
|
|
|
+ }
|
|
|
+ $_data['user_id'] = $user['id'];
|
|
|
+ $_data['diamond'] = -$diamondpayfate;
|
|
|
+ $_data['before'] = $user['diamond'];
|
|
|
+ $_data['after'] = $diamond;
|
|
|
+ $_data['memo'] = '查看有眼缘';
|
|
|
+ $_data['createtime'] = time();
|
|
|
+ $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;
|
|
|
+ } else {
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($res1 && $res2 && $res3 && $res4 && $res5) {
|
|
|
+ Db::commit();
|
|
|
+
|
|
|
+ $fate_user_info = \app\common\model\User::where(['id'=>$fate_user_id])->find();
|
|
|
+ $title = '眼缘提醒!';
|
|
|
+ $content = $fate_user_info->nickname.': 等你很久了,终于来了。希望你可以眼缘这里找到有趣的灵魂。无论白天还是深夜,无论快乐还是寂寞,始终有人陪你~';
|
|
|
+ \app\common\model\SysMsg::sendSysMsg($fate_user_id,6,$title,$content);
|
|
|
+
|
|
|
+ $this->success("眼缘添加成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error("添加失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|