ConsoleController.php 7.6 KB

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