StoreFinanceController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace addons\Store\backend\controllers;
  3. use addons\Store\common\services\StoreFinanceService;
  4. use addons\Store\common\services\StoreStatisticsService;
  5. use common\enums\DownloadEnum;
  6. use common\helpers\csv\CsvExportHelper;
  7. use Exception;
  8. use Yii;
  9. /**
  10. * 资产统计
  11. */
  12. class StoreFinanceController extends BaseController
  13. {
  14. /**
  15. * 门店财务数据
  16. *
  17. * @return string
  18. */
  19. public function actionIndex()
  20. {
  21. $request = Yii::$app->request;
  22. if ($request->isAjax) {
  23. try {
  24. if ($request->isGet) {
  25. $get = $request->get();
  26. $res = Yii::$app->services->validate->validate($get, [
  27. [['id', 'store_id', 'page', 'limit'], 'integer'],
  28. [['keyword'], 'string'],
  29. [['date'], 'safe']
  30. ]);
  31. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  32. $list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->getStoreFinanceList($get);
  33. $export_list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->storeFinanceFieldList();
  34. $list['export_list'] = $export_list;
  35. return $this->success('获取成功', $list);
  36. }
  37. if ($request->isPost) {
  38. if (\Yii::$app->request->post('flag') == 'EXPORT') {
  39. $post = \Yii::$app->request->post();
  40. $post['mall_id'] = $this->mall_id;
  41. $filename = 'o2o门店财务数据-' . date('YmdHis') . '_' . rand(10000, 99999);
  42. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_STORE_FINANCE, StoreFinanceService::class, 'exportStoreFinance', $post);
  43. if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
  44. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  45. }
  46. }
  47. } catch (\Exception $e) {
  48. return $this->error($e->getMessage());
  49. }
  50. }
  51. return $this->render('index');
  52. }
  53. public function actionGetStoreStatics()
  54. {
  55. $request = Yii::$app->request;
  56. if ($request->isAjax && $request->isGet) {
  57. try {
  58. $get = $request->get();
  59. $res = Yii::$app->services->validate->validate($get, [
  60. [['store_id'], 'integer'],
  61. [['date'], 'safe'],
  62. ]);
  63. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  64. $info = (new StoreFinanceService(['mall_id' => $this->mall_id]))->getStoreStatics($get);
  65. return $this->success('获取成功', $info);
  66. } catch (\Exception $e) {
  67. return $this->error($e->getMessage());
  68. }
  69. }
  70. }
  71. //门店财务详情
  72. public function actionDetail()
  73. {
  74. $request = Yii::$app->request;
  75. if ($request->isAjax) {
  76. try {
  77. if ($request->isGet) {
  78. $get = $request->get();
  79. $res = Yii::$app->services->validate->validate($get, [
  80. [['page', 'limit', 'store_id', 'order_status'], 'integer'],
  81. [['store_keyword', 'keyword', 'order_no', 'tabname'], 'string'],
  82. [['date'], 'safe']
  83. ]);
  84. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  85. if ($get['tabname'] == 'order-detail') {
  86. $list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->getStoreFinanceDetail($get);
  87. $export_list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->storeFinanceDetailFieldList();
  88. } else if ($get['tabname'] == 'cashier') {
  89. $list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->getCashierFinanceDetail($get);
  90. $export_list = (new StoreFinanceService(['mall_id' => $this->mall_id]))->cashierFinanceDetailFieldList();
  91. }
  92. $list['export_list'] = $export_list;
  93. return $this->success('获取成功', $list);
  94. }
  95. if ($request->isPost) {
  96. if (\Yii::$app->request->post('flag') == 'EXPORT') {
  97. $post = \Yii::$app->request->post();
  98. $post['mall_id'] = $this->mall_id;
  99. $filename = 'o2o门店财务明细-' . date('YmdHis') . '_' . rand(10000, 99999);
  100. $func_model = 'exportStoreFinanceData';
  101. if ($post['tabname'] == 'cashier') {
  102. $func_model = 'exportCashierFinanceData';
  103. }
  104. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_STORE_FINANCE, StoreFinanceService::class, $func_model, $post);
  105. if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
  106. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  107. }
  108. }
  109. } catch (\Exception $e) {
  110. return $this->error($e->getMessage());
  111. }
  112. }
  113. return $this->render('detail');
  114. }
  115. }