ConsoleController.php 6.1 KB

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