ConsoleController.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\stat\classes\StatOrderClass;
  4. use bizHd\stat\classes\StatVisitClass;
  5. use bizGhs\item\classes\ItemClass;
  6. use common\components\dict;
  7. use common\components\util;
  8. use bizGhs\order\classes\OrderClass;
  9. use Yii;
  10. class ConsoleController extends BaseController
  11. {
  12. public $guestAccess = ['init', 'profile'];
  13. //总览
  14. public function actionStat()
  15. {
  16. $where = ['mainId' => $this->mainId, 'debt' => 1]; // 重新赋值
  17. $pfDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
  18. $pfDebt = $pfDebt === null ? 0 : $pfDebt;
  19. $lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
  20. $lsDebt = $lsDebt === null ? 0 : $lsDebt;
  21. $totalDebt = bcadd($pfDebt, $lsDebt, 2);
  22. $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost', null, true);
  23. $totalItemNum = 0;
  24. $totalCost = 0;
  25. if (!empty($itemList)) {
  26. foreach ($itemList as $item) {
  27. $stock = $item->stock ?? 0;
  28. $cost = $item->cost ?? 0;
  29. $totalItemNum = bcadd($stock, $totalItemNum, 2);
  30. $currentCost = bcmul($stock, $cost, 2);
  31. $totalCost = bcadd($currentCost, $totalCost, 2);
  32. }
  33. }
  34. $totalItemNum = floor($totalItemNum);
  35. $main = $this->main;
  36. $totalCustom = $main->totalUser ?? 0;
  37. $totalVisit = $main->totalVisit ?? 0;
  38. $totalOrder = $main->finishOrder ?? 0;
  39. $overview = [
  40. ['name' => "品类", "url" => '/admin/stat/stock', 'value' => 12, 'type' => 1],
  41. ['name' => "花材", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
  42. ['name' => "总欠款", "url" => '/admin/home/member', 'value' => $totalDebt, 'type' => 4],
  43. ['name' => "总会员", "url" => '/admin/home/member', 'value' => $totalCustom, 'type' => 4],
  44. ['name' => "总访客", "url" => '/admin/home/member', 'value' => $totalVisit, 'type' => 4],
  45. ['name' => "总订单", "url" => '/admin/home/order', 'value' => $totalOrder, 'type' => 4],
  46. ];
  47. util::success(['overview' => $overview]);
  48. }
  49. //概况 ssh 2019.12.19
  50. public function actionProfile()
  51. {
  52. //$get = Yii::$app->request->get();
  53. $notice = [];
  54. $mainId = $this->mainId;
  55. $respond = \bizGhs\stat\classes\StatSaleClass::profile($mainId);
  56. $incomeList = $respond['income'] ?? [];
  57. $todaySale = 0;
  58. if (!empty($incomeList)) {
  59. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  60. foreach ($incomeList as $item) {
  61. if (isset($item['id']) && $item['id'] == 'allot') {
  62. continue;
  63. }
  64. $todaySale = bcadd($todaySale, $item['amount'], 2);
  65. }
  66. }
  67. $orderNum = $respond['totalOrderNum'] ?? 0;
  68. //访客数
  69. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  70. $wastage = \bizGhs\order\classes\StockWastageOrderClass::getTodayWaste($this->mainId);
  71. $hsReturn = StatOrderClass::statHsNum($this->mainId);
  72. $hsNum = $hsReturn['num'] ?? 0;
  73. $menu = [
  74. ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/cg/mall", 'pf' => 1,],
  75. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list", 'pf' => 1,],
  76. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list", 'pf' => 1,],
  77. ["name" => "拆散", "img" => "ghs/home/kcyjs.png", "url" => "/admin/part/list", 'pf' => 1,],
  78. ["name" => "损耗", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list", 'pf' => 1,],
  79. ["name" => "任务", "img" => "ghs/home/kcyjs.png", "url" => "/admin/work/list", 'pf' => 1,],
  80. ["name" => "供货商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/order", 'pf' => 1,],
  81. ["name" => "花材采购", "img" => "ghs/home/dbck.png", "url" => "/pagesPurchase/shopping", 'pf' => 1,],
  82. ["name" => "采购结账", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/list", 'pf' => 1,],
  83. ["name" => "花束", "img" => "ghs/home/kcyjs.png", "url" => "/admin/goods/list", 'pf' => 1,],
  84. ["name" => "绿植", "img" => "ghs/home/pandian.png", "url" => "/admin/goods/lz", 'pf' => 1,],
  85. ["name" => "绿植采购", "img" => "ghs/home/icon_caigou.png", "url" => "/admin/goods/plantCg", 'pf' => 1,],
  86. ];
  87. if ($this->shopAdminId == 126272) {
  88. $menu = [
  89. ["name" => "拆散", "img" => "ghs/home/dbck.png", "url" => "/admin/part/list", 'pf' => 1,],
  90. ["name" => "任务", "img" => "ghs/home/kcyjs.png", "url" => "/admin/work/list", 'pf' => 1,],
  91. ["name" => "绿植", "img" => "ghs/home/hcgl.png", "url" => "/admin/goods/lz", 'pf' => 1,],
  92. ["name" => "绿植采购", "img" => "ghs/home/hcgl.png", "url" => "/admin/goods/plantCg", 'pf' => 1,],
  93. ];
  94. }
  95. util::success([
  96. 'asset' => $this->main,
  97. 'notice' => $notice,
  98. 'todayData' => ['visit' => $visitCustom, 'income' => $todaySale, 'order' => $orderNum, 'wastage' => $wastage, 'bouquet' => $hsNum],
  99. 'incomeStat' => [],
  100. 'menu' => $menu
  101. ]);
  102. }
  103. //常用初始化
  104. public function actionInit()
  105. {
  106. $dict = dict::get();
  107. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  108. util::success(['dict' => $dict, 'shop' => $shop]);
  109. }
  110. //系统收入、客服收入、欠款
  111. public function actionStrokeCount()
  112. {
  113. if (empty($this->mainId)) {
  114. util::success([
  115. 'systemIncome' => 0,
  116. 'systemCount' => 0,
  117. 'debtCount' => 0,
  118. 'debtIncome' => 0,
  119. 'kfWxCount' => 0,
  120. 'kfWxIncome' => 0,
  121. 'cashCount' => 0,
  122. 'cashIncome' => 0,
  123. ]);
  124. }
  125. $incomeList = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop);
  126. $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
  127. $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;
  128. $systemIncome2 = $incomeList['system']['category']['pf']['amount'] ?? 0;
  129. $systemCount2 = $incomeList['system']['category']['pf']['num'] ?? 0;
  130. $systemCount = bcadd($systemCount1, $systemCount2);
  131. $systemIncome = bcadd($systemIncome1, $systemIncome2, 2);
  132. $debtIncome1 = $incomeList['debt']['category']['ls']['amount'] ?? 0;
  133. $debtCount1 = $incomeList['debt']['category']['ls']['num'] ?? 0;
  134. $debtIncome2 = $incomeList['debt']['category']['pf']['amount'] ?? 0;
  135. $debtCount2 = $incomeList['debt']['category']['pf']['num'] ?? 0;
  136. $debtIncome = bcadd($debtIncome1, $debtIncome2, 2);
  137. $debtCount = bcadd($debtCount1, $debtCount2);
  138. $kfWxIncome1 = $incomeList['kfWx']['category']['ls']['amount'] ?? 0;
  139. $kfWxCount1 = $incomeList['kfWx']['category']['ls']['num'] ?? 0;
  140. $kfWxIncome2 = $incomeList['kfWx']['category']['pf']['amount'] ?? 0;
  141. $kfWxCount2 = $incomeList['kfWx']['category']['pf']['num'] ?? 0;
  142. $kfWxIncome = bcadd($kfWxIncome1, $kfWxIncome2, 2);
  143. $kfWxCount = bcadd($kfWxCount1, $kfWxCount2);
  144. $cashIncome1 = $incomeList['cash']['category']['ls']['amount'] ?? 0;
  145. $cashCount1 = $incomeList['cash']['category']['ls']['num'] ?? 0;
  146. $cashIncome2 = $incomeList['cash']['category']['pf']['amount'] ?? 0;
  147. $cashCount2 = $incomeList['cash']['category']['pf']['num'] ?? 0;
  148. $cashIncome = bcadd($cashIncome1, $cashIncome2, 2);
  149. $cashCount = bcadd($cashCount1, $cashCount2);
  150. util::success([
  151. 'systemIncome' => $systemIncome,
  152. 'systemCount' => $systemCount,
  153. 'debtCount' => $debtCount,
  154. 'debtIncome' => $debtIncome,
  155. 'kfWxCount' => $kfWxCount,
  156. 'kfWxIncome' => $kfWxIncome,
  157. 'cashCount' => $cashCount,
  158. 'cashIncome' => $cashIncome,
  159. ]);
  160. }
  161. }