ConsoleController.php 9.3 KB

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