StatController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace backend\controllers;
  3. use biz\stat\services\StatIncomeCategoryService;
  4. use biz\stat\services\StatIncomeService;
  5. use biz\stat\services\StatIncomeSourceService;
  6. use biz\stat\services\StatIncomeUsageService;
  7. use common\components\dateUtil;
  8. use common\components\page;
  9. use common\services\xhMerchantCapitalService;
  10. use common\components\stringUtil;
  11. use common\services\xhUserUniteService;
  12. use common\services\xhUserAssetService;
  13. use common\services\xhUserAlipayService;
  14. use common\services\xhOrderService;
  15. use common\components\configDict;
  16. use common\components\util;
  17. use common\services\xhUserService;
  18. use common\models\xhUser;
  19. use common\services\xhMerchantService;
  20. use common\services\xhUserIntegralService;
  21. use Yii;
  22. use yii\web\Controller;
  23. use yii\data\Pagination;
  24. use common\models\xhMerchantCapital;
  25. use common\models\xhUserCapital;
  26. class StatController extends BackendController
  27. {
  28. /**
  29. * 商家的资金流水
  30. */
  31. public function actionList()
  32. {
  33. $get = Yii::$app->request->get();
  34. $query = xhMerchantCapital::find();
  35. $query->where(['merchantId' => $this->merchantId, 'io' => 1]);
  36. if (isset($get['payWay']) && $get['payWay'] != -1) {
  37. $query->andWhere(['payWay' => $get['payWay']]);
  38. }
  39. if (isset($get['date']) && !empty($get['date'])) {
  40. $arrDate = explode(' - ', $get['date']);
  41. $startTime = strtotime($arrDate[0]);
  42. $endTime = strtotime($arrDate[1]);
  43. $query->andWhere(['>=', 'addTime', $startTime]);
  44. $query->andWhere(['<', 'addTime', $endTime]);
  45. }
  46. $countQuery = clone $query;
  47. //总计
  48. $totalAmount = $countQuery->sum('amount');
  49. $totalCount = $countQuery->count();
  50. $pages = new Pagination(['totalCount' => $totalCount, 'pageSize' => 50]);
  51. $models = $query->offset($pages->offset)->limit($pages->limit)->orderBy('addTime desc')->all();
  52. $payWay = configDict::getConfig('payWayName');
  53. $capitalTypeList = configDict::getConfig('capitalTypeList');
  54. return $this->render('list', ['models' => $models, 'pages' => $pages, 'payWay' => $payWay, 'capitalTypeList' => $capitalTypeList, 'totalAmount' => $totalAmount]);
  55. }
  56. /**
  57. * 收入统计 shish 2019.9.21
  58. */
  59. public function actionIndex()
  60. {
  61. $date = dateUtil::getTime(1);
  62. $start = $date[0];
  63. $end = $date[1];
  64. /**变化趋势**/
  65. $latestIncome = StatIncomeService::getLatestIncome($start, $end);
  66. $latestIncomeDate = array_column($latestIncome, 'time');
  67. $latestIncomeAmount = array_column($latestIncome, 'amount');
  68. /** 来源 **/
  69. $source = StatIncomeSourceService::getLatestSource($start, $end);
  70. /** 分类 **/
  71. $category = StatIncomeCategoryService::getLatestIncome($start, $end);
  72. /** 用途 **/
  73. $usage = StatIncomeUsageService::getLatestIncome($start, $end);
  74. return $this->render('index', [
  75. 'latestIncomeDate' => json_encode($latestIncomeDate),
  76. 'latestIncomeAmount' => json_encode($latestIncomeAmount),
  77. 'source' => $source,
  78. 'category' => $category,
  79. 'usage' => $usage,
  80. ]);
  81. }
  82. public function actionPer()
  83. {
  84. return $this->render('per');
  85. }
  86. public function actionCustomer()
  87. {
  88. return $this->render('customer');
  89. }
  90. public function actionIncome()
  91. {
  92. $where = ['merchantId' => $this->merchantId];
  93. $return = StatIncomeService::getBackendList('*', $where, 'addTime desc');
  94. $pages = $return['pages'];
  95. $list = $return['list'];
  96. $list = [];
  97. return $this->render('income', ['list' => $list, 'pages' => $pages, 'list' => $list]);
  98. }
  99. //对帐 shish 2019.9.8
  100. public function actionCheckUp()
  101. {
  102. $this->errorExportJson();
  103. $id = Yii::$app->request->get('id');
  104. StatIncomeService::checkUp($id);
  105. util::ok();
  106. }
  107. }