|
|
@@ -0,0 +1,95 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace ghs\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
|
|
|
+{
|
|
|
+
|
|
|
+ //采购列表 shish 20211017
|
|
|
+ public function actionProfile()
|
|
|
+ {
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $where = [];
|
|
|
+ $where['shopId'] = $this->shopId;
|
|
|
+ if (isset($get['shopId']) && !empty($get['shopId'])) {
|
|
|
+ $where['shopId'] = $get['shopId'];
|
|
|
+ }
|
|
|
+ $selectTime = $get['selectTime'] ?? 'thisMonth';
|
|
|
+ if (!empty($selectTime)) {
|
|
|
+ $startTime = $get['startTime'] ?? '';
|
|
|
+ $endTime = $get['endTime'] ?? '';
|
|
|
+ $period = dateUtil::formatTime($selectTime, $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]);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|