| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace hd\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\stat\classes\StatCgGhsClass;
- use common\components\arrayUtil;
- use common\components\dateUtil;
- use Yii;
- use common\components\util;
- class StatCgGhsController extends BaseController
- {
- //采购列表 ssh 20211017
- public function actionProfile()
- {
- util::success(['list' => []]);
- //数据不准确,重新开发
- $get = Yii::$app->request->get();
- $where = [];
- $where['mainId'] = $this->mainId;
- $searchTime = $get['searchTime'] ?? 'today';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
- $where['time'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $list = StatCgGhsClass::getAllByCondition($where, null, '*');
- $ghsIds = [];
- $arr = [];
- if (!empty($list)) {
- foreach ($list as $ke => $item) {
- $ghsId = $item['ghsId'] ?? 0;
- $num = $item['num'] ?? 0;
- $refundNum = $item['refundNum'] ?? 0;
- $amount = $item['amount'] ?? 0;
- $refundAmount = $item['refundAmount'] ?? 0;
- $ghsIds[$ghsId] = 1;
- if (isset($arr[$ghsId]['num'])) {
- $arr[$ghsId]['num'] = bcadd($arr[$ghsId]['num'], $num, 2);
- } else {
- $arr[$ghsId]['num'] = $num;
- }
- if (isset($arr[$ghsId]['refundNum'])) {
- $arr[$ghsId]['refundNum'] = bcadd($arr[$ghsId]['refundNum'], $refundNum, 2);
- } else {
- $arr[$ghsId]['refundNum'] = $refundNum;
- }
- if (isset($arr[$ghsId]['amount'])) {
- $arr[$ghsId]['amount'] = bcadd($arr[$ghsId]['amount'], $amount, 2);
- } else {
- $arr[$ghsId]['amount'] = $amount;
- }
- if (isset($arr[$ghsId]['refundAmount'])) {
- $arr[$ghsId]['refundAmount'] = bcadd($arr[$ghsId]['refundAmount'], $refundAmount, 2);
- } else {
- $arr[$ghsId]['refundAmount'] = $refundAmount;
- }
- }
- }
- $ghsIds = array_keys($ghsIds);
- $ghsData = GhsClass::getByIds($ghsIds);
- $cg = [];
- foreach ($ghsData as $ghs) {
- $ghsId = $ghs['id'] ?? 0;
- $ghsName = $ghs['name'] ?? '';
- $ghsPy = $ghs['py'] ?? '';
- $num = $arr[$ghsId]['num'] ?? 0;
- $refundNum = $arr[$ghsId]['refundNum'] ?? 0;
- $amount = $arr[$ghsId]['amount'] ?? 0;
- $refundAmount = $arr[$ghsId]['refundAmount'] ?? 0;
- $lastAmount = bcsub($amount, $refundAmount, 2);
- $lastNum = bcsub($num, $refundNum, 2);
- $cg[] = [
- 'ghsId' => $ghsId,
- 'ghsName' => $ghsName,
- 'py' => $ghsPy,
- 'num' => $lastNum,
- 'amount' => $lastAmount,
- ];
- }
- $cg = arrayUtil::arraySort($cg, 'num');
- util::success(['list' => $cg]);
- }
- }
|