| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace hd\controllers;
- use biz\stat\classes\StatItemClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\arrayUtil;
- use common\components\dateUtil;
- use Yii;
- use common\components\util;
- class StatItemController extends BaseController
- {
- //花材销量 ssh 20211021
- public function actionProfile()
- {
- util::success(['list' => []]);
- //数据不准确,重新开发
- //查看财务的权限
- $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
- if ($lookMoney == 0) {
- util::fail('无法查看');
- }
- $get = Yii::$app->request->get();
- $where = [];
- $where['shopId'] = $this->shopId;
- if (isset($get['shopId']) && !empty($get['shopId'])) {
- $where['shopId'] = $get['shopId'];
- }
- $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 = StatItemClass::getAllByCondition($where, null, '*');
- if (empty($list)) {
- util::success(['list' => $list]);
- }
- $ids = array_column($list, 'itemId');
- $ids = array_unique(array_filter($ids));
- $productInfo = ProductClass::getByIds($ids, null, 'id');
- $stat = [];
- foreach ($list as $key => $val) {
- $itemId = $val['itemId'] ?? 0;
- $idsData[$itemId] = 0;
- $num = bcsub($val['num'], $val['refundNum'], 2);
- $amount = bcsub($val['amount'], $val['refundAmount'], 2);
- $name = $productInfo[$itemId]['name'] ?? '';
- $py = $productInfo[$itemId]['py'] ?? '';
- $stat[$itemId]['productId'] = $itemId;
- $stat[$itemId]['name'] = $name;
- $stat[$itemId]['py'] = $py;
- if (isset($stat[$itemId]['num'])) {
- $stat[$itemId]['num'] = bcadd($stat[$itemId]['num'], $num, 2);
- } else {
- $stat[$itemId]['num'] = $num;
- }
- if (isset($stat[$itemId]['amount'])) {
- $stat[$itemId]['amount'] = bcadd($stat[$itemId]['amount'], $amount, 2);
- } else {
- $stat[$itemId]['amount'] = $amount;
- }
- }
- $stat = arrayUtil::arraySort($stat, 'num');
- util::success(['list' => $stat]);
- }
- }
|