ConsoleController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. $where = ['mainId' => $this->mainId, 'debt' => 1]; // 重新赋值
  18. $pfDebt = OrderClass::sum($where, 'remainDebtPrice'); // 总欠款
  19. $pfDebt = $pfDebt === null ? 0 : $pfDebt;
  20. $lsDebt = \bizHd\order\classes\OrderClass::sum(['mainId' => $this->mainId, 'debt' => 1], 'remainDebtPrice');
  21. $lsDebt = $lsDebt === null ? 0 : $lsDebt;
  22. $totalDebt = bcadd($pfDebt, $lsDebt, 2);
  23. $itemList = ItemClass::getAllByCondition(['mainId' => $this->mainId], null, 'id,stock,cost', null, true);
  24. $totalItemNum = 0;
  25. $totalCost = 0;
  26. if (!empty($itemList)) {
  27. foreach ($itemList as $item) {
  28. $stock = $item->stock ?? 0;
  29. $cost = $item->cost ?? 0;
  30. $totalItemNum = bcadd($stock, $totalItemNum, 2);
  31. $currentCost = bcmul($stock, $cost, 2);
  32. $totalCost = bcadd($currentCost, $totalCost, 2);
  33. }
  34. }
  35. $totalItemNum = floor($totalItemNum);
  36. $main = $this->main;
  37. $totalCustom = $main->totalUser ?? 0;
  38. $totalVisit = $main->totalVisit ?? 0;
  39. $totalOrder = $main->finishOrder ?? 0;
  40. $overview = [
  41. ['name' => "花束", "url" => '/admin/stat/stock', 'value' => 10, 'type' => 1],
  42. ['name' => "花材", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
  43. ['name' => "库存值", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
  44. ['name' => "总欠款", "url" => '/admin/home/member', 'value' => $totalDebt, 'type' => 4],
  45. ['name' => "总客户", "url" => '/admin/home/member', 'value' => $totalCustom, '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/shop2.png", "url" => "/admin/cg/mall", 'pf' => 1,],
  76. ["name" => "改价", "img" => "ghs/home/gj2.png", "url" => "/admin/changePrice/list2", 'pf' => 1,],
  77. ["name" => "花材", "img" => "ghs/home/hcgl2.png", "url" => "/admin/item/list2", 'pf' => 1,],
  78. ["name" => "接花束", "img" => "ghs/home/shop2.png", "url" => "/admin/order/workOrder", 'pf' => 1,],
  79. ["name" => "拆散", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/part/list", 'pf' => 1,],
  80. ["name" => "损耗", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/breakage/list", 'pf' => 1,],
  81. ["name" => "任务", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/work/list", 'pf' => 1,],
  82. ["name" => "买花", "img" => "ghs/home/shop2.png", "url" => "/pagesPurchase/order", 'pf' => 1,],
  83. ["name" => "买花记录", "img" => "ghs/home/shop2.png", "url" => "/pagesPurchase/shopping", 'pf' => 1,],
  84. ["name" => "花束", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/goods/list", 'pf' => 1,],
  85. ["name" => "客户充值", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/recharge/rechargeCode", 'pf' => 1,],
  86. ];
  87. //查看财务的权限
  88. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  89. $warning = '';
  90. //$warning = '本月4号凌晨4点~5点系统升级,暂停使用';
  91. util::success([
  92. 'asset' => $this->main,
  93. 'notice' => $notice,
  94. 'warning'=> $warning,
  95. 'todayData' => ['visit' => $visitCustom, 'income' => $todaySale, 'order' => $orderNum, 'wastage' => $wastage, 'bouquet' => $hsNum],
  96. 'incomeStat' => [],
  97. 'menu' => $menu,
  98. 'lookMoney' => $lookMoney,
  99. ]);
  100. }
  101. //常用初始化
  102. public function actionInit()
  103. {
  104. $dict = dict::get($this->mainId);
  105. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  106. util::success(['dict' => $dict, 'shop' => $shop]);
  107. }
  108. //系统收入、客服收入、欠款
  109. public function actionStrokeCount()
  110. {
  111. if (empty($this->mainId)) {
  112. util::success([
  113. 'systemIncome' => 0,
  114. 'systemCount' => 0,
  115. 'debtCount' => 0,
  116. 'debtIncome' => 0,
  117. 'kfWxCount' => 0,
  118. 'kfWxIncome' => 0,
  119. 'cashCount' => 0,
  120. 'cashIncome' => 0,
  121. ]);
  122. }
  123. $return = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop);
  124. $incomeList = $return['incomeList'];
  125. $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
  126. $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;
  127. $systemIncome2 = $incomeList['system']['category']['pf']['amount'] ?? 0;
  128. $systemCount2 = $incomeList['system']['category']['pf']['num'] ?? 0;
  129. $systemCount = bcadd($systemCount1, $systemCount2);
  130. $systemIncome = bcadd($systemIncome1, $systemIncome2, 2);
  131. $debtIncome1 = $incomeList['debt']['category']['ls']['amount'] ?? 0;
  132. $debtCount1 = $incomeList['debt']['category']['ls']['num'] ?? 0;
  133. $debtIncome2 = $incomeList['debt']['category']['pf']['amount'] ?? 0;
  134. $debtCount2 = $incomeList['debt']['category']['pf']['num'] ?? 0;
  135. $debtIncome = bcadd($debtIncome1, $debtIncome2, 2);
  136. $debtCount = bcadd($debtCount1, $debtCount2);
  137. $kfWxIncome1 = $incomeList['kfWx']['category']['ls']['amount'] ?? 0;
  138. $kfWxCount1 = $incomeList['kfWx']['category']['ls']['num'] ?? 0;
  139. $kfWxIncome2 = $incomeList['kfWx']['category']['pf']['amount'] ?? 0;
  140. $kfWxCount2 = $incomeList['kfWx']['category']['pf']['num'] ?? 0;
  141. $kfWxIncome = bcadd($kfWxIncome1, $kfWxIncome2, 2);
  142. $kfWxCount = bcadd($kfWxCount1, $kfWxCount2);
  143. $cashIncome1 = $incomeList['cash']['category']['ls']['amount'] ?? 0;
  144. $cashCount1 = $incomeList['cash']['category']['ls']['num'] ?? 0;
  145. $cashIncome2 = $incomeList['cash']['category']['pf']['amount'] ?? 0;
  146. $cashCount2 = $incomeList['cash']['category']['pf']['num'] ?? 0;
  147. $cashIncome = bcadd($cashIncome1, $cashIncome2, 2);
  148. $cashCount = bcadd($cashCount1, $cashCount2);
  149. util::success([
  150. 'systemIncome' => $systemIncome,
  151. 'systemCount' => $systemCount,
  152. 'debtCount' => $debtCount,
  153. 'debtIncome' => $debtIncome,
  154. 'kfWxCount' => $kfWxCount,
  155. 'kfWxIncome' => $kfWxIncome,
  156. 'cashCount' => $cashCount,
  157. 'cashIncome' => $cashIncome,
  158. ]);
  159. }
  160. }