|
|
@@ -2,8 +2,8 @@
|
|
|
|
|
|
namespace hd\controllers;
|
|
|
|
|
|
-use biz\ghs\classes\GhsClass;
|
|
|
-use biz\stat\classes\StatCgGhsClass;
|
|
|
+use bizHd\product\classes\ProductClass;
|
|
|
+use bizHd\purchase\classes\PurchaseItemClass;
|
|
|
use common\components\arrayUtil;
|
|
|
use common\components\dateUtil;
|
|
|
use Yii;
|
|
|
@@ -12,87 +12,63 @@ use common\components\util;
|
|
|
class StatCgController extends BaseController
|
|
|
{
|
|
|
|
|
|
- //一整年采购了哪些花材
|
|
|
-
|
|
|
- //还可以选择供货商
|
|
|
-
|
|
|
- //做一个需求反馈的入口
|
|
|
-
|
|
|
+ //采购统计
|
|
|
public function actionProfile()
|
|
|
{
|
|
|
$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']]];
|
|
|
+ $where = ['mainId' => $this->mainId];
|
|
|
+ $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
|
|
|
+ $startTime = $get['startTime'] ?? '';
|
|
|
+ $endTime = $get['endTime'] ?? '';
|
|
|
+ $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
|
|
|
+ $start = $period['startTime'];
|
|
|
+ $end = $period['endTime'];
|
|
|
+ $startDate = date("Y-m-d 00:00:00", strtotime($start));
|
|
|
+ $endDate = date("Y-m-d 23:59:59", strtotime($end));
|
|
|
+ $where['payTime'] = ['between', [$startDate, $endDate]];
|
|
|
+ if (isset($get['ghsId']) && !empty($get['ghsId'])) {
|
|
|
+ $where['ghsId'] = $get['ghsId'];
|
|
|
}
|
|
|
- $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;
|
|
|
- }
|
|
|
+ $list = PurchaseItemClass::getAllByCondition($where, null, '*');
|
|
|
+ if (empty($list)) {
|
|
|
+ util::success(['list' => $list]);
|
|
|
+ }
|
|
|
+ $ids = array_column($list, 'productId');
|
|
|
+ $ids = array_unique(array_filter($ids));
|
|
|
+ $productInfo = ProductClass::getByIds($ids, null, 'id');
|
|
|
+ $stat = [];
|
|
|
+ foreach ($list as $key => $val) {
|
|
|
+ $productId = $val['productId'] ?? 0;
|
|
|
+ $xhUnitType = $val['xhUnitType'] ?? 0;
|
|
|
+ $xhUnitPrice = $val['xhUnitPrice'] ?? 0;
|
|
|
+ $ratio = $val['ratio'] ?? 20;
|
|
|
+ $beforeNum = bcsub($val['xhNum'], $val['refundNum'], 2);
|
|
|
+ if ($xhUnitType == 0) {
|
|
|
+ $num = $beforeNum;
|
|
|
+ } else {
|
|
|
+ $num = bcdiv($beforeNum, $ratio, 2);
|
|
|
+ }
|
|
|
|
|
|
- if (isset($arr[$ghsId]['refundAmount'])) {
|
|
|
- $arr[$ghsId]['refundAmount'] = bcadd($arr[$ghsId]['refundAmount'], $refundAmount, 2);
|
|
|
- } else {
|
|
|
- $arr[$ghsId]['refundAmount'] = $refundAmount;
|
|
|
- }
|
|
|
+ $amount = bcmul($num, $xhUnitPrice, 2);
|
|
|
|
|
|
+ $name = $productInfo[$productId]['name'] ?? '';
|
|
|
+ $py = $productInfo[$productId]['py'] ?? '';
|
|
|
+ $stat[$productId]['productId'] = $productId;
|
|
|
+ $stat[$productId]['name'] = $name;
|
|
|
+ $stat[$productId]['py'] = $py;
|
|
|
+ if (isset($stat[$productId]['num'])) {
|
|
|
+ $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2);
|
|
|
+ } else {
|
|
|
+ $stat[$productId]['num'] = $num;
|
|
|
+ }
|
|
|
+ if (isset($stat[$productId]['amount'])) {
|
|
|
+ $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $amount, 2);
|
|
|
+ } else {
|
|
|
+ $stat[$productId]['amount'] = $amount;
|
|
|
}
|
|
|
}
|
|
|
- $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]);
|
|
|
+ $stat = arrayUtil::arraySort($stat, 'num');
|
|
|
+ util::success(['list' => $stat]);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|