| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace ghs\controllers;
- use bizGhs\order\classes\StockWastageOrderItemClass;
- use bizGhs\stat\classes\StatSaleClass;
- use common\components\arrayUtil;
- use common\components\imgUtil;
- use Yii;
- use common\components\util;
- use common\components\dateUtil;
- class StatController extends BaseController
- {
- public function actionProfit()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能查看');
- }
- //惠雅鲜花员工不能看利润表
- $shopAdmin = $this->shopAdmin;
- $adminId = $shopAdmin->adminId ?? 0;
- if (in_array($adminId, [3405, 2812, 4004,2812])) {
- util::fail('暂无权限');
- }
- $mainId = $this->mainId;
- $respond = StatSaleClass::profile($mainId);
- $income = $respond['income'] ?? 0;
- $expend = $respond['expend'] ?? 0;
- $balance = $respond['balance'] ?? 0;
- util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance)]);
- }
- public function actionWastage()
- {
- $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);
- $start = date("Y-m-d 00:00:00", strtotime($period['startTime']));
- $end = date("Y-m-d 23:59:59", strtotime($period['endTime']));
- $where['addTime'] = ['between', [$start, $end]];
- }
- $wastageList = StockWastageOrderItemClass::getAllByCondition($where, null, '*', null, true);
- $stat = [];
- $totalCost = 0;
- $totalNum = 0;
- if (!empty($wastageList)) {
- foreach ($wastageList as $waste) {
- $name = $waste->name ?? '';
- $shortCover = $waste->cover ?? '';
- $cover = imgUtil::groupImg($shortCover);
- $num = $waste->itemNum ?? 0;
- $cost = $waste->itemCost ?? 0;
- $currentCost = bcmul($cost, $num, 2);
- $productId = $waste->productId ?? 0;
- if (isset($stat[$productId]) == false) {
- $stat[$productId]['name'] = $name;
- $stat[$productId]['cover'] = $cover;
- $stat[$productId]['num'] = 0;
- $stat[$productId]['amount'] = 0;
- }
- $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2);
- $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $currentCost, 2);
- $totalNum = bcadd($totalNum, $num, 2);
- $totalCost = bcadd($totalCost, $currentCost, 2);
- }
- $stat = array_values($stat);
- $stat = arrayUtil::arraySort($stat, 'num');
- }
- util::success(['stat' => $stat, 'totalNum' => $totalNum, 'totalCost' => $totalCost]);
- }
- }
|