feat: 修改IndexController类以优化用户交易统计查询

This commit is contained in:
mkm 2024-06-25 17:28:07 +08:00
parent 0b41bdf59c
commit b40b004e9e

View File

@ -4,6 +4,8 @@ namespace app\statistics\controller;
use app\admin\logic\statistic\TradeStatisticLogic; use app\admin\logic\statistic\TradeStatisticLogic;
use app\common\controller\BaseLikeController; use app\common\controller\BaseLikeController;
use app\common\model\user\User;
use app\common\model\user_recharge\UserRecharge;
use app\statistics\logic\OrderLogic; use app\statistics\logic\OrderLogic;
use app\statistics\logic\ProductLogic; use app\statistics\logic\ProductLogic;
use app\statistics\logic\UserLogic; use app\statistics\logic\UserLogic;
@ -12,27 +14,27 @@ use DateTime;
class IndexController extends BaseLikeController class IndexController extends BaseLikeController
{ {
public $store_id=0; public $store_id = 0;
public function index() public function index()
{ {
$time=$this->request->get('date',date('Y-m-d')); $time = $this->request->get('date', date('Y-m-d'));
$store_id = $this->store_id; $store_id = $this->store_id;
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$where['paid'] = 1; $where['paid'] = 1;
$res = OrderLogic::dayPayPrice($where,$time); $res = OrderLogic::dayPayPrice($where, $time);
if (OrderLogic::hasError()) { if (OrderLogic::hasError()) {
return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息 return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息
} }
return $this->success('ok', ['dayPayPrice' => $res,'title'=>'百合镇农(特)产品交易大数据']); return $this->success('ok', ['dayPayPrice' => $res, 'title' => '百合镇农(特)产品交易大数据']);
} }
public function user() public function user()
{ {
$time=$this->request->get('date',date('Y-m-d')); $time = $this->request->get('date', date('Y-m-d'));
$today = strtotime($time); $today = strtotime($time);
$dates=[]; $dates = [];
// 循环输出前5天的日期 // 循环输出前5天的日期
for ($i = 0; $i <= 4; $i++) { for ($i = 0; $i <= 4; $i++) {
// 计算前第$i天的日期时间戳 // 计算前第$i天的日期时间戳
@ -40,14 +42,14 @@ class IndexController extends BaseLikeController
// 将时间戳格式化为日期 // 将时间戳格式化为日期
$date = date('Y-m-d', $timestamp); $date = date('Y-m-d', $timestamp);
$dates[]=$date; $dates[] = $date;
} }
$store_id = $this->store_id; $store_id = $this->store_id;
$where=[]; $where = [];
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$res = UserLogic::userCount($where,$dates); $res = UserLogic::userCount($where, $dates);
if (UserLogic::hasError()) { if (UserLogic::hasError()) {
return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息 return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息
} }
@ -59,13 +61,13 @@ class IndexController extends BaseLikeController
*/ */
public function product_count() public function product_count()
{ {
$time=$this->request->get('date',date('Y-m-d')); $time = $this->request->get('date', date('Y-m-d'));
$store_id = $this->store_id; $store_id = $this->store_id;
$where=[]; $where = [];
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$res = ProductLogic::Count($where,$time); $res = ProductLogic::Count($where, $time);
if (ProductLogic::hasError()) { if (ProductLogic::hasError()) {
return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
} }
@ -76,30 +78,40 @@ class IndexController extends BaseLikeController
*/ */
public function order_user_num_count() public function order_user_num_count()
{ {
$time=$this->request->get('date',date('Y-m-d')); $time = $this->request->get('date', date('Y-m-d'));
$store_id = $this->store_id; $store_id = $this->store_id;
$where=[]; $where = [];
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$res = OrderLogic::Count($where,$time); $where['recharge_type']='INDUSTRYMEMBERS';
if (ProductLogic::hasError()) { $where['status']=1;
return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 $where['paid']=1;
} // $res = OrderLogic::Count($where,$time);
return $this->success('ok', $res); // if (ProductLogic::hasError()) {
// return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
// }
$res = UserRecharge::where($where)->whereTime('create_time', $time)->select()->each(function ($item) {
if($item['uid']){
$item['nickname']=User::where('id',$item['uid'])->value('nickname');
}else{
$item['nickname']='';
}
});
return $this->success('ok', $res?->toArray());
} }
/** /**
* 商品销量排行榜统计 * 商品销量排行榜统计
*/ */
public function sales_ranking() public function sales_ranking()
{ {
$time=$this->request->get('date',date('Y-m-d')); $time = $this->request->get('date', date('Y-m-d'));
$store_id = $this->store_id; $store_id = $this->store_id;
$where=[]; $where = [];
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$res = OrderLogic::sales($where,$time); $res = OrderLogic::sales($where, $time);
if (ProductLogic::hasError()) { if (ProductLogic::hasError()) {
return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
} }
@ -110,7 +122,7 @@ class IndexController extends BaseLikeController
*/ */
public function user_trade_count() public function user_trade_count()
{ {
$logic=(new TradeStatisticLogic()); $logic = (new TradeStatisticLogic());
$leftToday = $logic->getTopLeftTrade(['create_time' => 'today']); $leftToday = $logic->getTopLeftTrade(['create_time' => 'today']);
$leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']); $leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']);
$totalleft = [$leftToday, $leftyestoday]; $totalleft = [$leftToday, $leftyestoday];
@ -128,13 +140,13 @@ class IndexController extends BaseLikeController
*/ */
public function street_currday_order_count() public function street_currday_order_count()
{ {
$time=$this->request->get('date',date('Y-m-d')); $time = $this->request->get('date', date('Y-m-d'));
$store_id = $this->store_id; $store_id = $this->store_id;
$where=[]; $where = [];
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$res = OrderLogic::Currday($where,$time); $res = OrderLogic::Currday($where, $time);
if (ProductLogic::hasError()) { if (ProductLogic::hasError()) {
return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
} }