Commit 4098f95a authored by 董先生's avatar 董先生

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

parents f3a10155 624875d2
<?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
}
......@@ -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;//盈亏比例
......
......@@ -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]);
......
......@@ -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;
......
......@@ -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', 'stock_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', 'sl.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' => '数据异常'];
}
}
}
......@@ -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', 'stock_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', 'sl.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;
}
}
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