| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace ghs\controllers;
- use biz\stat\classes\StatItemClass;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\classes\OrderItemClass;
- 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()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $get = Yii::$app->request->get();
- $sort = $get['sort'] ?? 'num';
- $where = [];
- $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'];
- $currentStartDate = date('Y-m-d', strtotime($start));
- $currentEndDate = date('Y-m-d', strtotime($end));
- $currentStartTime = $currentStartDate . ' 00:00:00';
- $currentEndTime = $currentEndDate . ' 23:59:59';
- $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $list = OrderClass::getAllByCondition($where, null, '*');
- if (empty($list)) {
- util::success(['list' => []]);
- }
- $productInfo = ProductClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,name,py', 'id');
- $stat = [];
- foreach ($list as $order) {
- $orderSn = $order['orderSn'] ?? '';
- $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($itemList)) {
- foreach ($itemList as $item) {
- $productId = $item->productId ?? 0;
- $name = $productInfo[$productId]['name'] ?? '';
- $py = $productInfo[$productId]['py'] ?? '';
- $num = bcsub($item['xhNum'], $item['refundNum'], 2);
- $unitPrice = $item['xhUnitPrice'] ?? 0;
- $unitCost = $item['cost'] ?? 0;
- $unitGross = bcsub($unitPrice, $unitCost, 2);
- $currentAmount = bcmul($unitPrice, $num, 2);
- $currentGross = bcmul($unitGross, $num, 2);
- $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'], $currentAmount, 2);
- } else {
- $stat[$productId]['amount'] = $currentAmount;
- }
- if (isset($stat[$productId]['gross'])) {
- $stat[$productId]['gross'] = bcadd($stat[$productId]['gross'], $currentGross, 2);
- } else {
- $stat[$productId]['gross'] = $currentAmount;
- }
- }
- }
- }
- $rank = 'num';
- if ($sort == 'gross') {
- $rank = 'gross';
- }
- if ($sort == 'amount') {
- $rank = 'amount';
- }
- $stat = arrayUtil::arraySort($stat, $rank);
- util::success(['list' => $stat]);
- }
- }
|