CustomBalanceChangeController.php 2.0 KB

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