GhsDebtRecordController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\ghs\classes\GhsClass;
  4. use bizGhs\ghs\classes\GhsDebtRecordClass;
  5. use common\components\dateUtil;
  6. use common\components\util;
  7. use Yii;
  8. class GhsDebtRecordController extends BaseController
  9. {
  10. public $guestAccess = [];
  11. //欠款变动记录 ssh 20240628
  12. public function actionList()
  13. {
  14. $get = Yii::$app->request->get();
  15. $ghsId = $get['ghsId'] ?? 0;
  16. $endTime = $get['endTime']??'';
  17. if(empty($ghsId)){
  18. util::success([]);
  19. }
  20. $ghs = GhsClass::getById($ghsId,true);
  21. if(empty($ghs)){
  22. util::success([]);
  23. }
  24. if($ghs->ownMainId != $this->mainId){
  25. util::fail('不是你的供货商');
  26. }
  27. $where = [];
  28. $where['ghsId'] = $ghsId;
  29. if(!empty($endTime)){
  30. $time = bcadd(strtotime($endTime),86400);
  31. $endDate = date("Y-m-d 00:00:00",$time);
  32. $where['addTime<']=$endDate;
  33. }
  34. $list = GhsDebtRecordClass::getRecordList($where);
  35. util::success($list);
  36. }
  37. //应收款统计 ssh 20240528
  38. public function actionPastList()
  39. {
  40. $get = Yii::$app->request->get();
  41. $export = $get['export'] ?? 0;
  42. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  43. $startTime = $get['startTime'] ?? '';
  44. $endTime = $get['endTime'] ?? '';
  45. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  46. $end = $period['endTime'];
  47. $ghsList = GhsClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name,mobile', 'id');
  48. $currentDate = date('Y-m-d 00:00:00', bcadd(strtotime($end),86400));
  49. $totalAmount = 0;
  50. if(!empty($ghsList)){
  51. foreach($ghsList as $key => $ghs){
  52. $ghsId = $ghs['id']??0;
  53. $change = GhsDebtRecordClass::getByCondition(['ghsId'=>$ghsId,'addTime<'=>$currentDate],true,'addTime DESC');
  54. $amount = $change->balance ?? 0;
  55. $totalAmount = bcadd($totalAmount,$amount,2);
  56. $ghsList[$key]['currentDebAmount'] =$amount;
  57. }
  58. $ghsList = array_values($ghsList);
  59. }
  60. if ($export == 1) {
  61. $mainId = $this->mainId;
  62. if (empty($ghsList)) {
  63. util::fail('没有数据需要导出');
  64. }
  65. ini_set('memory_limit', '2045M');
  66. set_time_limit(0);
  67. GhsDebtRecordClass::exportPastList($ghsList, $mainId);
  68. util::stop();
  69. }
  70. util::success(['list' => $ghsList, 'totalAmount' => $totalAmount]);
  71. }
  72. }