链街Dcat后台
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.
 
 
 
 

105 lines
3.8 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 $data = [];
/**
* Model.
*
* @var string
*/
protected $eloquentClass = Model::class;
/**
* 获取统计列表数据
*/
public function get(GridModel $model)
{
// 获取当前页数
$currentPage = $model->getCurrentPage();
// 获取每页显示行数
$perPage = $model->getPerPage();
$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, $perPage);
$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 ,$perPage = 10)
{
// 获取筛选参数
$name = request()->input('name', '');
$marketId = request()->input('market_id');
$storeId = request()->input('store_id');
$time = date('Y-m-d',time());
$startTime = request()->input('start_time');
$endTime = 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()
{
$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);
$total = $orderGoodsActivity->groupBy('dtime')->get()->toArray();
return $total ?? [];
}
}