StatController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace hd\controllers;
  3. use biz\stat\classes\StatCgClass;
  4. use biz\stat\classes\StatRefundClass;
  5. use biz\stat\classes\StatSaleClass;
  6. use biz\stat\classes\StatStockInClass;
  7. use biz\stat\classes\StatStockOutClass;
  8. use common\components\dateUtil;
  9. use Yii;
  10. use common\components\util;
  11. class StatController extends BaseController
  12. {
  13. //按月统计损耗情况
  14. public function actionWaste()
  15. {
  16. ini_set('memory_limit', '2045M');
  17. set_time_limit(0);
  18. $mainId = $this->mainId;
  19. $list = \bizGhs\order\classes\StockWastageOrderClass::getAllByCondition(['mainId' => $mainId], null, '*');
  20. $arr = [];
  21. $totalNum = 0;
  22. $totalCost = 0;
  23. $totalPrice = 0;
  24. if (!empty($list)) {
  25. foreach ($list as $order) {
  26. $addTime = $order['addTime'];
  27. $time = date("Ym", strtotime($addTime));
  28. $date = date("Y年n月", strtotime($addTime));
  29. $bigNum = $order['bigNum'] ?? 0;
  30. $cost = $order['cost'] ?? 0;
  31. $price = $order['price'] ?? 0;
  32. if (isset($arr[$time])) {
  33. $arr[$time]['num'] = bcadd($arr[$time]['num'], $bigNum);
  34. $arr[$time]['cost'] = bcadd($arr[$time]['cost'], $cost, 2);
  35. $arr[$time]['price'] = bcadd($arr[$time]['price'], $price, 2);
  36. $arr[$time]['time'] = $date;
  37. } else {
  38. $arr[$time]['num'] = $bigNum;
  39. $arr[$time]['cost'] = $cost;
  40. $arr[$time]['price'] = $price;
  41. $arr[$time]['time'] = $date;
  42. }
  43. $totalNum = bcadd($totalNum, $bigNum);
  44. $totalCost = bcadd($totalCost, $cost, 2);
  45. $totalPrice = bcadd($totalPrice, $price, 2);
  46. }
  47. }
  48. $totalCost = floatval($totalCost);
  49. $totalPrice = floatval($totalPrice);
  50. util::success(['list' => $arr, 'totalNum' => $totalNum, 'totalCost' => $totalCost, 'totalPrice' => $totalPrice]);
  51. }
  52. //利润表 ssh 20230303
  53. public function actionProfit()
  54. {
  55. ini_set('memory_limit', '2045M');
  56. set_time_limit(0);
  57. $shopAdmin = $this->shopAdmin;
  58. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  59. util::fail('超管才能查看');
  60. }
  61. //惠雅鲜花员工不能看利润表
  62. $shopAdmin = $this->shopAdmin;
  63. $adminId = $shopAdmin->adminId ?? 0;
  64. if (in_array($adminId, [2366, 2812, 4004, 3405, 3407])) {
  65. util::fail('暂无权限');
  66. }
  67. $mainId = $this->mainId;
  68. $respond = \bizGhs\stat\classes\StatSaleClass::profile($mainId);
  69. $income = $respond['income'] ?? 0;
  70. $expend = $respond['expend'] ?? 0;
  71. $balance = $respond['balance'] ?? 0;
  72. //由于损耗而造成少赚的钱
  73. $wastageRespond = \bizGhs\stat\classes\StatSaleClass::wastage($mainId);
  74. $wastagePrice = $wastageRespond['totalPrice'] ?? 0;
  75. $wastagePrice = floatval($wastagePrice);
  76. util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'wastagePrice' => $wastagePrice]);
  77. }
  78. //统计列表 ssh 2020.1.5
  79. public function actionList()
  80. {
  81. $type = Yii::$app->request->get('type', 1);
  82. $incomeStat = [
  83. 'total' => (185 + 381 + 662 + 443),
  84. 'list' => [
  85. ['name' => '2.6', 'num' => 185],
  86. ['name' => '2.7', 'num' => 381],
  87. ['name' => '2.8', 'num' => 662],
  88. ['name' => '2.9', 'num' => 443],
  89. ],
  90. ];
  91. $visitStat = [
  92. 'total' => (115 + 341 + 622 + 423),
  93. 'list' => [
  94. ['name' => '2.6', 'num' => 115],
  95. ['name' => '2.7', 'num' => 341],
  96. ['name' => '2.8', 'num' => 622],
  97. ['name' => '2.9', 'num' => 423],
  98. ],
  99. ];
  100. $userStat = [
  101. 'total' => (185 + 341 + 622 + 423),
  102. 'list' => [
  103. ['name' => '2.6', 'num' => 185],
  104. ['name' => '2.7', 'num' => 341],
  105. ['name' => '2.8', 'num' => 622],
  106. ['name' => '2.9', 'num' => 423],
  107. ],
  108. ];
  109. $fansStat = [
  110. 'total' => (185 + 241 + 322 + 553),
  111. 'list' => [
  112. ['name' => '2.6', 'num' => 185],
  113. ['name' => '2.7', 'num' => 241],
  114. ['name' => '2.8', 'num' => 322],
  115. ['name' => '2.9', 'num' => 553],
  116. ],
  117. ];
  118. $incomeSourceStat = [
  119. 'total' => (299 + 366 + 2995),
  120. 'list' => [
  121. ['name' => '门店', 'num' => 299],
  122. ['name' => '微信朋友圈', 'num' => 366],
  123. ['name' => '美团', 'num' => 2995],
  124. ],
  125. ];
  126. $categoryStat = [
  127. 'total' => (552 + 155 + 295 + 365 + 600 + 504),
  128. 'list' => [
  129. ['name' => '花束', 'num' => 552],
  130. ['name' => '花篮', 'num' => 155],
  131. ['name' => '蝴蝶兰', 'num' => 295],
  132. ['name' => '绿植', 'num' => 365],
  133. ['name' => '永生花', 'num' => 600],
  134. ['name' => '散花', 'num' => 504],
  135. ],
  136. ];
  137. $useStat = [
  138. 'total' => (552 + 155 + 295 + 365 + 600 + 504),
  139. 'list' => [
  140. ['name' => '年销花', 'num' => 552],
  141. ['name' => '送爱人', 'num' => 155],
  142. ['name' => '婚庆', 'num' => 295],
  143. ['name' => '开业', 'num' => 365],
  144. ['name' => '送母亲', 'num' => 600],
  145. ['name' => '生日', 'num' => 504],
  146. ]
  147. ];
  148. $data = ['incomeStat' => $incomeStat,
  149. 'visitStat' => $visitStat,
  150. 'userStat' => $userStat,
  151. 'fansStat' => $fansStat,
  152. 'incomeSourceStat' => $incomeSourceStat,
  153. 'categoryStat' => $categoryStat,
  154. 'useStat' => $useStat,
  155. ];
  156. util::success($data);
  157. }
  158. }