ConsoleController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\stat\classes\StatSaleClass;
  4. use biz\stat\services\StatOutService;
  5. use bizGhs\order\classes\OrderClass;
  6. use bizHd\order\classes\OrderClass as HdOrderClass;
  7. use bizHd\stat\classes\StatVisitClass;
  8. use common\components\dict;
  9. use common\components\util;
  10. use Yii;
  11. class ConsoleController extends BaseController
  12. {
  13. public $guestAccess = ['init', 'profile'];
  14. //今日实收统计和欠款统计等
  15. public function actionStat()
  16. {
  17. $todayDate = date('Y-m-d');
  18. $todayStartTime = $todayDate . ' 00:00:00';
  19. $todayEndTime = $todayDate . ' 23:59:59';
  20. $where = ['shopId' => $this->shopId, 'debt' => 0, 'debtPrice' => '0.00'];
  21. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  22. $where['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  23. $todayActIncome = OrderClass::sum($where, 'actPrice'); // 今日实收
  24. $todayActIncome = $todayActIncome === null ? 0 : $todayActIncome;
  25. $where = ['shopId' => $this->shopId, 'debt' => 1]; // 查询条件重新赋值
  26. $where['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  27. $todayDebt = OrderClass::sum($where, 'remainDebtPrice'); // 今日欠款
  28. $todayDebt = $todayDebt === null ? 0 : $todayDebt;
  29. $where = ['shopId' => $this->shopId, 'debt' => 1]; // 重新赋值
  30. $totalDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
  31. $totalDebt = $totalDebt === null ? 0 : $totalDebt;
  32. util::success(['todayActIncome' => $todayActIncome, 'todayDebt' => $todayDebt, 'totalDebt' => $totalDebt]);
  33. }
  34. //今日笔数和总金额
  35. public function actionStrokeCount()
  36. {
  37. $todayDate = date('Y-m-d');
  38. $todayStartTime = $todayDate . ' 00:00:00';
  39. $todayEndTime = $todayDate . ' 23:59:59';
  40. //线上收入 180笔 12000元
  41. //xhGhsOrder actPrice 字段,条件:debtPrice=0 and status in (2,3,4) and payWay in (0,1)
  42. //xhOrder actPrice 字段,条件 status in (2,3,4) and payWay in (0,1)
  43. $where = ['shopId' => $this->shopId, 'debt' => 0, 'debtPrice' => '0.00'];
  44. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  45. $where['payWay'] = ['in', [0, 1]];
  46. $where['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  47. $ghsOnlineCount = OrderClass::getCount($where); // 批发今日收入总笔数
  48. $ghsActIncome = OrderClass::sum($where, 'actPrice'); // 批发今日实收总数
  49. Yii::info('批发今日收入总笔数:' . $ghsOnlineCount . ', 批发今日实收总数:' . $ghsActIncome);
  50. unset($where['debt']);
  51. unset($where['debtPrice']);
  52. $hdActualCount = HdOrderClass::getCount($where); // 花店今日收入总笔数
  53. $hdActualIncome = HdOrderClass::sum($where, 'actPrice'); // 花店今日收入金额总数
  54. Yii::info('花店今日收入总笔数:' . $hdActualCount . ', 花店今日收入金额总数:' . $hdActualIncome);
  55. $actualCount = $ghsOnlineCount + $hdActualCount;
  56. $actualIncome = bcadd($ghsActIncome, $hdActualIncome, 2);
  57. //现金收入 23笔 5980元
  58. //xhGhsOrder actPrice 字段,条件:debtPrice=0 and status in (2,3,4) and payWay=4
  59. //xhOrder actPrice 字段,条件 status in (2,3,4) and payWay=4
  60. $where = ['shopId' => $this->shopId, 'debt' => 0, 'debtPrice' => '0.00'];
  61. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  62. $where['payWay'] = 4;
  63. $where['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  64. $ghsCashCount = OrderClass::getCount($where); // 批发今日现金总笔数
  65. $ghsCashIncome = OrderClass::sum($where, 'actPrice'); // 批发今日现金金额总数
  66. Yii::info('批发今日现金总笔数:' . $ghsCashCount . ', 批发今日现金金额总数:' . $ghsCashIncome);
  67. unset($where['debt']);
  68. unset($where['debtPrice']);
  69. $hdCashCount = HdOrderClass::getCount($where); // 花店今日现金总笔数
  70. $hdCashIncome = HdOrderClass::sum($where, 'actPrice'); // 花店今日现金金额总数
  71. Yii::info('花店今日现金总笔数:' . $hdCashCount . ', 花店今日现金金额总数:' . $hdCashIncome);
  72. $cashCount = $ghsCashCount + $hdCashCount;
  73. $cashIncome = bcadd($ghsCashIncome, $hdCashIncome, 2);
  74. //批发欠款 39笔 13980元
  75. $where = ['shopId' => $this->shopId, 'debt' => 1];
  76. $where['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  77. $ghsDebtCount = OrderClass::getCount($where); // 批发今日欠款总笔数
  78. $ghsAllDebt = OrderClass::sum($where, 'remainDebtPrice'); // 批发今日总欠款
  79. $totalCount = bcadd($cashCount, $ghsDebtCount);
  80. $totalIncome = bcadd($cashIncome, $ghsAllDebt, 2);
  81. util::success([
  82. 'actualCount' => $actualCount,
  83. 'actualIncome' => $actualIncome,
  84. 'cashCount' => $cashCount,
  85. 'cashIncome' => $cashIncome,
  86. 'debtCount' => $ghsDebtCount,
  87. 'allDebt' => $ghsAllDebt,
  88. 'totalCount' => $totalCount,
  89. 'totalIncome' => $totalIncome,
  90. ]);
  91. }
  92. //概况 ssh 2019.12.19
  93. public function actionProfile()
  94. {
  95. $get = Yii::$app->request->get();
  96. $isMini = $get['isMini'] ?? 0;
  97. $notice = [];
  98. $admin = $this->admin;
  99. if ($isMini == 1 && !empty($admin)) {
  100. $miniOpenId = $admin['ghsMiniOpenId'] ?? '';
  101. if (empty($miniOpenId)) {
  102. $notice = [['title' => '绑定微信,下次自动登录后台', 'action' => '去绑定', 'page' => '/admin/staff/miniAutoLogin']];
  103. }
  104. }
  105. //今天销售
  106. $sale = StatSaleClass::getByCondition(['mainId' => $this->mainId, 'time' => date('Ymd')]);
  107. $todaySale = $sale['amount'] ?? 0;
  108. $orderNum = $sale['num'] ?? 0;
  109. //2021.4.14 lqh 今日支出
  110. $outData = StatOutService::getTodayNum($this->mainId);
  111. $todayOut = $outData['amount'] ?? '0.00';
  112. //访客数
  113. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  114. $todayData = ['income' => $todaySale, 'order' => $orderNum, 'expend' => $todayOut, 'visitCustom' => $visitCustom];
  115. $incomeStat = [];
  116. $menu = [
  117. ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
  118. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  119. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  120. ["name" => "供应商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  121. ["name" => "采购单", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  122. ["name" => "报损单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  123. ["name" => "预订单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/statBook"],
  124. ["name" => "新增出库", "img" => "ghs/home/dbck.png", "url" => "/admin/shop/selectShop"],
  125. ["name" => "出库记录", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  126. ["name" => "入库记录", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  127. ["name" => "销售结账单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/customList"],
  128. ["name" => "采购结账单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/list"],
  129. ];
  130. util::success(['asset' => $this->main, 'notice' => $notice, 'todayData' => $todayData, 'incomeStat' => $incomeStat, 'menu' => $menu,]);
  131. }
  132. //常用初始化
  133. public function actionInit()
  134. {
  135. $dict = dict::get();
  136. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  137. util::success(['dict' => $dict, 'shop' => $shop]);
  138. }
  139. }