ConsoleController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\stat\classes\StatVisitClass;
  4. use bizGhs\item\classes\ItemClass;
  5. use common\components\dict;
  6. use common\components\util;
  7. use bizGhs\order\classes\OrderClass;
  8. use Yii;
  9. class ConsoleController extends BaseController
  10. {
  11. public $guestAccess = ['init', 'profile'];
  12. //总览
  13. public function actionStat()
  14. {
  15. $where = ['mainId' => $this->mainId, 'debt' => 1]; // 重新赋值
  16. $pfDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
  17. $pfDebt = $pfDebt === null ? 0 : $pfDebt;
  18. $lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
  19. $lsDebt = $lsDebt === null ? 0 : $lsDebt;
  20. $totalDebt = bcadd($pfDebt, $lsDebt, 2);
  21. $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost', null, true);
  22. $totalItemNum = 0;
  23. $totalCost = 0;
  24. if (!empty($itemList)) {
  25. foreach ($itemList as $item) {
  26. $stock = $item->stock ?? 0;
  27. $cost = $item->cost ?? 0;
  28. $totalItemNum = bcadd($stock, $totalItemNum, 2);
  29. $currentCost = bcmul($stock, $cost, 2);
  30. $totalCost = bcadd($currentCost, $totalCost, 2);
  31. }
  32. }
  33. $totalItemNum = floor($totalItemNum);
  34. $main = $this->main;
  35. $totalCustom = $main->totalUser ?? 0;
  36. $totalVisit = $main->totalVisit ?? 0;
  37. $totalOrder = $main->finishOrder ?? 0;
  38. $overview = [
  39. ['name' => "库存(扎)", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
  40. ['name' => "库存(元)", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
  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/order', 'value' => $totalOrder, 'type' => 4],
  45. ];
  46. util::success(['overview' => $overview]);
  47. }
  48. //概况 ssh 2019.12.19
  49. public function actionProfile()
  50. {
  51. $get = Yii::$app->request->get();
  52. $isMini = $get['isMini'] ?? 0;
  53. $notice = [];
  54. //引导授权
  55. $admin = $this->admin;
  56. if ($isMini == 1 && !empty($admin)) {
  57. $miniOpenId = $admin['miniOpenId'] ?? '';
  58. if (empty($miniOpenId)) {
  59. $notice = [['title' => '绑定微信,下次自动登录后台', 'action' => '去绑定', 'page' => '/admin/staff/miniAutoLogin']];
  60. }
  61. }
  62. $mainId = $this->mainId;
  63. $respond = \bizGhs\stat\classes\StatSaleClass::profile($mainId);
  64. $incomeList = $respond['income'] ?? [];
  65. $todaySale = 0;
  66. if (!empty($incomeList)) {
  67. foreach ($incomeList as $item) {
  68. $todaySale = bcadd($todaySale, $item['amount'], 2);
  69. }
  70. }
  71. $expendList = $respond['expend'] ?? [];
  72. $todayOut = 0;
  73. if (!empty($expendList)) {
  74. foreach ($expendList as $item) {
  75. $todayOut = bcadd($todayOut, $item['amount'], 2);
  76. }
  77. }
  78. $orderNum = $respond['totalOrderNum'] ?? 0;
  79. //访客数
  80. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  81. util::success([
  82. 'asset' => $this->main,
  83. 'notice' => $notice,
  84. 'todayData' => ['visit' => $visitCustom, 'income' => $todaySale, 'order' => $orderNum, 'out' => $todayOut],
  85. 'incomeStat' => [],
  86. ]);
  87. }
  88. //常用初始化
  89. public function actionInit()
  90. {
  91. $dict = dict::get();
  92. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  93. util::success(['dict' => $dict, 'shop' => $shop]);
  94. }
  95. }