|
@@ -13,8 +13,6 @@ use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
use Modules\Common\Models\TjOptimizerDayNewUser;
|
|
|
use Modules\Common\Services\BaseService;
|
|
|
-use Modules\Common\Services\Statistic\CompanyDayUser;
|
|
|
-use Modules\Common\Services\Statistic\OptimizerDayUser;
|
|
|
|
|
|
class UserStatisticsService extends BaseService
|
|
|
{
|
|
@@ -31,23 +29,69 @@ class UserStatisticsService extends BaseService
|
|
|
* name: getTodayData
|
|
|
* @param int $accountId 账号id
|
|
|
* @param int $type 账号类型 1 其他 2 投放公司 3 优化师
|
|
|
+ * @param int $minId 小程序id
|
|
|
* date 2023/06/20 10:20
|
|
|
* @return array
|
|
|
*/
|
|
|
- public static function getTodayData($accountId, $type = 1)
|
|
|
+ public static function getTodayData($accountId, $type = 1,$minId=0)
|
|
|
{
|
|
|
$date = date("Y-m-d");
|
|
|
- $key = sprintf(self::PROMOTION_STATISTIC_RECORD_REDIS_KEY, $date);
|
|
|
- $new_user_recharge_total = self::getValue($key, sprintf(self::NEW_USER_RECHARGE_TOTAL, $accountId)); // 当日新增用户充值总额
|
|
|
- $new_user_recharge_num = self::getValue($key, sprintf(self::NEW_USER_RECHARGE_NUM, $accountId)); // 当日新增用户充值人数
|
|
|
- $new_user_num = self::getValue($key, sprintf(self::NEW_USER_NUM, $accountId)); // 当日新增用户人数
|
|
|
- [$recharge_coin_num, $recharge_vip_num] = self::getRechargeUserNum($accountId, $type);
|
|
|
+ $date = "2023-06-25";
|
|
|
+ $start = $date. " 00:00:00";
|
|
|
+ $end = $date . " 23:59:59";
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if ($minId > 0){
|
|
|
+ $where['miniprogram_id'] = $minId;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($type == 2){
|
|
|
+ $where['puser_id'] = $accountId;
|
|
|
+ }else if($type ==3){
|
|
|
+ $where['user_id'] = $accountId;
|
|
|
+ }
|
|
|
+ $new_user_num = DB::table('user_ranse_record_all')->where($where)->where('date', $date)->count(); // 新增用户人数
|
|
|
+ $info = DB::table('orders')->where('status', "<>", 'UNPAID')
|
|
|
+ ->where($where)
|
|
|
+ ->whereBetween("created_at", [$start, $end])
|
|
|
+ ->whereBetween('ranse_created_at', [$start, $end])
|
|
|
+ ->select(
|
|
|
+ DB::raw("sum(if(status = 'unpaid', 0, price)) as recharge_total"), // 单日新增用户充值金额
|
|
|
+ DB::raw("count(DISTINCT ranse_created_at,uid) as recharge_num") // 当日新增用户充值人数
|
|
|
+ )->first();
|
|
|
+ $new_user_recharge_total = $info->recharge_total ?: 0; // 新增用户充值总额
|
|
|
+ $new_user_recharge_num = $info->recharge_num ?: 0; // 新增用户充值人数
|
|
|
+ $info = DB::table('orders')->where('status', "<>", 'UNPAID')
|
|
|
+ ->where($where)
|
|
|
+ ->whereBetween("created_at", [$start, $end])
|
|
|
+ ->whereBetween('ranse_created_at', [$start, $end])
|
|
|
+ ->whereIn('order_type', ["COIN", "FIRST_COIN"])
|
|
|
+ ->select(
|
|
|
+ DB::raw("sum(if(status = 'unpaid', 0, price)) as recharge_total"), // 单日新增用户充值金额
|
|
|
+ DB::raw("count(DISTINCT ranse_created_at,uid) as recharge_num") // 当日新增用户充值人数
|
|
|
+ )->first(); // 普通充值金额
|
|
|
+ $recharge_coin_total = $info->recharge_total ?: 0; // 新增用户普通充值总额
|
|
|
+ $recharge_coin_num = $info->recharge_num ?: 0; // 新增用户普通充值总额
|
|
|
+ $info = DB::table('orders')->where('status', "<>", 'UNPAID')
|
|
|
+ ->where($where)
|
|
|
+ ->whereBetween("created_at", [$start, $end])
|
|
|
+ ->whereBetween('ranse_created_at', [$start, $end])
|
|
|
+ ->whereNotIn('order_type', ["COIN", "FIRST_COIN"])
|
|
|
+ ->select(
|
|
|
+ DB::raw("sum(if(status = 'unpaid', 0, price)) as recharge_total"), // 单日新增用户充值金额
|
|
|
+ DB::raw("count(DISTINCT ranse_created_at,uid) as recharge_num") // 当日新增用户充值人数
|
|
|
+ )->first(); // 会员充值金额
|
|
|
+ $recharge_vip_total = $info->recharge_total ?: 0; // 新增用户会员充值总额
|
|
|
+ $recharge_vip_num = $info->recharge_num ?: 0; // 新增用户会员充值总额
|
|
|
+
|
|
|
$data = [
|
|
|
'date' => $date,
|
|
|
'new_user_recharge_total' => $new_user_recharge_total ?: 0,
|
|
|
'new_user_recharge_num' => $new_user_recharge_num ?: 0,
|
|
|
'new_user_num' => $new_user_num ?: 0,
|
|
|
+ 'recharge_coin_total' => $recharge_coin_total ?: 0,
|
|
|
'recharge_coin_num' => $recharge_coin_num ?: 0,
|
|
|
+ 'recharge_vip_total' => $recharge_vip_total ?: 0,
|
|
|
'recharge_vip_num' => $recharge_vip_num ?: 0,
|
|
|
];
|
|
|
|
|
@@ -233,63 +277,17 @@ class UserStatisticsService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 充值人数查询
|
|
|
- * name: getRechargeUserNum
|
|
|
- * @param $accountId 账号id
|
|
|
- * @param $miniProgramId 小程序id
|
|
|
- * @param mixed $type 账号类型 2 投放公司 3 优化师
|
|
|
- * date 2023/06/20 10:18
|
|
|
- */
|
|
|
- private static function getRechargeUserNum($accountId, mixed $type): array
|
|
|
- {
|
|
|
- $start = date("Y-m-d") . " 00:00:00";
|
|
|
- $end = date("Y-m-d") . " 23:59:59";
|
|
|
- if ($type == 2) {
|
|
|
- // 投放公司
|
|
|
- $recharge_coin_num = DB::table('orders')->where('status', "<>", 'UNPAID')
|
|
|
- ->where('puser_id', $accountId)->whereBetween("created_at", [$start, $end])
|
|
|
- ->whereBetween('ranse_created_at', [$start, $end])
|
|
|
- ->whereIn("order_type", ["COIN", "FIRST_COIN"])->groupBy('uid', 'ranse_created_at')->count();
|
|
|
- $recharge_vip_num = DB::table('orders')->where('status', "<>", 'UNPAID')
|
|
|
- ->where('puser_id', $accountId)->whereBetween("created_at", [$start, $end])
|
|
|
- ->whereBetween('ranse_created_at', [$start, $end])
|
|
|
- ->whereNotIn("order_type", ["COIN", "FIRST_COIN"])->groupBy('uid', 'ranse_created_at')->count();
|
|
|
- } elseif ($type == 3) {
|
|
|
- // 优化师
|
|
|
- $recharge_coin_num = DB::table('orders')->where('status', "<>", 'UNPAID')
|
|
|
- ->where('user_id', $accountId)->whereBetween("created_at", [$start, $end])
|
|
|
- ->whereBetween('ranse_created_at', [$start, $end])
|
|
|
- ->whereIn("order_type", ["COIN", "FIRST_COIN"])->groupBy('uid', 'ranse_created_at')->count();
|
|
|
- $recharge_vip_num = DB::table('orders')->where('status', "<>", 'UNPAID')
|
|
|
- ->where('user_id', $accountId)->whereBetween("created_at", [$start, $end])
|
|
|
- ->whereBetween('ranse_created_at', [$start, $end])
|
|
|
- ->whereNotIn("order_type", ["COIN", "FIRST_COIN"])->groupBy('uid', 'ranse_created_at')->count();
|
|
|
- } else {
|
|
|
- // 其他暂不统计
|
|
|
- $recharge_coin_num = DB::table('orders')->where('status', "<>", 'UNPAID')
|
|
|
- ->whereBetween("created_at", [$start, $end])
|
|
|
- ->whereBetween('ranse_created_at', [$start, $end])
|
|
|
- ->whereIn("order_type", ["COIN", "FIRST_COIN"])->groupBy('uid', 'ranse_created_at')->count();
|
|
|
- $recharge_vip_num = DB::table('orders')->where('status', "<>", 'UNPAID')
|
|
|
- ->whereBetween("created_at", [$start, $end])
|
|
|
- ->whereBetween('ranse_created_at', [$start, $end])
|
|
|
- ->whereNotIn("order_type", ["COIN", "FIRST_COIN"])->groupBy('uid', 'ranse_created_at')->count();
|
|
|
- }
|
|
|
- return [$recharge_coin_num, $recharge_vip_num];
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
*
|
|
|
* name: getTodayData
|
|
|
* @param int $accountId 账号id
|
|
|
* @param mixed $type 账号类型 1 其他 2 投放公司 3 优化师
|
|
|
+ * @param mixed $miniProgramId 小程序id
|
|
|
*/
|
|
|
- public static function historyStats(int $accountId, $type)
|
|
|
+ public static function historyStats(int $accountId, $type,$miniProgramId)
|
|
|
{
|
|
|
- print_sql();
|
|
|
- $month = self::getStaticsData($accountId, date('Y-m-01'), date('Y-m-d', strtotime('yesterday')), $type);
|
|
|
- $lastMonth = self::getStaticsData($accountId, date('Y-m-01', strtotime(date('Y-m-01')) - 10), date('Y-m-d', strtotime(date('Y-m-01')) - 10), $type);
|
|
|
- $history = self::getHistoryData($accountId, $type);
|
|
|
+ $month = self::getStaticsData($accountId, date('Y-m-01'), date('Y-m-d', strtotime('yesterday')), $type,$miniProgramId);
|
|
|
+ $lastMonth = self::getStaticsData($accountId, date('Y-m-01', strtotime(date('Y-m-01')) - 10), date('Y-m-d', strtotime(date('Y-m-01')) - 10), $type,$miniProgramId);
|
|
|
+ $history = self::getHistoryData($accountId, $type,$miniProgramId);
|
|
|
return ['month' => $month, 'lastMonth' => $lastMonth, 'history' => $history];
|
|
|
}
|
|
|
|
|
@@ -315,11 +313,13 @@ class UserStatisticsService extends BaseService
|
|
|
}
|
|
|
$info = $sql->select(
|
|
|
DB::raw("sum(recharge_amount_total) as recharge_amount_total"), // 总充金额
|
|
|
+ DB::raw("sum(new_user_total) as new_user_total"), // 总充金额
|
|
|
DB::raw("sum(recharge_user_total) as recharge_user_total"), // 累计充值人数
|
|
|
)->first();
|
|
|
|
|
|
return [
|
|
|
'recharge_amount_total' => $info->recharge_amount_total ?: 0,
|
|
|
+ 'new_user_total' => $info->new_user_total ?: 0,
|
|
|
'recharge_user_total' => $info->recharge_user_total ?: 0,
|
|
|
];
|
|
|
}
|