ConsoleController.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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' => 10, 'type' => 1],
  41. ['name' => "绿植品类", "url" => '/admin/stat/stock', 'value' => 8, 'type' => 1],
  42. ['name' => "花材", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
  43. ['name' => "总欠款", "url" => '/admin/home/member', 'value' => $totalDebt, 'type' => 4],
  44. ['name' => "会员", "url" => '/admin/home/member', 'value' => $totalCustom, 'type' => 4],
  45. //['name' => "访客", "url" => '/admin/home/member', 'value' => $totalVisit, 'type' => 4],
  46. ['name' => "订单", "url" => '/admin/home/order', 'value' => $totalOrder, 'type' => 4],
  47. ];
  48. util::success(['overview' => $overview]);
  49. }
  50. //概况 ssh 2019.12.19
  51. public function actionProfile()
  52. {
  53. //$get = Yii::$app->request->get();
  54. $notice = [];
  55. $mainId = $this->mainId;
  56. $respond = \bizGhs\stat\classes\StatSaleClass::profile($mainId);
  57. $incomeList = $respond['income'] ?? [];
  58. $todaySale = 0;
  59. if (!empty($incomeList)) {
  60. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  61. foreach ($incomeList as $item) {
  62. if (isset($item['id']) && $item['id'] == 'allot') {
  63. continue;
  64. }
  65. $todaySale = bcadd($todaySale, $item['amount'], 2);
  66. }
  67. }
  68. $orderNum = $respond['totalOrderNum'] ?? 0;
  69. //访客数
  70. $visitCustom = StatVisitClass::getVisitNum($this->mainId);
  71. $wastage = \bizGhs\order\classes\StockWastageOrderClass::getTodayWaste($this->mainId);
  72. $hsReturn = StatOrderClass::statHsNum($this->mainId);
  73. $hsNum = $hsReturn['num'] ?? 0;
  74. $menu = [
  75. ["name" => "商城", "img" => "ghs/home/shop.png", "url" => "/admin/cg/mall", 'pf' => 1,],
  76. ["name" => "花材", "img" => "ghs/home/hcgl.png", "url" => "/admin/item/list", 'pf' => 1,],
  77. ["name" => "改价", "img" => "ghs/home/gj.png", "url" => "/admin/changePrice/list", 'pf' => 1,],
  78. ["name" => "拆散", "img" => "ghs/home/kcyjs.png", "url" => "/admin/part/list", 'pf' => 1,],
  79. ["name" => "损耗", "img" => "ghs/home/kcyjs.png", "url" => "/admin/breakage/list", 'pf' => 1,],
  80. ["name" => "任务", "img" => "ghs/home/kcyjs.png", "url" => "/admin/work/list", 'pf' => 1,],
  81. ["name" => "供货商", "img" => "ghs/home/icon_ghs.png", "url" => "/pagesPurchase/order", 'pf' => 1,],
  82. ["name" => "花材采购", "img" => "ghs/home/dbck.png", "url" => "/pagesPurchase/shopping", 'pf' => 1,],
  83. ["name" => "采购结账", "img" => "ghs/home/kcyjs.png", "url" => "/admin/clear/list", 'pf' => 1,],
  84. ["name" => "花束", "img" => "ghs/home/kcyjs.png", "url" => "/admin/goods/list", 'pf' => 1,],
  85. ["name" => "绿植", "img" => "ghs/home/pandian.png", "url" => "/admin/goods/lz", 'pf' => 1,],
  86. ["name" => "绿植采购", "img" => "ghs/home/icon_caigou.png", "url" => "/admin/goods/plantCg", 'pf' => 1,],
  87. ];
  88. //查看财务的权限
  89. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  90. util::success([
  91. 'asset' => $this->main,
  92. 'notice' => $notice,
  93. 'todayData' => ['visit' => $visitCustom, 'income' => $todaySale, 'order' => $orderNum, 'wastage' => $wastage, 'bouquet' => $hsNum],
  94. 'incomeStat' => [],
  95. 'menu' => $menu,
  96. 'lookMoney' => $lookMoney,
  97. ]);
  98. }
  99. //常用初始化
  100. public function actionInit()
  101. {
  102. $dict = dict::get();
  103. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  104. util::success(['dict' => $dict, 'shop' => $shop]);
  105. }
  106. //系统收入、客服收入、欠款
  107. public function actionStrokeCount()
  108. {
  109. if (empty($this->mainId)) {
  110. util::success([
  111. 'systemIncome' => 0,
  112. 'systemCount' => 0,
  113. 'debtCount' => 0,
  114. 'debtIncome' => 0,
  115. 'kfWxCount' => 0,
  116. 'kfWxIncome' => 0,
  117. 'cashCount' => 0,
  118. 'cashIncome' => 0,
  119. ]);
  120. }
  121. $incomeList = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop);
  122. $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
  123. $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;
  124. $systemIncome2 = $incomeList['system']['category']['pf']['amount'] ?? 0;
  125. $systemCount2 = $incomeList['system']['category']['pf']['num'] ?? 0;
  126. $systemCount = bcadd($systemCount1, $systemCount2);
  127. $systemIncome = bcadd($systemIncome1, $systemIncome2, 2);
  128. $debtIncome1 = $incomeList['debt']['category']['ls']['amount'] ?? 0;
  129. $debtCount1 = $incomeList['debt']['category']['ls']['num'] ?? 0;
  130. $debtIncome2 = $incomeList['debt']['category']['pf']['amount'] ?? 0;
  131. $debtCount2 = $incomeList['debt']['category']['pf']['num'] ?? 0;
  132. $debtIncome = bcadd($debtIncome1, $debtIncome2, 2);
  133. $debtCount = bcadd($debtCount1, $debtCount2);
  134. $kfWxIncome1 = $incomeList['kfWx']['category']['ls']['amount'] ?? 0;
  135. $kfWxCount1 = $incomeList['kfWx']['category']['ls']['num'] ?? 0;
  136. $kfWxIncome2 = $incomeList['kfWx']['category']['pf']['amount'] ?? 0;
  137. $kfWxCount2 = $incomeList['kfWx']['category']['pf']['num'] ?? 0;
  138. $kfWxIncome = bcadd($kfWxIncome1, $kfWxIncome2, 2);
  139. $kfWxCount = bcadd($kfWxCount1, $kfWxCount2);
  140. $cashIncome1 = $incomeList['cash']['category']['ls']['amount'] ?? 0;
  141. $cashCount1 = $incomeList['cash']['category']['ls']['num'] ?? 0;
  142. $cashIncome2 = $incomeList['cash']['category']['pf']['amount'] ?? 0;
  143. $cashCount2 = $incomeList['cash']['category']['pf']['num'] ?? 0;
  144. $cashIncome = bcadd($cashIncome1, $cashIncome2, 2);
  145. $cashCount = bcadd($cashCount1, $cashCount2);
  146. util::success([
  147. 'systemIncome' => $systemIncome,
  148. 'systemCount' => $systemCount,
  149. 'debtCount' => $debtCount,
  150. 'debtIncome' => $debtIncome,
  151. 'kfWxCount' => $kfWxCount,
  152. 'kfWxIncome' => $kfWxIncome,
  153. 'cashCount' => $cashCount,
  154. 'cashIncome' => $cashIncome,
  155. ]);
  156. }
  157. }