更新统计视图

This commit is contained in:
monanxiao 2023-03-22 16:06:49 +08:00
parent 7d229466e3
commit c238c0f50c
2 changed files with 259 additions and 34 deletions

View File

@ -18,6 +18,11 @@ use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Session;
use app\admin\model\InformationUserMsg;
use app\admin\model\InformationUserAddress;
use app\admin\model\ShopUser;
use app\admin\model\SupplyBrokerage as SupplyBrokerageModel;
use app\admin\model\StoreOrder;
class Api extends BaseController
{
@ -515,10 +520,37 @@ class Api extends BaseController
*/
public function main()
{
$res = Cache::store('file')->remember(self::class . '@main', function () {
$today = $this->mainGroup('today');
$yesterday = $this->mainGroup('yesterday');
$lastWeek = $this->mainGroup(date('Y-m-d', strtotime('- 7day')));
// 获取当前登录账号
$adminUserInfo = get_login_admin();
$mmm = [];
//权限组信息
if ($adminUserInfo['group_access'] != 1) {
$find = InformationUserAddress::where('admin_id', $adminUserInfo['id'])->find();
if ($find) {
if ($find['auth_range'] == 1) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
$mmm['village_id'] = $find['village_id'];
} elseif ($find['auth_range'] == 2) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
}elseif ($find['auth_range'] == 5) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
$mmm['village_id'] = $find['village_id'];
$mmm['brigade_id'] = $find['brigade_id'];
}
}
}
$res = Cache::store('file')->remember(self::class . '@main', function () use ($mmm){
$today = $this->mainGroup('today' , $mmm);
$yesterday = $this->mainGroup('yesterday', $mmm);
$lastWeek = $this->mainGroup(date('Y-m-d', strtotime('- 7day')), $mmm);
$lastWeekRate = [];
foreach ($lastWeek as $k => $item) {
@ -561,28 +593,66 @@ class Api extends BaseController
* @author xaboy
* @day 2020/6/25
*/
protected function mainGroup($date,$merId=null)
protected function mainGroup($date, $mmm)
{
// 获取当前地域成员
$userList = InformationUserMsg::where($mmm)
->with(['user'])
->select();
$payPrice = getModelTime(Db::connect('shop')->table('eb_store_order')->where('paid', 1)->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
}), $date, 'pay_time')->sum('pay_price');
// 地域成员ID
$arrUid = [];
$arrPhone = [];
foreach ($userList as $v) {
// 如果存在服务小组的话,则取出
if($v['user']['fa_supply_team_id'])
{
$arrUid[] = $v['user']['uid'];
$arrPhone[] = $v['user']['phone'];
}
}
$merId = null;
$payPrice = getModelTime(StoreOrder::whereIn('uid', $arrUid)
->where('paid', 1), $date, 'create_time')
->sum('pay_price');
// $list = SupplyBrokerageModel::whereIn('user_id', $arrUid)
// ->with(['user', 'merchant', 'supplyChain', 'level'])
// ->page($params['page'])
// ->limit($params['limit'])
// ->select();
$payUser = getModelTime(Db::connect('shop')->table('eb_store_order')->where('paid', 1)->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
}), $date, 'pay_time')->group('uid')->count();
// $payPrice = getModelTime(Db::connect('shop')->table('eb_store_order')->where('paid', 1)->when($merId, function ($query, $merId) {
// $query->where('mer_id', $merId);
// }), $date, 'pay_time')->sum('pay_price');
$userNum = (float)Db::connect('shop')->table('eb_user')->when($date, function ($query, $date) {
$payUser = getModelTime(StoreOrder::whereIn('uid', $arrUid)->where('paid', 1), $date, 'pay_time')->group('uid')->count();
$userNum = (float)ShopUser::whereIn('uid', $arrUid)->when($date, function ($query, $date) {
getModelTime($query, $date, 'create_time');
})->count();
$storeNum = (float)Db::connect('shop')->table('eb_merchant')->where('is_del', 0)->when($date, function ($query, $date) {
getModelTime($query, $date);
})->count();
$visitUserNum = (float)Db::connect('shop')->table('eb_user_visit')->alias('A')->join('eb_store_product B', 'A.type_id = B.product_id')->when($date, function ($query, $date) {
getModelTime($query, $date, 'A.create_time');
})->when($merId, function ($query, $merId) {
$query->where('B.mer_id', $merId);
})->where('A.type', 'product')->group('uid')->count();
// 可能存在问题,待更新
$storeNum = (float)Db::connect('shop')
->table('eb_merchant')
->where('is_del', 0)
->whereIn('mer_phone', $arrPhone)
->when($date, function ($query, $date) {
getModelTime($query, $date);
})->count();
$visitUserNum = (float)Db::connect('shop')
->table('eb_user_visit')
->alias('A')
->whereIn('A.uid', $arrUid)
->join('eb_store_product B', 'A.type_id = B.product_id')
->when($date, function ($query, $date) {
getModelTime($query, $date, 'A.create_time');
})->when($merId, function ($query, $merId) {
$query->where('B.mer_id', $merId);
})->where('A.type', 'product')->group('uid')->count();
$visitNum = (float)Db::connect('shop')->table('eb_user_visit')->when($date, function ($query, $date) {
getModelTime($query, $date, 'create_time');
@ -833,10 +903,59 @@ class Api extends BaseController
*/
public function product()
{
// 获取当前登录账号
$adminUserInfo = get_login_admin();
$mmm = [];
//权限组信息
if ($adminUserInfo['group_access'] != 1) {
$find = InformationUserAddress::where('admin_id', $adminUserInfo['id'])->find();
if ($find) {
if ($find['auth_range'] == 1) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
$mmm['village_id'] = $find['village_id'];
} elseif ($find['auth_range'] == 2) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
}elseif ($find['auth_range'] == 5) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
$mmm['village_id'] = $find['village_id'];
$mmm['brigade_id'] = $find['brigade_id'];
}
}
}
// 获取当前地域成员
$userList = InformationUserMsg::where($mmm)
->with(['user'])
->select();
// 地域成员ID
$arrUid = [];
$arrPhone = [];
foreach ($userList as $v) {
// 如果存在服务小组的话,则取出
if($v['user']['fa_supply_team_id'])
{
$arrUid[] = $v['user']['uid'];
$arrPhone[] = $v['user']['phone'];
}
}
$date = get_params('date') ?? 'today';
$merId = get_params('mer_id') ??'';
$res = Cache::store('file')->remember(self::class . '@product' . $merId . $date, function () use ($merId, $date) {
return Db::connect('shop')->table('eb_store_order_product')->alias('A')->Join('eb_store_order B', 'A.order_id = B.order_id')
$res = Cache::store('file')->remember(self::class . '@product' . $merId . $date, function () use ($merId, $date, $arrUid) {
return Db::connect('shop')->table('eb_store_order_product')
->alias('A')
->where('A.uid', $arrUid)
->Join('eb_store_order B', 'A.order_id = B.order_id')
->field(Db::raw('sum(A.product_num) as total,A.product_id,cart_info'))
->withAttr('cart_info', function ($val) {
return json_decode($val, true);
@ -860,11 +979,60 @@ class Api extends BaseController
//商品访客排行
public function productVisit()
{
// 获取当前登录账号
$adminUserInfo = get_login_admin();
$mmm = [];
//权限组信息
if ($adminUserInfo['group_access'] != 1) {
$find = InformationUserAddress::where('admin_id', $adminUserInfo['id'])->find();
if ($find) {
if ($find['auth_range'] == 1) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
$mmm['village_id'] = $find['village_id'];
} elseif ($find['auth_range'] == 2) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
}elseif ($find['auth_range'] == 5) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
$mmm['village_id'] = $find['village_id'];
$mmm['brigade_id'] = $find['brigade_id'];
}
}
}
// 获取当前地域成员
$userList = InformationUserMsg::where($mmm)
->with(['user'])
->select();
// 地域成员ID
$arrUid = [];
$arrPhone = [];
foreach ($userList as $v) {
// 如果存在服务小组的话,则取出
if($v['user']['fa_supply_team_id'])
{
$arrUid[] = $v['user']['uid'];
$arrPhone[] = $v['user']['phone'];
}
}
$date = get_params('date') ?? 'today';
$merId = get_params('mer_id') ??'';
$res = Cache::store('file')->remember(self::class . '@productVisit' . $merId . $date, function () use ($merId, $date) {
return Db::connect('shop')->table('eb_user_visit')->alias('A')->join('eb_store_product B', 'A.type_id = B.product_id')
$res = Cache::store('file')->remember(self::class . '@productVisit' . $merId . $date, function () use ($merId, $date, $arrUid) {
return Db::connect('shop')
->table('eb_user_visit')
->alias('A')
->whereIn('A.uid', $arrUid)
->join('eb_store_product B', 'A.type_id = B.product_id')
->join('eb_merchant C', 'C.mer_id = B.mer_id')
->field(Db::raw('count(A.type_id) as total,B.image,B.store_name'))
->when($date, function ($query, $date) {
@ -884,20 +1052,78 @@ class Api extends BaseController
*/
public function productCart()
{
// 获取当前登录账号
$adminUserInfo = get_login_admin();
$mmm = [];
//权限组信息
if ($adminUserInfo['group_access'] != 1) {
$find = InformationUserAddress::where('admin_id', $adminUserInfo['id'])->find();
if ($find) {
if ($find['auth_range'] == 1) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
$mmm['village_id'] = $find['village_id'];
} elseif ($find['auth_range'] == 2) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
}elseif ($find['auth_range'] == 5) {
$mmm['area_id'] = $find['area_id'];
$mmm['street_id'] = $find['street_id'];
$mmm['village_id'] = $find['village_id'];
$mmm['brigade_id'] = $find['brigade_id'];
}
}
}
// 获取当前地域成员
$userList = InformationUserMsg::where($mmm)
->with(['user'])
->select();
// 地域成员ID
$arrMerId = [];
foreach ($userList as $v) {
// 如果存在服务小组的话,则取出
if($v['user']['fa_supply_team_id'])
{
$mer_id = (float)Db::connect('shop')
->table('eb_merchant')
->where('is_del', 0)
->where('mer_phone', $v['user']['phone'])
->value('mer_id');
if($mer_id)
{
$arrMerId[] = $mer_id;
}
}
}
$date = get_params('date') ?? 'today';
$merId = get_params('mer_id') ??'';
$res = Cache::store('file')->remember(self::class . '@productCart' . $merId . $date, function () use ($merId, $date) {
return Db::connect('shop')->table('eb_store_product')->alias('A')->Join('eb_store_cart B', 'A.product_id = B.product_id')
->field(Db::raw('sum(B.cart_num) as total,A.product_id,A.store_name,A.image'))
->when($date, function ($query, $date) {
getModelTime($query, $date, 'B.create_time');
})->when($merId, function ($query, $merId) {
$query->where('A.mer_id', $merId);
})->where('B.product_type', 0)->where('B.is_pay', 0)->where('B.is_del', 0)
->where('B.is_new', 0)->where('B.is_fail', 0)->group('A.product_id')->limit(10)->order('total DESC')->select();
$res = Cache::store('file')->remember(self::class . '@productCart' . $merId . $date, function () use ($merId, $date, $arrMerId) {
return Db::connect('shop')
->table('eb_store_product')
->alias('A')
->whereIn('mer_id', $arrMerId)
->Join('eb_store_cart B', 'A.product_id = B.product_id')
->field(Db::raw('sum(B.cart_num) as total,A.product_id,A.store_name,A.image'))
->when($date, function ($query, $date) {
getModelTime($query, $date, 'B.create_time');
})->when($merId, function ($query, $merId) {
$query->where('A.mer_id', $merId);
})->where('B.product_type', 0)->where('B.is_pay', 0)->where('B.is_del', 0)
->where('B.is_new', 0)->where('B.is_fail', 0)->group('A.product_id')->limit(10)->order('total DESC')->select();
}, 2000 + random_int(600, 1200));
$result = ['data' => $res];
return table_assign(0, '', $result);
}

View File

@ -62,7 +62,6 @@ class Spread extends BaseController
}
}
if ($post) {
if (isset($post['area_id']) && !empty($post['area_id'])) {
$mmm['area_id'] = $post['area_id'];