提交 170e5183 authored 作者: Junlz's avatar Junlz

计算预估值

上级 8e838b48
<?php
namespace app\common\library;
class Tools
{
//获取
}
\ No newline at end of file
<?php
namespace app\common\model;
use think\Model;
class DayNums extends Model
{
// 表名
protected $name = 'day_nums';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'create_time';
//添加数据
public static function add ($data)
{
return self::insertGetId($data);
}
//统计数量
public static function count_nums($start_month,$end_month,$cid)
{
$res = self::where(["chief_id" => $cid])->whereBetween('create_time',[$start_month,$end_month])->select();
return $res;
}
}
\ No newline at end of file
......@@ -43,4 +43,13 @@ class Ex extends Model
return $data;
}
/***
* 统计站长每天的订单金额和订单量
* zhanglijun
*/
public static function get_day_income($start_time,$end_time,$popularize_id)
{
return self::where('name8' ,$popularize_id)->whereBetween('name2',[$start_time,$end_time])->field('name2,name8,name13')->select();
}
}
<?php
namespace app\common\model;
use think\Model;
use app\common\model\User;
class IncomeModel extends Model
{
// 表名
protected $name = 'month_income';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'create_time';
/***
* @param $popularize_id
* @param $month
* @return IncomeModel|null
* @throws \think\exception\DbException
* 获取收入
*/
public static function getIncome($popularize_id,$month)
{
return self::where(["chief_id" => $popularize_id,"month" => $month]);
}
public static function add($data)
{
return self::insertGetId($data);
}
}
\ No newline at end of file
<?php
namespace app\common\model;
use think\Model;
class NewUser extends Model
{
// 表名
protected $name = 'new_user';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'create_time';
public static function get_new_count($popularize_id,$start_time,$end_time)
{
$res = self::where(["popularize_id" => $popularize_id])->whereBetween('create_time',[$start_time,$end_time])->select();
return count($res);
}
}
\ No newline at end of file
......@@ -135,4 +135,15 @@ class User extends Model
}
return $level;
}
/****
* 获取用户的信息
* zhanglijun
* 2021.07.14
*/
public static function get_user_info($uid)
{
return self::get($uid);
}
}
<?php
namespace app\index\controller;
use app\admin\command\Api;
use app\common\model\DayNums;
use app\common\model\Ex;
use app\common\model\IncomeModel;
use app\common\model\NewUser;
use app\common\model\User;
use think\Db;
use think\Request;
class Income extends Api
{
private $uid;
private $user_info;
public function __construct($name = null)
{
if(empty($_COOKIE["token"])){
exit("您还未登录");
}
date_default_timezone_set('PRC');
$this->uid = $_COOKIE["uid"];
$this->user_info = User::get_user_info($this->uid);
parent::__construct($name);
}
/***
* 查询每个月的收入接口
* zhanglijun
* 2021-07-14
*/
public function get_income(Request $request)
{
$month = $request->get("month");
if(empty($month)){
$month = 1;
}
$popularize_id = $this->user_info["popularize_id"];
$data = IncomeModel::getIncome($popularize_id,$month);
$json_data = [
"code" => 1,
"msg" => "success",
"data" => $data
];
return json($json_data);
}
/***
* 计算预估收入
* zhanglijun
* 2021-07-14
*/
public function predict_income()
{
$order_income = 0.00;
$new_reward = 0.00;
$base_salary = 0.00;
$achievement_reward = 0.00;
$month_start = strtotime(date('Y-m-01', time()));
$curren_end = strtotime(date('Y-m-d', time()));
$diff_time = $curren_end - $month_start;
$days = bcdiv($diff_time,86400);
//计算平均订单
$popularize_id = $this->user_info["popularize_id"];
$res = DayNums::count_nums($month_start,$curren_end,$popularize_id);
if (empty($res)){
return '无数据';
}
$order_nums = array_sum(array_column($res,'order_num'));
//上个月的平均单量
$ave_order_num = bcdiv($order_nums,$days,2);
if ($order_nums >= 3000){
$base_salary = 1800;
$achievement_reward = 1000;
}
switch($ave_order_num){
case $ave_order_num >= 1 && $ave_order_num < 30:
$order_income = bcmul($order_nums,0.60,2);
break;
case $ave_order_num >= 30 && $ave_order_num < 50:
$order_income = bcmul($order_nums,0.70,2);
break;
case $ave_order_num >= 50:
$order_income = bcmul($order_nums,0.80,2);
break;
case $ave_order_num == 50:
$order_income = 0.00;
break;
}
$new_user = array_sum(array_column($res,'new_user'));
//上个月的平均拉新人数
$count = bcdiv($new_user,$days,2);
switch($count){
case $count >= 1 && $count < 50:
$new_reward = bcmul($count,5.00,2);
break;
case $count >= 50 && $count < 100:
$new_reward = bcmul($count,6.00,2);
break;
case $count >= 100:
$new_reward = bcmul($count,7.00,2);
break;
case $count == 0:
$new_reward = 0.00;
break;
}
$amount = bcadd(bcadd($base_salary,$order_income,2),bcadd($achievement_reward,$new_reward,2),2);
return $amount;
}
/****
* 计算上个月的收入
* zhanglijun
* 此脚本一个月跑一次
*/
public function last_month_income()
{
$order_income = 0.00;
$new_reward = 0.00;
$base_salary = 0.00;
$achievement_reward = 0.00;
$month_start = strtotime(date('Y-m-01', strtotime('-1 month')));
$month_end = strtotime(date('Y-m-t', strtotime('-1 month')));
//$diff_time = $month_end - $month_start;
$days = date("t",strtotime("-1 month"));
$last_month = date("m",strtotime("-1 month"));
//计算平均订单
$popularize_id = $this->user_info["popularize_id"];
$res = DayNums::count_nums($month_start,$month_end,$popularize_id);
if (empty($res)){
return '无数据';
}
$order_nums = array_sum(array_column($res,'order_num'));
//上个月的平均单量
$ave_order_num = bcdiv($order_nums,$days,2);
if ($order_nums >= 3000){
$base_salary = 1800;
$achievement_reward = 1000;
}
switch($ave_order_num){
case $ave_order_num >= 1 && $ave_order_num < 30:
$order_income = bcmul($order_nums,0.60,2);
break;
case $ave_order_num >= 30 && $ave_order_num < 50:
$order_income = bcmul($order_nums,0.70,2);
break;
case $ave_order_num >= 50:
$order_income = bcmul($order_nums,0.80,2);
break;
case $ave_order_num == 50:
$order_income = 0.00;
break;
}
$new_user = array_sum(array_column($res,'new_user'));
//上个月的平均拉新人数
$count = bcdiv($new_user,$days,2);
switch($count){
case $count >= 1 && $count < 50:
$new_reward = bcmul($count,5.00,2);
break;
case $count >= 50 && $count < 100:
$new_reward = bcmul($count,6.00,2);
break;
case $count >= 100:
$new_reward = bcmul($count,7.00,2);
break;
case $count == 0:
$new_reward = 0.00;
break;
}
$insert_data = [
"phone" => $this->user_info["mobile"] ?? 0,
"chief_id" => $popularize_id,
"base_salary" => $base_salary,
"order_subsidy" => $order_income,
"achievement_reward" => $achievement_reward,
"month" => $last_month,
"new_reward" => $new_reward,
"amount" => bcadd(bcadd($base_salary,$order_income,2),bcadd($achievement_reward,$new_reward,2),2),
"create_time" => time()
];
return IncomeModel::add($insert_data);
}
/***
* 订单金额统计
* zhanglijun
* 2021-07-14
*/
public function day_all_income(Request $request)
{
$new_reward = 0.00; //
$order_income = 0.00;
$base_salary = 0.00; //底薪
$achievement_reward = 0.00; //业绩达标
$y=date("Y",time());
$m=date("m",time());
$d=date("d",time() - 60*60*24);
$start_time = mktime(0, 0, 0, $m, $d ,$y);
$end_time=$start_time+60*60*24;
$popularize_id = $this->user_info["popularize_id"];
$res = Ex::get_day_income($start_time,$end_time,$popularize_id);
//前一天订单数量
$order_nums = array_sum(array_column($res,'name13'));
//前一天拉新人数
$new_user = NewUser::get_new_count($popularize_id,$start_time,$end_time);
$add_day_income = [
"phone" => $this->user_info["mobile"] ?? 0,
"chief_id" => $popularize_id,
"order_num" => $order_nums,
"new_user" => $new_user,
"create_time" => time()
];
return DayNums::add($add_day_income);
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论