feat(trade): 添加了交易模块的API功能
This commit is contained in:
parent
8fe86d5bd9
commit
9050f2c745
@ -14,6 +14,7 @@
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\logic\statistic\TradeStatisticLogic;
|
||||
use app\admin\logic\WorkbenchLogic;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
@ -617,530 +618,30 @@ class WorkbenchController extends BaseAdminController
|
||||
//当日订单金额
|
||||
public function top_trade()
|
||||
{
|
||||
$dates = [];
|
||||
$today = new DateTime();
|
||||
|
||||
$thirtyDaysAgo = new DateTime($today->format('Y-m-d'));
|
||||
$thirtyDaysAgo->modify('-30 days');
|
||||
|
||||
for ($i = 0; $i < 31; $i++) {
|
||||
$date = new DateTime($thirtyDaysAgo->format('Y-m-d'));
|
||||
$date->modify('+' . $i . ' days');
|
||||
$dates[] = $date->format('Y-m-d');
|
||||
$logic=(new TradeStatisticLogic());
|
||||
$leftToday = $logic->getTopLeftTrade(['create_time' => 'today']);
|
||||
$leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']);
|
||||
$rightOne = $logic->getTopRightOneTrade();
|
||||
$rightTwo = $logic->getTopRightTwoTrade();
|
||||
$right = ['today' => $rightOne, 'month' => $rightTwo];
|
||||
$totalleft = [$leftToday, $leftyestoday];
|
||||
$left = [];
|
||||
foreach ($totalleft as $k => $v) {
|
||||
$left['name'] = "当日订单金额";
|
||||
$left['x'] = $v['curve']['x'];
|
||||
$left['series'][$k]['money'] = round($v['total_money'], 2);
|
||||
$left['series'][$k]['value'] = array_values($v['curve']['y']);
|
||||
}
|
||||
$times = date('Y-m-d');
|
||||
$yesterday= date('Y-m-d', strtotime('-1 day'));
|
||||
$dates_two=[];
|
||||
for ($i = 0; $i < 24; $i++) {
|
||||
$dates_two[]=[$times." ".$i.":00:00",$times." ".$i.":59:59"];
|
||||
}
|
||||
$data = [
|
||||
"left" => [
|
||||
"name" => "当日订单金额",
|
||||
"x" => [
|
||||
"00",
|
||||
"01",
|
||||
"02",
|
||||
"03",
|
||||
"04",
|
||||
"05",
|
||||
"06",
|
||||
"07",
|
||||
"08",
|
||||
"09",
|
||||
"10",
|
||||
"11",
|
||||
"12",
|
||||
"13",
|
||||
"14",
|
||||
"15",
|
||||
"16",
|
||||
"17",
|
||||
"18",
|
||||
"19",
|
||||
"20",
|
||||
"21",
|
||||
"22",
|
||||
"23",
|
||||
"24"
|
||||
],
|
||||
"series" => [
|
||||
WorkbenchLogic::day_order_pay_price($dates_two,$times),
|
||||
WorkbenchLogic::day_order_pay_price($dates_two,$yesterday),
|
||||
]
|
||||
],
|
||||
"right" => [
|
||||
"today" => [
|
||||
"x" => [
|
||||
"00",
|
||||
"01",
|
||||
"02",
|
||||
"03",
|
||||
"04",
|
||||
"05",
|
||||
"06",
|
||||
"07",
|
||||
"08",
|
||||
"09",
|
||||
"10",
|
||||
"11",
|
||||
"12",
|
||||
"13",
|
||||
"14",
|
||||
"15",
|
||||
"16",
|
||||
"17",
|
||||
"18",
|
||||
"19",
|
||||
"20",
|
||||
"21",
|
||||
"22",
|
||||
"23",
|
||||
"24"
|
||||
],
|
||||
"series" => [
|
||||
WorkbenchLogic::day_order_count($dates_two,'今日订单数'),
|
||||
WorkbenchLogic::day_order_user($dates_two,'今日支付人数'),
|
||||
]
|
||||
],
|
||||
"month" => [
|
||||
WorkbenchLogic::month_order_count('本月订单数'),
|
||||
WorkbenchLogic::month_order_count('本月支付人数')
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$data['left'] = $left;
|
||||
$data['right'] = $right;
|
||||
return $this->data($data);
|
||||
}
|
||||
|
||||
//交易趋势
|
||||
public function bottom_trade()
|
||||
{
|
||||
$data = [
|
||||
"x" => [
|
||||
"2024-05-06",
|
||||
"2024-05-07",
|
||||
"2024-05-08",
|
||||
"2024-05-09",
|
||||
"2024-05-10",
|
||||
"2024-05-11",
|
||||
"2024-05-12",
|
||||
"2024-05-13",
|
||||
"2024-05-14",
|
||||
"2024-05-15",
|
||||
"2024-05-16",
|
||||
"2024-05-17",
|
||||
"2024-05-18",
|
||||
"2024-05-19",
|
||||
"2024-05-20",
|
||||
"2024-05-21",
|
||||
"2024-05-22",
|
||||
"2024-05-23",
|
||||
"2024-05-24",
|
||||
"2024-05-25",
|
||||
"2024-05-26",
|
||||
"2024-05-27",
|
||||
"2024-05-28",
|
||||
"2024-05-29",
|
||||
"2024-05-30",
|
||||
"2024-05-31",
|
||||
"2024-06-01",
|
||||
"2024-06-02",
|
||||
"2024-06-03",
|
||||
"2024-06-04"
|
||||
],
|
||||
"series" => [
|
||||
[
|
||||
"name" => "营业额",
|
||||
"desc" => "商品支付金额、充值金额、购买付费会员金额、线下收银金额",
|
||||
"money" => "3538021.24",
|
||||
"type" => 1,
|
||||
"rate" => 353802124,
|
||||
"value" => [
|
||||
"85.61",
|
||||
"161.06",
|
||||
"1215.65",
|
||||
"38.96",
|
||||
"324.79",
|
||||
"214.88",
|
||||
"228.82",
|
||||
"34.24",
|
||||
"8249.85",
|
||||
"573.35",
|
||||
"8586.24",
|
||||
"10.19",
|
||||
"90.19",
|
||||
"105.40",
|
||||
"62.59",
|
||||
"1051.34",
|
||||
"160.66",
|
||||
"241651.20",
|
||||
"111325.41",
|
||||
"2085393.05",
|
||||
"267.40",
|
||||
"1063972.04",
|
||||
"1217.31",
|
||||
"582.40",
|
||||
"757.02",
|
||||
"597.00",
|
||||
"0.08",
|
||||
"609.40",
|
||||
"10175.64",
|
||||
"279.47"
|
||||
]
|
||||
],
|
||||
[
|
||||
"name" => "交易毛利金额",
|
||||
"desc" => "交易毛利金额 = 营业额 - 支出金额",
|
||||
"money" => "3408415.79",
|
||||
"type" => 1,
|
||||
"rate" => 340841579,
|
||||
"value" => [
|
||||
"32.01",
|
||||
"79.21",
|
||||
"194.81",
|
||||
"38.16",
|
||||
"324.79",
|
||||
"204.88",
|
||||
"228.82",
|
||||
"31.88",
|
||||
"330.64",
|
||||
"553.64",
|
||||
"545.58",
|
||||
"1.28",
|
||||
"90.19",
|
||||
"105.40",
|
||||
"44.00",
|
||||
"1043.16",
|
||||
"45.94",
|
||||
"240254.48",
|
||||
"10346.41",
|
||||
"2080946.30",
|
||||
"189.00",
|
||||
"1060654.82",
|
||||
"629.30",
|
||||
"398.10",
|
||||
"91.70",
|
||||
"597.00",
|
||||
"0.08",
|
||||
"0.10",
|
||||
"10151.63",
|
||||
"262.48"
|
||||
]
|
||||
],
|
||||
[
|
||||
"name" => "商品支付金额",
|
||||
"desc" => "选定条件下,用户购买商品的实际支付金额,包括微信支付、余额支付、支付宝支付、线下支付金额(拼团商品在成团之后计入,线下支付订单在后台确认支付后计入)",
|
||||
"money" => 157433.34,
|
||||
"type" => 1,
|
||||
"rate" => 15743334,
|
||||
"value" => [
|
||||
"85.61",
|
||||
"161.06",
|
||||
"1215.65",
|
||||
"38.96",
|
||||
"324.69",
|
||||
"214.88",
|
||||
"228.82",
|
||||
"34.24",
|
||||
"8249.85",
|
||||
"573.35",
|
||||
"8586.24",
|
||||
"10.19",
|
||||
"90.19",
|
||||
"105.40",
|
||||
"62.59",
|
||||
"1051.34",
|
||||
"160.66",
|
||||
"1693.20",
|
||||
"111325.41",
|
||||
"5365.05",
|
||||
"189.00",
|
||||
"3448.64",
|
||||
"1217.31",
|
||||
"582.40",
|
||||
"757.02",
|
||||
"597.00",
|
||||
"0.08",
|
||||
"609.40",
|
||||
"10175.64",
|
||||
"279.47"
|
||||
]
|
||||
],
|
||||
[
|
||||
"name" => "购买会员金额",
|
||||
"desc" => "选定条件下,用户成功购买付费会员的金额",
|
||||
"money" => 0,
|
||||
"type" => 1,
|
||||
"rate" => 0,
|
||||
"value" => [
|
||||
0,
|
||||
"0.00",
|
||||
"0.00",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"0.00",
|
||||
"0.00",
|
||||
0,
|
||||
"0.00",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
0,
|
||||
"0.00",
|
||||
"0.00",
|
||||
0,
|
||||
0,
|
||||
"0.00",
|
||||
0,
|
||||
"0.00",
|
||||
"0.00",
|
||||
0
|
||||
]
|
||||
],
|
||||
[
|
||||
"name" => "充值金额",
|
||||
"desc" => "选定条件下,用户成功充值的金额",
|
||||
"money" => "3380587.90",
|
||||
"type" => 1,
|
||||
"rate" => 338058790,
|
||||
"value" => [
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.10",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"239958.00",
|
||||
"0.00",
|
||||
"2080028.00",
|
||||
"78.40",
|
||||
"1060523.40",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"0.00"
|
||||
]
|
||||
],
|
||||
[
|
||||
"name" => "线下收银金额",
|
||||
"desc" => "选定条件下,用户在线下扫码支付的金额",
|
||||
"money" => 0,
|
||||
"type" => 0,
|
||||
"rate" => 0,
|
||||
"value" => [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
[
|
||||
"name" => "支出金额",
|
||||
"desc" => "余额支付金额、支付佣金金额",
|
||||
"money" => "129605.45",
|
||||
"type" => 1,
|
||||
"rate" => 12960545,
|
||||
"value" => [
|
||||
"53.60",
|
||||
"81.85",
|
||||
"1020.84",
|
||||
"0.80",
|
||||
"0.00",
|
||||
"10.00",
|
||||
"0.00",
|
||||
"2.36",
|
||||
"7919.21",
|
||||
"19.71",
|
||||
"8040.66",
|
||||
"8.91",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"18.59",
|
||||
"8.18",
|
||||
"114.72",
|
||||
"1396.72",
|
||||
"100979.00",
|
||||
"4446.75",
|
||||
"78.40",
|
||||
"3317.22",
|
||||
"588.01",
|
||||
"184.30",
|
||||
"665.32",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"609.30",
|
||||
"24.01",
|
||||
"16.99"
|
||||
]
|
||||
],
|
||||
[
|
||||
"name" => "余额支付金额",
|
||||
"desc" => "用户下单时使用余额实际支付的金额",
|
||||
"money" => "128943.25",
|
||||
"type" => 0,
|
||||
"rate" => 1289432500,
|
||||
"value" => [
|
||||
"53.60",
|
||||
"81.85",
|
||||
"1020.84",
|
||||
"0.80",
|
||||
"0.00",
|
||||
"10.00",
|
||||
"0.00",
|
||||
"2.36",
|
||||
"7919.21",
|
||||
"19.71",
|
||||
"8040.66",
|
||||
"8.91",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"18.59",
|
||||
"8.18",
|
||||
"114.72",
|
||||
"1396.72",
|
||||
"100979.00",
|
||||
"4416.75",
|
||||
"0.00",
|
||||
"2763.42",
|
||||
"588.01",
|
||||
"184.30",
|
||||
"665.32",
|
||||
"0.00",
|
||||
"0.00",
|
||||
"609.30",
|
||||
"24.01",
|
||||
"16.99"
|
||||
]
|
||||
],
|
||||
[
|
||||
"name" => "支付佣金金额",
|
||||
"desc" => "后台给推广员支付的推广佣金,以实际支付为准",
|
||||
"money" => 662.2,
|
||||
"type" => 0,
|
||||
"rate" => 66220,
|
||||
"value" => [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"30.00",
|
||||
"78.40",
|
||||
"553.80",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
[
|
||||
"name" => "商品退款金额",
|
||||
"desc" => "用户成功退款的商品金额",
|
||||
"money" => 2321.81,
|
||||
"type" => 0,
|
||||
"rate" => 232181,
|
||||
"value" => [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"0.00",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"0.00",
|
||||
"730.80",
|
||||
"49.00",
|
||||
"219.00",
|
||||
0,
|
||||
"1323.01",
|
||||
"0.00",
|
||||
0,
|
||||
"0.00",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"0.00"
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
$data=(new TradeStatisticLogic())->getBottomTrade(['data'=>'2024/05/21-2024/06/19']);
|
||||
return $this->data($data);
|
||||
}
|
||||
}
|
||||
|
1004
app/admin/logic/statistic/TradeStatisticLogic.php
Normal file
1004
app/admin/logic/statistic/TradeStatisticLogic.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -340,12 +340,12 @@ if (!function_exists('setUnique')) {
|
||||
{
|
||||
return substr(md5($sku . $id), 12, 11) . $type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('generateUniqueVerificationCode')) {
|
||||
function generateUniqueVerificationCode() {
|
||||
function generateUniqueVerificationCode()
|
||||
{
|
||||
// 获取当前时间的毫秒部分
|
||||
list($msec, $sec) = explode(' ', microtime());
|
||||
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
|
||||
@ -355,20 +355,20 @@ if (!function_exists('generateUniqueVerificationCode')) {
|
||||
|
||||
// 将前缀、毫秒时间戳和随机数连接起来
|
||||
$type = rand(1, 10); // 生成一个1-10之间的随机数作为前缀
|
||||
return $type .'-'. $msectime . $randomNumber;
|
||||
return $type . '-' . $msectime . $randomNumber;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('verificationCode')) {
|
||||
function verificationCode() {
|
||||
function verificationCode()
|
||||
{
|
||||
$sec = time();
|
||||
// 将前缀、秒时间戳和随机数连接起来
|
||||
$type = rand(1, 10); // 生成一个1-10之间的随机数作为前缀
|
||||
$code = $type .'-'. $sec;
|
||||
$check = \app\common\model\store_order\StoreOrder::where('verify_code',$code)->count();
|
||||
if($check){
|
||||
$code = $type . '-' . $sec;
|
||||
$check = \app\common\model\store_order\StoreOrder::where('verify_code', $code)->count();
|
||||
if ($check) {
|
||||
verificationCode();
|
||||
}
|
||||
return $code;
|
||||
@ -376,10 +376,11 @@ if (!function_exists('verificationCode')) {
|
||||
}
|
||||
|
||||
if (!function_exists('createCode')) {
|
||||
function createCode($code) {
|
||||
$check = \app\common\model\store_order\StoreOrder::where('verify_code',$code)->count();
|
||||
if($check){
|
||||
$orderPickupCode = rand(1,10).'-'.str_pad(rand(0, 99999), 5, '0', STR_PAD_LEFT);
|
||||
function createCode($code)
|
||||
{
|
||||
$check = \app\common\model\store_order\StoreOrder::where('verify_code', $code)->count();
|
||||
if ($check) {
|
||||
$orderPickupCode = rand(1, 10) . '-' . str_pad(rand(0, 99999), 5, '0', STR_PAD_LEFT);
|
||||
return createCode($orderPickupCode);
|
||||
}
|
||||
return $code;
|
||||
@ -387,7 +388,8 @@ if (!function_exists('createCode')) {
|
||||
}
|
||||
|
||||
if (!function_exists('haversineDistance')) {
|
||||
function haversineDistance($latitude1, $longitude1, $latitude2, $longitude2) {
|
||||
function haversineDistance($latitude1, $longitude1, $latitude2, $longitude2)
|
||||
{
|
||||
$earthRadius = 6371; // 地球平均半径,单位是千米
|
||||
|
||||
// 将角度转换为弧度
|
||||
@ -400,7 +402,7 @@ if (!function_exists('haversineDistance')) {
|
||||
$lonDelta = $lonTo - $lonFrom;
|
||||
|
||||
$angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) +
|
||||
cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
|
||||
cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
|
||||
return $angle * $earthRadius;
|
||||
}
|
||||
}
|
||||
@ -409,7 +411,8 @@ if (!function_exists('haversineDistance')) {
|
||||
* 随机验证码
|
||||
*/
|
||||
if (!function_exists('generateRandomCode')) {
|
||||
function generateRandomCode($length = 4) {
|
||||
function generateRandomCode($length = 4)
|
||||
{
|
||||
$code = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$code .= random_int(0, 9);
|
||||
@ -458,3 +461,18 @@ if (!function_exists('append_to_array')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('countRate')) {
|
||||
/**
|
||||
* 计算环比增长率
|
||||
* @param $nowValue
|
||||
* @param $lastValue
|
||||
* @return float|int|string
|
||||
*/
|
||||
function countRate($nowValue, $lastValue)
|
||||
{
|
||||
if ($lastValue == 0 && $nowValue == 0) return 0;
|
||||
if ($lastValue == 0) return round(bcmul(bcdiv($nowValue, 1, 4), 100, 2), 2);
|
||||
if ($nowValue == 0) return -round(bcmul(bcdiv($lastValue, 1, 4), 100, 2), 2);
|
||||
return bcmul(bcdiv((bcsub($nowValue, $lastValue, 2)), $lastValue, 4), 100, 2);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user