签约房-装扮-降身卡功能开发
This commit is contained in:
@@ -75,7 +75,19 @@ class Decorate extends Model
|
||||
'a.type' => $type,
|
||||
];
|
||||
}
|
||||
$list = DB::name($this->table)->alias('a')->join('fa_vs_decorate_price b', 'a.did = b.did')->field('a.did,a.title,a.type,a.base_image,a.play_image,min(b.price) as price,special_num')->where($map)->group('b.did')->order('price asc')->select();
|
||||
if($type == 12){
|
||||
$map = [
|
||||
'type' => 12,
|
||||
'delete_time' => 0,
|
||||
'show_status' => 1,
|
||||
'is_buy' => 1
|
||||
];
|
||||
$list = DB::name($this->table)->where($map)->field('did,title,type,base_image,play_image,price')
|
||||
->order('price asc')
|
||||
->select();
|
||||
}else{
|
||||
$list = DB::name($this->table)->alias('a')->join('fa_vs_decorate_price b', 'a.did = b.did')->field('a.did,a.title,a.type,a.base_image,a.play_image,min(b.price) as price,special_num')->where($map)->group('b.did')->order('price asc')->select();
|
||||
}
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
$v['play_image'] = localpath_to_netpath($v['play_image']);
|
||||
@@ -90,19 +102,25 @@ class Decorate extends Model
|
||||
if (!$decorate) {
|
||||
return ['code' => 0, 'msg' => '参数错误'];
|
||||
}
|
||||
$decorate_price = DB::name('vs_decorate_price')->where(['did' => $did, 'is_delete' => 1])->order('day asc')->select();
|
||||
if (!$decorate_price) {
|
||||
return ['code' => 0, 'msg' => '参数错误'];
|
||||
}
|
||||
$result['title'] = $decorate['title'];
|
||||
foreach ($decorate_price as $k => $v) {
|
||||
$result['price_list'][$k]['price'] = (int)$v['price'];
|
||||
$result['price_list'][$k]['discount'] = $v['discount'];
|
||||
$result['price_list'][$k]['day'] = $v['day'];
|
||||
//月
|
||||
$result['price_list'][$k]['month'] = $v['day']/30;
|
||||
//有效期至
|
||||
$result['price_list'][$k]['end_time'] = date('Y-m-d',strtotime("+".$v['day']." day"));
|
||||
if($decorate['type'] == 12){
|
||||
$decorate_price = DB::name('vs_decorate_price')->where(['did' => $did, 'is_delete' => 1])->order('day asc')->select();
|
||||
if (!$decorate_price) {
|
||||
return ['code' => 0, 'msg' => '参数错误'];
|
||||
}
|
||||
$result['title'] = $decorate['title'];
|
||||
foreach ($decorate_price as $k => $v) {
|
||||
$result['price_list'][$k]['price'] = (int)$v['price'];
|
||||
$result['price_list'][$k]['discount'] = $v['discount'];
|
||||
$result['price_list'][$k]['day'] = $v['day'];
|
||||
//月
|
||||
$result['price_list'][$k]['month'] = $v['day']/30;
|
||||
//有效期至
|
||||
$result['price_list'][$k]['end_time'] = date('Y-m-d',strtotime("+".$v['day']." day"));
|
||||
}
|
||||
}else{
|
||||
$result['title'] = $decorate['title'];
|
||||
$result['price'] = (int)$decorate['price'];
|
||||
$result['base_image'] = localpath_to_netpath($decorate['base_image']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $result];
|
||||
}
|
||||
@@ -117,7 +135,7 @@ class Decorate extends Model
|
||||
* @param $log_remark 日志备注
|
||||
*
|
||||
*/
|
||||
public function pay_decorate($uid, $did, $day,$from_type=1,$give_uid=0,$log_remark=""){
|
||||
public function pay_decorate($uid, $did, $day=0,$from_type=1,$give_uid=0,$log_remark="",$num=1){
|
||||
if(empty($log_remark)){
|
||||
$log_remark = $this->FromType[$from_type];
|
||||
}
|
||||
@@ -135,25 +153,32 @@ class Decorate extends Model
|
||||
if(!$decorate_info){
|
||||
return ['code' => 0, 'msg' => '该装扮不存在'.$did, 'data' => null];
|
||||
}
|
||||
//该天数是否存在
|
||||
$map = [];
|
||||
$map = [
|
||||
'did' => $did,
|
||||
'day' => $day,
|
||||
'is_delete' => 1,
|
||||
];
|
||||
$decorate_price_info = db::name('vs_decorate_price')->where($map)->find();
|
||||
if(!$decorate_price_info){
|
||||
return ['code' => 0, 'msg' => '该装扮天数不存在', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 6 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 0, 'msg' => '该个人靓号已被购买', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 7 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 0, 'msg' => '该房间靓号已被购买', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 8 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 0, 'msg' => '该公会靓号已被购买', 'data' => null];
|
||||
if($decorate_info['type'] != 12){
|
||||
//该天数是否存在
|
||||
$map = [];
|
||||
$map = [
|
||||
'did' => $did,
|
||||
'day' => $day,
|
||||
'is_delete' => 1,
|
||||
];
|
||||
$decorate_price_info = db::name('vs_decorate_price')->where($map)->find();
|
||||
if(!$decorate_price_info){
|
||||
return ['code' => 0, 'msg' => '该装扮天数不存在', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 6 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 0, 'msg' => '该个人靓号已被购买', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 7 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 0, 'msg' => '该房间靓号已被购买', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 8 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 0, 'msg' => '该公会靓号已被购买', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
$decorate_price_info = [
|
||||
'price' => $decorate_info['price'],
|
||||
'day' => 0
|
||||
];
|
||||
}
|
||||
$start_time = $now_time = time();
|
||||
Db::startTrans();
|
||||
@@ -197,27 +222,36 @@ class Decorate extends Model
|
||||
if($decorate_price_info['day'] == 0){//如果礼物购买配置的天数为0,则永久有效
|
||||
$data['is_using'] = 1;
|
||||
$data['end_time'] = 0;
|
||||
$data['is_perpetual'] = 1;
|
||||
}else{
|
||||
$change_time = $day * 24 * 3600;
|
||||
$data['is_using'] = 2;
|
||||
$data['end_time'] = $now_time + $change_time;
|
||||
}
|
||||
$data['createtime'] = $now_time;
|
||||
$data['special_num'] = $decorate_info['special_num'];
|
||||
$data['special_num'] = $decorate_info['special_num'] ?? '';
|
||||
$result = db::name('vs_user_decorate')->insert($data);
|
||||
}else{
|
||||
if($decorate_price_info['day'] > 0){//是不是永久礼物
|
||||
if($decorate_price_info['price']<=0 && $user_decorate_data['end_time'] > $now_time + $change_time){
|
||||
return ['code' => 0, 'msg' => '您已购买过此装扮,请勿重复购买', 'data' => null];
|
||||
if($decorate_info['type'] == 12){
|
||||
$result = db::name('vs_user_decorate')->where('udid', $user_decorate_data['udid'])->update([
|
||||
'is_using' => 2,
|
||||
'num' => $user_decorate_data['num'] + $num,
|
||||
'end_time' => 0
|
||||
]);
|
||||
}else{
|
||||
if($decorate_price_info['day'] > 0){//是不是永久礼物
|
||||
if($decorate_price_info['price']<=0 && $user_decorate_data['end_time'] > $now_time + $change_time){
|
||||
return ['code' => 0, 'msg' => '您已购买过此装扮,请勿重复购买', 'data' => null];
|
||||
}
|
||||
if($user_decorate_data['end_time'] < $now_time){
|
||||
$user_decorate_data['end_time'] = 0;
|
||||
}
|
||||
$change_time = $day * 24 * 3600;
|
||||
$update['is_using'] = 2;
|
||||
$update['end_time'] = $user_decorate_data['end_time'] + $change_time;
|
||||
$result = db::name('vs_user_decorate')->where('udid', $user_decorate_data['udid'])->update($update);
|
||||
$start_time = $update['end_time'];
|
||||
}
|
||||
if($user_decorate_data['end_time'] < $now_time){
|
||||
$user_decorate_data['end_time'] = 0;
|
||||
}
|
||||
$change_time = $day * 24 * 3600;
|
||||
$update['is_using'] = 2;
|
||||
$update['end_time'] = $user_decorate_data['end_time'] + $change_time;
|
||||
$result = db::name('vs_user_decorate')->where('udid', $user_decorate_data['udid'])->update($update);
|
||||
$start_time = $update['end_time'];
|
||||
}
|
||||
}
|
||||
if(!$result){
|
||||
@@ -262,24 +296,33 @@ class Decorate extends Model
|
||||
|
||||
//用户装扮列表
|
||||
public function user_decorate($uid, $type,$page=1, $limit=10){
|
||||
|
||||
$reslut = db::name('vs_user_decorate')
|
||||
->alias('ud')->join('vs_decorate d', 'ud.did = d.did')
|
||||
->field('ud.udid,ud.user_id,ud.is_using,ud.end_time,ud.is_perpetual,ud.special_num,d.title,d.base_image,d.play_image,d.type')
|
||||
->where('ud.user_id', $uid)
|
||||
->where('ud.type', $type)
|
||||
->where(['ud.end_time'=>[">=",time()]])
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
foreach($reslut as $k => &$v){
|
||||
$remaining_day = ceil(($v['end_time'] - time())/86400);
|
||||
if($remaining_day <= 0){
|
||||
$remaining_day = 0;
|
||||
if($type == 12){
|
||||
$reslut = db::name('vs_user_decorate')
|
||||
->alias('ud')->join('vs_decorate d', 'ud.did = d.did')
|
||||
->field('ud.udid,ud.user_id,ud.is_using,ud.end_time,ud.is_perpetual,ud.special_num,d.title,d.base_image,d.play_image,d.type,ud.num')
|
||||
->where('ud.user_id', $uid)
|
||||
->where('ud.type', $type)
|
||||
->where(['ud.num'=>[">",0]])
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
}else{
|
||||
$reslut = db::name('vs_user_decorate')
|
||||
->alias('ud')->join('vs_decorate d', 'ud.did = d.did')
|
||||
->field('ud.udid,ud.user_id,ud.is_using,ud.end_time,ud.is_perpetual,ud.special_num,d.title,d.base_image,d.play_image,d.type')
|
||||
->where('ud.user_id', $uid)
|
||||
->where('ud.type', $type)
|
||||
->where(['ud.end_time'=>[">=",time()]])
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
foreach($reslut as $k => &$v){
|
||||
$remaining_day = ceil(($v['end_time'] - time())/86400);
|
||||
if($remaining_day <= 0){
|
||||
$remaining_day = 0;
|
||||
}
|
||||
//剩余天数 取整
|
||||
$v['remaining_day'] = $v['is_perpetual']==1 ? '永久' :$remaining_day;
|
||||
$v['end_time'] = date('Y-m-d H:i:s', $v['end_time']);
|
||||
}
|
||||
//剩余天数 取整
|
||||
$v['remaining_day'] = $v['is_perpetual']==1 ? '永久' :$remaining_day;
|
||||
$v['end_time'] = date('Y-m-d H:i:s', $v['end_time']);
|
||||
|
||||
}
|
||||
return ['code' => 1, 'msg' => "获取成功", 'data' => $reslut];
|
||||
}
|
||||
@@ -296,10 +339,15 @@ class Decorate extends Model
|
||||
if (empty($info)) {
|
||||
return ['code' => 0, 'msg' => '装扮不存在', 'data' => null];
|
||||
}
|
||||
if ($info['end_time'] < time()) {
|
||||
return ['code' => 0, 'msg' => '装扮已过期', 'data' => null];
|
||||
if($info['type'] == 12){
|
||||
if ($info['num']-1 < 0) {
|
||||
return ['code' => 0, 'msg' => '无可用装扮', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
if ($info['end_time'] < time()) {
|
||||
return ['code' => 0, 'msg' => '装扮已过期', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//清理该类型装扮使用状态
|
||||
@@ -324,6 +372,9 @@ class Decorate extends Model
|
||||
$data = [];
|
||||
$data['is_using'] = 1;
|
||||
$data['updatetime'] = time();
|
||||
if($info['type'] == 12){
|
||||
$data['num'] = $info['num'] - 1;
|
||||
}
|
||||
$reslut = Db::name('vs_user_decorate')->where($map)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
@@ -331,19 +382,46 @@ class Decorate extends Model
|
||||
}
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
//推送信息去所在房间
|
||||
//查询当前所在房间
|
||||
$room_id = db::name('vs_room_visitor')->where(['user_id' => $uid])->order('id' , 'desc')->value('room_id');
|
||||
if($room_id){
|
||||
//当前用户信息
|
||||
//推送信息
|
||||
$text['jia_jia'] = model('Decorate')->user_decorate_detail($uid,2);
|
||||
$text['FromUserInfo'] = db::name('user')->where('id',$uid)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$text['FromUserInfo']['dress'] = model('Decorate')->user_decorate_detail($uid,1);
|
||||
$text['FromUserInfo']['mic_cycle'] = model('Decorate')->user_decorate_detail($uid,3);
|
||||
$text['FromUserInfo']['chat_dress'] = model('Decorate')->user_decorate_detail($uid,5);
|
||||
$text['text'] = '用户 ' . $text['FromUserInfo']['nickname'] .' 修改了信息';
|
||||
model('Chat')->sendMsg(1035,$room_id,$text,$uid);
|
||||
if($info['type'] == 12){
|
||||
//使用降身卡,降低用户身价
|
||||
$reduce_ratio = db::name('vs_decorate')->where(['did' => $info['did']])->value('reduce_ratio') ?? 0;
|
||||
$market_value = db::name('user')->where(['id' => $uid])->value('market_value');
|
||||
if($reduce_ratio){
|
||||
$reduce_market_value = $market_value * $reduce_ratio / 100;
|
||||
}else{
|
||||
$reduce_market_value = 0;
|
||||
}
|
||||
if($reduce_market_value > 0){
|
||||
$up_market_value = $market_value - $reduce_market_value;
|
||||
if($up_market_value < 1){
|
||||
$up_market_value = 1;
|
||||
}
|
||||
db::name('user')->where(['id' => $uid])->update(['market_value' => $up_market_value]);
|
||||
//记录一条日志
|
||||
db::name('vs_user_market_value_log')->insert([
|
||||
'user id' => $uid,
|
||||
'before' => $market_value,
|
||||
'change value'=> $reduce_market_value,
|
||||
'afterwards'=> $up_market_value,
|
||||
'type' => 2,
|
||||
'createtime'=> time()
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
//推送信息去所在房间
|
||||
//查询当前所在房间
|
||||
$room_id = db::name('vs_room_visitor')->where(['user_id' => $uid])->order('id' , 'desc')->value('room_id');
|
||||
if($room_id){
|
||||
//当前用户信息
|
||||
//推送信息
|
||||
$text['jia_jia'] = model('Decorate')->user_decorate_detail($uid,2);
|
||||
$text['FromUserInfo'] = db::name('user')->where('id',$uid)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$text['FromUserInfo']['dress'] = model('Decorate')->user_decorate_detail($uid,1);
|
||||
$text['FromUserInfo']['mic_cycle'] = model('Decorate')->user_decorate_detail($uid,3);
|
||||
$text['FromUserInfo']['chat_dress'] = model('Decorate')->user_decorate_detail($uid,5);
|
||||
$text['text'] = '用户 ' . $text['FromUserInfo']['nickname'] .' 修改了信息';
|
||||
model('Chat')->sendMsg(1035,$room_id,$text,$uid);
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => "设置成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
@@ -367,7 +445,6 @@ class Decorate extends Model
|
||||
if (!$reslut) {
|
||||
return ['code' => 0, 'msg' => "取消装扮失败", 'data' => null];
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => "取消成功", 'data' => null];
|
||||
}
|
||||
|
||||
@@ -434,7 +511,7 @@ class Decorate extends Model
|
||||
if($user_decorate['is_perpetual']==2 && $user_decorate['end_time'] < time()){
|
||||
return $reslut;
|
||||
}
|
||||
if($type == 9){
|
||||
if(in_array($type, [9,12])){
|
||||
$reslut = db::name('vs_decorate')->where('did', $user_decorate['did'])->value('base_image');
|
||||
}else{
|
||||
$reslut = db::name('vs_decorate')->where('did', $user_decorate['did'])->value('play_image');
|
||||
|
||||
Reference in New Issue
Block a user