8 changed files with 227 additions and 24 deletions
-
65app/Admin/Actions/EXporter/GoodsActivitySales.php
-
84app/Admin/Actions/Tools/GoodsActivityExport.php
-
65app/Admin/Controllers/v3/GoodsActivityReportController.php
-
14app/Admin/Repositories/v3/GoodsActivityReport.php
-
6app/Admin/Widgets/Charts/OrderGoodsActivityCountChart.php
-
6app/Admin/Widgets/Charts/OrderGoodsActivityMarketChart.php
-
10app/Admin/Widgets/Charts/OrderGoodsActivityTotalChart.php
-
1app/Admin/routes.php
@ -0,0 +1,65 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Exporter; |
||||
|
|
||||
|
use Maatwebsite\Excel\Concerns\FromArray; |
||||
|
use Maatwebsite\Excel\Concerns\WithStrictNullComparison; |
||||
|
use App\Admin\Repositories\v3\GoodsActivityReport; |
||||
|
use App\Models\v3\Market as MarketModel; |
||||
|
use App\Models\v3\Store as StoreModel; |
||||
|
|
||||
|
class GoodsActivitySales implements FromArray, WithStrictNullComparison |
||||
|
{ |
||||
|
protected $params = []; |
||||
|
public function __construct($params) |
||||
|
{ |
||||
|
$this->params = $params; |
||||
|
} |
||||
|
|
||||
|
public function array(): array |
||||
|
{ |
||||
|
$result = [[ |
||||
|
'商品ID', |
||||
|
'商品名称', |
||||
|
'市场', |
||||
|
'店铺', |
||||
|
'售价(元)', |
||||
|
'原价(元)', |
||||
|
'销量(单)', |
||||
|
'补贴(元)', |
||||
|
]]; |
||||
|
$data = $this->getData($this->params); |
||||
|
$markets = MarketModel::getMarketArray(); |
||||
|
$stores = StoreModel::getStoreArray(); |
||||
|
foreach ($data as $value){ |
||||
|
$item = [ |
||||
|
$value['goods_id'], |
||||
|
$value['name']??'', |
||||
|
$markets[$value['market_id']]??'', |
||||
|
$stores[$value['store_id']]??'', |
||||
|
$value['price']??0, |
||||
|
$value['original_price']??0, |
||||
|
$value['total']??0, |
||||
|
$value['subsidy_total']??0 |
||||
|
]; |
||||
|
|
||||
|
$result[] = $item; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取数据 |
||||
|
*/ |
||||
|
public function getData($option = []) |
||||
|
{ |
||||
|
$params = $option; |
||||
|
$repository = new GoodsActivityReport(); |
||||
|
$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 = $repository->getDataModel($selects,$params); |
||||
|
$list = $orderGoodsActivity->orderBy('total','desc')->groupBy('goods_id','lanzu_order_goods.name','cover_img','market_id','store_id','price','original_price')->get()->toArray(); |
||||
|
|
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,84 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Tools; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Dcat\Admin\Tree\AbstractTool; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class GoodsActivityExport extends AbstractTool |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '<span class="feather icon-download">导出<span>'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$url = '/goods_activity_export?'; |
||||
|
$name = $request->get('name', ''); |
||||
|
$marketId = $request->get('market_id',0); |
||||
|
$storeId = $request->get('store_id',0); |
||||
|
$startTime = $request->get('start_time',''); |
||||
|
$endTime = $request->get('end_time',''); |
||||
|
|
||||
|
if(!empty($name)){ |
||||
|
$url .= '&name='.$name; |
||||
|
} |
||||
|
if(!empty($marketId)){ |
||||
|
$url .= '&market_id='.$marketId; |
||||
|
} |
||||
|
if(!empty($storeId)){ |
||||
|
$url .= '&store_id='.$storeId; |
||||
|
} |
||||
|
if(!empty($startTime)){ |
||||
|
$url .= '&start_time='.$startTime; |
||||
|
} |
||||
|
|
||||
|
if(!empty($endTime)){ |
||||
|
$url .= '&end_time='.$endTime; |
||||
|
} |
||||
|
return $this->response() |
||||
|
->success('导出中~') |
||||
|
->redirect($url); |
||||
|
} |
||||
|
public function parameters() |
||||
|
{ |
||||
|
return [ |
||||
|
'page' => request()->input('page', 1), |
||||
|
'name' => request()->input('name', ''), |
||||
|
'market_id' => request()->input('market_id',0), |
||||
|
'store_id' => request()->input('store_id',0), |
||||
|
'start_time' => request()->input('start_time',''), |
||||
|
'end_time' => request()->input('end_time',''), |
||||
|
]; |
||||
|
} |
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return '确定导出数据吗?'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue