ConsoleController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. $systemCount = $ghsOnlineCount + $hdActualCount;
  56. $systemIncome = bcadd($ghsActIncome, $hdActualIncome, 2);
  57. $systemIncome = floatval($systemIncome);
  58. //现金收入 23笔 5980元
  59. //xhGhsOrder actPrice 字段,条件:debtPrice=0 and status in (2,3,4) and payWay=4
  60. //xhOrder actPrice 字段,条件 status in (2,3,4) and payWay=4
  61. $where = ['shopId' => $this->shopId, 'debt' => 0, 'debtPrice' => '0.00'];
  62. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  63. $where['payWay'] = 4;
  64. $where['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  65. $ghsCashCount = OrderClass::getCount($where); // 批发今日现金总笔数
  66. $ghsCashIncome = OrderClass::sum($where, 'actPrice'); // 批发今日现金金额总数
  67. Yii::info('批发今日现金总笔数:' . $ghsCashCount . ', 批发今日现金金额总数:' . $ghsCashIncome);
  68. unset($where['debt']);
  69. unset($where['debtPrice']);
  70. $hdCashCount = HdOrderClass::getCount($where); // 花店今日现金总笔数
  71. $hdCashIncome = HdOrderClass::sum($where, 'actPrice'); // 花店今日现金金额总数
  72. Yii::info('花店今日现金总笔数:' . $hdCashCount . ', 花店今日现金金额总数:' . $hdCashIncome);
  73. $cashCount = $ghsCashCount + $hdCashCount;
  74. $cashIncome = bcadd($ghsCashIncome, $hdCashIncome, 2);
  75. $cashIncome = floatval($cashIncome);
  76. //批发欠款 39笔 13980元
  77. $where = ['shopId' => $this->shopId, 'debt' => 1];
  78. $where['addTime'] = ['between', [$todayStartTime, $todayEndTime]];
  79. $debtCount = OrderClass::getCount($where); // 批发今日欠款总笔数
  80. $debtAmount = OrderClass::sum($where, 'remainDebtPrice'); // 批发今日总欠款
  81. $debtAmount = floatval($debtAmount);
  82. $actTotalCount = bcadd($cashCount, $ghsCashCount);
  83. $actTotalIncome = bcadd($cashIncome, $ghsCashIncome, 2);
  84. $actTotalIncome = floatval($actTotalIncome);
  85. util::success([
  86. 'systemCount' => $systemCount,
  87. 'systemIncome' => $systemIncome,
  88. 'cashCount' => $cashCount,
  89. 'cashIncome' => $cashIncome,
  90. 'debtCount' => $debtCount,
  91. 'debtAmount' => $debtAmount,
  92. 'actTotalCount' => $actTotalCount,
  93. 'actTotalIncome' => $actTotalIncome,
  94. ]);
  95. }
  96. //概况 ssh 2019.12.19
  97. public function actionProfile()
  98. {
  99. $get = Yii::$app->request->get();
  100. $isMini = $get['isMini'] ?? 0;
  101. $notice = [];
  102. $admin = $this->admin;
  103. if ($isMini == 1 && !empty($admin)) {
  104. $miniOpenId = $admin['ghsMiniOpenId'] ?? '';
  105. if (empty($miniOpenId)) {
  106. $notice = [['title' => '绑定微信,下次自动登录后台', 'action' => '去绑定', 'page' => '/admin/staff/miniAutoLogin']];
  107. }
  108. }
  109. //今天销售
  110. $sale = StatSaleClass::getByCondition(['mainId' => $this->mainId, 'time' => date('Ymd')]);
  111. $todaySale = $sale['amount'] ?? 0;
  112. $orderNum = $sale['num'] ?? 0;
  113. //2021.4.14 lqh 今日支出
  114. $outData = StatOutService::getTodayNum($this->mainId);
  115. $todayOut = $outData['amount'] ?? '0.00';
  116. //访客数
  117. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  118. $todayData = ['income' => $todaySale, 'order' => $orderNum, 'expend' => $todayOut, 'visitCustom' => $visitCustom];
  119. $incomeStat = [];
  120. $menu = [
  121. ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
  122. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  123. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  124. ["name" => "供应商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/supplier"],
  125. ["name" => "采购单", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  126. ["name" => "报损单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  127. ["name" => "预订单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/statBook"],
  128. ["name" => "新增出库", "img" => "ghs/home/dbck.png", "url" => "/admin/shop/selectShop"],
  129. ["name" => "出库记录", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  130. ["name" => "入库记录", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  131. ["name" => "销售结账单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/customList"],
  132. ["name" => "采购结账单", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/list"],
  133. ];
  134. util::success(['asset' => $this->main, 'notice' => $notice, 'todayData' => $todayData, 'incomeStat' => $incomeStat, 'menu' => $menu,]);
  135. }
  136. //常用初始化
  137. public function actionInit()
  138. {
  139. $dict = dict::get();
  140. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  141. util::success(['dict' => $dict, 'shop' => $shop]);
  142. }
  143. }