|
@@ -451,10 +451,10 @@ class User extends Api
|
|
|
public function userAvatar()
|
|
|
{
|
|
|
$user = $this->auth->getUser();
|
|
|
- $gender = $this->request->request('gender'); // 性别:1=男,-1=女
|
|
|
+ $gender = $this->request->request('gender'); // 性别:1=男,0=女
|
|
|
$nickname_auth = $this->request->request('nickname');
|
|
|
$avatar_auth = $this->request->request('avatar');
|
|
|
- if (!$gender && !$nickname_auth && !$avatar_auth) $this->error('参数为空!');
|
|
|
+ if (!in_array($gender, [0, 1]) && !$nickname_auth && !$avatar_auth) $this->error('参数为空!');
|
|
|
// 随机获取昵称和头像
|
|
|
if(!$user->nickname && !$nickname_auth) {
|
|
|
$nicknameList = \app\admin\model\website\Nickname::select();//得到总条数
|
|
@@ -502,7 +502,7 @@ class User extends Api
|
|
|
$data['createtime'] = time();
|
|
|
$res1 = \app\common\model\AvatarAuth::insert($data);
|
|
|
}
|
|
|
- $gender && $user->gender = $gender;
|
|
|
+ in_array($gender, [0, 1]) && $user->gender = $gender;
|
|
|
$res2 = $user->save();
|
|
|
if($res1 && $res2 !== false) {
|
|
|
Db::commit();
|
|
@@ -871,7 +871,7 @@ class User extends Api
|
|
|
}
|
|
|
|
|
|
// 添加返利
|
|
|
- if ($fate_user['gender'] == -1) {
|
|
|
+ if ($fate_user['gender'] == 0) {
|
|
|
//女的返钱
|
|
|
if ($user->is_goddess == 1) {
|
|
|
$memo = '被查看有眼缘获得收益!';
|
|
@@ -1640,7 +1640,7 @@ class User extends Api
|
|
|
}
|
|
|
|
|
|
// 添加返利
|
|
|
- if ($fate_user['gender'] == -1) {
|
|
|
+ if ($fate_user['gender'] == 0) {
|
|
|
//女的返钱
|
|
|
if ($user->is_goddess == 1) {
|
|
|
$memo = '被查看有眼缘获得收益!';
|
|
@@ -1723,4 +1723,102 @@ class User extends Api
|
|
|
|
|
|
$this->success('设置成功', $status);
|
|
|
}
|
|
|
+
|
|
|
+ //查询是否可以聊天
|
|
|
+ public function getchatstatus() {
|
|
|
+ if ($this->auth->gender == 0) {
|
|
|
+ $this->success('可以聊天', '1');
|
|
|
+ }
|
|
|
+
|
|
|
+ $other_user_id = input('other_user_id', 0, 'intval');
|
|
|
+ if (!$other_user_id) {
|
|
|
+ $this->error('参数缺失');
|
|
|
+ }
|
|
|
+ if ($this->auth->id == $other_user_id) {
|
|
|
+ $this->error('这是您自己');
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = Db::name('user')->find($other_user_id);
|
|
|
+ if (!$info) {
|
|
|
+ $this->error('用户不存在');
|
|
|
+ }
|
|
|
+ //查询是否有眼缘
|
|
|
+ $fate_count = Db::name('user_fate')->where(['user_id' => $this->auth->id, 'fate_user_id' => $other_user_id, 'createtime' => ['egt', time() - 86400]])->count('id');
|
|
|
+ if ($fate_count) {
|
|
|
+ $this->success('可以聊天', '1');
|
|
|
+ }
|
|
|
+ //查询是否支付过
|
|
|
+ $pay_count = Db::name('user_chat_pay')->where(['user_id' => $this->auth->id, 'chat_user_id' => $other_user_id])->count('id');
|
|
|
+ if ($pay_count) {
|
|
|
+ $this->success('可以聊天', '1');
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('请先支付', '0');
|
|
|
+ }
|
|
|
+
|
|
|
+ //男士支付聊天钻石
|
|
|
+ public function paychat() {
|
|
|
+ $other_user_id = input('other_user_id', 0, 'intval');
|
|
|
+ if (!$other_user_id) {
|
|
|
+ $this->error('参数缺失');
|
|
|
+ }
|
|
|
+ if ($this->auth->id == $other_user_id) {
|
|
|
+ $this->error('这是您自己');
|
|
|
+ }
|
|
|
+ $info = Db::name('user')->find($other_user_id);
|
|
|
+ if (!$info) {
|
|
|
+ $this->error('用户不存在');
|
|
|
+ }
|
|
|
+ //查询是否支付过
|
|
|
+ $pay_count = Db::name('user_chat_pay')->where(['user_id' => $this->auth->id, 'chat_user_id' => $other_user_id])->count('id');
|
|
|
+ if ($pay_count) {
|
|
|
+ $this->error('已经支付过');
|
|
|
+ }
|
|
|
+ $manpaychat = (int)config('site.manpaychat'); //男士被查看有眼缘(未添加对方时)回复聊天支付钻石数量
|
|
|
+ if ($manpaychat <= 0) {
|
|
|
+ $this->error('支付数量异常,请联系管理员');
|
|
|
+ }
|
|
|
+ if ($this->auth->diamond < $manpaychat) {
|
|
|
+ $this->error(__('钻石余额不足,请先充值!'), [],100);
|
|
|
+ }
|
|
|
+
|
|
|
+ //开启事务
|
|
|
+ Db::startTrans();
|
|
|
+ //修改用户钻石余额
|
|
|
+ $user = Db::name('user')->find($this->auth);
|
|
|
+ $diamond = $user['diamond'] - $manpaychat;
|
|
|
+ $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'] = -$manpaychat;
|
|
|
+ $_data['before'] = $user['diamond'];
|
|
|
+ $_data['after'] = $diamond;
|
|
|
+ $_data['memo'] = '支付聊天';
|
|
|
+ $_data['createtime'] = time();
|
|
|
+ $res2 = Db::name('user_diamond_log')->insertGetId($_data);
|
|
|
+ //添加支付记录
|
|
|
+ $chat_pay['user_id'] = $user['id'];
|
|
|
+ $chat_pay['chat_user_id'] = $other_user_id;
|
|
|
+ $chat_pay['createtime'] = time();
|
|
|
+ $res3 = Db::name('user_chat_pay')->insertGetId($chat_pay);
|
|
|
+
|
|
|
+ if ($res1 && $res2 && $res3) {
|
|
|
+ Db::commit();
|
|
|
+ $this->success('支付成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('支付失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|