ConsoleController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\item\classes\ItemClass;
  4. use bizGhs\order\classes\OrderClass;
  5. use bizGhs\order\classes\StockWastageOrderClass;
  6. use bizGhs\stat\classes\StatKdClass;
  7. use bizGhs\stat\classes\StatSaleClass;
  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', 'Stroke-count', 'stat'];
  15. //总览
  16. public function actionStat()
  17. {
  18. $where = ['shopId' => $this->shopId, 'debt' => 1]; // 重新赋值
  19. $pfDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
  20. $pfDebt = $pfDebt === null ? 0 : $pfDebt;
  21. $lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
  22. $lsDebt = $lsDebt === null ? 0 : $lsDebt;
  23. $totalDebt = bcadd($pfDebt, $lsDebt, 2);
  24. $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost', null, true);
  25. $totalItemNum = 0;
  26. $totalCost = 0;
  27. if (!empty($itemList)) {
  28. foreach ($itemList as $item) {
  29. $stock = $item->stock ?? 0;
  30. $cost = $item->cost ?? 0;
  31. $totalItemNum = bcadd($stock, $totalItemNum, 2);
  32. $currentCost = bcmul($stock, $cost, 2);
  33. $totalCost = bcadd($currentCost, $totalCost, 2);
  34. }
  35. }
  36. $totalItemNum = floor($totalItemNum);
  37. $main = $this->main;
  38. $totalCustom = $main->totalUser ?? 0;
  39. $totalVisit = $main->totalVisit ?? 0;
  40. $totalOrder = $main->finishOrder ?? 0;
  41. $overview = [
  42. ['name' => "库存(扎)", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
  43. ['name' => "库存(元)", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
  44. ['name' => "总欠款", "url" => '/admin/shop/debtChange', 'value' => $totalDebt, 'type' => 1],
  45. ['name' => "总客户", "url" => '/admin/home/member', 'value' => $totalCustom, 'type' => 4],
  46. ['name' => "总访客", "url" => '/admin/home/member', 'value' => $totalVisit, 'type' => 4],
  47. ['name' => "总订单", "url" => '/admin/home/order', 'value' => $totalOrder, 'type' => 4],
  48. ];
  49. util::success(['overview' => $overview]);
  50. }
  51. //系统收入、客服收入、欠款
  52. public function actionStrokeCount()
  53. {
  54. if (empty($this->mainId)) {
  55. util::success([
  56. 'systemIncome' => 0,
  57. 'systemCount' => 0,
  58. 'debtCount' => 0,
  59. 'debtIncome' => 0,
  60. 'kfWxCount' => 0,
  61. 'kfWxIncome' => 0,
  62. 'cashCount' => 0,
  63. 'cashIncome' => 0,
  64. ]);
  65. }
  66. $incomeList = StatKdClass::eachChannelIncome($this->mainId, $this->shop);
  67. $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
  68. $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;
  69. $systemIncome2 = $incomeList['system']['category']['pf']['amount'] ?? 0;
  70. $systemCount2 = $incomeList['system']['category']['pf']['num'] ?? 0;
  71. $systemCount = bcadd($systemCount1, $systemCount2);
  72. $systemIncome = bcadd($systemIncome1, $systemIncome2, 2);
  73. $debtIncome1 = $incomeList['debt']['category']['ls']['amount'] ?? 0;
  74. $debtCount1 = $incomeList['debt']['category']['ls']['num'] ?? 0;
  75. $debtIncome2 = $incomeList['debt']['category']['pf']['amount'] ?? 0;
  76. $debtCount2 = $incomeList['debt']['category']['pf']['num'] ?? 0;
  77. $debtIncome = bcadd($debtIncome1, $debtIncome2, 2);
  78. $debtCount = bcadd($debtCount1, $debtCount2);
  79. $kfWxIncome1 = $incomeList['kfWx']['category']['ls']['amount'] ?? 0;
  80. $kfWxCount1 = $incomeList['kfWx']['category']['ls']['num'] ?? 0;
  81. $kfWxIncome2 = $incomeList['kfWx']['category']['pf']['amount'] ?? 0;
  82. $kfWxCount2 = $incomeList['kfWx']['category']['pf']['num'] ?? 0;
  83. $kfWxIncome = bcadd($kfWxIncome1, $kfWxIncome2, 2);
  84. $kfWxCount = bcadd($kfWxCount1, $kfWxCount2);
  85. $cashIncome1 = $incomeList['cash']['category']['ls']['amount'] ?? 0;
  86. $cashCount1 = $incomeList['cash']['category']['ls']['num'] ?? 0;
  87. $cashIncome2 = $incomeList['cash']['category']['pf']['amount'] ?? 0;
  88. $cashCount2 = $incomeList['cash']['category']['pf']['num'] ?? 0;
  89. $cashIncome = bcadd($cashIncome1, $cashIncome2, 2);
  90. $cashCount = bcadd($cashCount1, $cashCount2);
  91. util::success([
  92. 'systemIncome' => $systemIncome,
  93. 'systemCount' => $systemCount,
  94. 'debtCount' => $debtCount,
  95. 'debtIncome' => $debtIncome,
  96. 'kfWxCount' => $kfWxCount,
  97. 'kfWxIncome' => $kfWxIncome,
  98. 'cashCount' => $cashCount,
  99. 'cashIncome' => $cashIncome,
  100. ]);
  101. }
  102. //今日概况 ssh 20220723
  103. public function actionProfile()
  104. {
  105. $notice = [];
  106. $mainId = $this->mainId;
  107. $respond = StatSaleClass::profile($mainId);
  108. $incomeList = $respond['income'] ?? [];
  109. $todaySale = 0;
  110. if (!empty($incomeList)) {
  111. foreach ($incomeList as $item) {
  112. if (isset($item['id']) && $item['id'] == 'allot') {
  113. continue;
  114. }
  115. $todaySale = bcadd($todaySale, $item['amount'], 2);
  116. }
  117. }
  118. $expendList = $respond['expend'] ?? [];
  119. $todayOut = 0;
  120. if (!empty($expendList)) {
  121. foreach ($expendList as $item) {
  122. $todayOut = bcadd($todayOut, $item['amount'], 2);
  123. }
  124. }
  125. $orderNum = $respond['totalOrderNum'] ?? 0;
  126. $wastage = StockWastageOrderClass::getTodayWaste($this->mainId);
  127. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  128. $menu = [
  129. ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/home/mall"],
  130. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list"],
  131. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list"],
  132. ["name" => "采购", "img" => "ghs/home/icon_caigou.png", "url" => "/pagesPurchase/order"],
  133. ["name" => "损耗", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list"],
  134. ["name" => "预订", "img" => "ghs/home/kcyjs.png", "url" => "/admin/order/statBook"],
  135. ["name" => "调拨入库", "img" => "ghs/home/dbrk.png", "url" => "/pagesStorehouse/allot/allotPut"],
  136. ["name" => "调拨出库", "img" => "ghs/home/dbck.png", "url" => "/pagesStorehouse/allot/allotEx"],
  137. ["name" => "结账记录", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/customList"],
  138. ["name" => "支出", "img" => "ghs/home/kcyjs.png", "url" => "/admin/expend/list"],
  139. ["name" => "盘点", "img" => "ghs/home/pandian.png", "url" => "/pagesStorehouse/inventory/list"],
  140. ["name" => "库存预警", "img" => "ghs/home/kcyjs.png", "url" => "/admin/item/list?warning=1"],
  141. ];
  142. util::success([
  143. 'asset' => $this->main,
  144. 'notice' => $notice,
  145. 'todayData' => [
  146. 'income' => $todaySale,
  147. 'order' => $orderNum,
  148. 'expend' => $todayOut,
  149. 'visitCustom' => $visitCustom,
  150. 'wastage' => $wastage
  151. ],
  152. 'menu' => $menu
  153. ]);
  154. }
  155. //常用初始化
  156. public function actionInit()
  157. {
  158. $dict = dict::get();
  159. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  160. util::success(['dict' => $dict, 'shop' => $shop]);
  161. }
  162. }