MainWalletController.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * hdApp 中央钱包(可用余额)接口
  4. */
  5. namespace hd\controllers;
  6. use bizHd\shop\classes\MainWalletChangeClass;
  7. use common\components\dateUtil;
  8. use common\components\util;
  9. use Yii;
  10. class MainWalletController extends BaseController
  11. {
  12. public $guestAccess = [];
  13. /**
  14. * 钱包变动明细分页 + 区间汇总
  15. * GET:page、searchTime、startTime、endTime、capitalType(可选)
  16. */
  17. public function actionChangeList()
  18. {
  19. $get = Yii::$app->request->get();
  20. $where = [];
  21. $where['mainId'] = $this->mainId;
  22. if (isset($get['capitalType']) && $get['capitalType'] !== '') {
  23. $where['capitalType'] = (int) $get['capitalType'];
  24. }
  25. $searchTime = $get['searchTime'] ?? 'today';
  26. if (!empty($searchTime)) {
  27. $startTime = $get['startTime'] ?? '';
  28. $endTime = $get['endTime'] ?? '';
  29. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  30. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  31. }
  32. $list = MainWalletChangeClass::getChangeList($where);
  33. $summaryAmount = MainWalletChangeClass::getSummaryAmount($where);
  34. $main = $this->main;
  35. $walletBalance = $main->walletBalance ?? '0.00';
  36. $list['summary'] = [
  37. 'totalRecharge' => $summaryAmount['recharge'],
  38. 'totalConsume' => $summaryAmount['consume'],
  39. 'walletBalance' => round((float) $walletBalance, 2),
  40. ];
  41. util::success($list);
  42. }
  43. }