85 lines
3.2 KiB
PHP
85 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace app\controller\api\dataview;
|
|
|
|
use app\common\repositories\store\order\StoreOrderRepository;
|
|
use app\common\repositories\user\UserRelationRepository;
|
|
use app\common\repositories\user\UserVisitRepository;
|
|
use crmeb\basic\BaseController;
|
|
use app\common\repositories\system\merchant\MerchantRepository as repository;
|
|
use think\App;
|
|
use think\Db;
|
|
use think\exception\ValidateException;
|
|
|
|
class Merchant extends BaseController
|
|
{
|
|
/**
|
|
* @var repository
|
|
*/
|
|
protected $repository;
|
|
|
|
public $areaCode; // 区县地区码
|
|
|
|
public $streetCode; // 镇街道地区码
|
|
|
|
public function __construct(App $app, repository $repository)
|
|
{
|
|
parent::__construct($app);
|
|
$this->repository = $repository;
|
|
$this->areaCode = $this->request->param('areaCode', '');
|
|
$this->streetCode = $this->request->param('streetCode', '');
|
|
|
|
if ($this->areaCode == '' && $this->streetCode == '') {
|
|
throw new ValidateException('请选择地区');
|
|
}
|
|
}
|
|
|
|
// 商户列表
|
|
public function merchantList()
|
|
{
|
|
[$page, $limit] = $this->getPage();
|
|
$where = $this->request->params([ 'status', 'statusTag', 'is_trader', 'category_id', 'type_id', 'area_id', 'street_id']);
|
|
return app('json')->success($this->repository->lst($where, $page, $limit));
|
|
}
|
|
|
|
// 商户统计
|
|
public function merchantCountMain()
|
|
{
|
|
$merId = $this->request->param('mer_id');
|
|
$today = $this->mainGroup('today', $merId);
|
|
$yesterday = $this->mainGroup('yesterday', $merId);
|
|
$lastWeek = $this->mainGroup(date('Y-m-d', strtotime('- 7day')), $merId);
|
|
$lastWeekRate = [];
|
|
foreach ($lastWeek as $k => $item) {
|
|
if ($item == $today[$k])
|
|
$lastWeekRate[$k] = 0;
|
|
else if ($item == 0)
|
|
$lastWeekRate[$k] = $today[$k];
|
|
else if ($today[$k] == 0)
|
|
$lastWeekRate[$k] = -$item;
|
|
else
|
|
$lastWeekRate[$k] = (float)bcdiv(bcsub($today[$k], $item, 4), $item, 4);
|
|
}
|
|
$day = date('Y-m-d');
|
|
return app('json')->success(compact('today', 'yesterday', 'lastWeekRate', 'day'));
|
|
}
|
|
|
|
public function mainGroup($date, $merId)
|
|
{
|
|
$userVisitRepository = app()->make(UserVisitRepository::class);
|
|
$repository = app()->make(StoreOrderRepository::class);
|
|
$relationRepository = app()->make(UserRelationRepository::class);
|
|
|
|
$payPrice = (float)$repository->dayOrderPrice($date, $merId);
|
|
$payUser = (float)$repository->dayOrderUserNum($date, $merId);
|
|
$visitNum = (float)$userVisitRepository->dateVisitUserNum($date, $merId);
|
|
$likeStore = (float)$relationRepository->dayLikeStore($date, $merId);
|
|
$productNum = \think\facade\Db::name('store_product')->alias('p')->field('count(p.product_id) as think_count')
|
|
->join('merchant m', 'm.mer_id = p.mer_id')
|
|
->whereTime('p.create_time', '<=', $date)
|
|
->where('m.mer_id', $merId)
|
|
->count();
|
|
// Db::name('store_product')->where('mer_id', $merId)->count();
|
|
return compact('productNum','payPrice', 'payUser', 'visitNum', 'likeStore');
|
|
}
|
|
} |