ConsoleController.php 7.9 KB

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