ConsoleController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace hd\controllers;
  3. use bizGhs\stat\classes\StatSaleClass;
  4. use bizHd\custom\classes\CustomClass;
  5. use bizHd\goods\classes\GoodsClass;
  6. use bizHd\order\classes\OrderClass;
  7. use bizHd\shop\classes\ShopExtClass;
  8. use bizHd\stat\classes\StatVisitClass;
  9. use bizGhs\item\classes\ItemClass;
  10. use common\components\dict;
  11. use common\components\util;
  12. use bizHd\stat\classes\StatOrderClass;
  13. class ConsoleController extends BaseController
  14. {
  15. public $guestAccess = ['init', 'profile'];
  16. //总览
  17. public function actionStat()
  18. {
  19. //不要用缓存!!!!
  20. // 优化慢查询:直接在数据库层聚合库存和成本,避免取出全量数据到PHP内存中循环计算
  21. $stat = ItemClass::getByCondition(
  22. ['mainId' => $this->mainId, 'virtualStock' => 0, 'delStatus' => 0],
  23. false,
  24. false,
  25. 'SUM(stock) as totalItemNum, SUM(stock * avCost) as totalCost'
  26. );
  27. $totalItemNum = floor($stat['totalItemNum'] ?? 0);
  28. $totalCost = round($stat['totalCost'] ?? 0, 2);
  29. $goodsCount = GoodsClass::getCount(['mainId' => $this->mainId]);
  30. $customCount = CustomClass::getCount(['shopId' => $this->shopId]);
  31. $orderCount = OrderClass::getCount(['mainId' => $this->mainId, 'status' => 4]);
  32. $debtCount = OrderClass::debtCount($this->mainId);
  33. $overview = [
  34. ['name' => "花材数", "url" => '/admin/stat/stock', 'value' => $totalItemNum, 'type' => 1],
  35. ['name' => "花材值", "url" => '/admin/stat/stock', 'value' => $totalCost, 'type' => 1],
  36. ['name' => "花束", "url" => '/admin/goods/list', 'value' => $goodsCount, 'type' => 1],
  37. ['name' => "总客户", "url" => '/admin/home/member', 'value' => $customCount, 'type' => 1],
  38. ['name' => "总订单", "url" => '/admin/home/order', 'value' => $orderCount, 'type' => 4],
  39. ['name' => "总挂账", "url" => '/admin/home/order', 'value' => $debtCount, 'type' => 4],
  40. ];
  41. util::success(['overview' => $overview]);
  42. }
  43. //概况 ssh 2019.12.19
  44. public function actionProfile()
  45. {
  46. $mainId = $this->mainId;
  47. //--------- 今日的收入、订单和客户 ---------
  48. $respond = StatSaleClass::profile($mainId);
  49. $orderNum = $respond['totalOrderNum'] ?? 0;
  50. $incomeList = $respond['income'] ?? [];
  51. $todaySale = 0;
  52. if (!empty($incomeList)) {
  53. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  54. foreach ($incomeList as $item) {
  55. if (isset($item['id']) && $item['id'] == 'allot') {
  56. continue;
  57. }
  58. $todaySale = bcadd($todaySale, $item['amount'], 2);
  59. }
  60. }
  61. //访客数
  62. $visitCustom = StatVisitClass::getVisitNum($this->shopId);
  63. $wastage = \bizGhs\order\classes\StockWastageOrderClass::getTodayWaste($this->mainId);
  64. $hsReturn = StatOrderClass::statHsNum($this->mainId);
  65. $hsNum = $hsReturn['num'] ?? 0;
  66. //--------- 昨日的收入、订单和客户 ---------
  67. $_GET['searchTime'] = 'yesterday'; // 必须要有的,让其获取昨天的收入
  68. $respond = StatSaleClass::profile($mainId);
  69. $incomeList = $respond['income'] ?? [];
  70. $yesterdayIncome = 0;
  71. if (!empty($incomeList)) {
  72. //这里有二个地方同时要修改,请搜索关键词:index_show_income
  73. foreach ($incomeList as $item) {
  74. if (isset($item['id']) && $item['id'] == 'allot') {
  75. continue;
  76. }
  77. $yesterdayIncome = bcadd($yesterdayIncome, $item['amount'], 2);
  78. }
  79. }
  80. $yesterdayOrderNum = $respond['totalOrderNum'] ?? 0;
  81. $yesterdayVisitCustom = StatVisitClass::getVisitNum($this->shopId, date("Ymd", strtotime("-1 day")));
  82. $menu = [
  83. ["name" => "商城", "img" => "ghs/home/shop2.png", "url" => "/admin/cg/mall", 'pf' => 1,],
  84. ["name" => "改价", "img" => "ghs/home/gj2.png", "url" => "/admin/changePrice/list2", 'pf' => 1,],
  85. ["name" => "绿植花材", "img" => "ghs/home/hcgl2.png", "url" => "/admin/item/list2", 'pf' => 1,],
  86. ["name" => "接花束", "img" => "ghs/home/shop2.png", "url" => "/admin/order/workOrder", 'pf' => 1,],
  87. ["name" => "拆散", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/part/list", 'pf' => 1,],
  88. ["name" => "损耗", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/breakage/list", 'pf' => 1,],
  89. ["name" => "任务", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/work/list", 'pf' => 1,],
  90. ["name" => "进货", "img" => "ghs/home/shop2.png", "url" => "/pagesPurchase/order", 'pf' => 1,],
  91. ["name" => "进货记录", "img" => "ghs/home/shop2.png", "url" => "/pagesPurchase/shopping", 'pf' => 1,],
  92. ["name" => "花束", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/goods/list", 'pf' => 1,],
  93. ["name" => "客户充值", "img" => "ghs/home/kcyjs2.png", "url" => "/admin/recharge/rechargeCode", 'pf' => 1,],
  94. ];
  95. //查看财务的权限
  96. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  97. $warning = '';
  98. $warningUrl = '';
  99. //$warning = '挂账和结账重大调整 查看 >';
  100. //$warningUrl = '/admin/notice/warning';
  101. util::success([
  102. 'asset' => $this->main,
  103. 'notice' => [],
  104. 'warning' => $warning,
  105. 'warningUrl' => $warningUrl,
  106. 'todayData' => [
  107. 'visit' => $visitCustom,
  108. 'income' => $todaySale,
  109. 'order' => $orderNum,
  110. 'wastage' => $wastage,
  111. 'bouquet' => $hsNum
  112. ],
  113. 'yesterdayData' => [
  114. 'visit' => $yesterdayVisitCustom,
  115. 'income' => $yesterdayIncome,
  116. 'order' => $yesterdayOrderNum
  117. ],
  118. 'menu' => $menu,
  119. 'lookMoney' => $lookMoney,
  120. ]);
  121. }
  122. //常用初始化
  123. public function actionInit()
  124. {
  125. $dict = dict::get($this->mainId);
  126. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shop->id], false, false, 'reachVip');
  127. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  128. $shop['reachVip'] = $shopExt['reachVip'];
  129. util::success(['dict' => $dict, 'shop' => $shop]);
  130. }
  131. //系统收入、客服收入、欠款
  132. public function actionStrokeCount()
  133. {
  134. if (empty($this->mainId)) {
  135. util::success([
  136. 'systemIncome' => 0,
  137. 'systemCount' => 0,
  138. 'debtCount' => 0,
  139. 'debtIncome' => 0,
  140. 'kfWxCount' => 0,
  141. 'kfWxIncome' => 0,
  142. 'cashCount' => 0,
  143. 'cashIncome' => 0,
  144. ]);
  145. }
  146. $return = \bizGhs\stat\classes\StatKdClass::eachChannelIncome($this->mainId, $this->shop);
  147. $incomeList = $return['incomeList'];
  148. $systemIncome1 = $incomeList['system']['category']['ls']['amount'] ?? 0;
  149. $systemCount1 = $incomeList['system']['category']['ls']['num'] ?? 0;
  150. $systemIncome2 = $incomeList['system']['category']['pf']['amount'] ?? 0;
  151. $systemCount2 = $incomeList['system']['category']['pf']['num'] ?? 0;
  152. $systemCount = bcadd($systemCount1, $systemCount2);
  153. $systemIncome = bcadd($systemIncome1, $systemIncome2, 2);
  154. $debtIncome1 = $incomeList['debt']['category']['ls']['amount'] ?? 0;
  155. $debtCount1 = $incomeList['debt']['category']['ls']['num'] ?? 0;
  156. $debtIncome2 = $incomeList['debt']['category']['pf']['amount'] ?? 0;
  157. $debtCount2 = $incomeList['debt']['category']['pf']['num'] ?? 0;
  158. $debtIncome = bcadd($debtIncome1, $debtIncome2, 2);
  159. $debtCount = bcadd($debtCount1, $debtCount2);
  160. $kfWxIncome1 = $incomeList['kfWx']['category']['ls']['amount'] ?? 0;
  161. $kfWxCount1 = $incomeList['kfWx']['category']['ls']['num'] ?? 0;
  162. $kfWxIncome2 = $incomeList['kfWx']['category']['pf']['amount'] ?? 0;
  163. $kfWxCount2 = $incomeList['kfWx']['category']['pf']['num'] ?? 0;
  164. $kfWxIncome = bcadd($kfWxIncome1, $kfWxIncome2, 2);
  165. $kfWxCount = bcadd($kfWxCount1, $kfWxCount2);
  166. $cashIncome1 = $incomeList['cash']['category']['ls']['amount'] ?? 0;
  167. $cashCount1 = $incomeList['cash']['category']['ls']['num'] ?? 0;
  168. $cashIncome2 = $incomeList['cash']['category']['pf']['amount'] ?? 0;
  169. $cashCount2 = $incomeList['cash']['category']['pf']['num'] ?? 0;
  170. $cashIncome = bcadd($cashIncome1, $cashIncome2, 2);
  171. $cashCount = bcadd($cashCount1, $cashCount2);
  172. util::success([
  173. 'systemIncome' => $systemIncome,
  174. 'systemCount' => $systemCount,
  175. 'debtCount' => $debtCount,
  176. 'debtIncome' => $debtIncome,
  177. 'kfWxCount' => $kfWxCount,
  178. 'kfWxIncome' => $kfWxIncome,
  179. 'cashCount' => $cashCount,
  180. 'cashIncome' => $cashIncome,
  181. ]);
  182. }
  183. }