CustomBalanceChangeController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\custom\classes\CustomBalanceChangeClass;
  4. use bizGhs\custom\classes\CustomClass;
  5. use common\components\util;
  6. use Yii;
  7. class CustomBalanceChangeController extends BaseController
  8. {
  9. public $guestAccess = [];
  10. //欠款变动明细
  11. public function actionList()
  12. {
  13. $get = Yii::$app->request->get();
  14. $export = $get['export'] ?? 0;
  15. $where = [];
  16. $where['mainId'] = $this->mainId;
  17. $searchTime = $get['searchTime'] ?? '';
  18. if (!empty($searchTime)) {
  19. $startTime = $get['startTime'] ?? '';
  20. $endTime = $get['endTime'] ?? '';
  21. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  22. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  23. } else {
  24. if ($export == 1) {
  25. util::fail('请选择时间');
  26. }
  27. }
  28. if ($export == 1) {
  29. ini_set('memory_limit', '2045M');
  30. set_time_limit(0);
  31. if (isset($where['addTime']) == false) {
  32. util::fail('请选时间段');
  33. }
  34. $start = $where['addTime'][1][0];
  35. $end = $where['addTime'][1][1];
  36. $monthTime = bcmul(31, 86400);
  37. $startArea = strtotime($start);
  38. $endArea = strtotime($end);
  39. $diff = bcsub($endArea, $startArea);
  40. if ($diff > $monthTime) {
  41. util::fail('最长可导出一个月');
  42. }
  43. }
  44. $customId = $get['customId'] ?? 0;
  45. if (!empty($customId)) {
  46. $custom = CustomClass::getById($customId);
  47. CustomClass::valid($custom, $this->shopId);
  48. $where['customId'] = $customId;
  49. }
  50. $respond = CustomBalanceChangeClass::getChangeList($where);
  51. if ($export == 1) {
  52. CustomBalanceChangeClass::exportData($respond, $this->mainId);
  53. }
  54. util::success($respond);
  55. }
  56. }