Commit 0e877c54 authored by houyadong's avatar houyadong

成员交易逻辑修改-bug

parent c9bee5eb
......@@ -699,8 +699,14 @@ class PkTopAction extends IdentityAction
$pageSize = 10;
$order = I('order', 0);
$gInfo = D('Group')->getGroup($this->GID);
$top = $order == 1 ? 50 : 0;
$phb = D('User')->getGroupEntrustList($gInfo, $top,$p, $pageSize);
if($order == 1){
$top = 50;
$isTop3 = 0;
}else{
$top = 500;
$isTop3 = 1;
}
$phb = D('User')->getGroupEntrustList($gInfo, $top,1,$isTop3,$p, $pageSize);
$this->assign([
'p' => $p,
'pageSize' => $pageSize,
......
......@@ -174,14 +174,16 @@ class UserModel extends Model
}
/**
* 获取训练区或大赛区的成员交易,找出该大赛前3名的委托记录置顶
* @param $gId string 大赛id
* @param $top int 显示前几名,0全部
* @param $p int 页码
* @param $pageSize int 每页显示条数
* @return array
* 训练区和大赛区的成员交易,找出该大赛前3名的委托记录
* * @param $gId string 大赛id
* * @param $top int 只取排行榜前几名:0全部
* * @param $top_type int 排行榜类型:0总收益 1周收益
* * @param $isTop3 int 是否置顶排行榜前三名当日最新交易
* * @param $p int 页码
* * @param $pageSize int 每页显示条数
* * @return array
*/
public function getGroupEntrustList($gInfo,$top = 0,$p = 1,$pageSize = 5)
public function getGroupEntrustList($gInfo,$top = 0,$top_type = 0,$isTop3 = 0,$p = 1,$pageSize = 5)
{
$gId = $gInfo['group_id'];
$is_xlq = $gInfo['category'] == 1 ? 1 : 0;
......@@ -192,14 +194,13 @@ class UserModel extends Model
return M()->db(2,getModel($gInfo['web_id']));
}
};
$model = $getModel($is_xlq,$gInfo);
if($is_xlq == 1){
$uinfo_table_name = 'syn_userinfo';
$table_name = 'syn_entrust';
$his_table_name = 'syn_hisentrust';
$uinfo_where = [
'category' => 1
'category' => 1,'zt' => 1,
];
$entrust_where = [
'bz' => ['in',D('Group')->ids],
......@@ -219,34 +220,35 @@ class UserModel extends Model
'status'=>['in',['已报','已成']],
];
}
if($top == 0){
# 取前3名置顶
#置顶逻辑
if($top_type == 0){
$uinfo_where['new_phb'] = ['between',[1,3]];
$u_order = 'new_phb asc';
}else{
# 取前$top名,近300条
$uinfo_where['new_phb'] = ['between',[1,$top]];
$uinfo_where['new_phb'] = ['gt',0];
$u_order = 'lastweekup desc,new_phb asc';
}
$top3_uids = $getModel($is_xlq,$gInfo)->table($uinfo_table_name)->where($uinfo_where)->order($u_order)->limit(3)->getField('uid,new_phb', true);
$i = 1;
foreach($top3_uids as $k=>$v){
$top3_uids[$k] = $i;
$i++;
}
$top_uid = $model->table($uinfo_table_name)->where($uinfo_where)->order('new_phb asc')->getField('uid,new_phb,lastweekup', true);
unset($uinfo_where);
#截取前三名的id
$top3_uids = array_slice($top_uid, 0, 3);
$list = [];
#第一页显示该大赛总收益排名前三的用户在当天最新的一条交易记录
if($top == 0 && !empty($top3_uids)){
if(!empty($top3_uids) && $isTop3 == 1){
#获取置顶数据
$top3_data = $model->table($table_name)
$top3_data = $getModel($is_xlq,$gInfo)->table($table_name)
->field('*,(case when cj_time then cj_time else CONCAT_WS(" " ,date, time) end) sort_time')
->where($entrust_where)
->where(['userid'=>['in',array_keys($top3_uids)]])
->group('userid')
->order('FIELD(userid,"'.implode('","',array_keys($top3_uids)).'") asc,cj_time desc')
->select();
if(empty($top3_data)){
$top3_data = $model->table($his_table_name)
$top3_data = $getModel($is_xlq,$gInfo)->table($his_table_name)
->field('*,cj_time sort_time')
->where($entrust_where)
->where(['userid'=>['in',array_keys($top3_uids)],'cj_time'=>['gt',date('Y-m-d H:i:s',strtotime('today'))]])
->group('userid')
->order('FIELD(userid,"'.implode('","',array_keys($top3_uids)).'") asc,cj_time desc')
->select();
}
......@@ -258,24 +260,41 @@ class UserModel extends Model
$tmp[$v['userid']] = 1;
}
}
$top3_ids = array_column($top3_data,'id');
if(!empty($top3_ids)){
$entrust_where['id'] = ['not in',$top3_ids];
}
if($p == 1){
$list = (array)$top3_data;
$top3_htxh = array_column($top3_data,'htxh'); #前三名当天最新的交易数据id
if(!empty($top3_htxh)){
$entrust_where['htxh'] = ['not in',$top3_htxh];
}
}
#限制名次
unset($uinfo_where['new_phb']);
if($top_type == 0){
$uinfo_where['new_phb'] = ['between',[1,$top]];
$u_order = 'new_phb asc';
}else{
$uinfo_where['new_phb'] = ['gt',0];
$u_order = 'lastweekup desc,new_phb asc';
}
if($top == 0){
$top_uid = $getModel($is_xlq,$gInfo)->table($uinfo_table_name)->where($uinfo_where)->order($u_order)->getField('uid,new_phb,zongup,lastweekup', true);
}else{
$limit = $top;
$top_uid = $getModel($is_xlq,$gInfo)->table($uinfo_table_name)->where($uinfo_where)->order($u_order)->limit($limit)->getField('uid,new_phb,zongup,lastweekup', true);
}
$i = 1;
foreach($top_uid as $k=>$v){
$top_uid[$k]['new_phb'] = $i;
$i++;
}
if($top > 0 && !empty($top_uid)){
$entrust_where['userid'] = ['in',array_keys($top_uid)];
}
#取委托总条数和页数
$model = $getModel($is_xlq,$gInfo);
$today_count = $model->table($table_name)->where($entrust_where)->cache(true,3600)->count();
$his_count = $today_count + $model->table($his_table_name)->where($entrust_where)->cache(true,3600)->count();
$today_count = $getModel($is_xlq,$gInfo)->table($table_name)->where($entrust_where)->cache(true,3600)->count();
$his_count = $getModel($is_xlq,$gInfo)->table($his_table_name)->where($entrust_where)->limit(20 * $pageSize)->getField('htxh',true);
$count = $today_count + count($his_count);
$today_max_page = ceil($today_count / $pageSize);
if($p <= $today_max_page){
$today_list = $model->table($table_name)
$today_list = $getModel($is_xlq,$gInfo)->table($table_name)
->field('*,(case when cj_time then cj_time else CONCAT_WS(" " ,date, time) end) sort_time')
->where($entrust_where)
->order('sort_time desc')
......@@ -292,58 +311,62 @@ class UserModel extends Model
if($p >= $today_max_page){
$p = $p > ($today_max_page + $his_max_page) ? ($today_max_page + $his_max_page) : $p;
if($his_count > 0){
$his_list = $model->table($his_table_name)
$his_list = $getModel($is_xlq,$gInfo)->table($his_table_name)
->where($entrust_where)
->order('cj_time desc')
->page(($p - $today_max_page < 0 ? 1 : $p - $today_max_page),$pageSize)
->select();
}
}
$list = array_merge((array)$list,(array)$today_list,(array)$his_list);
$list = array_merge((array)$top3_data,(array)$today_list,(array)$his_list);
#补全数据
if($list){
$uids = array_column($list,'userid');
if(!empty($uids)){
$top_uid = $model->table($uinfo_table_name)->where(['uid'=>['in',$uids]])->getField('uid,new_phb,lastweekup', true);
}
$stockHq = array();
$stockCodes = array_column($list, 'stock_code');
$res = D('Stock')->stockQuotation(implode(',', $stockCodes), ['type' => 1]);
if (count($stockCodes) == 1) {
$typeCode = strtolower($list[0]['stock_type'] . $stockCodes);
$stockHq[$typeCode] = $res;
} else {
$stockHq = $res;
}
$nick_name_arry = getUser( array_column($list,'CD'), 'nick');
foreach ($list as $k=>$v){
$return = [
'entrust_bs'=>$v['entrust_bs'],
'show_time' => $v['cj_time'] ? substr($v['cj_time'], 11, 8) : $v['time'],
'amount'=>$v['amount'],
'userid' => $v['userid'],
];
#获利比
$stockCodeType = strtolower($v['stock_type'] . $v['stock_code']);
$quo = $stockHq[$stockCodeType];
if ($quo) {
#根据成交价和最新价算涨跌
$nowPrice = formatPrice(($quo['nowprice'] > 0 ? $quo['nowprice'] : $quo['closePrice']));
$return['zd'] = formatPrice(($nowPrice - $v['cj_price']) / $v['cj_price'] * 100, 2) . '%';
if($top == 0){
$top_uid = $getModel($is_xlq,$gInfo)->table($uinfo_table_name)->where(['uid'=>['in',$uids]])->getField('uid,new_phb,zongup,lastweekup', true);
}
$stockHq = array();
$stockCodes = array_column($list, 'stock_code');
$res = D('Stock')->stockQuotation(implode(',', $stockCodes), ['type' => 1]);
if (count($stockCodes) == 1) {
$typeCode = strtolower($list[0]['stock_type'] . $stockCodes);
$stockHq[$typeCode] = $res;
} else {
$stockHq = $res;
}
$nick_name_arry = getUser( array_column($list,'CD'), 'nick');
foreach ($list as $k=>$v){
$return = [
'entrust_bs'=>$v['entrust_bs'],
'show_time' => $v['cj_time'] ? substr($v['cj_time'], 11, 8) : $v['time'],
'amount'=>$v['amount'],
'userid' => $v['userid'],
'is_wt' => !$v['cj_time'] ? 1 : 0,
'wt_price' => !$v['cj_time'] ? $v['price'] : ''
];
#获利比
$stockCodeType = strtolower($v['stock_type'] . $v['stock_code']);
$quo = $stockHq[$stockCodeType];
if ($quo) {
#根据成交价和最新价算涨跌
$nowPrice = formatPrice(($quo['nowprice'] > 0 ? $quo['nowprice'] : $quo['closePrice']));
$return['zd'] = formatPrice(($nowPrice - $v['cj_price']) / $v['cj_price'] * 100, 2) . '%';
}
#App
$return['goTradeInfo'] = D('Common')->setGoTrade($gInfo, explode('X', $v['userid'])[1], $v['username'], 2);
#排名
$phb = $top_uid[$v['userid']]['new_phb'];
$return['phb'] = $phb ? $phb : '--';
#周收益
$return['lastweekup'] = $top_uid[$v['userid']]['lastweekup'];
#昵称
$return['username'] = $nick_name_arry[$v['CD']];
$list[$k] = $return;
}
#App
$return['goTradeInfo'] = D('Common')->setGoTrade($gInfo, explode('X', $v['userid'])[1], $v['username'], 2);
#排名
$phb = $top_uid[$v['userid']]['new_phb'];
$return['phb'] = $phb ? $phb : '--';
#周收益
$return['lastweekup'] = $top_uid[$v['userid']]['lastweekup'];
#昵称
$return['username'] = $nick_name_arry[$v['CD']];
$list[$k] = $return;
}
}
return [$list,($today_count + $his_count)];
return [$list,$count];
}
//完成勋章,只有参赛勋章
......
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