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
...@@ -20,15 +20,15 @@ use app\apicom\model\JWT; ...@@ -20,15 +20,15 @@ use app\apicom\model\JWT;
if (!function_exists('isLogin')) { if (!function_exists('isLogin')) {
function isLogin($token) function isLogin($token)
{ {
if(!empty($token)){ if (!empty($token)) {
$decoded = JWT::decode($token, JWT_TOKEN_KEY, array('HS256')); $decoded = JWT::decode($token, JWT_TOKEN_KEY, array('HS256'));
$doHost = $_SERVER['HTTP_HOST']; $doHost = $_SERVER['HTTP_HOST'];
if($doHost == $decoded->doHost){ if ($doHost == $decoded->doHost) {
return $decoded->uid; return $decoded->uid;
}else{ } else {
return 0; return 0;
} }
}else{ } else {
return 0; return 0;
} }
} }
...@@ -47,9 +47,9 @@ if (!function_exists('get_agents_info')) { ...@@ -47,9 +47,9 @@ if (!function_exists('get_agents_info')) {
** ajax json 2018 05 29 ** ajax json 2018 05 29
***/ ***/
if (!function_exists('ajaxmsg')) { if (!function_exists('ajaxmsg')) {
function ajaxmsg($msg = "", $type = 1,$data = '',$is_end = true) function ajaxmsg($msg = "", $type = 1, $data = '', $is_end = true)
{ {
$json['status'] = $type.''; $json['status'] = $type . '';
if (is_array($msg)) { if (is_array($msg)) {
foreach ($msg as $key => $v) { foreach ($msg as $key => $v) {
$json[$key] = $v; $json[$key] = $v;
...@@ -57,20 +57,21 @@ if (!function_exists('ajaxmsg')) { ...@@ -57,20 +57,21 @@ if (!function_exists('ajaxmsg')) {
} elseif (!empty($msg)) { } elseif (!empty($msg)) {
$json['message'] = $msg; $json['message'] = $msg;
} }
if($data) $json['data'] = $data; if ($data) $json['data'] = $data;
if ($is_end) { if ($is_end) {
echo json_encode($json,JSON_UNESCAPED_SLASHES); echo json_encode($json, JSON_UNESCAPED_SLASHES);
exit; exit;
} else { } else {
echo json_encode($json,JSON_UNESCAPED_SLASHESn); echo json_encode($json, JSON_UNESCAPED_SLASHESn);
exit; exit;
} }
} }
} }
if (!function_exists('sina_sssj_a')) { if (!function_exists('sina_sssj_a')) {
//获得实时行情 //获得实时行情
function sina_sssj_a($gp){ function sina_sssj_a($gp)
$d=fenxi($gp); {
$d = fenxi($gp);
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://hq.sinajs.cn/list=" . $d); curl_setopt($ch, CURLOPT_URL, "http://hq.sinajs.cn/list=" . $d);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
...@@ -78,8 +79,8 @@ if (!function_exists('sina_sssj_a')) { ...@@ -78,8 +79,8 @@ if (!function_exists('sina_sssj_a')) {
$output = curl_exec($ch); $output = curl_exec($ch);
curl_close($ch); curl_close($ch);
$t2 = explode(',', mb_convert_encoding($output, "utf-8", "gbk")); $t2 = explode(',', mb_convert_encoding($output, "utf-8", "gbk"));
$t2['32']=substr($t2['0'],21); $t2['32'] = substr($t2['0'], 21);
$t2['0']=substr($t2['0'],11,8); $t2['0'] = substr($t2['0'], 11, 8);
return $t2; return $t2;
} }
} }
...@@ -255,41 +256,55 @@ if (!function_exists('getTypeNameForMoney')) { ...@@ -255,41 +256,55 @@ if (!function_exists('getTypeNameForMoney')) {
function getTypeNameForMoney($type_id = 33) function getTypeNameForMoney($type_id = 33)
{ {
$type = [ $type = [
'1'=>'充值成功', '1' => '充值成功',
'2'=>'提现冻结', '2' => '提现冻结',
'3'=>'提现成功', '3' => '提现成功',
'4'=>'提现失败', '4' => '提现失败',
'5'=>'撤销提现', '5' => '撤销提现',
'6'=>'提现退回', '6' => '提现退回',
'7'=>'追加保证金', '7' => '追加保证金',
'8'=>'冻结保证金', '8' => '冻结保证金',
'9'=>'返还保证金', '9' => '返还保证金',
'10'=>'邀请人推广返佣', '10' => '邀请人推广返佣',
'11'=>'代理商佣金入账', '11' => '代理商佣金入账',
'12'=>'代理商分成入账', '12' => '代理商分成入账',
'13'=>'提取佣金', '13' => '提取佣金',
'14'=>'提取分成', '14' => '提取分成',
'15'=>'终止配资', '15' => '终止配资',
'16'=>'扣配资管理费', '16' => '扣配资管理费',
'17'=>'扣递延费', '17' => '扣递延费',
'18'=>'后台转账', '18' => '后台转账',
'19'=>'管理员操作', '19' => '管理员操作',
'20'=>'配资结算', '20' => '配资结算',
'21'=>'配资审核不通过', '21' => '配资审核不通过',
'22'=>'配资审核通过', '22' => '配资审核通过',
'23'=>'申请配资续期', '23' => '申请配资续期',
'24'=>'扩大配资审核通过', '24' => '扩大配资审核通过',
'25'=>'扩大配资审核未通过', '25' => '扩大配资审核未通过',
'26'=>'追加保证金审核通过', '26' => '追加保证金审核通过',
'27'=>'追加保证金审核未通过', '27' => '追加保证金审核未通过',
'28'=>'配资续期审核通过', '28' => '配资续期审核通过',
'29'=>'配资续期审核未通过', '29' => '配资续期审核未通过',
'30'=>'配资提前终止审核通过', '30' => '配资提前终止审核通过',
'31'=>'配资提前终止审核未通过', '31' => '配资提前终止审核未通过',
'32'=>'按月配资手续费自动扣款', '32' => '按月配资手续费自动扣款',
'33'=>'冻结金额', '33' => '冻结金额',
'34'=>'扣除金额', '34' => '扣除金额',
'85'=>'提取盈利' '85' => '提取盈利'
];
return $type[$type_id];
}
}
/**
* 根据type 获取期权明细类型
*/
if (!function_exists('getTypeNameForEsop')) {
function getTypeNameForEsop($type_id = 1)
{
$type = [
'1' => '释放期权',
'2' => '买入股票',
'3' => '申请提现'
]; ];
return $type[$type_id]; return $type[$type_id];
} }
...@@ -313,7 +328,7 @@ if (!function_exists('agents_back_money')) { ...@@ -313,7 +328,7 @@ if (!function_exists('agents_back_money')) {
{ {
$back_money = Db::name('agents_back_money')->where('mid', $mid)->sum('affect'); $back_money = Db::name('agents_back_money')->where('mid', $mid)->sum('affect');
$back_money = $back_money ? $back_money : 0.00; $back_money = $back_money ? $back_money : 0.00;
return round($back_money,2); return round($back_money, 2);
} }
} }
/* /*
...@@ -324,13 +339,13 @@ if (!function_exists('agents_profit_money')) { ...@@ -324,13 +339,13 @@ if (!function_exists('agents_profit_money')) {
{ {
$far_user = get_agents_info($mid); $far_user = get_agents_info($mid);
$arr = getSonAgentArr($mid); $arr = getSonAgentArr($mid);
$arr_str= implode(',',$arr); $arr_str = implode(',', $arr);
if($arr_str !='') $map = "affect_mid in ({$arr_str}) and mid = {$far_user['agent_far']}"; if ($arr_str != '') $map = "affect_mid in ({$arr_str}) and mid = {$far_user['agent_far']}";
else return 0; else return 0;
$back_money = Db::name('agents_back_money')->where($map)->sum('affect'); $back_money = Db::name('agents_back_money')->where($map)->sum('affect');
$back_money = $back_money ? $back_money : 0.00; $back_money = $back_money ? $back_money : 0.00;
return round($back_money,2); return round($back_money, 2);
} }
} }
/* /*
...@@ -340,20 +355,20 @@ if (!function_exists('agents_back_rate')) { ...@@ -340,20 +355,20 @@ if (!function_exists('agents_back_rate')) {
function agents_back_rate($mid) function agents_back_rate($mid)
{ {
$user = get_agents_info($mid); $user = get_agents_info($mid);
if($user['agent_rate'] && (!$user['agent_id'] || $user['agent_id']==1)){ if ($user['agent_rate'] && (!$user['agent_id'] || $user['agent_id'] == 1)) {
$rate = $user['agent_rate']; $rate = $user['agent_rate'];
}else{ } else {
if($user['agent_id'] ==2){ if ($user['agent_id'] == 2) {
$agent_1 = get_agents_info($user['agent_far']); $agent_1 = get_agents_info($user['agent_far']);
$rate = bcmul($agent_1['agent_rate'],$user['agent_rate'],2); $rate = bcmul($agent_1['agent_rate'], $user['agent_rate'], 2);
$rate = bcdiv($rate,100,2); $rate = bcdiv($rate, 100, 2);
}elseif($user['agent_id']==3){ } elseif ($user['agent_id'] == 3) {
$agent_1 = get_agents_info($user['agent_far']); $agent_1 = get_agents_info($user['agent_far']);
$agent_2 = get_agents_info($agent_1['agent_far']); $agent_2 = get_agents_info($agent_1['agent_far']);
$agent_rate = $agent_1['agent_rate'] * $agent_2['agent_rate']; $agent_rate = $agent_1['agent_rate'] * $agent_2['agent_rate'];
$rate = bcmul($agent_rate,$user['agent_rate'],2); $rate = bcmul($agent_rate, $user['agent_rate'], 2);
$rate = bcdiv($rate,10000,2); $rate = bcdiv($rate, 10000, 2);
}else $rate = config('member_back_rate'); } else $rate = config('member_back_rate');
} }
return $rate; return $rate;
} }
...@@ -365,18 +380,18 @@ if (!function_exists('get_plus_rate')) { ...@@ -365,18 +380,18 @@ if (!function_exists('get_plus_rate')) {
function get_plus_rate($mid) function get_plus_rate($mid)
{ {
$user = get_agents_info($mid); $user = get_agents_info($mid);
if($user['agent_id'] ==1){ if ($user['agent_id'] == 1) {
$rate = agents_back_rate($mid); $rate = agents_back_rate($mid);
}elseif($user['agent_id'] ==2){ } elseif ($user['agent_id'] == 2) {
$agent_1 = get_agents_info($user['agent_far']); $agent_1 = get_agents_info($user['agent_far']);
$agent_1_rate = $agent_1['agent_rate'] ? $agent_1['agent_rate'] : config('agent_back_rate'); $agent_1_rate = $agent_1['agent_rate'] ? $agent_1['agent_rate'] : config('agent_back_rate');
$rate = $user['agent_rate'] * $agent_1_rate / 100; $rate = $user['agent_rate'] * $agent_1_rate / 100;
}elseif($user['agent_id'] ==3){ } elseif ($user['agent_id'] == 3) {
$agent_1 = get_agents_info($user['agent_far']); $agent_1 = get_agents_info($user['agent_far']);
$agent_1_rate = $agent_1['agent_rate'] ? $agent_1['agent_rate'] : config('agent_back_rate'); $agent_1_rate = $agent_1['agent_rate'] ? $agent_1['agent_rate'] : config('agent_back_rate');
$agent_2 = get_agents_info($agent_1['agent_far']); $agent_2 = get_agents_info($agent_1['agent_far']);
$rate = $user['agent_rate'] * $agent_2['agent_rate'] * $agent_1_rate / 10000; $rate = $user['agent_rate'] * $agent_2['agent_rate'] * $agent_1_rate / 10000;
}else{ } else {
$rate = config('member_back_rate'); $rate = config('member_back_rate');
} }
return $rate; return $rate;
...@@ -389,9 +404,8 @@ if (!function_exists('agents_back_come')) { ...@@ -389,9 +404,8 @@ if (!function_exists('agents_back_come')) {
function agents_back_come($mid) function agents_back_come($mid)
{ {
$user = Db::name('member')->field('id,mobile')->where('id', $mid)->find(); $user = Db::name('member')->field('id,mobile')->where('id', $mid)->find();
$note = '用户'.$user['mobile'].'名下'; $note = '用户' . $user['mobile'] . '名下';
return $note; return $note;
} }
} }
/* /*
...@@ -423,9 +437,9 @@ if (!function_exists('getEndBack')) { ...@@ -423,9 +437,9 @@ if (!function_exists('getEndBack')) {
$time_n = time(); $time_n = time();
$rate_time = config('member_back_time') ? config('member_back_time') : 0; $rate_time = config('member_back_time') ? config('member_back_time') : 0;
$agent_time = $time + ($rate_time * 86400 * 30); $agent_time = $time + ($rate_time * 86400 * 30);
if($agent_time > $time_n){ if ($agent_time > $time_n) {
$end_time = getTimeFormt($agent_time,5); $end_time = getTimeFormt($agent_time, 5);
}else{ } else {
$end_time = '已到期'; $end_time = '已到期';
} }
...@@ -439,16 +453,16 @@ if (!function_exists('getSonAgentArr')) { ...@@ -439,16 +453,16 @@ if (!function_exists('getSonAgentArr')) {
{ {
$user = Db::name('member')->field('id,agent_id')->where('agent_far', $mid)->select(); $user = Db::name('member')->field('id,agent_id')->where('agent_far', $mid)->select();
$arr = array(); $arr = array();
if (!empty($user)){ if (!empty($user)) {
foreach ($user as $k=>$v){ foreach ($user as $k => $v) {
if($v['id']) array_push($arr,$v['id']); if ($v['id']) array_push($arr, $v['id']);
$user_info = getSonAgentArr2($v['id']); $user_info = getSonAgentArr2($v['id']);
foreach ($user_info as $key=>$val){ foreach ($user_info as $key => $val) {
if($val['id']) array_push($arr,$val['id']); if ($val['id']) array_push($arr, $val['id']);
} }
} }
} }
array_push($arr,$mid); array_push($arr, $mid);
return $arr; return $arr;
} }
} }
...@@ -468,20 +482,20 @@ if (!function_exists('yan_time')) { ...@@ -468,20 +482,20 @@ if (!function_exists('yan_time')) {
function yan_time($last_time = 23.95) function yan_time($last_time = 23.95)
{ {
$t = time() - strtotime(date("Y-m-d", time())); $t = time() - strtotime(date("Y-m-d", time()));
$t2 = 3600 * 9.5+300;//早盘开盘时间 $t2 = 3600 * 9.5 + 300; //早盘开盘时间
$t3 = 3600 * 11.5;//早盘停盘时间 $t3 = 3600 * 11.5; //早盘停盘时间
$t4 = 3600 * 13;//下午开盘时间 $t4 = 3600 * 13; //下午开盘时间
$t5 = 3600 * $last_time;//默认下午停盘时间14:55 $t5 = 3600 * $last_time; //默认下午停盘时间14:55
if (!(($t > $t2 && $t < $t3) || ($t > $t4 && $t < $t5))) { if (!(($t > $t2 && $t < $t3) || ($t > $t4 && $t < $t5))) {
return false;// return false; //
} }
if (date('N', time()) > 5) { //周六周日 if (date('N', time()) > 5) { //周六周日
return false;// return false; //
} }
$array = festival();//返回节假日 $array = festival(); //返回节假日
if (in_array(date("md", time()), $array)) {//如果是节假日 if (in_array(date("md", time()), $array)) { //如果是节假日
return false; return false;
} }
return true; return true;
} }
} }
\ No newline at end of file
<?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 ...@@ -166,15 +166,7 @@ class Trade extends Common
//提交交易费用信息 //提交交易费用信息
$Delivery = new Delivery; $Delivery = new Delivery;
$avail = ($moneyinfo['avail']) - $effectMoney; $avail = ($moneyinfo['avail']) - $effectMoney;
$Qdata = z_market($data["gupiao_code"],$data['market']); Position::addPosition($data['code'], $data['market'],$data['count'],$data['sub_id'],$broker['lid'],$broker['user'],$broker['stockjobber']);
//参考成本价
$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);
//print_r("佣金: ".$commission." 过户费: ".$transfer." 总计:".$effectMoney);Db::rollback();exit; //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']); $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; //print_r($del_res);Db::rollback();exit;
......
...@@ -205,9 +205,9 @@ class Position extends Model{ ...@@ -205,9 +205,9 @@ class Position extends Model{
* $sub_id 子账号 * $sub_id 子账号
* $code 股票代码 * $code 股票代码
*/ */
public static function getCodePosition($sub_id,$code){ public static function getCodePosition($sub_id,$code,$market){
$res=Db::name('stock_position') $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]) ->where(['buying'=>0])
->find(); ->find();
if(empty($res)){return false;} if(empty($res)){return false;}
...@@ -418,12 +418,13 @@ class Position extends Model{ ...@@ -418,12 +418,13 @@ class Position extends Model{
* $user 证券账户 * $user 证券账户
* $soure 证券来源 * $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); //$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; $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); $stockinfo = z_market($code,$market);
$data = array(); $data = array();
$data[0]['sub_id'] = $sub_id; $data[0]['sub_id'] = $sub_id;
...@@ -435,14 +436,13 @@ class Position extends Model{ ...@@ -435,14 +436,13 @@ class Position extends Model{
$data[0]['count'] = $count; $data[0]['count'] = $count;
$data[0]['stock_count'] = $position['stock_count']+$count; $data[0]['stock_count'] = $position['stock_count']+$count;
$data[0]['canbuy_count'] = $position['canbuy_count']+$count; $data[0]['canbuy_count'] = $position['canbuy_count']+$count;
$data[0]['ck_price'] = self::calculate($sub_id,$code,'price');//参考成本价 $data[0]['ck_price'] = $new_price;//参考成本价;
dump($data[0]['ck_price']);die; $data[0]['buy_average_price'] = $new_price;//买入均价
$data[0]['buy_average_price'] = self::calculate($sub_id,$code,'average');//买入均价 $data[0]['ck_profit_price'] = $new_price;//参考盈亏成本价
$data[0]['ck_profit_price'] = '';//参考盈亏成本价
$data[0]['now_price'] = $stockinfo["current_price"];//'当前价' $data[0]['now_price'] = $stockinfo["current_price"];//'当前价'
$data[0]['market_value'] = $stockinfo["current_price"] * $count;//最新市值 $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]['ck_profit'] = $position['ck_profit']; //参考浮动盈亏
$data[0]['profit_rate'] = $count > 0 && $ck_price > 0 ? bcdiv(strval($data[0]['ck_profit']),strval($ck_price * $count * 100),2) : 0; //盈亏比例 $data[0]['profit_rate'] = $position['profit_rate']; //盈亏比例
$data[0]['buying'] = 0;//买入成功 $data[0]['buying'] = 0;//买入成功
$data[0]['selling'] = 0;//1、在途卖出 $data[0]['selling'] = 0;//1、在途卖出
$data[0]['gudong_code'] = "";//股东代码 无法模拟暂时空 $data[0]['gudong_code'] = "";//股东代码 无法模拟暂时空
......
...@@ -82,6 +82,8 @@ class Esopplan extends Admin ...@@ -82,6 +82,8 @@ class Esopplan extends Admin
$data = $this->request->post(); $data = $this->request->post();
$data['create_time'] = time(); $data['create_time'] = time();
$data['plan_account'] = $data['plan_account'] * 100; $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); $result_up = Db::name("esop_plan")->insert($data);
if ($result_up === 1) { if ($result_up === 1) {
......
...@@ -8,6 +8,7 @@ use app\money\model\EsopPlan as EsopPlanModel; ...@@ -8,6 +8,7 @@ use app\money\model\EsopPlan as EsopPlanModel;
use app\money\model\EsopPlanRecord as EsopPlanRecordModel; use app\money\model\EsopPlanRecord as EsopPlanRecordModel;
use app\member\model\Member as MemberModel; use app\member\model\Member as MemberModel;
use app\stock\model\StockList as StockListModel; use app\stock\model\StockList as StockListModel;
use Exception;
use think\Db; use think\Db;
use think\Hook; use think\Hook;
use think\Cache; use think\Cache;
...@@ -66,6 +67,7 @@ class EsopplanRecord extends Admin ...@@ -66,6 +67,7 @@ class EsopplanRecord extends Admin
->setRowList($data_list) ->setRowList($data_list)
->fetch(); // 渲染模板 ->fetch(); // 渲染模板
} }
/** /**
* 自动任务,根据设定的期权计划执行释放期权 * 自动任务,根据设定的期权计划执行释放期权
*/ */
...@@ -76,11 +78,13 @@ class EsopplanRecord extends Admin ...@@ -76,11 +78,13 @@ class EsopplanRecord extends Admin
$where['status'] = 1; $where['status'] = 1;
//开始释放期权日期不大于当前日期 //开始释放期权日期不大于当前日期
$where['release_time'] = ['<=', date("Y-m-d")]; $where['release_time'] = ['<=', date("Y-m-d")];
//已释放天数小于总天数,已释放期权小于期权总值,待行权值大于0 //待行权值大于0
$esop_plan_list = EsopPlanModel::where($where)->where("remain_account>0 and release_account<plan_account and days<duration")->select(); $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) { 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(); ->where(['type' => 1, 'esop_plan_id' => $v['id']])->find();
if (!$esop_plan_record_today) { if (!$esop_plan_record_today) {
//计算释放期权金额 //计算释放期权金额
...@@ -90,15 +94,15 @@ class EsopplanRecord extends Admin ...@@ -90,15 +94,15 @@ class EsopplanRecord extends Admin
$affect = $v['plan_account'] % $v['duration']; $affect = $v['plan_account'] % $v['duration'];
} }
//释放期权,更新期权表 //释放期权,更新期权表
$updateData[] = [ $updateData = [
'account' => $v['account'] + $affect, 'account' => $v['account'] + $affect,
'days' => $v['days'] + 1, 'days' => $v['days'] + 1,
'remain_account' => $v['plan_account'] - $affect, 'remain_account' => $v['plan_account'] - $affect,
'release_account' => $v['release_account'] + $affect 'release_account' => $v['release_account'] + $affect
]; ];
EsopPlanModel::where(['id' => $v['id']])->update($updateData); EsopPlanModel::where(['id' => $v['id']])->update($updateData);
//写入明细表 //写入明细表
$arr[] = [ $arr = [
'mid' => $v['mid'], 'mid' => $v['mid'],
'stock_id' => $v['stock_id'], 'stock_id' => $v['stock_id'],
'esop_plan_id' => $v['id'], 'esop_plan_id' => $v['id'],
......
<?php <?php
namespace app\money\model;
use think\helper\Hash; namespace app\money\model;
use app\money\model\Role as RoleModel;
use think\model; use think\helper\Hash;
use think\Db; use app\money\model\Role as RoleModel;
use think\model;
class EsopPlan extends Model use think\Db;
class EsopPlan extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = '__ESOP_PLAN__';
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')
protected $table = '__ESOP__PLAN__'; ->view('stock_list', 'title', 'stock_list.id=p.stock_id', 'left')
->where($map)
->order($order)
public static function getAll($map=[], $order='') ->paginate()
{ ->each(function ($item, $key) {
$data_list = self::view('esop_plan p', true) $item->account = money_convert($item->account);
->view('member', 'mobile, name, id_card', 'member.id=p.mid', 'left') $item->plan_account = money_convert($item->plan_account);
->view('stock_list', 'title', 'stock_list.id=p.stock_id', 'left') $item->remain_account = money_convert($item->remain_account);
->where($map) $item->release_account = money_convert($item->release_account);
->order($order) });
->paginate()
->each( function($item, $key){ return $data_list;
$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 $data_list;
}
/*
* 释放时自动更新期权计划信息
*
*/
public static function plan_up($id,$mmoney){
return self::where(["id"=>$id])->update($mmoney);
}
/**
*获取期权计划列表
* @author 2024-06-20
*/
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 <?php
namespace app\money\model;
use think\helper\Hash; namespace app\money\model;
use app\money\model\Role as RoleModel;
use think\model; use think\helper\Hash;
use think\Db; use app\money\model\Role as RoleModel;
use think\model;
class EsopPlanRecord extends Model use think\Db;
class EsopPlanRecord extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = '__ESOP_PLAN_RECORD__';
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')
->view('stock_list', 'title', 'stock_list.id=pr.stock_id', 'left')
->where($map)
->order($order)
->paginate()
->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')
protected $table = '__ESOP__PLAN__Record__'; ->view("esop_plan ep", 'title,code', 'stock_list.id=ep.stock_id', 'left')
->where($where)
->field($field)
public static function getAll($map=[], $order='') ->order($order)
{ ->paginate();
$data_list = self::view('esop_plan_record pr', true) return $esop_plan_list;
->view('member', 'mobile, name, id_card', 'member.id=pr.mid', 'left')
->view('stock_list', 'title', 'stock_list.id=pr.stock_id', 'left')
->where($map)
->order($order)
->paginate()
->each( function($item, $key){
$item->affect = money_convert($item->affect);
$item->surplus = money_convert($item->surplus);
});
return $data_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