ConsoleController.php 9.1 KB

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