Commit 9533edcf authored by twj's avatar twj

ESOPAPP接口

parent 24917866
......@@ -20,15 +20,15 @@ use app\apicom\model\JWT;
if (!function_exists('isLogin')) {
function isLogin($token)
{
if(!empty($token)){
if (!empty($token)) {
$decoded = JWT::decode($token, JWT_TOKEN_KEY, array('HS256'));
$doHost = $_SERVER['HTTP_HOST'];
if($doHost == $decoded->doHost){
if ($doHost == $decoded->doHost) {
return $decoded->uid;
}else{
} else {
return 0;
}
}else{
} else {
return 0;
}
}
......@@ -47,9 +47,9 @@ if (!function_exists('get_agents_info')) {
** ajax json 2018 05 29
***/
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)) {
foreach ($msg as $key => $v) {
$json[$key] = $v;
......@@ -57,20 +57,21 @@ if (!function_exists('ajaxmsg')) {
} elseif (!empty($msg)) {
$json['message'] = $msg;
}
if($data) $json['data'] = $data;
if ($data) $json['data'] = $data;
if ($is_end) {
echo json_encode($json,JSON_UNESCAPED_SLASHES);
echo json_encode($json, JSON_UNESCAPED_SLASHES);
exit;
} else {
echo json_encode($json,JSON_UNESCAPED_SLASHESn);
echo json_encode($json, JSON_UNESCAPED_SLASHESn);
exit;
}
}
}
if (!function_exists('sina_sssj_a')) {
//获得实时行情
function sina_sssj_a($gp){
$d=fenxi($gp);
function sina_sssj_a($gp)
{
$d = fenxi($gp);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://hq.sinajs.cn/list=" . $d);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
......@@ -78,8 +79,8 @@ if (!function_exists('sina_sssj_a')) {
$output = curl_exec($ch);
curl_close($ch);
$t2 = explode(',', mb_convert_encoding($output, "utf-8", "gbk"));
$t2['32']=substr($t2['0'],21);
$t2['0']=substr($t2['0'],11,8);
$t2['32'] = substr($t2['0'], 21);
$t2['0'] = substr($t2['0'], 11, 8);
return $t2;
}
}
......@@ -255,41 +256,55 @@ if (!function_exists('getTypeNameForMoney')) {
function getTypeNameForMoney($type_id = 33)
{
$type = [
'1'=>'充值成功',
'2'=>'提现冻结',
'3'=>'提现成功',
'4'=>'提现失败',
'5'=>'撤销提现',
'6'=>'提现退回',
'7'=>'追加保证金',
'8'=>'冻结保证金',
'9'=>'返还保证金',
'10'=>'邀请人推广返佣',
'11'=>'代理商佣金入账',
'12'=>'代理商分成入账',
'13'=>'提取佣金',
'14'=>'提取分成',
'15'=>'终止配资',
'16'=>'扣配资管理费',
'17'=>'扣递延费',
'18'=>'后台转账',
'19'=>'管理员操作',
'20'=>'配资结算',
'21'=>'配资审核不通过',
'22'=>'配资审核通过',
'23'=>'申请配资续期',
'24'=>'扩大配资审核通过',
'25'=>'扩大配资审核未通过',
'26'=>'追加保证金审核通过',
'27'=>'追加保证金审核未通过',
'28'=>'配资续期审核通过',
'29'=>'配资续期审核未通过',
'30'=>'配资提前终止审核通过',
'31'=>'配资提前终止审核未通过',
'32'=>'按月配资手续费自动扣款',
'33'=>'冻结金额',
'34'=>'扣除金额',
'85'=>'提取盈利'
'1' => '充值成功',
'2' => '提现冻结',
'3' => '提现成功',
'4' => '提现失败',
'5' => '撤销提现',
'6' => '提现退回',
'7' => '追加保证金',
'8' => '冻结保证金',
'9' => '返还保证金',
'10' => '邀请人推广返佣',
'11' => '代理商佣金入账',
'12' => '代理商分成入账',
'13' => '提取佣金',
'14' => '提取分成',
'15' => '终止配资',
'16' => '扣配资管理费',
'17' => '扣递延费',
'18' => '后台转账',
'19' => '管理员操作',
'20' => '配资结算',
'21' => '配资审核不通过',
'22' => '配资审核通过',
'23' => '申请配资续期',
'24' => '扩大配资审核通过',
'25' => '扩大配资审核未通过',
'26' => '追加保证金审核通过',
'27' => '追加保证金审核未通过',
'28' => '配资续期审核通过',
'29' => '配资续期审核未通过',
'30' => '配资提前终止审核通过',
'31' => '配资提前终止审核未通过',
'32' => '按月配资手续费自动扣款',
'33' => '冻结金额',
'34' => '扣除金额',
'85' => '提取盈利'
];
return $type[$type_id];
}
}
/**
* 根据type 获取期权明细类型
*/
if (!function_exists('getTypeNameForEsop')) {
function getTypeNameForEsop($type_id = 1)
{
$type = [
'1' => '释放期权',
'2' => '买入股票',
'3' => '申请提现'
];
return $type[$type_id];
}
......@@ -313,7 +328,7 @@ if (!function_exists('agents_back_money')) {
{
$back_money = Db::name('agents_back_money')->where('mid', $mid)->sum('affect');
$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')) {
{
$far_user = get_agents_info($mid);
$arr = getSonAgentArr($mid);
$arr_str= implode(',',$arr);
if($arr_str !='') $map = "affect_mid in ({$arr_str}) and mid = {$far_user['agent_far']}";
$arr_str = implode(',', $arr);
if ($arr_str != '') $map = "affect_mid in ({$arr_str}) and mid = {$far_user['agent_far']}";
else return 0;
$back_money = Db::name('agents_back_money')->where($map)->sum('affect');
$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')) {
function agents_back_rate($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'];
}else{
if($user['agent_id'] ==2){
} else {
if ($user['agent_id'] == 2) {
$agent_1 = get_agents_info($user['agent_far']);
$rate = bcmul($agent_1['agent_rate'],$user['agent_rate'],2);
$rate = bcdiv($rate,100,2);
}elseif($user['agent_id']==3){
$rate = bcmul($agent_1['agent_rate'], $user['agent_rate'], 2);
$rate = bcdiv($rate, 100, 2);
} elseif ($user['agent_id'] == 3) {
$agent_1 = get_agents_info($user['agent_far']);
$agent_2 = get_agents_info($agent_1['agent_far']);
$agent_rate = $agent_1['agent_rate'] * $agent_2['agent_rate'];
$rate = bcmul($agent_rate,$user['agent_rate'],2);
$rate = bcdiv($rate,10000,2);
}else $rate = config('member_back_rate');
$rate = bcmul($agent_rate, $user['agent_rate'], 2);
$rate = bcdiv($rate, 10000, 2);
} else $rate = config('member_back_rate');
}
return $rate;
}
......@@ -365,18 +380,18 @@ if (!function_exists('get_plus_rate')) {
function get_plus_rate($mid)
{
$user = get_agents_info($mid);
if($user['agent_id'] ==1){
if ($user['agent_id'] == 1) {
$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_rate = $agent_1['agent_rate'] ? $agent_1['agent_rate'] : config('agent_back_rate');
$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_rate = $agent_1['agent_rate'] ? $agent_1['agent_rate'] : config('agent_back_rate');
$agent_2 = get_agents_info($agent_1['agent_far']);
$rate = $user['agent_rate'] * $agent_2['agent_rate'] * $agent_1_rate / 10000;
}else{
} else {
$rate = config('member_back_rate');
}
return $rate;
......@@ -389,9 +404,8 @@ if (!function_exists('agents_back_come')) {
function agents_back_come($mid)
{
$user = Db::name('member')->field('id,mobile')->where('id', $mid)->find();
$note = '用户'.$user['mobile'].'名下';
$note = '用户' . $user['mobile'] . '名下';
return $note;
}
}
/*
......@@ -423,9 +437,9 @@ if (!function_exists('getEndBack')) {
$time_n = time();
$rate_time = config('member_back_time') ? config('member_back_time') : 0;
$agent_time = $time + ($rate_time * 86400 * 30);
if($agent_time > $time_n){
$end_time = getTimeFormt($agent_time,5);
}else{
if ($agent_time > $time_n) {
$end_time = getTimeFormt($agent_time, 5);
} else {
$end_time = '已到期';
}
......@@ -439,16 +453,16 @@ if (!function_exists('getSonAgentArr')) {
{
$user = Db::name('member')->field('id,agent_id')->where('agent_far', $mid)->select();
$arr = array();
if (!empty($user)){
foreach ($user as $k=>$v){
if($v['id']) array_push($arr,$v['id']);
if (!empty($user)) {
foreach ($user as $k => $v) {
if ($v['id']) array_push($arr, $v['id']);
$user_info = getSonAgentArr2($v['id']);
foreach ($user_info as $key=>$val){
if($val['id']) array_push($arr,$val['id']);
foreach ($user_info as $key => $val) {
if ($val['id']) array_push($arr, $val['id']);
}
}
}
array_push($arr,$mid);
array_push($arr, $mid);
return $arr;
}
}
......@@ -468,20 +482,20 @@ if (!function_exists('yan_time')) {
function yan_time($last_time = 14.95)
{
$t = time() - strtotime(date("Y-m-d", time()));
$t2 = 3600 * 9.5+300;//早盘开盘时间
$t3 = 3600 * 11.5;//早盘停盘时间
$t4 = 3600 * 13;//下午开盘时间
$t5 = 3600 * $last_time;//默认下午停盘时间14:55
$t2 = 3600 * 9.5 + 300; //早盘开盘时间
$t3 = 3600 * 11.5; //早盘停盘时间
$t4 = 3600 * 13; //下午开盘时间
$t5 = 3600 * $last_time; //默认下午停盘时间14:55
if (!(($t > $t2 && $t < $t3) || ($t > $t4 && $t < $t5))) {
return false;//
return false; //
}
if (date('N', time()) > 5) { //周六周日
return false;//
return false; //
}
$array = festival();//返回节假日
if (in_array(date("md", time()), $array)) {//如果是节假日
$array = festival(); //返回节假日
if (in_array(date("md", time()), $array)) { //如果是节假日
return false;
}
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
......@@ -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,15 +94,15 @@ 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,
'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'],
'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__';
public static function getAll($map = [], $order = '')
{
// 设置当前模型对应的完整数据表名称
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')
->view('stock_list', 'title', 'stock_list.id=p.stock_id', 'left')
->where($map)
->order($order)
->paginate()
->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 $data_list;
}
/*
* 释放时自动更新期权计划信息
*
*/
public static function plan_up($id,$mmoney){
return self::where(["id"=>$id])->update($mmoney);
}
$data_list = self::view('esop_plan p', true)
->view('member', 'mobile, name, id_card', 'member.id=p.mid', 'left')
->view('stock_list', 'title', 'stock_list.id=p.stock_id', 'left')
->where($map)
->order($order)
->paginate()
->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 $data_list;
}
/**
*获取期权计划列表
* @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
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__';
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')
{
// 设置当前模型对应的完整数据表名称
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;
}
$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