Commit 624875d2 authored by twj's avatar twj

Merge branch 'dev' of http://rungit.jxdsy.cn:10000/sugar/stock_new into dev

parents 62a2f8d0 ce7b5a94
......@@ -9,4 +9,7 @@
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
return ['app\stock\command\Crontab'];
\ No newline at end of file
return [
'Crontab'=>'app\stock\command\Crontab',
'Trust' => 'app\market\command\TrustCommand',
];
This diff is collapsed.
......@@ -37,9 +37,9 @@ class Trade extends Common
$res['market_value'] = 0;
foreach ($pos as $k => $v ) {
$data = z_market($v['gupiao_code']);
if($data['Price'] == '') continue;
$res['return_money'] += ($data['Price'] - $v['buy_average_price']) * $v['stock_count'];
$res['market_value'] += $data['Price'] * $v['stock_count'];
if($data['current_price'] == '') continue;
$res['return_money'] += ($data['current_price'] - $v['buy_average_price']) * $v['stock_count'];
$res['market_value'] += $data['current_price'] * $v['stock_count'];
}
// 提盈额度计算
$all = $res['market_value'] + $res['avail'];
......@@ -86,16 +86,16 @@ class Trade extends Common
//查询子账户
$data[$k]['sub_account'] = $res['sub_account'];
//提取当前价格
$data[$k]['now_price'] = $Qdata['Price'];
$data[$k]['now_price'] = $Qdata['current_price'];
//市值 = 当前价格*数量
$data[$k]['market_value'] = round((int)$Qdata['Price']*(int)$item['stock_count'],2);
$data[$k]['market_value'] = round((int)$Qdata['current_price']*(int)$item['stock_count'],2);
//参考成本价
$data[$k]['ck_price'] = Position::calculate($subid,$item["gupiao_code"],'price');
//买入均价
$data[$k]['buy_average_price'] = Position::calculate($subid,$item["gupiao_code"],'average');
//参考盈亏
//$data[$k]['ck_profit'] = $item['stock_count'] > 0 ? round(($Qdata['Price']-$data[$k]['buy_average_price'])*$item['stock_count'], 2) : 0;
$data[$k]['ck_profit'] = $item['stock_count'] > 0 ? bcmul(strval((int)$Qdata["Price"]-(int)$data[$k]['buy_average_price']),strval($item['stock_count']),2) : 0;//参考浮动盈亏
$data[$k]['ck_profit'] = $item['stock_count'] > 0 ? bcmul(strval((int)$Qdata["current_price"]-(int)$data[$k]['buy_average_price']),strval($item['stock_count']),2) : 0;//参考浮动盈亏
//盈亏比例
//$data[$k]['profit_rate'] = $item['stock_count'] > 0 ? round(($data[$k]['ck_profit'] / ($data[$k]['buy_average_price'] * $item['stock_count'])) * 100, 2) : 0;
//$data[$k]['profit_rate'] = $item['stock_count'] > 0 ? bcdiv(strval($data[$k]['ck_profit']),strval($data[$k]['buy_average_price']*$item['stock_count']*100),2) : 0;//盈亏比例
......@@ -166,15 +166,7 @@ class Trade extends Common
//提交交易费用信息
$Delivery = new Delivery;
$avail = ($moneyinfo['avail']) - $effectMoney;
$Qdata = z_market($data["gupiao_code"],$data['market']);
//参考成本价
$ck_price = Position::calculate($data['sub_id'],$data["gupiao_code"],'price');
//买入均价
$buy_average_price = Position::calculate($data['sub_id'],$data["gupiao_code"],'average');
//参考盈亏
//$data[$k]['ck_profit'] = $item['stock_count'] > 0 ? round(($Qdata['Price']-$data[$k]['buy_average_price'])*$item['stock_count'], 2) : 0;
Position::addPosition($data['code'], $data['market'],$data['count'],$data['sub_id'],$broker['lid'],$broker['user'],$broker['stockjobber'],$ck_price, 0);
Position::addPosition($data['code'], $data['market'],$data['count'],$data['sub_id'],$broker['lid'],$broker['user'],$broker['stockjobber']);
//print_r("佣金: ".$commission." 过户费: ".$transfer." 总计:".$effectMoney);Db::rollback();exit;
$del_res = $Delivery->add_m_delivery_order($data, $data['count'],$data['price'],$data['sub_id'],$broker['lid'],$broker['user'],$broker['stockjobber'],$commission,$transfer,$Trust_no,$avail,$amount, $data['model']);
//print_r($del_res);Db::rollback();exit;
......
......@@ -205,9 +205,9 @@ class Position extends Model{
* $sub_id 子账号
* $code 股票代码
*/
public static function getCodePosition($sub_id,$code){
public static function getCodePosition($sub_id,$code,$market){
$res=Db::name('stock_position')
->where(['sub_id'=>$sub_id,'gupiao_code'=>$code])
->where(['sub_id'=>$sub_id,'gupiao_code'=>$code,'market'=>$market])
->where(['buying'=>0])
->find();
if(empty($res)){return false;}
......@@ -363,7 +363,7 @@ class Position extends Model{
$data[0]['gudong_code'] = "";//股东代码 无法模拟暂时空
$data[0]['type'] = $stockinfo["exchange_code"];//帐号类别
$data[0]['jigou_type'] = 1;
$data[0]['jiyisuo'] = $stockinfo["exchange_code"]==0? "深交所":"上交所";//交易所
$data[0]['jiyisuo'] = toMarket($stockinfo["code"]) == "HK" ? "港交所":toMarket($stockinfo["code"])=='SZ'? "深交所":"上交所";//交易所
$data[0]['info'] = "";
$result = Db::name('stock_position')->insert($data[0],true);
}elseif($model==1){
......@@ -401,7 +401,7 @@ class Position extends Model{
$data[0]['gudong_code'] = "";//股东代码 无法模拟暂时空
$data[0]['type'] = $stockinfo["exchange_code"];//帐号类别
$data[0]['jigou_type'] = 1;
$data[0]['jiyisuo'] = $stockinfo["exchange_code"]==0? "深交所":"上交所";//交易所
$data[0]['jiyisuo'] = toMarket($stockinfo["code"]) == "HK" ? "港交所":toMarket($stockinfo["code"])=='SZ'? "深交所":"上交所";//交易所
$data[0]['info'] = "";
}
$result = Db::name('stock_position')->where(['id'=>$position_res['id']])->update($data[0]);
......@@ -418,12 +418,13 @@ class Position extends Model{
* $user 证券账户
* $soure 证券来源
*/
public static function addPosition($code,$market,$count,$sub_id,$lid,$user,$soure,$ck_price,$Trust_no)
public static function addPosition($code,$market,$count,$sub_id,$lid,$user,$soure)
{
//if(!$count) return false;
if(!$count) return false;
//$canbuy = self::getCanbuyCount($sub_id,$code);
$position = self::getCodePosition($sub_id, $code);
$position = self::getCodePosition($sub_id,$code,$market);
$canbuy_count=$position['canbuy_count']+$count;
$new_price=round(($position['canbuy_count']*$position['buy_average_price']+$count*$position['ck_price'])/$canbuy_count,3);
$stockinfo = z_market($code,$market);
$data = array();
$data[0]['sub_id'] = $sub_id;
......@@ -435,14 +436,13 @@ class Position extends Model{
$data[0]['count'] = $count;
$data[0]['stock_count'] = $position['stock_count']+$count;
$data[0]['canbuy_count'] = $position['canbuy_count']+$count;
$data[0]['ck_price'] = self::calculate($sub_id,$code,'price');//参考成本价
dump($data[0]['ck_price']);die;
$data[0]['buy_average_price'] = self::calculate($sub_id,$code,'average');//买入均价
$data[0]['ck_profit_price'] = '';//参考盈亏成本价
$data[0]['ck_price'] = $new_price;//参考成本价;
$data[0]['buy_average_price'] = $new_price;//买入均价
$data[0]['ck_profit_price'] = $new_price;//参考盈亏成本价
$data[0]['now_price'] = $stockinfo["current_price"];//'当前价'
$data[0]['market_value'] = $stockinfo["current_price"] * $count;//最新市值
$data[0]['ck_profit'] = $count > 0 ? bcmul(strval($stockinfo["current_price"] - $ck_price),strval($count),2) : 0; //参考浮动盈亏
$data[0]['profit_rate'] = $count > 0 && $ck_price > 0 ? bcdiv(strval($data[0]['ck_profit']),strval($ck_price * $count * 100),2) : 0; //盈亏比例
$data[0]['ck_profit'] = $position['ck_profit']; //参考浮动盈亏
$data[0]['profit_rate'] = $position['profit_rate']; //盈亏比例
$data[0]['buying'] = 0;//买入成功
$data[0]['selling'] = 0;//1、在途卖出
$data[0]['gudong_code'] = "";//股东代码 无法模拟暂时空
......
......@@ -323,7 +323,7 @@ class Trust extends Model{
{
//查询股票最新行情
$Qdata = z_market($data['code'],$data['market']);
$price = $data['price'] <= 0 ? $Qdata['Price'] : $data['price'];
$price = $data['price'] <= 0 ? $Qdata['current_price'] : $data['price'];
//判断股票价格是否符号购买条件
if (config('stock_buy_price') > 0) {
if ($price < config('stock_buy_price')) {
......@@ -376,7 +376,7 @@ class Trust extends Model{
{
//查询股票最新行情
$Qdata = z_market($data['code'],$data['market']);
$price = $data['price'] <= 0 ? $Qdata['Price'] : $data['price'];
$price = $data['price'] <= 0 ? $Qdata['current_price'] : $data['price'];
if(config('site_trade_sell') == 0) {
return array('status' => 0, 'message' => '系统设置不允许卖出股票');
......@@ -387,7 +387,7 @@ class Trust extends Model{
return ['status'=>0, 'message'=>'可卖股票不足'];
}
//当股票跌停时买一至买五价格为空
if(intval($Qdata["Bp1"]) <= 0 || intval($Qdata['Bv1']*100) < $data['count']){
if(intval($Qdata["buy_one_price"]) <= 0 || intval($Qdata['buy_one_amount']*100) < $data['count']){
return ['status'=>0, 'message'=>'当前买盘不足,无法即时成交!'];
}
//检查子账户余额
......@@ -398,7 +398,7 @@ class Trust extends Model{
if($data['price'] > 0 && $data['model'] == 1){ //model = 1 是委托状态
$trade_money = intval($data['count']) * intval($data['price']);
}else{
$price = $Qdata['Price'];
$price = $Qdata['current_price'];
//如果没有委托价格使用下面的公式
$trade_money = intval($data['count']) * intval($price);
}
......@@ -426,16 +426,16 @@ class Trust extends Model{
$trade_money = $count * $price;
}else{
$price = 0;
$v_arr[1] = $Qdata['Sv1'] * 100;
$v_arr[2] = $Qdata['Sv2'] * 100;
$v_arr[3] = $Qdata['Sv3'] * 100;
$v_arr[4] = $Qdata['Sv4'] * 100;
$v_arr[5] = $Qdata['Sv5'] * 100;
$p_arr[1] = $Qdata['Sp1'];
$p_arr[2] = $Qdata['Sp2'];
$p_arr[3] = $Qdata['Sp3'];
$p_arr[4] = $Qdata['Sp4'];
$p_arr[5] = $Qdata['Sp5'];
$v_arr[1] = $Qdata['sell_one_amount'] * 100;
$v_arr[2] = $Qdata['sell_two_amount'] * 100;
$v_arr[3] = $Qdata['sell_three_amount'] * 100;
$v_arr[4] = $Qdata['sell_four_amount'] * 100;
$v_arr[5] = $Qdata['sell_five_amount'] * 100;
$p_arr[1] = $Qdata['sell_one_price'];
$p_arr[2] = $Qdata['sell_two_price'];
$p_arr[3] = $Qdata['sell_three_price'];
$p_arr[4] = $Qdata['sell_four_price'];
$p_arr[5] = $Qdata['sell_five_price'];
$tmd = 0;
foreach ($v_arr as $key => $v ){
$tmd = $tmd + $v;
......@@ -464,7 +464,7 @@ class Trust extends Model{
$res = Db::name('stock_list')->where(['code' => $code, 'status' => 1])->find();
//判断是否超过该只股票限额
$pos = Db::name('stock_position')->where(['sub_id' => $subid,'gupiao_code' => $code,'buying' => 0])->sum('stock_count');
if (isset($res['quota']) && ($res['quota'] < (($pos * $Qdata['Price']) + $trade_money))) {
if (isset($res['quota']) && ($res['quota'] < (($pos * $Qdata['current_price']) + $trade_money))) {
return ['status'=>0, 'message'=>'该股票超过了单支股票最大购买限额'];
}
return;
......
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