ShopYeChangeController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopYeChangeClass;
  4. use common\components\dict;
  5. use common\components\util;
  6. use common\components\dateUtil;
  7. use Yii;
  8. class ShopYeChangeController extends BaseController
  9. {
  10. public $guestAccess = [];
  11. public function actionList()
  12. {
  13. $get = Yii::$app->request->get();
  14. $status = $get['status'] ?? 0;
  15. $export = $get['export']??0;
  16. $where = [];
  17. $where['mainId'] = $this->mainId;
  18. if (!empty($status)) {
  19. $where['status'] = $status;
  20. }
  21. $tx = $get['tx'] ?? 0;
  22. if (!empty($tx)) {
  23. $where['tx'] = $tx;
  24. }
  25. // 事件类型
  26. if (isset($get['capitalType']) && $get['capitalType'] !== '') {
  27. $where['capitalType'] = (int)$get['capitalType'];
  28. }
  29. // 收支类型筛选:1 收入,0 支出;未传参时不筛选
  30. if (isset($get['io']) && $get['io'] !== '') {
  31. $where['io'] = (int)$get['io'];
  32. }
  33. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : '';
  34. $startTime = $get['startTime'] ?? '';
  35. $endTime = $get['endTime'] ?? '';
  36. if (!empty($searchTime)) {
  37. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  38. $start = date("Y-m-d 00:00:00", strtotime($period['startTime']));
  39. $end = date("Y-m-d 23:59:59", strtotime($period['endTime']));
  40. $where['addTime'] = ['between', [$start, $end]];
  41. }
  42. $list = ShopYeChangeClass::getChangeList($where);
  43. if ($export == 1) {
  44. ini_set('memory_limit', '2045M');
  45. set_time_limit(0);
  46. if (isset($where['addTime']) == false) {
  47. util::fail('请选时间段');
  48. }
  49. $start = $where['addTime'][1][0];
  50. $end = $where['addTime'][1][1];
  51. $monthTime = bcmul(31, 86400);
  52. $startArea = strtotime($start);
  53. $endArea = strtotime($end);
  54. $diff = bcsub($endArea, $startArea);
  55. if ($diff > $monthTime) {
  56. util::fail('最长可导出一个月');
  57. }
  58. ShopYeChangeClass::exportData($list, $this->mainId);
  59. }
  60. util::success($list);
  61. }
  62. }