Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
stock_new
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sugar
stock_new
Commits
4098f95a
Commit
4098f95a
authored
Jun 20, 2024
by
董先生
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
http://rungit.jxdsy.cn:10000/sugar/stock_new
into dev
parents
f3a10155
624875d2
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
524 additions
and
49 deletions
+524
-49
application/apicom/home/Esop.php
application/apicom/home/Esop.php
+123
-6
application/command.php
application/command.php
+4
-1
application/market/command/TrustCommand.php
application/market/command/TrustCommand.php
+304
-0
application/market/home/Trade.php
application/market/home/Trade.php
+6
-6
application/market/model/Position.php
application/market/model/Position.php
+2
-2
application/market/model/Trust.php
application/market/model/Trust.php
+15
-15
application/money/model/EsopPlan.php
application/money/model/EsopPlan.php
+63
-12
application/money/model/EsopPlanRecord.php
application/money/model/EsopPlanRecord.php
+7
-7
No files found.
application/apicom/home/Esop.php
View file @
4098f95a
<?php
namespace
app\apicom\home
;
use
app\money\model\EsopPlan
as
EsopPlanModel
;
use
app\money\model\EsopPlanRecord
as
EsopPlanRecordModel
;
use
think\db
;
use
think\Request
;
use
think\helper\Hash
;
class
Esop
extends
Common
{
...
...
@@ -12,18 +14,133 @@ class Esop extends Common
* 期权计划
* @return [type] [description]
*/
public
function
getEsopPlanList
(){
if
(
!
MID
)
ajaxmsg
(
'登陆后才能进行查询'
,
0
);
public
function
getEsopPlanList
()
{
if
(
!
MID
)
ajaxmsg
(
'登陆后才能进行查询'
,
0
);
// 获取查询条件
$map
=
$this
->
getMap
();
$map
[
'mid'
]
=
MID
;
$map
[
'mid'
]
=
MID
;
$order
=
'id desc'
;
$page
=
intval
(
$this
->
request
->
param
(
"page"
));
$page
=
$page
?
$page
:
1
;
$offset
=
$page
;
// 数据列表
$data_list
=
EsopPlanModel
::
getEsopPlanList
(
$map
,
"*"
,
$order
,
$offset
);
$data_list
=
EsopPlanModel
::
getEsopPlanList
(
$map
,
$order
,
$offset
);
foreach
(
$data_list
as
$k
=>
$v
)
{
$data_list
[
$k
][
'release_account'
]
=
bcdiv
(
$v
[
'release_account'
],
100
,
2
);
$data_list
[
$k
][
'plan_account'
]
=
bcdiv
(
$v
[
'plan_account'
],
100
,
2
);
$data_list
[
$k
][
'remain_account'
]
=
bcdiv
(
$v
[
'remain_account'
],
100
,
2
);
$data_list
[
$k
][
'account'
]
=
bcdiv
(
$v
[
'account'
],
100
,
2
);
}
ajaxmsg
(
'数据列表'
,
1
,
$data_list
);
}
ajaxmsg
(
'数据列表'
,
1
,
$data_list
);
/**
* 期权计划
* @return [type] [description]
*/
public
function
getEsopPlanRecordList
()
{
if
(
!
MID
)
ajaxmsg
(
'登陆后才能进行查询'
,
0
);
// 获取查询条件
$map
=
$this
->
getMap
();
$map
[
'mid'
]
=
MID
;
$order
=
'id desc'
;
//期权计划ID
$esop_plan_id
=
intval
(
$this
->
request
->
param
(
"esop_plan_id"
));
if
(
$esop_plan_id
)
{
$map
[
'esop_plan_id'
]
=
$esop_plan_id
;
}
$page
=
intval
(
$this
->
request
->
param
(
"page"
));
$page
=
$page
?
$page
:
1
;
$offset
=
$page
;
// 数据列表
$data_list
=
EsopPlanRecordModel
::
getEsopPlanRecordList
(
$map
,
$order
,
$offset
,
15
);
foreach
(
$data_list
as
$k
=>
$v
)
{
$data_list
[
$k
][
'affect'
]
=
bcdiv
(
$v
[
'affect'
],
100
,
2
);
$data_list
[
$k
][
'surplus'
]
=
bcdiv
(
$v
[
'surplus'
],
100
,
2
);
$data_list
[
$k
][
'type'
]
=
getTypeNameForEsop
(
$v
[
'type'
]);
$data_list
[
$k
][
'stock'
]
=
[];
if
(
$v
[
'stock_trust_id'
])
{
}
}
ajaxmsg
(
'数据列表'
,
1
,
$data_list
);
}
/**
* 查询可提现期权
* @return [type] [description]
*/
public
function
getEsopPlanForWithdraw
()
{
if
(
!
MID
)
ajaxmsg
(
'登陆后才能进行查询'
,
0
);
// 获取查询条件
$map
=
$this
->
getMap
();
$map
[
'mid'
]
=
MID
;
$order
=
'id desc'
;
// 数据列表
$data_list
=
EsopPlanModel
::
view
(
'esop_plan ep'
,
'id,account'
)
->
view
(
'stock_list'
,
'title'
,
'stock_list.id=ep.stock_id'
,
'left'
)
->
where
([
'ep.account'
=>
[
'>'
,
0
],
'ep.mid'
=>
MID
,
'ep.status'
=>
1
])
->
select
();
foreach
(
$data_list
as
$k
=>
$v
)
{
$data_list
[
$k
][
'account'
]
=
bcdiv
(
$v
[
'account'
],
100
,
2
);
}
ajaxmsg
(
'数据列表'
,
1
,
$data_list
);
}
/*
* 操作提现操作
*/
public
function
doWithdraw
()
{
$data
=
[];
//银行卡id
$data
[
'bank_id'
]
=
$this
->
request
->
param
(
'bank_id'
);
//用户id
$data
[
'mid'
]
=
MID
;
//提现申请金额
$data
[
'money'
]
=
$this
->
request
->
param
(
"money"
);
//期权计划id
$data
[
'esop_plan_id'
]
=
$this
->
request
->
param
(
"esop_plan_id"
);
if
(
!
$data
[
'esop_plan_id'
])
{
ajaxmsg
(
'请选择要提现的期权!'
,
0
);
}
//提现规则基本校验
$result
=
$this
->
validate
(
$data
,
"Withdraw.create"
);
if
(
true
!==
$result
)
{
ajaxmsg
(
$result
,
0
);
}
if
(
$data
[
'money'
]
<
0
)
{
ajaxmsg
(
'提现金额错误!'
,
0
);
}
//校验当前期权计划余额
$money_res
=
EsopPlanModel
::
where
([
'id'
=>
$data
[
'esop_plan_id'
]])
->
find
();
if
(
empty
(
$money_res
[
'account'
])
||
(
$money_res
[
'account'
]
<=
0
))
{
ajaxmsg
(
'查询账户资金出错!'
,
0
);
}
if
(
isset
(
$money_res
[
'account'
])
&&
$money_res
[
'account'
]
<
$data
[
'money'
])
{
ajaxmsg
(
'提现金额已经大于可用余额!'
,
0
);
}
//查询是否已申请过提现,一次只能有一笔提现
$withdraw_info
=
Db
::
name
(
'money_withdraw'
)
->
where
([
'mid'
=>
MID
])
->
where
([
'status'
=>
0
])
->
find
();
if
(
!
empty
(
$withdraw_info
))
{
ajaxmsg
(
'您已有提现申请,请耐心等待审核。'
,
0
);
}
//校验支付密码
$c
=
Db
::
name
(
'member'
)
->
where
([
"id"
=>
MID
])
->
find
();
if
(
Hash
::
check
((
string
)
$data
[
'paywd'
],
$c
[
'paywd'
]))
{
$res
=
EsopPlanModel
::
esopWithdraw
(
$data
);
}
else
{
ajaxmsg
(
'支付密码错误'
,
0
);
}
if
(
$res
[
'status'
])
{
ajaxmsg
(
'提现申请已提交,请耐心等待审核'
,
1
);
}
else
{
ajaxmsg
(
'提现申请提交失败'
,
0
);
}
}
}
\ No newline at end of file
}
application/command.php
View file @
4098f95a
...
...
@@ -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'
,
];
application/market/command/TrustCommand.php
0 → 100644
View file @
4098f95a
<?php
declare
(
strict_types
=
1
);
namespace
app\market\command
;
use
app\market\model\Deal_stock
;
use
app\market\model\Position
;
use
app\market\model\SubAccountMoney
;
use
think\console\Command
;
use
think\console\Input
;
use
think\console\input\Argument
;
use
think\console\input\Option
;
use
think\console\Output
;
use
think\Db
;
class
TrustCommand
extends
Command
{
protected
function
configure
()
{
// 指令配置
$this
->
setName
(
'Trust'
)
->
setDescription
(
'交易脚本'
);
}
protected
function
execute
(
Input
$input
,
Output
$output
)
{
// 启动协程
//if(!checkTradeTime()) return false;
$time
=
config
(
'trust_active_time'
)
*
60
??
TRUST_ACTIVE_TIME
;
// 处理超时委托线程
$res_c
=
Db
::
name
(
'stock_trust'
)
->
where
(
'status'
,
'已委托'
)
->
where
(
"add_time"
,
"<="
,
time
()
-
$time
)
->
select
();
if
(
!
empty
(
$res_c
))
$this
->
cancelTrusts
(
$res_c
);
// 处理委托交易线程
//$res_t = Db::name('stock_trust')->where('status','已委托')->where("add_time", "between",[time() - $time, time()])->whereDay('trust_date')->select()->toArray();
$res_t
=
Db
::
name
(
'stock_trust'
)
->
where
(
'status'
,
'已委托'
)
->
select
();
if
(
!
empty
(
$res_t
))
$this
->
goturnTrusts
(
$res_t
);
}
/* 将最新委托转成不可撤销状态,等待交易 */
protected
function
goturnTrusts
(
$res
){
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
' 交易委托: '
.
count
(
$res
)
.
" 个"
);
foreach
(
$res
as
$k
=>
$item
){
//查询股票最新行情
$Qdata
=
z_market
(
$item
[
'gupiao_code'
]);
Db
::
startTrans
();
if
(
$this
->
checkTrust
(
$item
)){
if
(
$item
[
'info'
]
!==
'system'
){
switch
(
$item
[
'flag1'
])
{
case
0
;
//'买入委托'
$eprice
=
self
::
getPrice
(
$Qdata
,
$item
[
'gupiao_code'
],
$item
[
'trust_price'
],
'buy'
,
$item
[
'trust_count'
]);
if
(
$eprice
>
0
){
$item
[
'trust_price'
]
=
$eprice
;
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
' '
.
$item
[
'gupiao_name'
]
.
$item
[
'gupiao_code'
]
.
' '
.
$item
[
'trust_price'
]
.
' 买入价格:'
.
$eprice
);
$order_res
=
$this
->
orderTrust
(
$Qdata
,
$item
,
6
);
//实盘买入模式:6
}
else
{
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
' '
.
$item
[
'gupiao_name'
]
.
$item
[
'gupiao_code'
]
.
' '
.
$item
[
'trust_price'
]
.
' 价格检查:'
.
$eprice
);
}
break
;
case
1
;
//'卖出委托':
$eprice
=
self
::
getPrice
(
$Qdata
,
$item
[
'gupiao_code'
],
$item
[
'trust_price'
],
'sell'
,
$item
[
'trust_count'
]);
if
(
$eprice
>
0
){
$item
[
'trust_price'
]
=
$eprice
;
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
' '
.
$item
[
'gupiao_name'
]
.
$item
[
'gupiao_code'
]
.
' '
.
$item
[
'trust_price'
]
.
' 卖出价格:'
.
$eprice
);
$order_res
=
$this
->
orderTrust
(
$Qdata
,
$item
,
5
);
//实盘卖出模式:5
}
else
{
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
' '
.
$item
[
'gupiao_name'
]
.
$item
[
'gupiao_code'
]
.
' '
.
$item
[
'trust_price'
]
.
' 价格检查:'
.
$eprice
);
}
break
;
default
:
$order_res
=
[];
}
}
else
{
//如果是系统强制平仓就不检查市价
$order_res
=
$this
->
orderTrust
(
$Qdata
,
$item
,
5
);
}
if
(
isset
(
$order_res
)
&&
!
empty
(
$order_res
)){
//$this->output->writeln(date('Y-m-d H:i:s').' '.$item['gupiao_name'].$item['gupiao_code'].' 时间:'.date('H:i:s', $item['add_time']).' '.$item['trust_count'].'股 '.$item['flag2'].' 成交');
Db
::
commit
();
}
else
{
Db
::
rollback
();
continue
;
}
}
else
{
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
' '
.
$item
[
'gupiao_name'
]
.
$item
[
'gupiao_code'
]
.
' 交易状态更新失败'
);
}
}
}
/* 撤销超时委托 */
protected
function
cancelTrusts
(
$res
)
{
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
' 超时委托: '
.
count
(
$res
)
.
" 个"
);
$subaccount
=
new
SubAccountMoney
();
foreach
(
$res
as
$k
=>
$v
){
Db
::
startTrans
();
$info
=
Db
::
name
(
'stock_trust'
)
->
where
([
'trust_no'
=>
$v
[
'trust_no'
]])
->
lock
(
true
)
->
find
();
if
(
!
empty
(
$info
)){
$row
=
[];
$row
[
'status'
]
=
"已撤"
;
$row
[
'cancel_order_flag'
]
=
1
;
$row
[
'cancel_order_count'
]
=
$v
[
'trust_count'
];
$trust
=
Db
::
name
(
'stock_trust'
)
->
where
([
'trust_no'
=>
$v
[
'trust_no'
]])
->
update
(
$row
);
$affect
=
Db
::
name
(
'stock_delivery_order'
)
->
where
([
'trust_no'
=>
$v
[
'trust_no'
]])
->
value
(
'liquidation_amount'
);
if
(
!
$affect
)
{
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
' 在订单数据库中,委托单号: '
.
$v
[
'trust_no'
]
.
" 没有找到"
);
}
switch
(
$info
[
'flag2'
]){
case
'买入委托'
:
//解冻并转入子账户可用余额
$subm_res
=
$subaccount
->
up_moneylog
(
$v
[
'sub_id'
],
$affect
,
8
);
$position_in
=
$subm_res
?
true
:
false
;
break
;
case
'卖出委托'
:
$position
=
Db
::
name
(
'stock_position'
)
->
where
([
'sub_id'
=>
$v
[
'sub_id'
],
'gupiao_code'
=>
$info
[
'gupiao_code'
]])
->
find
();
$position
[
'canbuy_count'
]
=
$position
[
'canbuy_count'
]
+
$v
[
'trust_count'
];
$position_in
=
Db
::
name
(
'stock_position'
)
->
where
([
'sub_id'
=>
$v
[
'sub_id'
],
'gupiao_code'
=>
$info
[
'gupiao_code'
]])
->
update
(
$position
);
$subm_res
=
$subaccount
->
up_moneylog
(
$v
[
'sub_id'
],
$affect
,
9
);
break
;
}
$delivery
=
Db
::
name
(
'stock_delivery_order'
)
->
where
([
'trust_no'
=>
$v
[
'trust_no'
]])
->
delete
();
if
(
$trust
&&
$delivery
&&
$subm_res
&&
$position_in
){
Db
::
commit
();
}
else
{
Db
::
rollback
();
continue
;
}
}
//$this->output->writeln(date('Y-m-d H:i:s').' '.$v['gupiao_name'].$v['gupiao_code'].' 时间:'.date('H:i:s', $v['add_time']).' '.$v['trust_count'].'股 撤单成功');
}
}
/*写入委托表*/
protected
function
checkTrust
(
$item
)
{
$row
=
[
'status'
=>
"已成"
,
//状态说明
'volume'
=>
$item
[
'trust_count'
],
//成交数量
'amount'
=>
$item
[
'trust_count'
]
*
$item
[
'trust_price'
],
//成交金额
'cancel_order_flag'
=>
1
,
//撤单标志 1、已成
];
$trust
=
Db
::
name
(
'stock_trust'
)
->
where
([
'trust_no'
=>
$item
[
'trust_no'
]])
->
update
(
$row
);
return
$trust
;
}
/*交易买入/卖出*/
protected
function
orderTrust
(
$Qdata
,
$trust
,
$trustModel
)
{
$subaccount
=
new
SubAccountMoney
();
//检查交割明细
$dev_info
=
Db
::
name
(
'stock_delivery_order'
)
->
where
([
'trust_no'
=>
$trust
[
'trust_no'
]])
->
find
();
//print_r($dev_info);return false;
$affect
=
$dev_info
[
'liquidation_amount'
];
if
(
!
$affect
)
return
false
;
//$moneyinfo = SubAccountMoney::getAccountMoney($trust['sub_id']);
//计算佣金
//$commission = commission($trust['trust_count'] * $trust['trust_price'],$moneyinfo['commission_scale'],$moneyinfo['min_commission']);
//如果时卖出模式时加上印花税
//$stamps = $trustModel === 5 ? stamps($trust['trust_count'] * $trust['trust_price']) : 0;
//计算过户费
//$transfer = transfer($trust['trust_count'] * $trust['trust_price']);
//计算手续费
//$fee = $commission + $stamps + $transfer;
//$cha = $dev_info['commission'] + $dev_info['transfer_fee'] - $fee;
//这里用(最新价格-委托价格*委托数量),以便加入子账户中
$Balance
=
round
((
$Qdata
[
'current_price'
]
-
$trust
[
'trust_price'
])
*
$trust
[
'trust_count'
],
2
);
//print_r($trust['sub_id'].' '.$affect.' '.$trustModel.' '.$Balance);return false;
//写入子账户资金变化表
$sm_res
=
$subaccount
->
up_moneylog
(
$trust
[
'sub_id'
],
$affect
,
$trustModel
,
$return_money
=
0
,
$Balance
);
//写入成交表
$deal_stock
=
new
Deal_stock
();
$deal_res
=
$deal_stock
->
add_m_deal_stock
(
$Qdata
,
$trust
[
'trust_count'
],
$trust
[
'trust_price'
],
$trust
[
'sub_id'
],
$trust
[
'lid'
],
$trust
[
'login_name'
],
$trust
[
'soruce'
],
$trust
[
'trust_no'
],
1
);
//查询持仓表
$postmd
=
Db
::
name
(
'stock_position'
)
->
where
([
'sub_id'
=>
$trust
[
'sub_id'
],
'gupiao_code'
=>
$trust
[
'gupiao_code'
]])
->
find
();
$canbuy
=
!
empty
(
$postmd
)
?
$postmd
[
'stock_count'
]
:
0
;
//if($canbuy <= 0) $this->output->writeln(date('Y-m-d H:i:s').$trust['gupiao_name'].' '.$trust['gupiao_code'].' 可卖数量: '.$canbuy);
//组合数据后修改交割表
$delivery
=
[];
$position
=
[];
switch
(
$trustModel
)
{
case
6
:
//'买入委托' //实盘买入模式:6
$delivery
[
'amount'
]
=
$canbuy
+
$trust
[
'trust_count'
];
$delivery
[
'amount'
]
=
$canbuy
+
$trust
[
'trust_count'
];
$canbuy
=
$canbuy
+
$trust
[
'trust_count'
];
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
$trust
[
'gupiao_name'
]
.
' '
.
$trust
[
'gupiao_code'
]
.
' 买入后数量: '
.
$canbuy
);
break
;
case
5
:
//'卖出委托' //实盘卖出模式:5
$delivery
[
'amount'
]
=
$canbuy
-
$trust
[
'trust_count'
];
$delivery
[
'amount'
]
=
$canbuy
-
$trust
[
'trust_count'
];
$canbuy
=
$canbuy
-
$trust
[
'trust_count'
];
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
$trust
[
'gupiao_name'
]
.
' '
.
$trust
[
'gupiao_code'
]
.
' 卖出后数量: '
.
$canbuy
);
break
;
default
:
$delivery
[
'amount'
]
=
$trust
[
'trust_count'
];
$delivery
[
'amount'
]
=
$trust
[
'trust_count'
];
break
;
}
$delivery
[
'status'
]
=
'1'
;
// 改变订单状态
//$delivery['deal_price'] = $trust['trust_price'];
//$delivery['deal_date'] = date("Y-m-d",time());
//$delivery['transfer_fee'] = $transfer;
//$delivery['commission'] = $commission;
//$delivery['residual_quantity'] = $trust['trust_count'] * $trust['trust_price'];
//$delivery['liquidation_amount'] = $trust['trust_count'] * $trust['trust_price'] + $fee;
//$delivery['residual_amount'] = $dev_info['residual_amount'] + $dev_info['liquidation_amount'] - $delivery['liquidation_amount'];
$delivery_res
=
Db
::
name
(
'stock_delivery_order'
)
->
where
([
'trust_no'
=>
$trust
[
'trust_no'
]])
->
update
(
$delivery
);
// 新增/修改持仓列表
$position_res
=
Position
::
add_m_position
(
$Qdata
,
$canbuy
,
$trust
[
'sub_id'
],
$trust
[
'lid'
],
$trust
[
'login_name'
],
$trust
[
'soruce'
],
$trust
[
'trust_price'
],
2
,
$trust
[
'trust_no'
]);
//print_r($canbuy);return;
if
(
$sm_res
&&
$deal_res
&&
$delivery_res
&&
$position_res
)
return
true
;
$this
->
output
->
writeln
(
date
(
'Y-m-d H:i:s'
)
.
' sm_res: '
.
$sm_res
.
" deal_res:"
.
$deal_res
.
" delivery_res:"
.
$delivery_res
.
" position_res:"
.
$position_res
);
return
false
;
}
protected
function
getPrice
(
$Qdata
,
$stockCode
,
$price
,
$direction
,
$count
=
100
)
{
try
{
// 最新行情
$eprice
=
0
;
$Qdata
=
$Qdata
?:
z_market
(
$stockCode
);
switch
(
$direction
)
{
case
'buy'
:
if
(
$price
<=
0
){
// 从1档递进取价格
for
(
$stall
=
1
;
$stall
<=
5
;
$stall
++
)
{
switch
(
$stall
)
{
case
1
:
// 卖一
$key
=
'sell_one_price'
;
//价格
$val
=
'sell_one_amount'
;
//卖一量(手)
break
;
case
2
:
// 卖二
$key
=
'sell_two_price'
;
//价格
$val
=
'sell_two_amount'
;
//卖二量(手)
break
;
case
3
:
// 卖三
$key
=
'sell_three_price'
;
//价格
$val
=
'sell_three_amount'
;
//卖三量(手)
break
;
case
4
:
// 卖四
$key
=
'sell_four_price'
;
//价格
$val
=
'sell_four_amount'
;
//卖四量(手)
break
;
case
5
:
// 卖五
$key
=
'sell_five_price'
;
//价格
$val
=
'sell_five_amount'
;
//卖五量(手)
break
;
}
$price
=
$Qdata
[
$key
];
if
(
$price
>
0
&&
$count
<=
$Qdata
[
$val
]
*
10000
){
$eprice
=
$price
;
break
;
}
}
}
else
{
$eprice
=
$price
>=
$Qdata
[
'current_price'
]
&&
$Qdata
[
'current_price'
]
>
0
&&
$price
<=
$Qdata
[
'sell_five_price'
]
?
$price
:
0
;
}
break
;
case
'sell'
:
if
(
$price
<=
0
){
// 从1档递进取价格
for
(
$stall
=
1
;
$stall
<=
5
;
$stall
++
)
{
switch
(
$stall
)
{
case
1
:
// 卖一
$key
=
'buy_one_price'
;
//价格
$val
=
'buy_one_amount'
;
//卖一量(手)
break
;
case
2
:
// 卖二
$key
=
'buy_two_price'
;
//价格
$val
=
'buy_two_amount'
;
//卖二量(手)
break
;
case
3
:
// 卖三
$key
=
'buy_three_price'
;
//价格
$val
=
'buy_three_amount'
;
//卖三量(手)
break
;
case
4
:
// 卖四
$key
=
'buy_four_price'
;
//价格
$val
=
'buy_four_amount'
;
//卖四量(手)
break
;
case
5
:
// 卖五
$key
=
'buy_five_price'
;
//价格
$val
=
'buy_five_amount'
;
//卖五量(手)
break
;
}
$price
=
$Qdata
[
$key
];
if
(
$price
>
0
&&
$count
<=
$Qdata
[
$val
]
*
10000
){
$eprice
=
$price
;
break
;
}
}
}
else
{
$eprice
=
$price
<=
$Qdata
[
'current_price'
]
&&
$Qdata
[
'current_price'
]
>
0
&&
$price
<=
$Qdata
[
'buy_one_price'
]
?
$price
:
0
;
}
break
;
}
}
catch
(
\Exception
$e
)
{
$eprice
=
0
;
}
return
$eprice
;
}
}
application/market/home/Trade.php
View file @
4098f95a
...
...
@@ -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
[
'
P
rice'
]
==
''
)
continue
;
$res
[
'return_money'
]
+=
(
$data
[
'
P
rice'
]
-
$v
[
'buy_average_price'
])
*
$v
[
'stock_count'
];
$res
[
'market_value'
]
+=
$data
[
'
P
rice'
]
*
$v
[
'stock_count'
];
if
(
$data
[
'
current_p
rice'
]
==
''
)
continue
;
$res
[
'return_money'
]
+=
(
$data
[
'
current_p
rice'
]
-
$v
[
'buy_average_price'
])
*
$v
[
'stock_count'
];
$res
[
'market_value'
]
+=
$data
[
'
current_p
rice'
]
*
$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
[
'
P
rice'
];
$data
[
$k
][
'now_price'
]
=
$Qdata
[
'
current_p
rice'
];
//市值 = 当前价格*数量
$data
[
$k
][
'market_value'
]
=
round
((
int
)
$Qdata
[
'
P
rice'
]
*
(
int
)
$item
[
'stock_count'
],
2
);
$data
[
$k
][
'market_value'
]
=
round
((
int
)
$Qdata
[
'
current_p
rice'
]
*
(
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
[
"
P
rice"
]
-
(
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_p
rice"
]
-
(
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;//盈亏比例
...
...
application/market/model/Position.php
View file @
4098f95a
...
...
@@ -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
]);
...
...
application/market/model/Trust.php
View file @
4098f95a
...
...
@@ -323,7 +323,7 @@ class Trust extends Model{
{
//查询股票最新行情
$Qdata
=
z_market
(
$data
[
'code'
],
$data
[
'market'
]);
$price
=
$data
[
'price'
]
<=
0
?
$Qdata
[
'
P
rice'
]
:
$data
[
'price'
];
$price
=
$data
[
'price'
]
<=
0
?
$Qdata
[
'
current_p
rice'
]
:
$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
[
'
P
rice'
]
:
$data
[
'price'
];
$price
=
$data
[
'price'
]
<=
0
?
$Qdata
[
'
current_p
rice'
]
:
$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
[
'
P
rice'
];
$price
=
$Qdata
[
'
current_p
rice'
];
//如果没有委托价格使用下面的公式
$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
[
'
P
rice'
])
+
$trade_money
)))
{
if
(
isset
(
$res
[
'quota'
])
&&
(
$res
[
'quota'
]
<
((
$pos
*
$Qdata
[
'
current_p
rice'
])
+
$trade_money
)))
{
return
[
'status'
=>
0
,
'message'
=>
'该股票超过了单支股票最大购买限额'
];
}
return
;
...
...
application/money/model/EsopPlan.php
View file @
4098f95a
...
...
@@ -4,6 +4,10 @@ namespace app\money\model;
use
think\helper\Hash
;
use
app\money\model\Role
as
RoleModel
;
use
app\money\model\EsopPlanRecord
as
EsopPlanRecordModel
;
use
app\money\model\Withdraw
as
MoneyWithdrawModel
;
use
app\member\model\Bank
as
BankModel
;
use
app\member\model\MemberMessage
as
MemberMessageModel
;
use
think\model
;
use
think\Db
;
...
...
@@ -36,23 +40,70 @@ class EsopPlan extends Model
*获取期权计划列表
* @author 2024-06-20
*/
public
static
function
getEsopPlanList
(
$where
=
[],
$
field
=
'*'
,
$
order
=
'id asc'
,
$offset
,
$pagesize
=
15
)
public
static
function
getEsopPlanList
(
$where
=
[],
$order
=
'id asc'
,
$offset
,
$pagesize
=
15
)
{
$esop_plan_list
=
self
::
view
(
'esop_plan ep'
,
true
)
->
view
(
"stock_list sl"
,
'title,code'
,
's
tock_list
.id=ep.stock_id'
,
'left'
)
$esop_plan_list
=
self
::
view
(
'esop_plan ep'
,
'id,mid,account,plan_account,release_account,remain_account,release_time'
)
->
view
(
"stock_list sl"
,
'title,code'
,
's
l
.id=ep.stock_id'
,
'left'
)
->
field
([
"CONCAT(ROUND(release_account / plan_account * 100, 2), ' % ')"
=>
'accuracy'
])
->
field
([
"FROM_UNIXTIME(create_time,'%Y-%m-%d %T')"
=>
'create_time'
])
->
field
([
"FROM_UNIXTIME(
ep.
create_time,'%Y-%m-%d %T')"
=>
'create_time'
])
->
where
(
$where
)
->
field
(
$field
)
->
order
(
$order
)
->
page
(
$offset
,
$pagesize
)
->
select
()
->
each
(
function
(
$item
,
$key
)
{
$item
->
account
=
money_convert
(
$item
->
account
);
$item
->
plan_account
=
money_convert
(
$item
->
plan_account
);
$item
->
remain_account
=
money_convert
(
$item
->
remain_account
);
$item
->
release_account
=
money_convert
(
$item
->
release_account
);
});;
->
select
();
return
$esop_plan_list
;
}
/**
* 期权提现
*/
public
static
function
esopWithdraw
(
$parameter
)
{
$bank_id
=
$parameter
[
'bank_id'
];
$bank
=
BankModel
::
bankInfo
(
$bank_id
);
//银行卡信息
$where1
[
'id'
]
=
$parameter
[
'mid'
];
//会员ID
$where1
[
'status'
]
=
1
;
//会员状态
$names
=
Db
::
name
(
'member'
)
->
field
(
'name'
)
->
where
(
$where1
)
->
find
();
//用户基本信息
//组合提现记录
$data
[
'bank'
]
=
$bank
[
'bank'
]
.
"|"
.
$bank
[
'card'
]
.
'|'
.
$bank
[
'province'
]
.
$bank
[
'city'
]
.
$bank
[
'branch'
]
.
"|"
.
$names
[
'name'
];
$data
[
'mid'
]
=
$parameter
[
'mid'
];
$data
[
'money'
]
=
$parameter
[
'money'
]
*
100
;
$data
[
'order_no'
]
=
'tx'
.
generate_rand_str
(
10
,
3
);
$data
[
'create_time'
]
=
time
();
$data
[
'create_ip'
]
=
get_client_ip
(
1
);
Db
::
startTrans
();
//查看当前期权的信息
$money_info
=
self
::
where
([
'id'
=>
$data
[
'esop_plan_id'
]])
->
find
();
//计算余额
$account
=
bcsub
(
$money_info
[
'account'
],
$data
[
'money'
]);
try
{
$res1
=
MoneyWithdrawModel
::
create
(
$data
);
//写入期权变化明细表
$arr
=
[
'mid'
=>
$parameter
[
'mid'
],
'stock_id'
=>
$parameter
[
'stock_id'
],
'esop_plan_id'
=>
$parameter
[
'esop_plan_id'
],
'affect'
=>
$parameter
[
'money'
],
'surplus'
=>
$account
,
'heatos'
=>
-
1
,
'type'
=>
3
,
'info'
=>
"期权申请提现,金额:"
.
$parameter
[
'money'
],
'create_time'
=>
time
(),
'create_ip'
=>
get_client_ip
(
1
)
];
$res2
=
EsopPlanRecordModel
::
create
(
$arr
);
//更新期权信息
$res3
=
self
::
where
(
'id'
,
$parameter
[
'esop_plan_id'
])
->
update
(
'account'
,
$account
);
if
(
$res1
&&
$res2
&&
$res3
)
{
Db
::
commit
();
return
[
'status'
=>
1
,
'message'
=>
'提交成功'
];
}
else
{
Db
::
rollback
();
return
[
'status'
=>
0
,
'message'
=>
'提交失败'
];
}
}
catch
(
\Exception
$e
)
{
Db
::
rollback
();
return
[
'status'
=>
0
,
'message'
=>
'数据异常'
];
}
}
}
application/money/model/EsopPlanRecord.php
View file @
4098f95a
...
...
@@ -34,15 +34,15 @@ class EsopPlanRecord extends Model
*获取期权明细记录列表
* @author 2024-06-20
*/
public
static
function
getEsopPlanRecordList
(
$where
=
[],
$
field
=
'*'
,
$order
=
'id asc'
)
public
static
function
getEsopPlanRecordList
(
$where
=
[],
$
order
=
'id asc'
,
$offset
,
$pagesize
)
{
$esop_plan_
list
=
self
::
view
(
'esop_plan_record epr'
,
true
)
->
view
(
"stock_list sl"
,
'title,code'
,
's
tock_list.id=ep
.stock_id'
,
'left'
)
->
view
(
"esop_plan ep"
,
'title,code'
,
'stock_list.id=ep.stock_id'
,
'left'
)
$esop_plan_
record_list
=
self
::
view
(
'esop_plan_record epr'
,
"id,mid,stock_id,stock_trust_id,affect,surplus,heatos,type,info"
)
->
view
(
"stock_list sl"
,
'title,code'
,
's
l.id=epr
.stock_id'
,
'left'
)
->
field
([
"FROM_UNIXTIME(epr.create_time,'%Y-%m-%d %T')"
=>
'create_time'
]
)
->
where
(
$where
)
->
field
(
$field
)
->
order
(
$order
)
->
paginate
();
return
$esop_plan_list
;
->
page
(
$offset
,
$pagesize
)
->
select
();
return
$esop_plan_record_list
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment