StatController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
  58. if ($lookMoney == 0) {
  59. util::fail('无法查看');
  60. }
  61. $shopAdmin = $this->shopAdmin;
  62. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  63. util::fail('超管才能查看');
  64. }
  65. //惠雅鲜花员工不能看利润表
  66. $shopAdmin = $this->shopAdmin;
  67. $adminId = $shopAdmin->adminId ?? 0;
  68. if (in_array($adminId, [2366, 2812, 4004, 3405, 3407])) {
  69. util::fail('暂无权限');
  70. }
  71. $mainId = $this->mainId;
  72. $respond = \bizGhs\stat\classes\StatSaleClass::profile($mainId);
  73. $income = $respond['income'] ?? 0;
  74. $expend = $respond['expend'] ?? 0;
  75. $balance = $respond['balance'] ?? 0;
  76. //由于损耗而造成少赚的钱
  77. $wastageRespond = \bizGhs\stat\classes\StatSaleClass::wastage($mainId);
  78. $wastagePrice = $wastageRespond['totalPrice'] ?? 0;
  79. $wastagePrice = floatval($wastagePrice);
  80. util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'wastagePrice' => $wastagePrice]);
  81. }
  82. //统计列表 ssh 2020.1.5
  83. public function actionList()
  84. {
  85. $type = Yii::$app->request->get('type', 1);
  86. $incomeStat = [
  87. 'total' => (185 + 381 + 662 + 443),
  88. 'list' => [
  89. ['name' => '2.6', 'num' => 185],
  90. ['name' => '2.7', 'num' => 381],
  91. ['name' => '2.8', 'num' => 662],
  92. ['name' => '2.9', 'num' => 443],
  93. ],
  94. ];
  95. $visitStat = [
  96. 'total' => (115 + 341 + 622 + 423),
  97. 'list' => [
  98. ['name' => '2.6', 'num' => 115],
  99. ['name' => '2.7', 'num' => 341],
  100. ['name' => '2.8', 'num' => 622],
  101. ['name' => '2.9', 'num' => 423],
  102. ],
  103. ];
  104. $userStat = [
  105. 'total' => (185 + 341 + 622 + 423),
  106. 'list' => [
  107. ['name' => '2.6', 'num' => 185],
  108. ['name' => '2.7', 'num' => 341],
  109. ['name' => '2.8', 'num' => 622],
  110. ['name' => '2.9', 'num' => 423],
  111. ],
  112. ];
  113. $fansStat = [
  114. 'total' => (185 + 241 + 322 + 553),
  115. 'list' => [
  116. ['name' => '2.6', 'num' => 185],
  117. ['name' => '2.7', 'num' => 241],
  118. ['name' => '2.8', 'num' => 322],
  119. ['name' => '2.9', 'num' => 553],
  120. ],
  121. ];
  122. $incomeSourceStat = [
  123. 'total' => (299 + 366 + 2995),
  124. 'list' => [
  125. ['name' => '门店', 'num' => 299],
  126. ['name' => '微信朋友圈', 'num' => 366],
  127. ['name' => '美团', 'num' => 2995],
  128. ],
  129. ];
  130. $categoryStat = [
  131. 'total' => (552 + 155 + 295 + 365 + 600 + 504),
  132. 'list' => [
  133. ['name' => '花束', 'num' => 552],
  134. ['name' => '花篮', 'num' => 155],
  135. ['name' => '蝴蝶兰', 'num' => 295],
  136. ['name' => '绿植', 'num' => 365],
  137. ['name' => '永生花', 'num' => 600],
  138. ['name' => '散花', 'num' => 504],
  139. ],
  140. ];
  141. $useStat = [
  142. 'total' => (552 + 155 + 295 + 365 + 600 + 504),
  143. 'list' => [
  144. ['name' => '年销花', 'num' => 552],
  145. ['name' => '送爱人', 'num' => 155],
  146. ['name' => '婚庆', 'num' => 295],
  147. ['name' => '开业', 'num' => 365],
  148. ['name' => '送母亲', 'num' => 600],
  149. ['name' => '生日', 'num' => 504],
  150. ]
  151. ];
  152. $data = ['incomeStat' => $incomeStat,
  153. 'visitStat' => $visitStat,
  154. 'userStat' => $userStat,
  155. 'fansStat' => $fansStat,
  156. 'incomeSourceStat' => $incomeSourceStat,
  157. 'categoryStat' => $categoryStat,
  158. 'useStat' => $useStat,
  159. ];
  160. util::success($data);
  161. }
  162. }