| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace addons\Store\backend\controllers;
- use addons\Store\common\services\StoreFinanceService;
- use addons\Store\common\services\StoreStatisticsService;
- use common\enums\DownloadEnum;
- use common\helpers\csv\CsvExportHelper;
- use Exception;
- use Yii;
- /**
- * 资产统计
- */
- class StoreFinanceController extends BaseController
- {
- /**
- * 门店财务数据
- *
- * @return string
- */
- public function actionIndex()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- try {
- if ($request->isGet) {
- $get = $request->get();
- $res = Yii::$app->services->validate->validate($get, [
- [['id', 'store_id', 'page', 'limit'], 'integer'],
- [['keyword'], 'string'],
- [['date'], 'safe']
- ]);
- if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
- $list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->getStoreFinanceList($get);
- $export_list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->storeFinanceFieldList();
- $list['export_list'] = $export_list;
- return $this->success('获取成功', $list);
- }
- if ($request->isPost) {
- if (\Yii::$app->request->post('flag') == 'EXPORT') {
- $post = \Yii::$app->request->post();
- $post['mall_id'] = $this->mall_id;
- $filename = 'o2o门店财务数据-' . date('YmdHis') . '_' . rand(10000, 99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_STORE_FINANCE, StoreFinanceService::class, 'exportStoreFinance', $post);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- return $this->render('index');
- }
- public function actionGetStoreStatics()
- {
- $request = Yii::$app->request;
- if ($request->isAjax && $request->isGet) {
- try {
- $get = $request->get();
- $res = Yii::$app->services->validate->validate($get, [
- [['store_id'], 'integer'],
- [['date'], 'safe'],
- ]);
- if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
- $info = (new StoreFinanceService(['mall_id' => $this->mall_id]))->getStoreStatics($get);
- return $this->success('获取成功', $info);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- //门店财务详情
- public function actionDetail()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- try {
- if ($request->isGet) {
- $get = $request->get();
- $res = Yii::$app->services->validate->validate($get, [
- [['page', 'limit', 'store_id', 'order_status'], 'integer'],
- [['store_keyword', 'keyword', 'order_no', 'tabname'], 'string'],
- [['date'], 'safe']
- ]);
- if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
- if ($get['tabname'] == 'order-detail') {
- $list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->getStoreFinanceDetail($get);
- $export_list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->storeFinanceDetailFieldList();
- } else if ($get['tabname'] == 'cashier') {
- $list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->getCashierFinanceDetail($get);
- $export_list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->cashierFinanceDetailFieldList();
- }
- $list['export_list'] = $export_list;
- return $this->success('获取成功', $list);
- }
- if ($request->isPost) {
- if (\Yii::$app->request->post('flag') == 'EXPORT') {
- $post = \Yii::$app->request->post();
- $post['mall_id'] = $this->mall_id;
- $filename = 'o2o门店财务明细-' . date('YmdHis') . '_' . rand(10000, 99999);
- $func_model = 'exportStoreFinanceData';
- if ($post['tabname'] == 'cashier') {
- $func_model = 'exportCashierFinanceData';
- }
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_STORE_FINANCE, StoreFinanceService::class, $func_model, $post);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- return $this->render('detail');
- }
- }
|