ConsoleController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\stat\classes\StatSaleClass;
  4. use biz\stat\classes\StatStockOutClass;
  5. use biz\stat\services\StatOutService;
  6. use bizHd\stat\classes\StatViewClass;
  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 Yii;
  13. use common\components\util;
  14. class ConsoleController extends BaseController
  15. {
  16. public $guestAccess = ['init', 'profile'];
  17. //概况 ssh 2019.12.19
  18. public function actionProfile()
  19. {
  20. $notice = [
  21. //['title' => '您的试用期还有7天,点击免费续期1年 ', 'action' => '查看', 'page' => '/admin/recharge/renew'],
  22. ];
  23. //今天客户与粉丝数
  24. $userData = StatUserService::getTodayNum($this->shopId);
  25. $customNum = isset($userData['riseUserNum']) ? $userData['riseUserNum'] : 0;
  26. //今天总收入-出库收入= 营业收入
  27. $sale = StatSaleClass::getByCondition(['shopId' => $this->shopId, 'time' => date('Ymd')]);
  28. $todaySale = $sale['amount'] ?? 0;
  29. //2021.4.14 linqh 今日支出
  30. $outData = StatOutService::getTodayNum($this->shopId);
  31. $todayOut = $outData['amount'] ?? '0.00';
  32. //今天开单数
  33. $statOrder = \bizHd\stat\classes\StatOrderClass::getByCondition(['shopId' => $this->shopId, 'time' => date('Ymd')]);
  34. $orderNum = $statOrder['riseNum'] ?? 0;
  35. $view = StatViewClass::getByCondition(['shopId' => $this->shopId, 'time' => date('Ymd')]);
  36. $viewNum = $view['riseNum'] ?? 0;
  37. $todayData = ['income' => $todaySale, 'order' => $orderNum, 'custom' => $customNum, 'expend' => $todayOut, 'view' => $viewNum];
  38. $incomeStat = [];
  39. if (httpUtil::isMiniProgram() == false) {
  40. //当月的收入
  41. $currentMonthIncome = StatIncomeMonthService::getCurrentMonthIncome($this->shopId);
  42. //上个月收入
  43. $previousMonthIncome = StatIncomeMonthService::getPreviousMonthIncome($this->shopId);
  44. //最近7天收入变化趋势
  45. $latestIncome = StatIncomeService::getLatestSevenDay($this->shopId);
  46. $incomeStat = [
  47. 'month' => $currentMonthIncome,
  48. 'week' => 999,
  49. 'previousMonth' => $previousMonthIncome,
  50. 'list' => $latestIncome,
  51. ];
  52. }
  53. $asset = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  54. util::success([
  55. 'asset' => $asset,
  56. 'notice' => $notice,
  57. 'todayData' => $todayData,
  58. 'incomeStat' => $incomeStat,
  59. ]);
  60. }
  61. //常用初始化
  62. public function actionInit()
  63. {
  64. $dict = dict::get();
  65. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  66. util::success(['dict' => $dict, 'shop' => $shop]);
  67. }
  68. }