ConsoleController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\stat\classes\StatSaleClass;
  4. use biz\stat\services\StatOutService;
  5. use bizGhs\clear\classes\ClearClass;
  6. use bizGhs\item\classes\ItemClass;
  7. use bizGhs\order\classes\OrderClass;
  8. use bizHd\order\classes\OrderClass as HdOrderClass;
  9. use bizHd\stat\classes\StatVisitClass;
  10. use common\components\dict;
  11. use common\components\util;
  12. use Yii;
  13. class ConsoleController extends BaseController
  14. {
  15. public $guestAccess = ['init', 'profile'];
  16. //总览
  17. public function actionStat()
  18. {
  19. $where = ['shopId' => $this->shopId, 'debt' => 1]; // 重新赋值
  20. $totalDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
  21. $totalDebt = $totalDebt === null ? 0 : $totalDebt;
  22. $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost', null, true);
  23. $totalItemNum = 0;
  24. $totalCost = 0;
  25. if (!empty($itemList)) {
  26. foreach ($itemList as $item) {
  27. $stock = $item->stock ?? 0;
  28. $cost = $item->cost ?? 0;
  29. $totalItemNum = bcadd($stock, $totalItemNum, 2);
  30. $currentCost = bcmul($stock, $cost, 2);
  31. $totalCost = bcadd($currentCost, $totalCost, 2);
  32. }
  33. }
  34. $shop = $this->shop;
  35. $totalCustom = $shop->totalUser ?? 0;
  36. $totalVisit = $shop->totalVisit ?? 0;
  37. $totalOrder = $shop->finishOrder ?? 0;
  38. $overview = [
  39. ['name' => "库存(扎)", "url" => '/admin/home/member', 'value' => $totalItemNum, 'type' => 4],
  40. ['name' => "库存(元)", "url" => '/admin/home/member', 'value' => $totalCost, 'type' => 4],
  41. ['name' => "总欠款", "url" => '/admin/home/member', 'value' => $totalDebt, 'type' => 4],
  42. ['name' => "总客户", "url" => '/admin/home/member', 'value' => $totalCustom, 'type' => 4],
  43. ['name' => "总访客", "url" => '/admin/home/member', 'value' => $totalVisit, 'type' => 4],
  44. ['name' => "总订单", "url" => '/admin/home/member', 'value' => $totalOrder, 'type' => 4],
  45. ];
  46. util::success(['overview' => $overview]);
  47. }
  48. //今日笔数和总金额
  49. public function actionStrokeCount()
  50. {
  51. util::success([
  52. 'systemIncome' => 0,
  53. 'systemCount' => 0,
  54. 'debtCount' => 0,
  55. 'debtIncome' => 0,
  56. 'kfWxCount' => 0,
  57. 'kfWxIncome' => 0,
  58. ]);
  59. }
  60. //概况 ssh 2019.12.19
  61. public function actionProfile()
  62. {
  63. $get = Yii::$app->request->get();
  64. $isMini = $get['isMini'] ?? 0;
  65. $notice = [];
  66. $admin = $this->admin;
  67. if ($isMini == 1 && !empty($admin)) {
  68. $miniOpenId = $admin['ghsMiniOpenId'] ?? '';
  69. if (empty($miniOpenId)) {
  70. $notice = [['title' => '绑定微信,下次自动登录后台', 'action' => '去绑定', 'page' => '/admin/staff/miniAutoLogin']];
  71. }
  72. }
  73. //今天销售
  74. $sale = StatSaleClass::getByCondition(['mainId' => $this->mainId, 'time' => date('Ymd')]);
  75. $todaySale = $sale['amount'] ?? 0;
  76. $orderNum = $sale['num'] ?? 0;
  77. //2021.4.14 lqh 今日支出
  78. $outData = StatOutService::getTodayNum($this->mainId);
  79. $todayOut = $outData['amount'] ?? '0.00';
  80. //访客数
  81. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  82. $todayData = ['income' => $todaySale, 'order' => $orderNum, 'expend' => $todayOut, 'visitCustom' => $visitCustom];
  83. $incomeStat = [];
  84. $menu = [
  85. ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
  86. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  87. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  88. ["name" => "供应商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  89. ["name" => "采购单", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  90. ["name" => "报损单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  91. ["name" => "预订单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/statBook"],
  92. ["name" => "新增出库", "img" => "ghs/home/dbck.png", "url" => "/admin/shop/selectShop"],
  93. ["name" => "出库记录", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  94. ["name" => "入库记录", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  95. ["name" => "销售结账单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/customList"],
  96. ["name" => "支出登记", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/addExpend"],
  97. ];
  98. util::success(['asset' => $this->main, 'notice' => $notice, 'todayData' => $todayData, 'incomeStat' => $incomeStat, 'menu' => $menu,]);
  99. }
  100. //常用初始化
  101. public function actionInit()
  102. {
  103. $dict = dict::get();
  104. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  105. util::success(['dict' => $dict, 'shop' => $shop]);
  106. }
  107. }