ConsoleController.php 7.8 KB

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