5 changed files with 180 additions and 0 deletions
@ -0,0 +1,74 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace app\model; |
||||
|
|
||||
|
class StockIndexInrTrade extends BaseModel |
||||
|
{ |
||||
|
protected $name = 'stock_index_inr_trade'; |
||||
|
protected $pk = 'trade_id'; |
||||
|
|
||||
|
// 获取持仓成本 |
||||
|
public static function getTradeOrderBuyNum(int $user_id,string $contract_id,int $trade_type) |
||||
|
{ |
||||
|
$num=0; |
||||
|
$money=0; |
||||
|
//查询持仓订单总成本 |
||||
|
$list=self::where([ |
||||
|
'user_id'=>$user_id, |
||||
|
'status'=>1, |
||||
|
'contract_id'=>$contract_id, |
||||
|
'trade_type'=>$trade_type |
||||
|
])->field('order_number,deal_price,service_cost')->select(); |
||||
|
if(!empty($list)) { |
||||
|
$list_arr=$list->toArray(); |
||||
|
foreach ($list_arr as $val){ |
||||
|
$order_num=$val['order_number']*$val['deal_price'] ;//+ $val['service_cost']; |
||||
|
$money+=$order_num; |
||||
|
$num+=$val['order_number']; |
||||
|
} |
||||
|
} |
||||
|
return [ |
||||
|
'buy_num'=>$num, |
||||
|
'buy_money'=>$money |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 获取累计盈亏 |
||||
|
public static function getTradeOrderDailyNum(int $user_id) |
||||
|
{ |
||||
|
$num=0; |
||||
|
//查询持仓订单总成本 |
||||
|
$list=self::where([ |
||||
|
'user_id'=>$user_id, |
||||
|
'status'=>3 |
||||
|
])->field('order_number,closing_price,deal_price,closing_cost,service_cost,trade_type')->select(); |
||||
|
if(!empty($list)) { |
||||
|
$list_arr=$list->toArray(); |
||||
|
foreach ($list_arr as $val){ |
||||
|
if($val['trade_type']==1){ |
||||
|
$order_num=$val['order_number']*($val['closing_price']-$val['deal_price']); |
||||
|
}else{ |
||||
|
$order_num=$val['order_number']*($val['deal_price']-$val['closing_price']); |
||||
|
} |
||||
|
$num+=$order_num; |
||||
|
} |
||||
|
} |
||||
|
return $num; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public static function getTradeOrderFee(int $user_id) |
||||
|
{ |
||||
|
$info=self::where([ |
||||
|
['user_id','=',$user_id], |
||||
|
['status','in',[1,3]] |
||||
|
])->field('sum(service_cost+closing_cost) as fee')->find(); |
||||
|
if(empty($info)){ |
||||
|
return 0; |
||||
|
}else{ |
||||
|
$info=$info->toArray(); |
||||
|
return empty($info['fee']) ? 0 : $info['fee']; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue