ConsoleController.php 3.0 KB

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