feat(statistics): 修改统计模块代码,优化订单逻辑,更改数据库连接配置

This commit is contained in:
mkm 2024-07-18 17:14:13 +08:00
parent 82a2bf0fa5
commit 3381e942e2
3 changed files with 42 additions and 10 deletions

View File

@ -92,7 +92,11 @@ class IndexController extends BaseLikeController
return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息
}
$res['date']=$dates_two;
$res['dayPayPrice']=Db::name('demo_order_money')->where($where)->sum('money');
$money=Db::name('demo_order_money')->where($where)->sum('money');
$where['paid']=1;
// $pay_price=Db::connect('demo')->name('store_order')->where($where)->whereDay('create_time')->sum('pay_price');
$price=Db::connect('demo')->name('user_recharge')->where($where)->sum('price');
$res['dayPayPrice']=bcadd($money,$price,2);
return $this->success('ok', $res);
}
@ -131,7 +135,7 @@ class IndexController extends BaseLikeController
// if (ProductLogic::hasError()) {
// return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
// }
$res = UserRecharge::where($where)->whereTime('create_time', $time)->select()->each(function ($item) {
$res = Db::connect('demo')->name('user_recharge')->where($where)->whereTime('create_time', $time)->select()->each(function ($item) {
if ($item['uid']) {
$item['nickname'] = User::where('id', $item['uid'])->value('nickname');
} else {
@ -147,14 +151,19 @@ class IndexController extends BaseLikeController
{
$time = $this->request->get('date');
$store_id = $this->request->get('store_id', 0);
$where = [];
$where = ['paid','=',1];
if ($store_id) {
$where['store_id'] = $store_id;
}
$res = OrderLogic::sales($where, $time);
if (ProductLogic::hasError()) {
return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
// $res = OrderLogic::sales($where, $time);
// if (ProductLogic::hasError()) {
// return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息
// }
$select = Db::connect('demo')->name('store_order')->where($where);
if ($time) {
$select->whereDay('create_time', $time);
}
$res = $select->limit(20)->order('id desc')->field('id,order_id,pay_price,create_time')->select()->toArray();
return $this->success('ok', $res);
}
/**

View File

@ -5,6 +5,7 @@ namespace app\statistics\logic;
use app\common\logic\BaseLogic;
use app\common\model\store_order\StoreOrder;
use app\common\model\user_recharge\UserRecharge;
use think\facade\Db;
class OrderLogic extends BaseLogic
{
@ -58,9 +59,11 @@ class OrderLogic extends BaseLogic
}
public static function dayPayPrice($where, $time)
{
$todayAmount = UserRecharge::where($where)
->whereDay('create_time', $time)
->sum('price');
// $todayAmount = UserRecharge::where($where)
// ->whereDay('create_time', $time)
// ->sum('price');
$todayAmount=Db::connect('demo')->name('user_recharge')->where($where)->sum('price');
$pay_price = StoreOrder::where($where)
->whereDay('create_time', $time)
->sum('pay_price');

View File

@ -17,7 +17,7 @@ return [
// 数据库连接端口
'hostport' => getenv('DB_PORT'),
// 数据库编码默认采用utf8
'charset' => 'utf8',
'charset' => 'utf8mb4',
// 数据库表前缀
'prefix' => 'la_',
// 断线重连
@ -27,5 +27,25 @@ return [
// 自定义分页类
'bootstrap' => ''
],
'demo' => [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => getenv('DB_HOST_TWO'),
// 数据库名
'database' => getenv('DB_DATABASE_TWO'),
// 数据库用户名
'username' => getenv('DB_USERNAME_TWO'),
// 数据库密码
'password' => getenv('DB_PASSWORD_TWO'),
// 数据库连接端口
'hostport' => getenv('DB_PORT'),
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8mb4',
// 数据库表前缀
'prefix' => 'la_',
],
],
];