ConsoleController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\stat\classes\StatSaleClass;
  4. use biz\stat\services\StatOutService;
  5. use bizHd\stat\classes\StatViewClass;
  6. use bizHd\stat\classes\StatVisitClass;
  7. use bizHd\stat\services\StatIncomeMonthService;
  8. use bizHd\stat\services\StatIncomeService;
  9. use bizHd\stat\services\StatUserService;
  10. use common\components\dict;
  11. use common\components\httpUtil;
  12. use common\components\util;
  13. use Yii;
  14. class ConsoleController extends BaseController
  15. {
  16. public $guestAccess = ['init', 'profile'];
  17. //概况 ssh 2019.12.19
  18. public function actionProfile()
  19. {
  20. $get = Yii::$app->request->get();
  21. $isMini = $get['isMini'] ?? 0;
  22. $notice = [];
  23. $admin = $this->admin;
  24. if ($isMini == 1 && !empty($admin)) {
  25. $miniOpenId = $admin['miniOpenId'] ?? '';
  26. if (empty($miniOpenId)) {
  27. $notice = [['title' => '绑定微信,下次自动登录后台', 'action' => '去绑定', 'page' => '/admin/staff/miniAutoLogin']];
  28. }
  29. }
  30. //今天客户与粉丝数
  31. $userData = StatUserService::getTodayNum($this->shopId);
  32. $customNum = isset($userData['riseUserNum']) ? $userData['riseUserNum'] : 0;
  33. //今天销售
  34. $sale = StatSaleClass::getByCondition(['shopId' => $this->shopId, 'time' => date('Ymd')]);
  35. $todaySale = $sale['amount'] ?? 0;
  36. $orderNum = $sale['num'] ?? 0;
  37. //2021.4.14 linqh 今日支出
  38. $outData = StatOutService::getTodayNum($this->shopId);
  39. $todayOut = $outData['amount'] ?? '0.00';
  40. //访客数
  41. $visitCustom = StatVisitClass::getVisitNum($this->shop);
  42. $todayData = ['income' => $todaySale, 'order' => $orderNum, 'custom' => $customNum, 'expend' => $todayOut, 'visitCustom' => $visitCustom];
  43. $incomeStat = [];
  44. if (httpUtil::isMiniProgram() == false) {
  45. //当月的收入
  46. $currentMonthIncome = StatIncomeMonthService::getCurrentMonthIncome($this->shopId);
  47. //上个月收入
  48. $previousMonthIncome = StatIncomeMonthService::getPreviousMonthIncome($this->shopId);
  49. //最近7天收入变化趋势
  50. $latestIncome = StatIncomeService::getLatestSevenDay($this->shopId);
  51. $incomeStat = [
  52. 'month' => $currentMonthIncome,
  53. 'week' => 999,
  54. 'previousMonth' => $previousMonthIncome,
  55. 'list' => $latestIncome,
  56. ];
  57. }
  58. $shopInfo = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  59. $menu = [
  60. ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
  61. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  62. ["name" => "供应商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  63. ["name" => "报损单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  64. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/pagesStorehouse/stockWarn/manage"],
  65. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  66. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  67. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"]
  68. ];
  69. $agent = $shopInfo['agentLevel'] ?? 0;
  70. if ($agent == 1) {
  71. //代理商显示邀请开店按钮
  72. $menu = [
  73. ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
  74. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  75. ["name" => "供应商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  76. ["name" => "报损单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  77. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/pagesStorehouse/stockWarn/manage"],
  78. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  79. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  80. ["name" => "邀请开店", "img" => "ghs/home/yqyl.png", "url" => "/pagesInvite/list"]
  81. ];
  82. }
  83. util::success([
  84. 'asset' => $shopInfo,
  85. 'notice' => $notice,
  86. 'todayData' => $todayData,
  87. 'incomeStat' => $incomeStat,
  88. 'menu' => $menu,
  89. ]);
  90. }
  91. //常用初始化
  92. public function actionInit()
  93. {
  94. $dict = dict::get();
  95. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  96. util::success(['dict' => $dict, 'shop' => $shop]);
  97. }
  98. }