|
@@ -10,29 +10,10 @@ use think\Db;
|
|
|
*/
|
|
|
class Gift extends Api
|
|
|
{
|
|
|
- protected $noNeedLogin = ['getGiftList','getGiftType'];
|
|
|
+ protected $noNeedLogin = [];
|
|
|
protected $noNeedRight = '*';
|
|
|
- public $giftModel;
|
|
|
- public $gifttypeModel;
|
|
|
-
|
|
|
- public function _initialize()
|
|
|
- {
|
|
|
- parent::_initialize();
|
|
|
- $this->giftModel = new \app\common\model\Gift();
|
|
|
- $this->gifttypeModel = new \app\common\model\GiftType();
|
|
|
- }
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 获取礼物类型
|
|
|
- */
|
|
|
- public function getgifttype() {
|
|
|
- // 获取基本信息
|
|
|
- $where = [];
|
|
|
- $where["is_show"] = 1;
|
|
|
- $giftList = $this->gifttypeModel->field("id,name")->where($where)->order("weight","desc")->select();
|
|
|
- $this->success("获取成功!",$giftList);
|
|
|
- }
|
|
|
|
|
|
//聊天送礼物
|
|
|
public function givegift_typing() {
|
|
@@ -62,7 +43,7 @@ class Gift extends Api
|
|
|
{
|
|
|
$this->error("请选择礼物");
|
|
|
}
|
|
|
- $giftvalue = bcmul($giftinfo['value'],$number,2);
|
|
|
+ $giftvalue = bcmul($giftinfo['price'],$number,2);
|
|
|
|
|
|
//被赠送人信息
|
|
|
$touserinfo = Db::name('user')->where('id',$user_id)->find();
|
|
@@ -70,116 +51,96 @@ class Gift extends Api
|
|
|
{
|
|
|
$this->error("不存在的用户");
|
|
|
}
|
|
|
+
|
|
|
if($touserinfo['is_kefu'] == 1){
|
|
|
$this->error('不可以给客服送礼物');
|
|
|
}
|
|
|
|
|
|
|
|
|
- $money = 0.00;
|
|
|
Db::startTrans();
|
|
|
- //需要走计费的规则:男的 || 女的 需要收费的
|
|
|
- if ($this->auth->gender == 1 || ($this->auth->gender == 0 && $this->auth->is_cost == 1)) {
|
|
|
- // 判断当前用户余额
|
|
|
- if($giftinfo['wallettype'] == 1){
|
|
|
- $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
|
|
|
- if($user_gold < $giftvalue)
|
|
|
- {
|
|
|
- $this->error("您的金币不足");
|
|
|
- }
|
|
|
- }else{
|
|
|
- $user_jewel = model('wallet')->getWallet($this->auth->id,'jewel');
|
|
|
- if($user_jewel < $giftvalue)
|
|
|
- {
|
|
|
- $this->error("您的钻石不足");
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
+ // 判断当前用户余额
|
|
|
+ $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
|
|
|
+ if($user_gold < $giftvalue)
|
|
|
+ {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error("您的金币不足");
|
|
|
+ }
|
|
|
|
|
|
- // 添加礼物赠送记录表
|
|
|
- $data = [
|
|
|
- 'user_id' => $this->auth->id,
|
|
|
- 'user_to_id' => $user_id,
|
|
|
- 'gift_id' => $giftinfo['id'],
|
|
|
- 'gift_name' => $giftinfo['name'],
|
|
|
- 'number' => $number,
|
|
|
-
|
|
|
- 'createtime' => time(),
|
|
|
- 'wallettype' => $giftinfo['wallettype'],
|
|
|
- ];
|
|
|
- if($giftinfo['wallettype'] == 1){
|
|
|
- $data['price'] = $giftvalue;
|
|
|
- }else{
|
|
|
- $data['jewel'] = $giftvalue;
|
|
|
- }
|
|
|
+ // 添加礼物赠送记录表
|
|
|
+ $data = [
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'user_to_id' => $user_id,
|
|
|
+ 'gift_id' => $giftinfo['id'],
|
|
|
+ 'gift_name' => $giftinfo['name'],
|
|
|
+ 'number' => $number,
|
|
|
+ 'price' => $giftinfo['price'],
|
|
|
+ 'total_price' => $giftvalue,
|
|
|
+ 'createtime' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ //每个礼物都要计算平台抽成和房主抽成
|
|
|
+ $gift_plat_scale = config('site.gift_plat_scale');
|
|
|
+ $data['platvalue'] = bcmul($gift_plat_scale/100 ,$data['total_price'],1);//平台抽成
|
|
|
+ $data['getvalue'] = bcsub($data['total_price'] ,$data['platvalue'],1);//减去抽成剩余价值
|
|
|
+
|
|
|
+ $money_to_gold = config('site.money_to_gold');
|
|
|
+ $data['getmoney'] = bcdiv($data['getvalue'] ,$money_to_gold,2);//收益
|
|
|
+
|
|
|
+ $log_id = Db::name('gift_user_typing')->insertGetId($data);
|
|
|
+ if(!$log_id){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('赠送失败');
|
|
|
+ }
|
|
|
|
|
|
- $log_id = Db::name('gift_user_typing')->insertGetId($data);
|
|
|
- if(!$log_id){
|
|
|
+ if($giftvalue > 0){
|
|
|
+ // 扣除当前用户金币
|
|
|
+ $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,53,'赠送礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_typing',$log_id);
|
|
|
+ if($wallet_rs['status'] === false){
|
|
|
Db::rollback();
|
|
|
- $this->error('赠送失败');
|
|
|
+ $this->error($wallet_rs['msg']);
|
|
|
}
|
|
|
+ }
|
|
|
+ if($data['getmoney'] > 0){
|
|
|
+ // 添加获赠用户收益
|
|
|
+ $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$data['getmoney'],54,'获得礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_typing',$log_id,2);
|
|
|
+ if($wallet_rs['status'] === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($wallet_rs['msg']);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if($giftvalue > 0){
|
|
|
-
|
|
|
- // 扣除当前用户余额
|
|
|
- if($giftinfo['wallettype'] == 1){
|
|
|
-
|
|
|
-
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,53,'赠送礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_typing',$log_id);
|
|
|
- if($wallet_rs['status'] === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error($wallet_rs['msg']);
|
|
|
- }
|
|
|
-
|
|
|
- // 添加赠送用户余额
|
|
|
- $money_to_gold = config('site.money_to_gold');//送金币礼物得积分
|
|
|
- $gift_plat_scale = config('site.gift_plat_scale');
|
|
|
-
|
|
|
- $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
|
|
|
|
|
|
- $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,54,'获得礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_typing',$log_id,2);
|
|
|
- if($wallet_rs['status'] === false){
|
|
|
+ //增加赠送用户上级余额
|
|
|
+ if ($touserinfo['intro_uid']) {
|
|
|
+ //获取返利比率
|
|
|
+ $agent_info = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->field('is_agent,h_intro_income_rebate_rate')->find();
|
|
|
+ $intro_income_rebate_rate = ($agent_info['is_agent'] == 1) ? $agent_info['h_intro_income_rebate_rate'] : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
|
|
|
+ if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
|
|
|
+ //上级获得金额
|
|
|
+ $intro_uid_money = bcdiv(bcmul($data['getmoney'],$intro_income_rebate_rate,2),100,2);
|
|
|
+ if ($intro_uid_money > 0) {
|
|
|
+ $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人聊天礼物获赠奖励','gift_user_typing',$log_id);
|
|
|
+ if($intro_result['status']===false)
|
|
|
+ {
|
|
|
Db::rollback();
|
|
|
- $this->error($wallet_rs['msg']);
|
|
|
- }
|
|
|
-
|
|
|
- //增加赠送用户上级余额
|
|
|
- if ($touserinfo['intro_uid']) {
|
|
|
- //获取返利比率
|
|
|
- $agent_info = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->field('is_agent,h_intro_income_rebate_rate')->find();
|
|
|
- $intro_income_rebate_rate = ($agent_info['is_agent'] == 1) ? $agent_info['h_intro_income_rebate_rate'] : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
|
|
|
- if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
|
|
|
- //上级获得金额
|
|
|
- $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
|
|
|
- if ($intro_uid_money > 0) {
|
|
|
- $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人聊天礼物获赠奖励','gift_user_typing',$log_id);
|
|
|
- if($intro_result['status']===false)
|
|
|
- {
|
|
|
- Db::rollback();
|
|
|
- $this->error($intro_result['msg']);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($this->auth->gender == 1 && $touserinfo['gender'] == 0) {
|
|
|
- //增加亲密度
|
|
|
- /*$user_intimacy_rs = addintimacy($this->auth->id, $user_id, $giftvalue);
|
|
|
- if (!$user_intimacy_rs['status']) {
|
|
|
- Db::rollback();
|
|
|
- $this->error('您的网络开小差啦~');
|
|
|
- }*/
|
|
|
- }
|
|
|
- }else{
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'jewel',-$giftvalue,33,'赠送礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_typing',$log_id);
|
|
|
- if($wallet_rs['status'] === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error($wallet_rs['msg']);
|
|
|
+ $this->error($intro_result['msg']);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if ($this->auth->gender == 1 && $touserinfo['gender'] == 0) {
|
|
|
+ //增加亲密度
|
|
|
+ /*$user_intimacy_rs = addintimacy($this->auth->id, $user_id, $giftvalue);
|
|
|
+ if (!$user_intimacy_rs['status']) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('您的网络开小差啦~');
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
Db::commit();
|
|
|
|
|
|
//发送消息
|
|
@@ -188,7 +149,7 @@ class Gift extends Api
|
|
|
$tenim->sendMessageToUser($this->auth->id, $user_id, $user_intimacy_rs['level_remark'], 1);
|
|
|
}*/
|
|
|
|
|
|
- $return_data['money'] = $money; //获得金额
|
|
|
+ $return_data['money'] = $data['getmoney']; //获得金额
|
|
|
// $return_data['level_remark'] = isset($user_intimacy_rs) ? $user_intimacy_rs['level_remark'] : ''; //亲密度等级提示语
|
|
|
$return_data['level_remark'] = ''; //亲密度等级提示语
|
|
|
|
|
@@ -198,14 +159,17 @@ class Gift extends Api
|
|
|
|
|
|
//礼物列表
|
|
|
public function giftlist() {
|
|
|
- $type = input('type',0);
|
|
|
-
|
|
|
- $where['status'] = 1;
|
|
|
- if($type){
|
|
|
- $where['type'] = $type;
|
|
|
+ $is_vip = $this->is_vip($this->auth->id);
|
|
|
+
|
|
|
+ $where = [
|
|
|
+ 'is_show' => 1,
|
|
|
+ 'is_vip' => 0,
|
|
|
+ ];
|
|
|
+ if($is_vip){
|
|
|
+ $where['is_vip'] = 1;
|
|
|
}
|
|
|
|
|
|
- $giftList = Db::name('gift')->field('id, name, value, image, special, wallettype')->where($where)->order("sort, value")->select();
|
|
|
+ $giftList = Db::name('gift')->where($where)->order('weigh','desc')->select();
|
|
|
$giftList = list_domain_image($giftList,['image','special']);
|
|
|
$this->success("获取成功!",$giftList);
|
|
|
}
|