| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <?php
- namespace ghs\controllers;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\item\classes\ItemClass;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\classes\StockWastageOrderClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizGhs\stat\classes\StatKdClass;
- use bizGhs\stat\classes\StatSaleClass;
- use bizHd\purchase\classes\PurchaseClass;
- //use bizHd\stat\classes\StatVisitClass;
- use bizGhs\stat\classes\StatVisitClass;
- use common\components\dict;
- use common\components\util;
- use Yii;
- class ConsoleController extends BaseController
- {
- public $guestAccess = ['init', 'profile', 'Stroke-count', 'stat'];
- //总览
- public function actionStat()
- {
- //$where = ['shopId' => $this->shopId, '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,avCost,cost,virtualStock,delStatus', null, true);
- $totalItemNum = 0;
- $totalCost = 0;
- if (!empty($itemList)) {
- foreach ($itemList as $item) {
- if ($item->virtualStock == 0 && $item->delStatus == 0) {
- $stock = $item->stock ?? 0;
- $cost = $item->avCost ?? 0;
- $totalItemNum = bcadd($stock, $totalItemNum, 2);
- $currentCost = bcmul($stock, $cost, 2);
- $totalCost = bcadd($currentCost, $totalCost, 2);
- }
- }
- }
- $totalItemNum = floor($totalItemNum);
- $totalBalance = CustomClass::sum(['ownMainId'=>$this->mainId],'balance');
- $may = $totalBalance<0 ? abs($totalBalance) : 0;
- $overview = [
- ['name' => "库存数", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
- ['name' => "库存值", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
- ['name' => "应收款", "url" => '/admin/shop/debtChange', 'value' => $may, 'type' => 1],
- ['name' => "未命名", "url" => '/admin/home/member', 'value' => 0, 'type' => 4],
- ['name' => "总访客", "url" => '/admin/home/member', 'value' => 0, 'type' => 4],
- ['name' => "总订单", "url" => '/admin/home/order', 'value' => 0, 'type' => 4],
- ];
- util::success(['overview' => $overview]);
- }
- //系统收入、客服收入、欠款
- public function actionStrokeCount()
- {
- if (empty($this->mainId)) {
- util::success([
- 'systemIncome' => 0,
- 'systemCount' => 0,
- 'debtCount' => 0,
- 'debtIncome' => 0,
- 'kfWxCount' => 0,
- 'kfWxIncome' => 0,
- 'cashCount' => 0,
- 'cashIncome' => 0,
- ]);
- }
- $return = StatKdClass::eachChannelIncome($this->mainId, $this->shop);
- $incomeList = $return['incomeList'];
- $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
- $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;
- $systemIncome2 = $incomeList['system']['category']['pf']['amount'] ?? 0;
- $systemCount2 = $incomeList['system']['category']['pf']['num'] ?? 0;
- $systemCount = bcadd($systemCount1, $systemCount2);
- $systemIncome = bcadd($systemIncome1, $systemIncome2, 2);
- $debtIncome1 = $incomeList['debt']['category']['ls']['amount'] ?? 0;
- $debtCount1 = $incomeList['debt']['category']['ls']['num'] ?? 0;
- $debtIncome2 = $incomeList['debt']['category']['pf']['amount'] ?? 0;
- $debtCount2 = $incomeList['debt']['category']['pf']['num'] ?? 0;
- $debtIncome = bcadd($debtIncome1, $debtIncome2, 2);
- $debtCount = bcadd($debtCount1, $debtCount2);
- $kfWxIncome1 = $incomeList['kfWx']['category']['ls']['amount'] ?? 0;
- $kfWxCount1 = $incomeList['kfWx']['category']['ls']['num'] ?? 0;
- $kfWxIncome2 = $incomeList['kfWx']['category']['pf']['amount'] ?? 0;
- $kfWxCount2 = $incomeList['kfWx']['category']['pf']['num'] ?? 0;
- $kfWxIncome = bcadd($kfWxIncome1, $kfWxIncome2, 2);
- $kfWxCount = bcadd($kfWxCount1, $kfWxCount2);
- $cashIncome1 = $incomeList['cash']['category']['ls']['amount'] ?? 0;
- $cashCount1 = $incomeList['cash']['category']['ls']['num'] ?? 0;
- $cashIncome2 = $incomeList['cash']['category']['pf']['amount'] ?? 0;
- $cashCount2 = $incomeList['cash']['category']['pf']['num'] ?? 0;
- $cashIncome = bcadd($cashIncome1, $cashIncome2, 2);
- $cashCount = bcadd($cashCount1, $cashCount2);
- util::success([
- 'systemIncome' => $systemIncome,
- 'systemCount' => $systemCount,
- 'debtCount' => $debtCount,
- 'debtIncome' => $debtIncome,
- 'kfWxCount' => $kfWxCount,
- 'kfWxIncome' => $kfWxIncome,
- 'cashCount' => $cashCount,
- 'cashIncome' => $cashIncome,
- ]);
- }
- /**
- * 昨日各渠道收入合计(与 stat-kd/profile、kdIncome 页「合计」口径一致)
- */
- public function actionGetYesterdayIncome()
- {
- if (empty($this->mainId)) {
- util::success(['income' => 0]);
- return;
- }
- // 固定查昨日,避免与 kdIncome 选「昨天」日期不一致
- Yii::$app->request->setQueryParams(array_merge(Yii::$app->request->get(), [
- 'searchTime' => 'yesterday',
- ]));
- $contain = intval(Yii::$app->request->get('contain', 0));
- $return = StatKdClass::eachChannelIncome($this->mainId, $this->shop, $contain);
- $incomeList = $return['incomeList'] ?? [];
- $totalIncome = '0.00';
- if (!empty($incomeList)) {
- foreach ($incomeList as $item) {
- $amount = $item['amount'] ?? 0;
- $totalIncome = bcadd($totalIncome, $amount, 2);
- }
- }
- util::success(['income' => floatval($totalIncome)]);
- }
- //今日概况 ssh 20220723
- public function actionProfile()
- {
- $get = Yii::$app->request->get();
- $version = $get['version'] ?? 1;
- $notice = [];
- $shop = $this->shop;
- if (!empty($shop)) {
- //到期前25天提醒
- $deadline = $shop->deadline;
- $currentTime = time();
- $deadTime = strtotime($deadline);
- $remainingSeconds = $deadTime - $currentTime;
- $remainingDays = ceil($remainingSeconds / 86400);
-
- // 到期前7天提醒
- if ($remainingSeconds <= 604800) {
- if ($remainingSeconds <= 0) {
- $notice[] = ['title' => '系统已到期', 'action' => '续费', 'page' => '/admin/shop/renew'];
- } else {
- $notice[] = ['title' => "系统{$remainingDays}天后到期,请及时续费", 'action' => '续费', 'page' => '/admin/shop/renew'];
- }
- }
- }
- //$notice[] = ['title' => '客户多个订单开始支持一键分享', 'action' => '查看', 'page' => '/admin/book/detail?id=calc'];
- //$notice[] = ['title' => '如果你发现一个问题很重要,一直没给你处理,在小群多反应几次,用反应次数强调重要性,目前批发店多反应问题多,都在排队。', 'action' => '', 'page' => ''];
- //$notice[] = ['title' => '新功能:客户端和后台使用跑腿的流程', 'action' => '', 'page' => '/admin/book/detail?id=use_pt'];
- //$notice[] = ['title' => '新订单通知预计明天恢复', 'action' => '', 'page' => ''];
- //$notice[] = ['title' => '急事请连续打二次电话 15280215347', 'action' => '', 'page' => ''];
- $mainId = $this->mainId;
- $respond = StatSaleClass::profile($mainId);
- $incomeList = $respond['income'] ?? [];
- $todaySale = 0;
- if (!empty($incomeList)) {
- //这里有二个地方同时要修改,请搜索关键词:index_show_income
- foreach ($incomeList as $item) {
- if (isset($item['id']) && $item['id'] == 'allot') {
- continue;
- }
- $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/shop3.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/hcgl.png", "url" => "/admin/item/simple"],
- ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock"],
- ["name" => "采购", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
- ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
- ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
- ["name" => "计算器", "img" => "ghs/home/kcyjs.png", "url" => "/admin/tools/calculator"],
- ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
- ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => 0],
- ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
- ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
- ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
- ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
- ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
- ["name" => "损耗", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
- ];
- $menuV2 = [
- ["name" => "商城码", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
- ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list2"],
- ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list2"],
- ["name" => "配送片区", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/orderListByDist"],
- ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock2"],
- ["name" => "采购", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
- ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
- ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
- ["name" => "计算器", "img" => "ghs/home/kcyjs.png", "url" => "/admin/tools/calculator"],
- ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
- ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => 0],
- ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
- ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
- ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
- ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
- ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
- ["name" => "报损", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
- ["name" => "拆散", "img" => "ghs/home/kcyjs.png", "url" => "/admin/part/list"],
- ["name" => "收款流水", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/scanPay"],
- ["name" => "收款码", "img" => "ghs/home/shop.png", "url" => "/admin/cg/code"]
- ];
- $menuV3 = [
- ["name" => "商城码", "img" => "ghs/home/shop3.png", "url" => "/admin/home/mall"],
- ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list2"],
- ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list2"],
- ["name" => "配送片区", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/orderListByDist"],
- ["name" => "改库存", "img" => "ghs/home/kcyjs.png", "url" => "/admin/changePrice/changeStock2"],
- ["name" => "采购", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
- ["name" => "采购记录", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
- ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
- ["name" => "计算器", "img" => "ghs/home/kcyjs.png", "url" => "/admin/tools/calculator"],
- ["name" => "买花", "img" => "ghs/home/icon_buy_item.png", "url" => "buyGhs"],
- ["name" => "买花记录", "img" => "ghs/home/icon_buy_record.png", "url" => "buyRecord", 'remindNum' => 0],
- ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
- ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
- ["name" => "员工", "img" => "ghs/home/yggl.png", "url" => "/admin/staff/list"],
- ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/warning"],
- ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
- ["name" => "报损", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
- ["name" => "拆散", "img" => "ghs/home/kcyjs.png", "url" => "/admin/part/list"],
- ["name" => "收款流水", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/scanPay"],
- ["name" => "收款码", "img" => "ghs/home/shop.png", "url" => "/admin/cg/code"]
- ];
- $menuIconMap = [
- '商城码' => 'mall_code',
- '改价' => 'modify_price',
- '花材' => 'item',
- '配送片区' => 'send_dist',
- '改库存' => 'modify_stock',
- '采购' => 'purchase',
- '采购记录' => 'purchase_record',
- '调拨入库' => 'in_stock',
- '计算器' => 'calculator',
- '买花' => 'stock_in',
- '买花记录' => 'stock_in_record',
- '调拨出库' => 'out_stock',
- '支出' => 'expend',
- '员工' => 'staff',
- '库存预警' => 'stock_warning',
- '盘点' => 'check',
- '报损' => 'breakage',
- '损耗' => 'breakage',
- '拆散' => 'break_up',
- '收款流水' => 'gather_record',
- '收款码' => 'gather_code',
- '商城' => 'mall_code',
- '花材(简)' => 'item',
- ];
- if ($version == 2) {
- $menu = $menuV2;
- } elseif ($version == 3) {
- $menu = [];
- foreach ($menuV2 as $item) {
- $menuItem = $item;
- unset($menuItem['img']);
- $menuItem['icon'] = $menuIconMap[$item['name']] ?? 'item';
- $menu[] = $menuItem;
- }
- }elseif($version == 4) {
- $menu = [];
- foreach ($menuV3 as $item) {
- $menuItem = $item;
- unset($menuItem['img']);
- $menuItem['icon'] = $menuIconMap[$item['name']] ?? 'item';
- $menu[] = $menuItem;
- }
- }
- //查看财务的权限
- $lookMoney = ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
- $warning = '';
- $warningUrl = '';
- //$warning = '本页右上方,暂不显示昨天收入金额';
- //$warningUrl = '/admin/notice/warning';
- util::success([
- 'asset' => $this->main,
- 'notice' => $notice,
- 'warning' => $warning,
- 'warningUrl' => $warningUrl,
- 'todayData' => [
- 'income' => $todaySale,
- 'order' => $orderNum,
- 'expend' => $todayOut,
- 'visitCustom' => $visitCustom,
- 'wastage' => $wastage
- ],
- 'menu' => $menu,
- 'lookMoney' => $lookMoney,
- ]);
- }
- //常用数据初始化
- public function actionInit()
- {
- $dict = dict::get();
- $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
- util::success(['dict' => $dict, 'shop' => $shop]);
- }
- }
|