ConsoleController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\stat\services\StatOutService;
  4. use bizGhs\clear\classes\ClearClass;
  5. use bizGhs\item\classes\ItemClass;
  6. use bizGhs\order\classes\OrderClass;
  7. use bizGhs\stat\classes\StatKdClass;
  8. use bizGhs\stat\classes\StatSaleClass;
  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. $incomeList = StatKdClass::eachChannelIncome($this->mainId, $this->shop);
  52. $systemIncome = $incomeList['system']['amount'] ?? 0;
  53. $systemCount = $incomeList['system']['num'] ?? 0;
  54. $debtIncome = $incomeList['debt']['amount'] ?? 0;
  55. $debtCount = $incomeList['debt']['num'] ?? 0;
  56. $kfWxIncome = $incomeList['kfWx']['amount'] ?? 0;
  57. $kfWxCount = $incomeList['kfWx']['num'] ?? 0;
  58. util::success([
  59. 'systemIncome' => $systemIncome,
  60. 'systemCount' => $systemCount,
  61. 'debtCount' => $debtCount,
  62. 'debtIncome' => $debtIncome,
  63. 'kfWxCount' => $kfWxCount,
  64. 'kfWxIncome' => $kfWxIncome,
  65. ]);
  66. }
  67. //今日概况 ssh 20220723
  68. public function actionProfile()
  69. {
  70. $get = Yii::$app->request->get();
  71. $isMini = $get['isMini'] ?? 0;
  72. $notice = [];
  73. $admin = $this->admin;
  74. if ($isMini == 1 && !empty($admin)) {
  75. $miniOpenId = $admin['ghsMiniOpenId'] ?? '';
  76. if (empty($miniOpenId)) {
  77. $notice = [['title' => '绑定微信,下次自动登录后台', 'action' => '去绑定', 'page' => '/admin/staff/miniAutoLogin']];
  78. }
  79. }
  80. $mainId = $this->mainId;
  81. $respond = StatSaleClass::profile($mainId);
  82. $incomeList = $respond['income'] ?? [];
  83. $todaySale = 0;
  84. if (!empty($incomeList)) {
  85. foreach ($incomeList as $item) {
  86. $todaySale = bcadd($todaySale, $item['amount'], 2);
  87. }
  88. }
  89. $expendList = $respond['expend'] ?? [];
  90. $todayOut = 0;
  91. if (!empty($expendList)) {
  92. foreach ($expendList as $item) {
  93. $todayOut = bcadd($todayOut, $item['amount'], 2);
  94. }
  95. }
  96. $orderNum = $respond['totalOrderNum'] ?? 0;
  97. //访客数
  98. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  99. $menu = [
  100. ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
  101. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  102. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  103. ["name" => "供应商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  104. ["name" => "采购单", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  105. ["name" => "报损单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  106. ["name" => "预订单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/statBook"],
  107. ["name" => "新增出库", "img" => "ghs/home/dbck.png", "url" => "/admin/shop/selectShop"],
  108. ["name" => "出库记录", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  109. ["name" => "入库记录", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  110. ["name" => "销售结账单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/customList"],
  111. ["name" => "支出登记", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/addExpend"],
  112. ];
  113. util::success(['asset' => $this->main, 'notice' => $notice,
  114. 'todayData' => ['income' => $todaySale, 'order' => $orderNum, 'expend' => $todayOut, 'visitCustom' => $visitCustom], 'menu' => $menu,]);
  115. }
  116. //常用初始化
  117. public function actionInit()
  118. {
  119. $dict = dict::get();
  120. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  121. util::success(['dict' => $dict, 'shop' => $shop]);
  122. }
  123. }