Commit 068ce049 by 冷斌

fix bug

parent da7dcc25
...@@ -3,20 +3,20 @@ ...@@ -3,20 +3,20 @@
class Model_Guard extends PhalApi_Model_NotORM { class Model_Guard extends PhalApi_Model_NotORM {
/* 守护用户列表 */ /* 守护用户列表 */
public function getGuardList($data) { public function getGuardList($data) {
$rs=array(); $rs=array();
$liveuid=$data['liveuid']; $liveuid=$data['liveuid'];
$nowtime=time(); $nowtime=time();
$w=date('w',$nowtime); $w=date('w',$nowtime);
//获取本周开始日期,如果$w是0,则表示周日,减去 6 天 //获取本周开始日期,如果$w是0,则表示周日,减去 6 天
$first=1; $first=1;
//周一 //周一
$week=date('Y-m-d H:i:s',strtotime( date("Ymd",$nowtime)."-".($w ? $w - $first : 6).' days')); $week=date('Y-m-d H:i:s',strtotime( date("Ymd",$nowtime)."-".($w ? $w - $first : 6).' days'));
$week_start=strtotime( date("Ymd",$nowtime)."-".($w ? $w - $first : 6).' days'); $week_start=strtotime( date("Ymd",$nowtime)."-".($w ? $w - $first : 6).' days');
//本周结束日期 //本周结束日期
//周天 //周天
$week_end=strtotime("{$week} +1 week"); $week_end=strtotime("{$week} +1 week");
...@@ -29,22 +29,22 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -29,22 +29,22 @@ class Model_Guard extends PhalApi_Model_NotORM {
->fetchAll(); ->fetchAll();
foreach($list as $k=>$v){ foreach($list as $k=>$v){
$userinfo=getUserInfo($v['uid']); $userinfo=getUserInfo($v['uid']);
$userinfo['type']=$v['type']; $userinfo['type']=$v['type'];
$userinfo['contribute']=$this->getWeekContribute($v['uid'],$week_start,$week_end); $userinfo['contribute']=$this->getWeekContribute($v['uid'],$week_start,$week_end);
$order[]=$userinfo['contribute']; $order[]=$userinfo['contribute'];
$order2[]=$userinfo['type']; $order2[]=$userinfo['type'];
$rs[]=$userinfo; $rs[]=$userinfo;
} }
array_multisort($order, SORT_DESC, $order2, SORT_DESC, $rs); array_multisort($order, SORT_DESC, $order2, SORT_DESC, $rs);
return $rs; return $rs;
} }
public function getWeekContribute($uid,$starttime=0,$endtime=0){ public function getWeekContribute($uid,$starttime=0,$endtime=0){
$contribute='0'; $contribute='0';
if($uid>0){ if($uid>0){
...@@ -55,7 +55,7 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -55,7 +55,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
if($endtime>0 ){ if($endtime>0 ){
$where.=" and addtime < {$endtime}"; $where.=" and addtime < {$endtime}";
} }
$contribute=DI()->notorm->users_coinrecord $contribute=DI()->notorm->users_coinrecord
->where($where) ->where($where)
->sum('totalcoin'); ->sum('totalcoin');
...@@ -63,7 +63,7 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -63,7 +63,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
$contribute=0; $contribute=0;
} }
} }
return (string)$contribute; return (string)$contribute;
} }
...@@ -76,7 +76,7 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -76,7 +76,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
return $list; return $list;
} }
/* 购买守护 */ /* 购买守护 */
public function buyGuard($data){ public function buyGuard($data){
$rs = array('code' => 0, 'msg' => '购买成功', 'info' => array()); $rs = array('code' => 0, 'msg' => '购买成功', 'info' => array());
...@@ -84,7 +84,7 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -84,7 +84,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
$liveuid=$data['liveuid']; $liveuid=$data['liveuid'];
$stream=$data['stream']; $stream=$data['stream'];
$guardid=$data['guardid']; $guardid=$data['guardid'];
$guardinfo=DI()->notorm->guard $guardinfo=DI()->notorm->guard
->select('*') ->select('*')
->where('id=?',$guardid) ->where('id=?',$guardid)
...@@ -94,7 +94,7 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -94,7 +94,7 @@ class Model_Guard extends PhalApi_Model_NotORM {
$rs['msg'] = '守护信息不存在'; $rs['msg'] = '守护信息不存在';
return $rs; return $rs;
} }
$addtime=time(); $addtime=time();
$isexist=DI()->notorm->guard_users $isexist=DI()->notorm->guard_users
->select('*') ->select('*')
...@@ -104,13 +104,13 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -104,13 +104,13 @@ class Model_Guard extends PhalApi_Model_NotORM {
$rs['code'] = 1004; $rs['code'] = 1004;
$rs['msg'] = '已经是尊贵守护了,不能购买普通守护'; $rs['msg'] = '已经是尊贵守护了,不能购买普通守护';
return $rs; return $rs;
} }
$type='expend'; $type='expend';
$action='buyguard'; $action='buyguard';
$giftid= $guardinfo['id']; $giftid= $guardinfo['id'];
$total= $guardinfo['coin']; $total= $guardinfo['coin'];
/* 更新用户余额 消费 */ /* 更新用户余额 消费 */
$isok=DI()->notorm->users $isok=DI()->notorm->users
->where('id = ? and coin>=?', $uid,$total) ->where('id = ? and coin>=?', $uid,$total)
...@@ -120,25 +120,26 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -120,25 +120,26 @@ class Model_Guard extends PhalApi_Model_NotORM {
$rs['msg'] = '余额不足'; $rs['msg'] = '余额不足';
return $rs; return $rs;
} }
/* 分销 */ /* 分销 */
setAgentProfit($uid,$total); setAgentProfit($uid,$total);
DI()->notorm->users DI()->notorm->users
->where('id = ?', $liveuid) ->where('id = ?', $liveuid)
->update( array('votes' => new NotORM_Literal("votes + {$total}"),'votestotal' => new NotORM_Literal("votestotal + {$total}") )); ->update( array('votes' => new NotORM_Literal("votes + {$total}"),'votestotal' => new NotORM_Literal("votestotal + {$total}") ));
$insert_votes=[ $insert_votes=[
'type'=>'income', 'type'=>'income',
'action'=>$action, 'action'=>$action,
'uid'=>$liveuid, 'uid'=>$liveuid,
'votes'=>$total, 'votes'=>$total,
'addtime'=>$addtime, 'addtime'=>$addtime,
'coin' => $isok['coin']
]; ];
DI()->notorm->users_voterecord->insert($insert_votes); DI()->notorm->users_voterecord->insert($insert_votes);
$showid=0; $showid=0;
if($stream){ if($stream){
$stream2=explode('_',$stream); $stream2=explode('_',$stream);
...@@ -147,13 +148,13 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -147,13 +148,13 @@ class Model_Guard extends PhalApi_Model_NotORM {
$showid=0; $showid=0;
} }
} }
$insert=array("type"=>$type,"action"=>$action,"uid"=>$uid,"touid"=>$liveuid,"giftid"=>$giftid,"giftcount"=>'1',"totalcoin"=>$total,"showid"=>$showid,"addtime"=>$addtime ); $insert=array("type"=>$type,"action"=>$action,"uid"=>$uid,"touid"=>$liveuid,"giftid"=>$giftid,"giftcount"=>'1',"totalcoin"=>$total,"showid"=>$showid,"addtime"=>$addtime );
DI()->notorm->users_coinrecord->insert($insert); DI()->notorm->users_coinrecord->insert($insert);
$endtime=$addtime + $guardinfo['length_time']; $endtime=$addtime + $guardinfo['length_time'];
if($isexist){ if($isexist){
if($isexist['type'] == $guardinfo['type'] && $isexist['endtime'] > $addtime){ if($isexist['type'] == $guardinfo['type'] && $isexist['endtime'] > $addtime){
/* 同类型未到期 只更新到期时间 */ /* 同类型未到期 只更新到期时间 */
DI()->notorm->guard_users DI()->notorm->guard_users
...@@ -180,34 +181,34 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -180,34 +181,34 @@ class Model_Guard extends PhalApi_Model_NotORM {
); );
DI()->notorm->guard_users DI()->notorm->guard_users
->insert( $data ); ->insert( $data );
} }
/* 清除缓存 */ /* 清除缓存 */
delCache("userinfo_".$uid); delCache("userinfo_".$uid);
delCache("userinfo_".$liveuid); delCache("userinfo_".$liveuid);
$userinfo2 =DI()->notorm->users $userinfo2 =DI()->notorm->users
->select('consumption,coin') ->select('consumption,coin')
->where('id = ?', $uid) ->where('id = ?', $uid)
->fetchOne(); ->fetchOne();
$level=getLevel($userinfo2['consumption']); $level=getLevel($userinfo2['consumption']);
$guard=DI()->notorm->guard_users $guard=DI()->notorm->guard_users
->select('type,endtime') ->select('type,endtime')
->where('uid = ? and liveuid=?', $uid,$liveuid) ->where('uid = ? and liveuid=?', $uid,$liveuid)
->fetchOne(); ->fetchOne();
$key='getUserGuard_'.$uid.'_'.$liveuid; $key='getUserGuard_'.$uid.'_'.$liveuid;
setcaches($key,$guard); setcaches($key,$guard);
$liveuidinfo =DI()->notorm->users $liveuidinfo =DI()->notorm->users
->select('votestotal') ->select('votestotal')
->where('id = ?', $liveuid) ->where('id = ?', $liveuid)
->fetchOne(); ->fetchOne();
$guard_nums=$this->getGuardNums($liveuid); $guard_nums=$this->getGuardNums($liveuid);
$info=array( $info=array(
'coin'=>$userinfo2['coin'], 'coin'=>$userinfo2['coin'],
'votestotal'=>$liveuidinfo['votestotal'], 'votestotal'=>$liveuidinfo['votestotal'],
...@@ -217,12 +218,12 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -217,12 +218,12 @@ class Model_Guard extends PhalApi_Model_NotORM {
'type'=>$guard['type'], 'type'=>$guard['type'],
'endtime'=>date("Y.m.d",$guard['endtime']), 'endtime'=>date("Y.m.d",$guard['endtime']),
); );
$rs['info'][0]=$info; $rs['info'][0]=$info;
return $rs; return $rs;
} }
/* 获取用户守护信息 */ /* 获取用户守护信息 */
public function getUserGuard($uid,$liveuid){ public function getUserGuard($uid,$liveuid){
$rs=array( $rs=array(
...@@ -235,11 +236,11 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -235,11 +236,11 @@ class Model_Guard extends PhalApi_Model_NotORM {
$guardinfo=DI()->notorm->guard_users $guardinfo=DI()->notorm->guard_users
->select('type,endtime') ->select('type,endtime')
->where('uid = ? and liveuid=?', $uid,$liveuid) ->where('uid = ? and liveuid=?', $uid,$liveuid)
->fetchOne(); ->fetchOne();
setcaches($key,$guardinfo); setcaches($key,$guardinfo);
} }
$nowtime=time(); $nowtime=time();
if($guardinfo && $guardinfo['endtime']>$nowtime){ if($guardinfo && $guardinfo['endtime']>$nowtime){
$rs=array( $rs=array(
'type'=>$guardinfo['type'], 'type'=>$guardinfo['type'],
...@@ -248,15 +249,15 @@ class Model_Guard extends PhalApi_Model_NotORM { ...@@ -248,15 +249,15 @@ class Model_Guard extends PhalApi_Model_NotORM {
} }
return $rs; return $rs;
} }
/* 获取主播守护总数 */ /* 获取主播守护总数 */
public function getGuardNums($liveuid){ public function getGuardNums($liveuid){
$nowtime=time(); $nowtime=time();
$nums=DI()->notorm->guard_users $nums=DI()->notorm->guard_users
->where('liveuid=? and endtime>?',$liveuid,$nowtime) ->where('liveuid=? and endtime>?',$liveuid,$nowtime)
->count(); ->count();
return (string)$nums; return (string)$nums;
} }
} }
...@@ -147,12 +147,12 @@ class Model_Live extends PhalApi_Model_NotORM { ...@@ -147,12 +147,12 @@ class Model_Live extends PhalApi_Model_NotORM {
->group('uid') ->group('uid')
->fetchAll(); ->fetchAll();
foreach($total as $k=>$v){ foreach($total as $k=>$v){
DI()->notorm->users $u = DI()->notorm->users
->where('id = ?', $v['uid']) ->where('id = ?', $v['uid'])
->update(array('coin' => new NotORM_Literal("coin + {$v['total']}"))); ->update(array('coin' => new NotORM_Literal("coin + {$v['total']}")));
delcache('userinfo_'.$v['uid']); delcache('userinfo_'.$v['uid']);
$insert=array("type"=>'income',"action"=>'game_return',"uid"=>$v['uid'],"touid"=>$v['uid'],"giftid"=>$game['id'],"giftcount"=>1,"totalcoin"=>$v['total'],"showid"=>0,"addtime"=>$nowtime ); $insert=array('coin' => $u['coin'], "type"=>'income',"action"=>'game_return',"uid"=>$v['uid'],"touid"=>$v['uid'],"giftid"=>$game['id'],"giftcount"=>1,"totalcoin"=>$v['total'],"showid"=>0,"addtime"=>$nowtime );
DI()->notorm->users_coinrecord->insert($insert); DI()->notorm->users_coinrecord->insert($insert);
} }
...@@ -400,6 +400,7 @@ class Model_Live extends PhalApi_Model_NotORM { ...@@ -400,6 +400,7 @@ class Model_Live extends PhalApi_Model_NotORM {
'uid'=>$liveuid, 'uid'=>$liveuid,
'votes'=>$total, 'votes'=>$total,
'addtime'=>time(), 'addtime'=>time(),
'coin' => $ifok['coin']
]; ];
DI()->notorm->users_voterecord->insert($insert_votes); DI()->notorm->users_voterecord->insert($insert_votes);
...@@ -546,6 +547,7 @@ class Model_Live extends PhalApi_Model_NotORM { ...@@ -546,6 +547,7 @@ class Model_Live extends PhalApi_Model_NotORM {
'uid'=>$liveuid, 'uid'=>$liveuid,
'votes'=>$anthor_total, 'votes'=>$anthor_total,
'addtime'=>time(), 'addtime'=>time(),
'coin' => $ifok['coin']
]; ];
DI()->notorm->users_voterecord->insert($insert_votes); DI()->notorm->users_voterecord->insert($insert_votes);
} }
...@@ -831,6 +833,7 @@ class Model_Live extends PhalApi_Model_NotORM { ...@@ -831,6 +833,7 @@ class Model_Live extends PhalApi_Model_NotORM {
'uid'=>$liveuid, 'uid'=>$liveuid,
'votes'=>$total, 'votes'=>$total,
'addtime'=>time(), 'addtime'=>time(),
'coin' => $ifok['coin']
]; ];
DI()->notorm->users_voterecord->insert($insert_votes); DI()->notorm->users_voterecord->insert($insert_votes);
......
...@@ -1205,7 +1205,7 @@ ...@@ -1205,7 +1205,7 @@
DI()->notorm->users_agent_profit DI()->notorm->users_agent_profit
->insert(array('uid'=>$agent['one_uid'],'one_profit' =>$distribut1 )); ->insert(array('uid'=>$agent['one_uid'],'one_profit' =>$distribut1 ));
} }
DI()->notorm->users $u = DI()->notorm->users
->where('id=?',$agent['one_uid']) ->where('id=?',$agent['one_uid'])
->update(array('votes' => new NotORM_Literal("votes + {$distribut1}"))); ->update(array('votes' => new NotORM_Literal("votes + {$distribut1}")));
$isinsert=1; $isinsert=1;
...@@ -1215,6 +1215,7 @@ ...@@ -1215,6 +1215,7 @@
'uid'=>$agent['one_uid'], 'uid'=>$agent['one_uid'],
'votes'=>$distribut1, 'votes'=>$distribut1,
'addtime'=>time(), 'addtime'=>time(),
'coin' => $u['coin']
]; ];
DI()->notorm->users_voterecord->insert($insert_votes); DI()->notorm->users_voterecord->insert($insert_votes);
} }
...@@ -1235,7 +1236,7 @@ ...@@ -1235,7 +1236,7 @@
DI()->notorm->users_agent_profit DI()->notorm->users_agent_profit
->insert(array('uid'=>$agent['two_uid'],'two_profit' =>$distribut2 )); ->insert(array('uid'=>$agent['two_uid'],'two_profit' =>$distribut2 ));
} }
DI()->notorm->users $u = DI()->notorm->users
->where('id=?',$agent['two_uid']) ->where('id=?',$agent['two_uid'])
->update(array('votes' => new NotORM_Literal("votes + {$distribut2}"))); ->update(array('votes' => new NotORM_Literal("votes + {$distribut2}")));
$isinsert=1; $isinsert=1;
...@@ -1245,6 +1246,7 @@ ...@@ -1245,6 +1246,7 @@
'uid'=>$agent['two_uid'], 'uid'=>$agent['two_uid'],
'votes'=>$distribut2, 'votes'=>$distribut2,
'addtime'=>time(), 'addtime'=>time(),
'coin' => $u['coin']
]; ];
DI()->notorm->users_voterecord->insert($insert_votes); DI()->notorm->users_voterecord->insert($insert_votes);
} }
...@@ -1336,7 +1338,7 @@ ...@@ -1336,7 +1338,7 @@
if($family_total){ if($family_total){
DI()->notorm->users $u = DI()->notorm->users
->where('id = ?', $familyinfo['uid']) ->where('id = ?', $familyinfo['uid'])
->update( array( 'votes' => new NotORM_Literal("votes + {$family_total}") )); ->update( array( 'votes' => new NotORM_Literal("votes + {$family_total}") ));
...@@ -1346,6 +1348,7 @@ ...@@ -1346,6 +1348,7 @@
'uid'=>$familyinfo['uid'], 'uid'=>$familyinfo['uid'],
'votes'=>$family_total, 'votes'=>$family_total,
'addtime'=>time(), 'addtime'=>time(),
'coin' => $u['coin']
]; ];
DI()->notorm->users_voterecord->insert($insert_votes); DI()->notorm->users_voterecord->insert($insert_votes);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment