| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace ghs\controllers;
- use bizGhs\item\classes\ItemClass;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\classes\StockWastageOrderClass;
- use bizGhs\stat\classes\StatKdClass;
- use bizGhs\stat\classes\StatSaleClass;
- use bizHd\stat\classes\StatVisitClass;
- use common\components\dict;
- use common\components\util;
- use Yii;
- class ConsoleController extends BaseController
- {
- public $guestAccess = ['init', 'profile'];
- //总览
- public function actionStat()
- {
- $where = ['mainId' => $this->mainId, 'debt' => 1]; // 重新赋值
- $pfDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
- $pfDebt = $pfDebt === null ? 0 : $pfDebt;
- $lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
- $lsDebt = $lsDebt === null ? 0 : $lsDebt;
- $totalDebt = bcadd($pfDebt, $lsDebt, 2);
- $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost', null, true);
- $totalItemNum = 0;
- $totalCost = 0;
- if (!empty($itemList)) {
- foreach ($itemList as $item) {
- $stock = $item->stock ?? 0;
- $cost = $item->cost ?? 0;
- $totalItemNum = bcadd($stock, $totalItemNum, 2);
- $currentCost = bcmul($stock, $cost, 2);
- $totalCost = bcadd($currentCost, $totalCost, 2);
- }
- }
- $totalItemNum = floor($totalItemNum);
- $main = $this->main;
- $totalCustom = $main->totalUser ?? 0;
- $totalVisit = $main->totalVisit ?? 0;
- $totalOrder = $main->finishOrder ?? 0;
- $overview = [
- ['name' => "库存(扎)", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
- ['name' => "库存(元)", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
- ['name' => "总欠款", "url" => '/admin/home/member', 'value' => $totalDebt, 'type' => 4],
- ['name' => "总客户", "url" => '/admin/home/member', 'value' => $totalCustom, 'type' => 4],
- ['name' => "总访客", "url" => '/admin/home/member', 'value' => $totalVisit, 'type' => 4],
- ['name' => "总订单", "url" => '/admin/home/order', 'value' => $totalOrder, 'type' => 4],
- ];
- util::success(['overview' => $overview]);
- }
- //系统收入、客服收入、欠款
- public function actionStrokeCount()
- {
- $incomeList = StatKdClass::eachChannelIncome($this->mainId, $this->shop);
- $systemIncome = $incomeList['system']['amount'] ?? 0;
- $systemCount = $incomeList['system']['num'] ?? 0;
- $debtIncome = $incomeList['debt']['amount'] ?? 0;
- $debtCount = $incomeList['debt']['num'] ?? 0;
- $kfWxIncome = $incomeList['kfWx']['amount'] ?? 0;
- $kfWxCount = $incomeList['kfWx']['num'] ?? 0;
- util::success([
- 'systemIncome' => $systemIncome,
- 'systemCount' => $systemCount,
- 'debtCount' => $debtCount,
- 'debtIncome' => $debtIncome,
- 'kfWxCount' => $kfWxCount,
- 'kfWxIncome' => $kfWxIncome,
- ]);
- }
- //今日概况 ssh 20220723
- public function actionProfile()
- {
- $get = Yii::$app->request->get();
- $isMini = $get['isMini'] ?? 0;
- $notice = [];
- $admin = $this->admin;
- if ($isMini == 1 && !empty($admin)) {
- $miniOpenId = $admin['ghsMiniOpenId'] ?? '';
- if (empty($miniOpenId)) {
- $notice = [['title' => '绑定微信,下次自动登录后台', 'action' => '去绑定', 'page' => '/admin/staff/miniAutoLogin']];
- }
- }
- $mainId = $this->mainId;
- $respond = StatSaleClass::profile($mainId);
- $incomeList = $respond['income'] ?? [];
- $todaySale = 0;
- if (!empty($incomeList)) {
- foreach ($incomeList as $item) {
- $todaySale = bcadd($todaySale, $item['amount'], 2);
- }
- }
- $expendList = $respond['expend'] ?? [];
- $todayOut = 0;
- if (!empty($expendList)) {
- foreach ($expendList as $item) {
- $todayOut = bcadd($todayOut, $item['amount'], 2);
- }
- }
- $orderNum = $respond['totalOrderNum'] ?? 0;
- $wastage = StockWastageOrderClass::getTodayWaste($this->mainId);
- $visitCustom = StatVisitClass::getVisitNum($this->mainId);
- $menu = [
- ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
- ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
- ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
- ["name" => "供应商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
- ["name" => "采购单", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
- ["name" => "报损单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
- ["name" => "预订单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/statBook"],
- ["name" => "新增出库", "img" => "ghs/home/dbck.png", "url" => "/admin/shop/selectShop"],
- ["name" => "出库记录", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
- ["name" => "入库记录", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
- ["name" => "销售结账单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/customList"],
- ["name" => "支出登记", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/addExpend"],
- ];
- util::success(['asset' => $this->main, 'notice' => $notice,
- 'todayData' => ['income' => $todaySale, 'order' => $orderNum, 'expend' => $todayOut, 'visitCustom' => $visitCustom, 'wastage' => $wastage],
- 'menu' => $menu,]);
- }
- //常用初始化
- public function actionInit()
- {
- $dict = dict::get();
- $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
- util::success(['dict' => $dict, 'shop' => $shop]);
- }
- }
|