Commit 3d6d3313 authored by wuxiaoli's avatar wuxiaoli

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

parents a0a36be5 7779accc
This diff is collapsed.
<?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;
class Esop extends Common
{
/**
* 期权计划
* @return [type] [description]
*/
public function getEsopPlanList(){
if(!MID) ajaxmsg('登陆后才能进行查询',0);
// 获取查询条件
$map = $this->getMap();
$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);
ajaxmsg('数据列表',1,$data_list);
}
}
\ No newline at end of file
......@@ -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;}
......@@ -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'] = "";//股东代码 无法模拟暂时空
......
......@@ -82,6 +82,8 @@ class Esopplan extends Admin
$data = $this->request->post();
$data['create_time'] = time();
$data['plan_account'] = $data['plan_account'] * 100;
$data['remain_account'] = $data['plan_account'] * 100;
$data['create_ip'] = get_client_ip(1);
//业务逻辑处理
$result_up = Db::name("esop_plan")->insert($data);
if ($result_up === 1) {
......
......@@ -8,6 +8,7 @@ use app\money\model\EsopPlan as EsopPlanModel;
use app\money\model\EsopPlanRecord as EsopPlanRecordModel;
use app\member\model\Member as MemberModel;
use app\stock\model\StockList as StockListModel;
use Exception;
use think\Db;
use think\Hook;
use think\Cache;
......@@ -66,6 +67,7 @@ class EsopplanRecord extends Admin
->setRowList($data_list)
->fetch(); // 渲染模板
}
/**
* 自动任务,根据设定的期权计划执行释放期权
*/
......@@ -76,11 +78,13 @@ class EsopplanRecord extends Admin
$where['status'] = 1;
//开始释放期权日期不大于当前日期
$where['release_time'] = ['<=', date("Y-m-d")];
//已释放天数小于总天数,已释放期权小于期权总值,待行权值大于0
$esop_plan_list = EsopPlanModel::where($where)->where("remain_account>0 and release_account<plan_account and days<duration")->select();
//待行权值大于0
$where['remain_account'] = ['>', 0];
//已释放天数小于总天数,已释放期权小于期权总值
$esop_plan_list = EsopPlanModel::where($where)->where("release_account<plan_account and days<duration")->select();
foreach ($esop_plan_list as $k => $v) {
//更加明细记录判断执行的当天是否已释放过
$esop_plan_record_today = EsopPlanRecordModel::where("FROM_UNIXTIME(createtime,'%Y-%m-%d')=curdate()")
$esop_plan_record_today = EsopPlanRecordModel::where("FROM_UNIXTIME(create_time,'%Y-%m-%d')=curdate()")
->where(['type' => 1, 'esop_plan_id' => $v['id']])->find();
if (!$esop_plan_record_today) {
//计算释放期权金额
......@@ -90,7 +94,7 @@ class EsopplanRecord extends Admin
$affect = $v['plan_account'] % $v['duration'];
}
//释放期权,更新期权表
$updateData[] = [
$updateData = [
'account' => $v['account'] + $affect,
'days' => $v['days'] + 1,
'remain_account' => $v['plan_account'] - $affect,
......@@ -98,7 +102,7 @@ class EsopplanRecord extends Admin
];
EsopPlanModel::where(['id' => $v['id']])->update($updateData);
//写入明细表
$arr[] = [
$arr = [
'mid' => $v['mid'],
'stock_id' => $v['stock_id'],
'esop_plan_id' => $v['id'],
......
<?php
namespace app\money\model;
use think\helper\Hash;
use app\money\model\Role as RoleModel;
use think\model;
use think\Db;
class EsopPlan extends Model
{
namespace app\money\model;
use think\helper\Hash;
use app\money\model\Role as RoleModel;
use think\model;
use think\Db;
class EsopPlan extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = '__ESOP__PLAN__';
protected $table = '__ESOP_PLAN__';
public static function getAll($map=[], $order='')
public static function getAll($map = [], $order = '')
{
$data_list = self::view('esop_plan p', true)
->view('member', 'mobile, name, id_card', 'member.id=p.mid', 'left')
......@@ -20,7 +22,7 @@
->where($map)
->order($order)
->paginate()
->each( function($item, $key){
->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);
......@@ -28,16 +30,29 @@
});
return $data_list;
}
/*
* 释放时自动更新期权计划信息
*
/**
*获取期权计划列表
* @author 2024-06-20
*/
public static function plan_up($id,$mmoney){
return self::where(["id"=>$id])->update($mmoney);
}
public static function getEsopPlanList($where = [], $field = '*', $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')
->field(["CONCAT(ROUND(release_account / plan_account * 100, 2), ' % ')" => 'accuracy'])
->field(["FROM_UNIXTIME(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);
});;
return $esop_plan_list;
}
?>
}
<?php
namespace app\money\model;
use think\helper\Hash;
use app\money\model\Role as RoleModel;
use think\model;
use think\Db;
class EsopPlanRecord extends Model
{
namespace app\money\model;
use think\helper\Hash;
use app\money\model\Role as RoleModel;
use think\model;
use think\Db;
class EsopPlanRecord extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = '__ESOP__PLAN__Record__';
protected $table = '__ESOP_PLAN_RECORD__';
public static function getAll($map=[], $order='')
public static function getAll($map = [], $order = '')
{
$data_list = self::view('esop_plan_record pr', true)
->view('member', 'mobile, name, id_card', 'member.id=pr.mid', 'left')
......@@ -20,13 +22,27 @@
->where($map)
->order($order)
->paginate()
->each( function($item, $key){
->each(function ($item, $key) {
$item->affect = money_convert($item->affect);
$item->surplus = money_convert($item->surplus);
});
return $data_list;
}
/**
*获取期权明细记录列表
* @author 2024-06-20
*/
public static function getEsopPlanRecordList($where = [], $field = '*', $order = 'id asc')
{
$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')
->where($where)
->field($field)
->order($order)
->paginate();
return $esop_plan_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