ConsoleController.php 6.0 KB

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