You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.2 KiB
71 lines
2.2 KiB
2 months ago
|
<?php
|
||
|
namespace app\model;
|
||
|
|
||
|
class GoldFuturesTradeModel extends BaseModel
|
||
|
{
|
||
|
protected $name = 'gold_futures_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'];
|
||
|
}
|
||
|
}
|
||
|
}
|