ConsoleController.php 9.0 KB

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