| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace hd\controllers;
- use bizHd\goods\classes\KindClass;
- use bizHd\item\classes\ItemClass;
- use bizHd\order\classes\OrderClass;
- use bizHd\order\classes\OrderGoodsClass;
- use bizHd\part\classes\PartClass;
- use bizHd\part\classes\PartItemClass;
- use bizHd\work\classes\WorkClass;
- use common\components\dateUtil;
- use Yii;
- use common\components\util;
- class StatKindController extends BaseController
- {
- //各渠道收入 ssh 20220711
- public function actionProfile()
- {
- $get = Yii::$app->request->get();
- $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';
- $mainId = $this->mainId;
- $kindList = KindClass::getAllByCondition(['mainId' => $mainId, 'flower' => 1, 'delStatus' => 0, 'status' => 1], null, '*', 'id');
- $kindStat = [];
- $where = ['mainId' => $mainId, 'status' => 1];
- $where['finishTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $workList = WorkClass::getAllByCondition($where, null, '*', null, true);
- if (!empty($workList)) {
- foreach ($workList as $work) {
- $kindId = $work->kindId ?? 0;
- if (empty($kindId)) {
- continue;
- }
- $kindName = $kindList[$kindId]['name'] ?? '';
- $num = $work->num ?? 0;
- $flowerNum = $work->flowerNum ?? 0;
- $totalFlowerNum = bcmul($flowerNum, $num);
- if (isset($kindStat[$kindId]['makeNum'])) {
- $kindStat[$kindId]['makeNum'] = bcadd($kindStat[$kindId]['makeNum'], $num);
- $kindStat[$kindId]['flowerNum'] = bcadd($totalFlowerNum, $kindStat[$kindId]['flowerNum']);
- } else {
- $kindStat[$kindId]['makeNum'] = $num;
- $kindStat[$kindId]['flowerNum'] = $totalFlowerNum;
- $kindStat[$kindId]['kindName'] = $kindName;
- if (isset($kindStat[$kindId]['saleNum']) == false) {
- $kindStat[$kindId]['saleNum'] = 0;
- }
- }
- }
- }
- $where = ['mainId' => $mainId, 'payStatus' => 1, 'payTime' => ['between', [$currentStartTime, $currentEndTime]]];
- $orderList = OrderClass::getAllByCondition($where, null, '*', null, true);
- if (!empty($orderList)) {
- foreach ($orderList as $order) {
- $orderSn = $order->orderSn ?? '';
- $sonList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($sonList)) {
- foreach ($sonList as $son) {
- $flower = $son->flower ?? 0;
- if ($flower == 0) {
- continue;
- }
- $kindId = $son->kindId ?? 0;
- if (empty($kindId)) {
- continue;
- }
- $num = $son->num ?? 0;
- $kindName = $kindList[$kindId]['name'] ?? '';
- if (isset($kindStat[$kindId]['saleNum'])) {
- $kindStat[$kindId]['saleNum'] = bcadd($kindStat[$kindId]['saleNum'], $num);
- } else {
- $kindStat[$kindId]['saleNum'] = $num;
- $kindStat[$kindId]['kindName'] = $kindName;
- if (isset($kindStat[$kindId]['makeNum']) == false) {
- $kindStat[$kindId]['makeNum'] = 0;
- $kindStat[$kindId]['flowerNum'] = 0;
- }
- }
- }
- }
- }
- }
- $itemList = ItemClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, 'id,name,mainId,delStatus,ratio', 'id');
- $partStat = [];
- $partList = PartClass::getAllByCondition(['mainId' => $mainId, 'addTime' => ['between', [$currentStartTime, $currentEndTime]]], null, '*', null, true);
- if (!empty($partList)) {
- foreach ($partList as $part) {
- $orderSn = $part->orderSn ?? '';
- $partItemList = PartItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($partItemList)) {
- foreach ($partItemList as $pItem) {
- $productId = $pItem->productId ?? 0;
- $ratio = $itemList[$productId]['ratio'] ?? 10;
- $ratioType = $itemList[$productId]['ratioType'] ?? 0;
- if ($ratioType == 1) {
- continue;
- }
- $name = $itemList[$productId]['name'] ?? '';
- $num = $pItem->itemNum ?? 0;
- $smallNum = bcmul($ratio, $num);
- if (isset($partStat[$productId]['num'])) {
- $partStat[$productId]['num'] = bcadd($partStat[$productId]['num'], $num);
- $partStat[$productId]['smallNum'] = bcadd($partStat[$productId]['smallNum'], $smallNum);
- } else {
- $partStat[$productId]['num'] = $num;
- $partStat[$productId]['smallNum'] = $smallNum;
- $partStat[$productId]['name'] = $name;
- }
- }
- }
- }
- }
- util::success(['kindStat' => $kindStat, 'partStat' => $partStat]);
- }
- }
|