ConsoleController.php 8.5 KB

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