You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
4.6 KiB
128 lines
4.6 KiB
<?php
|
|
|
|
namespace App\Admin\Repositories\v3;
|
|
|
|
use App\Models\LanzuOrderGoods as Model;
|
|
use Dcat\Admin\Grid\Model as GridModel;
|
|
use Dcat\Admin\Repositories\EloquentRepository;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class GoodsActivityReport extends EloquentRepository
|
|
{
|
|
public $params = [];
|
|
/**
|
|
* Model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $eloquentClass = Model::class;
|
|
|
|
public function __construct($params = [])
|
|
{
|
|
$this->params = $params;
|
|
}
|
|
|
|
/**
|
|
* 获取统计列表数据
|
|
*/
|
|
public function get(GridModel $model)
|
|
{
|
|
// 获取当前页数
|
|
$currentPage = $model->getCurrentPage();
|
|
// 获取每页显示行数
|
|
$perPage = $model->getPerPage();
|
|
|
|
$where = [];
|
|
if(!empty($this->params) && isset($this->params['market_id']) && !empty($this->params['market_id'])){
|
|
$where = ['market_id'=>$this->params['market_id']];
|
|
}
|
|
|
|
$selects = 'SUM(number) as total,SUM((original_price-price)*number) as subsidy_total,price,original_price,lanzu_order_goods.goods_id,lanzu_order_goods.name,lanzu_order_goods.cover_img,lanzu_order_main.market_id,lanzu_order.store_id';
|
|
$orderGoodsActivity = $this->getDataModel($selects,$where);
|
|
$list = $orderGoodsActivity->orderBy('total','desc')->groupBy('goods_id','lanzu_order_goods.name','cover_img','market_id','store_id','price','original_price')->paginate($perPage);
|
|
$list = $list->toArray();
|
|
|
|
return $model->makePaginator(
|
|
$list['total'] ?? 0,$list['data'] ?? []
|
|
);
|
|
|
|
}
|
|
|
|
public function getDataModel($selects,$params = [])
|
|
{
|
|
$time = date('Y-m-d',time());
|
|
// 获取筛选参数
|
|
$name = $params['name'] ?? request()->input('name', '');
|
|
$marketId = $params['market_id'] ?? request()->input('market_id',0);
|
|
$storeId = $params['store_id'] ?? request()->input('store_id',0);
|
|
|
|
$startTime = $params['start_time'] ?? request()->input('start_time','');
|
|
$endTime = $params['end_time'] ?? request()->input('end_time','');
|
|
|
|
$orderGoodsActivity = Model::select(DB::raw($selects))
|
|
->join('lanzu_order','lanzu_order_goods.order_id','=','lanzu_order.id')
|
|
->join('lanzu_order_main','lanzu_order.order_main_id','=','lanzu_order_main.global_order_id')
|
|
->where('lanzu_order_goods.activity_type',2)
|
|
->where('lanzu_order_goods.status',1)
|
|
->whereIn('lanzu_order_main.state',[4,5,10,11]);
|
|
|
|
if($name){
|
|
$orderGoodsActivity->where('lanzu_order_goods.name','like',"%$name%");
|
|
}
|
|
if($marketId){
|
|
$orderGoodsActivity->where('market_id',$marketId);
|
|
}
|
|
if($storeId){
|
|
$orderGoodsActivity->where('store_id',$storeId);
|
|
}
|
|
if($startTime){
|
|
$date = $startTime;
|
|
$startTime = $startTime.' 00:00:00';
|
|
|
|
$orderGoodsActivity->where('lanzu_order_goods.created_at','>=',strtotime($startTime));
|
|
}else{
|
|
$date = '2020-06-01';
|
|
}
|
|
if($endTime){
|
|
$date = $date.' 至 '.$endTime;
|
|
$endTime = $endTime.' 23:59:59';
|
|
|
|
$orderGoodsActivity->where('lanzu_order_goods.created_at','<=',strtotime($endTime));
|
|
}else{
|
|
$date .= ' 至 '.$time;
|
|
}
|
|
// if(empty($startTime) && empty($endTime)){
|
|
// $date = $time;
|
|
// $todayStart = $time.' 00:00:00';
|
|
// $todayEnd = $time.' 23:59:59';
|
|
// $orderGoodsActivity->where([['lanzu_order_goods.created_at','>=',strtotime($todayStart)]]);
|
|
// $orderGoodsActivity->where([['lanzu_order_goods.created_at','<=',strtotime($todayEnd)]]);
|
|
// }
|
|
|
|
return $orderGoodsActivity;
|
|
}
|
|
|
|
/**
|
|
* 获取总数
|
|
*/
|
|
public function getCountData($params = [])
|
|
{
|
|
$selects = "SUM(lanzu_order_goods.number) as total,SUM((original_price-price)*number) as subsidy_total,FROM_UNIXTIME(lanzu_order_goods.created_at,'%Y-%m-%d') as dtime";
|
|
$orderGoodsActivity = $this->getDataModel($selects,$params);
|
|
$total = $orderGoodsActivity->groupBy('dtime')->get()->toArray();
|
|
|
|
return $total ?? [];
|
|
}
|
|
|
|
/**
|
|
* 分市场获取
|
|
*/
|
|
public function getMarketData($params = [])
|
|
{
|
|
$selects = "SUM(lanzu_order_goods.number) as total,SUM((original_price-price)*number) as subsidy_total,market_id";
|
|
$orderGoodsActivity = $this->getDataModel($selects,$params);
|
|
$total = $orderGoodsActivity->groupBy('market_id')->get()->toArray();
|
|
|
|
return $total ?? [];
|
|
}
|
|
}
|