|
@@ -4,6 +4,7 @@ namespace App\Http\Admin;
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Request;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class OrderController extends AdminBaseController
|
|
|
{
|
|
@@ -13,6 +14,298 @@ class OrderController extends AdminBaseController
|
|
|
$this->setWebsite(__NAMESPACE__);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function analysis()
|
|
|
+ {
|
|
|
+ $yesterday_time = strtotime(date('Y-m-d', strtotime("-1 day")));
|
|
|
+ $today_time = strtotime(date('Y-m-d'));
|
|
|
+
|
|
|
+ // 昨天订单总数
|
|
|
+ $yesterdayOrderTotal = $this->totalOrderNum($yesterday_time);
|
|
|
+
|
|
|
+ // 今天订单总数
|
|
|
+ $todayOrderTotal = $this->totalOrderNum($today_time);
|
|
|
+
|
|
|
+ ########################################################################################
|
|
|
+
|
|
|
+ // 昨天用户量
|
|
|
+ $yesterdayMemberTotal = $this->totalMember($yesterday_time);
|
|
|
+
|
|
|
+ // 今天用户量
|
|
|
+ $todayMemberTotal = $this->totalMember($today_time);
|
|
|
+
|
|
|
+ ########################################################################################
|
|
|
+
|
|
|
+ // 昨天支付金额
|
|
|
+ $yesterdayMoneyTotal = $this->totalMoneyNum($yesterday_time);
|
|
|
+
|
|
|
+ // 今天支付金额
|
|
|
+ $todayMoneyTotal = $this->totalMoneyNum($today_time);
|
|
|
+
|
|
|
+ ########################################################################################
|
|
|
+
|
|
|
+ $monthFirstDay = strtotime(date("Y-m-1 00:00:00"));
|
|
|
+ $monthLastDay = strtotime(date("Y-m-" . date("t") . " 23:59:59"));
|
|
|
+
|
|
|
+ // 本月的订单总数
|
|
|
+ $monthOrderTotal = $this->totalOrderNum($monthFirstDay, $monthLastDay);
|
|
|
+
|
|
|
+ // 本月的交易金额
|
|
|
+ $monthMoneyTotal = $this->totalMoneyNum($monthFirstDay, $monthLastDay);
|
|
|
+
|
|
|
+ ########################################################################################
|
|
|
+
|
|
|
+ // 获取上个月第一天的时间戳
|
|
|
+ $firstDayOfLastMonth = strtotime("first day of last month", $monthFirstDay);
|
|
|
+ $lastDayOfLastMonth = strtotime("last day of last month", $monthLastDay);
|
|
|
+
|
|
|
+ // 上月的订单总数
|
|
|
+ $lastMonthOrderTotal = $this->totalOrderNum($firstDayOfLastMonth, $lastDayOfLastMonth);
|
|
|
+
|
|
|
+ // 上月的交易金额
|
|
|
+ $lastMonthMoneyTotal = $this->totalMoneyNum($firstDayOfLastMonth, $lastDayOfLastMonth);
|
|
|
+
|
|
|
+ ########################################################################################
|
|
|
+
|
|
|
+ // 总收入数
|
|
|
+ $todayMoneyAll = $this->totalMoneyNum();
|
|
|
+
|
|
|
+ // 总用户数
|
|
|
+ $todayMemberAll = $this->totalMember();
|
|
|
+
|
|
|
+ return responseMessage(1001, '', [
|
|
|
+ 'yesterdayOrderTotal' => round($yesterdayOrderTotal, 2),
|
|
|
+ 'todayOrderTotal' => round($todayOrderTotal, 2),
|
|
|
+ 'yesterdayMemberTotal' => round($yesterdayMemberTotal, 2),
|
|
|
+ 'todayMemberTotal' => round($todayMemberTotal, 2),
|
|
|
+ 'yesterdayMoneyTotal' => round($yesterdayMoneyTotal, 2),
|
|
|
+ 'todayMoneyTotal' => round($todayMoneyTotal, 2),
|
|
|
+ 'monthOrderTotal' => round($monthOrderTotal, 2),
|
|
|
+ 'monthMoneyTotal' => round($monthMoneyTotal, 2),
|
|
|
+ 'lastMonthOrderTotal' => round($lastMonthOrderTotal, 2),
|
|
|
+ 'lastMonthMoneyTotal' => round($lastMonthMoneyTotal, 2),
|
|
|
+ 'todayMoneyAll' => round($todayMoneyAll, 2),
|
|
|
+ 'todayMemberAll' => round($todayMemberAll, 2),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按年统计
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function statisByYear($year)
|
|
|
+ {
|
|
|
+ $arr = [];
|
|
|
+
|
|
|
+ for ($m = 1; $m <= 12; $m++) {
|
|
|
+ $monthFirstDay = strtotime(date($year . "-" . $m . "-1 00:00:00"));
|
|
|
+ $monthLastDay = strtotime(date($year . "-" . $m . "-" . date('t',strtotime($year . "-" . $m)) . " 23:59:59"));
|
|
|
+ $arr[] = $this->totalMoneyNum($monthFirstDay, $monthLastDay);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $arr;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 最近7天的订单量 todo 优化查询方式
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function sevenDayOrder()
|
|
|
+ {
|
|
|
+ $days = [];
|
|
|
+ $count = [];
|
|
|
+ $total = [];
|
|
|
+ for ($i = 0; $i < 7; $i++) {
|
|
|
+ $day = date('Y-m-d', strtotime('-' . $i . ' day'));
|
|
|
+ array_unshift($days, $day);
|
|
|
+ array_unshift($count, $this->totalOrderNum(strtotime($day)));
|
|
|
+ array_unshift($total, $this->totalMoneyNum(strtotime($day)));
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseMessage(1001, '', ['days' => $days, 'count' => $count, 'total' => $total]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取支付金额
|
|
|
+ *
|
|
|
+ * @param int $start_time
|
|
|
+ * @param int $end_time
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function totalMoneyNum(int $start_time = 0, int $end_time = 0): mixed
|
|
|
+ {
|
|
|
+ if (empty($end_time)) {
|
|
|
+ $end_time = $start_time + 24 * 3600;
|
|
|
+ }
|
|
|
+
|
|
|
+ ########## 软件
|
|
|
+ $data1 = $this->getOrderSum('order_product', $start_time, $end_time);
|
|
|
+
|
|
|
+ return $data1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 注册人数
|
|
|
+ */
|
|
|
+ private function totalMember(int $start_time = 0, int $end_time = 0)
|
|
|
+ {
|
|
|
+ if (empty($start_time)) {
|
|
|
+ return DB::table('user')->count();
|
|
|
+ } else {
|
|
|
+ if (empty($end_time)) {
|
|
|
+ $end_time = $start_time + 24 * 3600;
|
|
|
+ }
|
|
|
+
|
|
|
+ return DB::table('user')->where('is_delete', 0)->whereBetween('created_at', [$start_time, $end_time])->count();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 所有的订单数量
|
|
|
+ private function totalOrderNum($start_time, int $end_time = 0)
|
|
|
+ {
|
|
|
+ ########## 软件
|
|
|
+ $data1 = $this->getOrderNum('order_product', $start_time, $end_time);
|
|
|
+
|
|
|
+ return $data1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $table
|
|
|
+ * @param int $start_time
|
|
|
+ * @param int $end_time
|
|
|
+ * @return array|int
|
|
|
+ */
|
|
|
+ private function getOrderNum(string $table, int $start_time = 0, int $end_time = 0): int|array
|
|
|
+ {
|
|
|
+
|
|
|
+ if (empty($start_time)) {
|
|
|
+ return DB::table($table)->count();
|
|
|
+ } else {
|
|
|
+ if (empty($end_time)) {
|
|
|
+ $end_time = $start_time + 24 * 3600;
|
|
|
+ }
|
|
|
+ return DB::table($table)->where('order_status', 2)->where('is_delete', 0)->whereBetween('created_at', [ $start_time, $end_time])->count();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $table
|
|
|
+ * @param int $start_time
|
|
|
+ * @param int $end_time
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ private function getOrderSum(string $table, int $start_time, int $end_time = 0): mixed
|
|
|
+ {
|
|
|
+ if (empty($start_time)) {
|
|
|
+ return DB::table($table)->where('order_status', 2)->where('is_delete', 0)->sum('order_amount_total');
|
|
|
+ } else {
|
|
|
+ if (empty($end_time)) {
|
|
|
+ $end_time = $start_time + 24 * 3600;
|
|
|
+ }
|
|
|
+
|
|
|
+ return DB::table($table)->where('order_status', 2)->where('is_delete', 0)->whereBetween('created_at', [$start_time, $end_time])->sum('order_amount_total');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function softOrder()
|
|
|
+ {
|
|
|
+ $mid = Request::input('mid');
|
|
|
+ if (empty($mid)) {
|
|
|
+ return responseMessage(2001, '参数错误');
|
|
|
+ }
|
|
|
+ // 获取商品信息
|
|
|
+ $productInfo = DB::table('product')->where('mid', $mid)->first();
|
|
|
+ if (empty($productInfo)) {
|
|
|
+ return responseMessage(2001, '参数错误2');
|
|
|
+ }
|
|
|
+
|
|
|
+ $days = [];
|
|
|
+ $countArr = [];
|
|
|
+ for ($i = 0; $i < 15; $i++) {
|
|
|
+ $day = date('Y-m-d', strtotime('-' . $i . ' day'));
|
|
|
+ array_unshift($days, $day);
|
|
|
+
|
|
|
+ $start_time = strtotime($day);
|
|
|
+ $end_time = $start_time + 24 * 3600;
|
|
|
+
|
|
|
+ $count = DB::table('order_product')
|
|
|
+ ->where('product_id', $productInfo['id'])
|
|
|
+ ->where('order_status', 2)
|
|
|
+ ->where('is_delete', 0)
|
|
|
+ ->whereBetween('created_at', [$start_time, $end_time])->count();
|
|
|
+
|
|
|
+ array_unshift($countArr, $count);
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseMessage(1001, '', ['days' => $days, 'count' => $countArr]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按小时统计订单数量
|
|
|
+ public function softHour()
|
|
|
+ {
|
|
|
+ $mid = Request::input('mid');
|
|
|
+ if (empty($mid)) {
|
|
|
+ return responseMessage(2001, '参数错误');
|
|
|
+ }
|
|
|
+ // 获取商品信息
|
|
|
+ $productInfo = DB::table('product')->where('mid', $mid)->first();
|
|
|
+ if (empty($productInfo)) {
|
|
|
+ return responseMessage(2001, '参数错误2');
|
|
|
+ }
|
|
|
+
|
|
|
+ $countArr = [];
|
|
|
+ for ($i = 0; $i < 5; $i++) {
|
|
|
+ $day = date('Y-m-d', strtotime('-' . $i . ' day'));
|
|
|
+ $days[] = $day;
|
|
|
+ $count = $this->getHourData($day, $productInfo['id']);
|
|
|
+
|
|
|
+ $countArr[] = [
|
|
|
+ "name" => $day,
|
|
|
+ "type" => 'line',
|
|
|
+// "stack" => 'Total',
|
|
|
+ "data" => $count
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $hours = [];
|
|
|
+ for ($i = 0; $i < 24; $i++) {
|
|
|
+ $hours[] = $i + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseMessage(1001, '', ['days' => $days, 'hours' => $hours, 'count' => $countArr]);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getHourData($day, $productId)
|
|
|
+ {
|
|
|
+ $start_time = strtotime($day);
|
|
|
+
|
|
|
+ $countArr = [];
|
|
|
+ for ($i = 0; $i < 24; $i++) {
|
|
|
+ $end_time = $start_time + 3600;
|
|
|
+
|
|
|
+ $count = DB::table('order_product')
|
|
|
+ ->where('product_id', $productId)
|
|
|
+ ->where('order_status', 2)
|
|
|
+ ->where('is_delete', 0)
|
|
|
+ ->whereBetween('created_at', [$start_time, $end_time])->count();
|
|
|
+ $countArr[] = $count;
|
|
|
+
|
|
|
+ $start_time = $end_time;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $countArr;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
##################################################################################################################
|
|
|
### 订单退款 ################################################################################################
|
|
|
##################################################################################################################
|