ConsoleController.php 8.4 KB

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