StatController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. $payCodeIncome = $respond['payCodeIncome'] ?? 0;
  77. //由于损耗而造成的损失
  78. $wastageRespond = \bizGhs\stat\classes\StatSaleClass::wastage($mainId);
  79. $wastagePrice = $wastageRespond['totalPrice'] ?? 0;
  80. $wastagePrice = floatval($wastagePrice);
  81. util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'wastagePrice' => $wastagePrice, 'payCodeIncome' => $payCodeIncome]);
  82. }
  83. //统计列表 ssh 2020.1.5
  84. public function actionList()
  85. {
  86. $type = Yii::$app->request->get('type', 1);
  87. $incomeStat = [
  88. 'total' => (185 + 381 + 662 + 443),
  89. 'list' => [
  90. ['name' => '2.6', 'num' => 185],
  91. ['name' => '2.7', 'num' => 381],
  92. ['name' => '2.8', 'num' => 662],
  93. ['name' => '2.9', 'num' => 443],
  94. ],
  95. ];
  96. $visitStat = [
  97. 'total' => (115 + 341 + 622 + 423),
  98. 'list' => [
  99. ['name' => '2.6', 'num' => 115],
  100. ['name' => '2.7', 'num' => 341],
  101. ['name' => '2.8', 'num' => 622],
  102. ['name' => '2.9', 'num' => 423],
  103. ],
  104. ];
  105. $userStat = [
  106. 'total' => (185 + 341 + 622 + 423),
  107. 'list' => [
  108. ['name' => '2.6', 'num' => 185],
  109. ['name' => '2.7', 'num' => 341],
  110. ['name' => '2.8', 'num' => 622],
  111. ['name' => '2.9', 'num' => 423],
  112. ],
  113. ];
  114. $fansStat = [
  115. 'total' => (185 + 241 + 322 + 553),
  116. 'list' => [
  117. ['name' => '2.6', 'num' => 185],
  118. ['name' => '2.7', 'num' => 241],
  119. ['name' => '2.8', 'num' => 322],
  120. ['name' => '2.9', 'num' => 553],
  121. ],
  122. ];
  123. $incomeSourceStat = [
  124. 'total' => (299 + 366 + 2995),
  125. 'list' => [
  126. ['name' => '门店', 'num' => 299],
  127. ['name' => '微信朋友圈', 'num' => 366],
  128. ['name' => '美团', 'num' => 2995],
  129. ],
  130. ];
  131. $categoryStat = [
  132. 'total' => (552 + 155 + 295 + 365 + 600 + 504),
  133. 'list' => [
  134. ['name' => '花束', 'num' => 552],
  135. ['name' => '花篮', 'num' => 155],
  136. ['name' => '蝴蝶兰', 'num' => 295],
  137. ['name' => '绿植', 'num' => 365],
  138. ['name' => '永生花', 'num' => 600],
  139. ['name' => '散花', 'num' => 504],
  140. ],
  141. ];
  142. $useStat = [
  143. 'total' => (552 + 155 + 295 + 365 + 600 + 504),
  144. 'list' => [
  145. ['name' => '年销花', 'num' => 552],
  146. ['name' => '送爱人', 'num' => 155],
  147. ['name' => '婚庆', 'num' => 295],
  148. ['name' => '开业', 'num' => 365],
  149. ['name' => '送母亲', 'num' => 600],
  150. ['name' => '生日', 'num' => 504],
  151. ]
  152. ];
  153. $data = ['incomeStat' => $incomeStat,
  154. 'visitStat' => $visitStat,
  155. 'userStat' => $userStat,
  156. 'fansStat' => $fansStat,
  157. 'incomeSourceStat' => $incomeSourceStat,
  158. 'categoryStat' => $categoryStat,
  159. 'useStat' => $useStat,
  160. ];
  161. util::success($data);
  162. }
  163. }