| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace ghs\controllers;
- use bizGhs\order\classes\StockWastageOrderClass;
- 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, [2366, 2812, 4004, 3405, 3407])) {
- 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 actionWaste()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $list = StockWastageOrderClass::getAllByCondition(['mainId' => 742], null, '*');
- $arr = [];
- if (!empty($list)) {
- foreach ($list as $order) {
- $addTime = $order['addTime'];
- $time = date("Ym", strtotime($addTime));
- $bigNum = $order['bigNum'];
- $cost = $order['cost'];
- if (isset($arr[$time])) {
- $arr[$time]['num'] = bcadd($arr[$time]['num'], $bigNum);
- $arr[$time]['cost'] = bcadd($arr[$time]['cost'], $cost, 2);
- $arr[$time]['time'] = $time;
- } else {
- $arr[$time]['num'] = $bigNum;
- $arr[$time]['cost'] = $cost;
- $arr[$time]['time'] = $time;
- }
- }
- }
- util::success(['list' => $arr]);
- }
- //损耗花材
- 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]);
- }
- }
|