| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace ghs\controllers;
- use bizGhs\ghs\classes\GhsClass;
- use bizGhs\ghs\classes\GhsDebtRecordClass;
- use common\components\dateUtil;
- use common\components\util;
- use Yii;
- class GhsDebtRecordController extends BaseController
- {
- public $guestAccess = [];
- //欠款变动记录 ssh 20240628
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $ghsId = $get['ghsId'] ?? 0;
- $endTime = $get['endTime']??'';
- if(empty($ghsId)){
- util::success([]);
- }
- $ghs = GhsClass::getById($ghsId,true);
- if(empty($ghs)){
- util::success([]);
- }
- if($ghs->ownMainId != $this->mainId){
- util::fail('不是你的供货商');
- }
- $where = [];
- $where['ghsId'] = $ghsId;
- if(!empty($endTime)){
- $time = bcadd(strtotime($endTime),86400);
- $endDate = date("Y-m-d 00:00:00",$time);
- $where['addTime<']=$endDate;
- }
- $list = GhsDebtRecordClass::getRecordList($where);
- util::success($list);
- }
- //应收款统计 ssh 20240528
- public function actionPastList()
- {
- $get = Yii::$app->request->get();
- $export = $get['export'] ?? 0;
- $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
- $end = $period['endTime'];
- $ghsList = GhsClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name,mobile', 'id');
- $currentDate = date('Y-m-d 00:00:00', bcadd(strtotime($end),86400));
- $totalAmount = 0;
- if(!empty($ghsList)){
- foreach($ghsList as $key => $ghs){
- $ghsId = $ghs['id']??0;
- $change = GhsDebtRecordClass::getByCondition(['ghsId'=>$ghsId,'addTime<'=>$currentDate],true,'addTime DESC');
- $amount = $change->balance ?? 0;
- $totalAmount = bcadd($totalAmount,$amount,2);
- $ghsList[$key]['currentDebAmount'] =$amount;
- }
- $ghsList = array_values($ghsList);
- }
- if ($export == 1) {
- $mainId = $this->mainId;
- if (empty($ghsList)) {
- util::fail('没有数据需要导出');
- }
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- GhsDebtRecordClass::exportPastList($ghsList, $mainId);
- util::stop();
- }
- util::success(['list' => $ghsList, 'totalAmount' => $totalAmount]);
- }
- }
|