Commit a405709d authored by houyadong's avatar houyadong

成员交易逻辑修改

parent 2b63d2df
......@@ -1663,4 +1663,52 @@ function p($data, $flag = true)
die;
}
}
/**
* app版本判断
* @param opt 判断条件
* @param 判断版本
* @param 当前版本
* @param 版本标识
*/
function checkVersion($opt='>=',$version,$cur_version ='' ,$os='') {
$os_now = $os ? substr($cur_version,0,1) : '';
$version_now=str_replace(array('A','iOS'),array('',''),$cur_version);
if($opt=='>'){
if($os_now==$os&&$version_now>$version){
return true;
}else{
return false;
}
}
if($opt=='>='){
if($os_now==$os&&$version_now>=$version){
return true;
}else{
return false;
}
}
if($opt=='='){
if($os_now==$os&&$version_now==$version){
return true;
}else{
return false;
}
}
if($opt=='<'){
if($os_now==$os&&$version_now<$version){
return true;
}else{
return false;
}
}
if($opt=='<='){
if($os_now==$os&&$version_now<=$version){
return true;
}else{
return false;
}
}
}
?>
\ No newline at end of file
......@@ -15,7 +15,7 @@ define('DB_HOST', '123.57.129.189');
define('DB_USER', 'stock_sa'); //交易站数据库帐号
define('DB_PW', 'd#!%$38a'); //交易站数据库密码
define('REDIS_HOST', '39.105.203.195');
define('REDIS_HOST', '123.57.166.35');
define('REDIS_PORT', 63899);
define('REDIS_AUTH', '1!!KqwiL$lotAZjRjxC');
......
......@@ -699,60 +699,15 @@ class PkTopAction extends IdentityAction
$pageSize = 10;
$order = I('order', 0);
$gInfo = D('Group')->getGroup($this->GID);
//查看前n名
$uids = [];
if ($order == 1) {
$phb = $this->getPhb(1, 50, 'zongup');
$uids = array_column($phb[0], 'uid');
}
$phb = D('User')->getWtList($gInfo, $p, $pageSize, $uids);
$wtList = $phb[0];
//取最新价
$stockHq = [];
$stockCodes = array_column($wtList, 'stock_code');
$res = D('Stock')->stockQuotation(implode(',', $stockCodes), ['type' => 1]);
if (count($stockCodes) == 1) {
$typeCode = strtolower($wtList[0]['stock_type'] . $stockCodes);
$stockHq[$typeCode] = $res;
} else {
$stockHq = $res;
}
foreach ($wtList as &$e) {
$stockCodeType = strtolower($e['stock_type'] . $e['stock_code']);
$quo = $stockHq[$stockCodeType];
if ($quo) {
$nowPrice = formatPrice(($quo['nowprice'] > 0 ? $quo['nowprice'] : $quo['closePrice']));
$e['now_price'] = $nowPrice;
$e['zd'] = formatPrice(($nowPrice - $e['cj_price']) / $e['cj_price'] * 100, 2) . '%';
}
}
$nick_name_arry = getUser(array_column($wtList, 'CD'), 'nick');
$tids = array_column($wtList, 'userid');
$tInfo = M("userinfo", " ", C('DB_CONFIG_MNCG3'))->where(['uid' => ['in', $tids]])->cache(true, 60)->getField('uid,new_phb,zongup,lastweekup');
foreach ($wtList as &$n) {
$nick_name = $nick_name_arry[$n['CD']];
$n['username'] = $nick_name;
$n['cj_time'] = substr($n['cj_time'], 11, 8);
$n['entrust_bs'] = $n['entrust_bs'] == 'r' ? '买入' : '卖出';
$n['price'] = number_format($n['price'], 2, '.', '');
$n['cj_price'] = number_format($n['cj_price'], 2, '.', '');
//大赛排名和总盈利率
$n['phb'] = $tInfo[$n['userid']]['new_phb'];
$n['zongup'] = $tInfo[$n['userid']]['zongup'];
$n['lastweekup'] = $tInfo[$n['userid']]['lastweekup'];
//点击用户名和股票名跳转需要的参数
$n['goTradeInfo'] = $this->setGoTrade($gInfo, $n['CD'], $nick_name, 2);
$n['StockTrade'] = json_encode(['name' => $n['stock_name'], 'code' => $n['stock_code'], 'market' => $n['stock_type'], 'zqlb' => $n['zqlb']]);
}
$top = $order == 1 ? 50 : 0;
$phb = D('User')->getGroupEntrustList($gInfo, $top,$p, $pageSize);
$this->assign([
'p' => $p,
'pageSize' => $pageSize,
'pages' => ceil($phb[1] / $pageSize),
'wtList'=> $phb[0],
'count' => $phb[1],
'order' => $order,
'wtList'=> $wtList
]);
if (IS_GET) {
//我的排名
......
......@@ -115,13 +115,7 @@ class UserModel extends Model
//从委托表和历史委托表取委托数据
public function getWtList($gInfo, $p = 1, $pageSize = 10, $uids = [])
{
// if($userList===0){
// $userList=$this->getUserList($gInfo);
// }
$gid = $gInfo['teamid'];
// $phbs=array_column($userList,'new_phb','uid');
// var_dump($userList);;
// var_dump($phbs);exit;
$db = M()->db(11, getModel($gInfo['web_id']));
$where = ['bz' => $gid, 'status' => '已成'];
if (!empty($uids)) {
......@@ -132,7 +126,6 @@ class UserModel extends Model
if ($suffix) {
$entrustList = $db->table($hisTable)->where($where)->order('cj_time desc')->cache(true, 3600)->page($p . ',' . $pageSize)->select();
$total = $db->table($hisTable)->where($where)->cache(true, 3600)->count();
// $userNum = $db->table($hisTable)->where($where)->cache(true,3600)->count('distinct userid');
} else {
if ($p == 1) {
$count = $db->table('entrust')->where($where)->count();
......@@ -141,13 +134,10 @@ class UserModel extends Model
$memcache_data = ['count' => $count, 'page' => max($page, 1), 'limit' => $limit];
S($gid . '_part_page', $memcache_data, 7200);
}
// var_dump('a'.$page);exit;
$cache = S($gid . '_part_page');
if (isset($cache['count'])) {
$page = intval($cache['page']);
$limit = intval($cache['limit']);
// $count = intval($cache['count']);
// var_dump($page);exit;
if ($p < $page) {
$entrustList = $db->table('entrust')->where($where)->order('cj_time desc')->cache(true, 60)->page($p . ',' . $pageSize)->select();
}
......@@ -183,6 +173,152 @@ class UserModel extends Model
return [$entrustList, $total ? $total : 0];
}
/**
* 获取训练区或大赛区的成员交易,找出该大赛前3名的委托记录置顶
* @param $gId string 大赛id
* @param $top int 显示前几名,0全部
* @param $p int 页码
* @param $pageSize int 每页显示条数
* @return array
*/
public function getGroupEntrustList($gInfo,$top = 0,$p = 1,$pageSize = 5)
{
$is_xlq = $gInfo['category'] == 1 ? 1 : 0;
$gId = $gInfo['group_id'];
#是否归档
$group = D('Group')->getGroup($gId);
if($is_xlq == 1){
$model = M()->db(1,C('DB_CONFIG_SYN'));
$uinfo_table_name = 'syn_userinfo';
$table_name = 'syn_entrust';
$his_table_name = 'syn_hisentrust';
$uinfo_where = [
'category' => 1
];
$entrust_where = [
'bz' => ['in',D('Group')->ids],
'status'=>['in',['已报','已成']],
];
}else{
$suffix = D('Userinfo')->getTable($gId);
$model = M()->db(2,getModel($group['web_id']));
$uinfo_table_name = 'userinfo';
$table_name = 'entrust';
$his_table_name = $suffix ? 'mncg_archive.hisentrust' . $suffix : 'hisentrust';
$uinfo_where = [
'zt' => 1, 'sex' => $group['teamid']
];
$entrust_where = [
'bz' => $gId,
'status'=>['in',['已报','已成']],
];
}
if($top == 0){
# 取前3名置顶
$uinfo_where['new_phb'] = ['between',[1,3]];
}else{
# 取前$top名,近300条
$uinfo_where['new_phb'] = ['between',[1,$top]];
}
$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)){
#获取置顶数据
$top3_data = $model->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('sort_time desc')
->select();
$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;
}
}
if($top > 0 && !empty($top_uid)){
$entrust_where['userid'] = ['in',array_keys($top_uid)];
}
#取委托总条数和页数
$today_count = $model->table($table_name)->where($entrust_where)->count();
$his_count = $today_count + $model->table($his_table_name)->where($entrust_where)->count();
$today_max_page = ceil($today_count / $pageSize);
if($p <= $today_max_page){
$today_list = $model->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')
->page($p,$pageSize)
->select();
}
#计算偏移量,根据页码去当日数据表取或归档数据表取数据
if($p >= $today_max_page){
$his_max_page = $his_count >= $pageSize * 20 ? 20 : ceil($his_count / $pageSize);
$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)
->where($entrust_where)
->order('cj_time desc')
->page(($p - $his_max_page < 0 ? 1 : $p - $his_max_page),$pageSize)
->select();
}
}
$list = array_merge((array)$list,(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) . '%';
}
#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)];
}
//完成勋章,只有参赛勋章
public function finishXunzhang($userId, $userName, $mobile, $xzType)
{
......
......@@ -3,12 +3,12 @@
<div class="member-des-item" uid="{$vo.userid}">
<p class="item-b1">
<span class="out username" goTradeInfo='{$vo.goTradeInfo}'>{$vo.username}</span>
<eq name="vo.entrust_bs" value="r">买入<else/>卖出</eq>股票
<span class="item-b1-time">{$vo.cj_time}</span>
<eq value="r" name="vo.entrust_bs">买入<else/>卖出</eq>股票
<span class="item-b1-time">{$vo.show_time}</span>
</p>
<table cellspacing="0" cellpadding="0">
<tr>
<td><eq name="vo.entrust_bs" value="r">买入<else/>卖出</eq>数量:<span class="num">{$vo.amount|default='-'}</span></td>
<td><eq value="r" name="vo.entrust_bs">买入<else/>卖出</eq>数量:<span class="num">{$vo.amount|default='-'}</span></td>
<td>当前获利:<span class="<egt name='vo.zd' value='0'>red<else/>green</egt> ">{$vo.zd|default='-'}</span></td>
</tr>
</table>
......
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