StatController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\PurchaseOrderClass;
  4. use bizGhs\order\classes\StockWastageOrderClass;
  5. use bizGhs\order\classes\StockWastageOrderItemClass;
  6. use bizGhs\stat\classes\StatSaleClass;
  7. use common\components\arrayUtil;
  8. use common\components\imgUtil;
  9. use Yii;
  10. use common\components\util;
  11. use common\components\dateUtil;
  12. class StatController extends BaseController
  13. {
  14. //采购运费统计 ssh 20230427
  15. public function actionCgFreight()
  16. {
  17. $get = Yii::$app->request->get();
  18. $where = [];
  19. $where['mainId'] = $this->mainId;
  20. $where['status'] = 4;
  21. $searchTime = $get['searchTime'] ?? 'today';
  22. if (!empty($searchTime)) {
  23. $startTime = $get['startTime'] ?? '';
  24. $endTime = $get['endTime'] ?? '';
  25. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  26. $start = date("Y-m-d 00:00:00", strtotime($period['startTime']));
  27. $end = date("Y-m-d 23:59:59", strtotime($period['endTime']));
  28. $where['entryTime'] = ['between', [$start, $end]];
  29. }
  30. $cgList = PurchaseOrderClass::getAllByCondition($where, null, '*');
  31. util::success(['list' => $cgList]);
  32. }
  33. public function actionProfit()
  34. {
  35. ini_set('memory_limit', '2045M');
  36. set_time_limit(0);
  37. $shopAdmin = $this->shopAdmin;
  38. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  39. util::fail('超管才能查看');
  40. }
  41. //惠雅鲜花员工不能看利润表
  42. $shopAdmin = $this->shopAdmin;
  43. $adminId = $shopAdmin->adminId ?? 0;
  44. if (in_array($adminId, [2366, 2812, 4004, 3405, 3407])) {
  45. util::fail('暂无权限');
  46. }
  47. $mainId = $this->mainId;
  48. $respond = StatSaleClass::profile($mainId);
  49. $income = $respond['income'] ?? 0;
  50. $expend = $respond['expend'] ?? 0;
  51. $balance = $respond['balance'] ?? 0;
  52. //由于损耗而造成少赚的钱
  53. $wastageRespond = StatSaleClass::wastage($mainId);
  54. $wastagePrice = $wastageRespond['totalPrice'] ?? 0;
  55. $wastagePrice = floatval($wastagePrice);
  56. util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance), 'wastagePrice' => $wastagePrice]);
  57. }
  58. //按月统计损耗情况
  59. public function actionWaste()
  60. {
  61. ini_set('memory_limit', '2045M');
  62. set_time_limit(0);
  63. $mainId = $this->mainId;
  64. $list = StockWastageOrderClass::getAllByCondition(['mainId' => $mainId], null, '*');
  65. $arr = [];
  66. $totalNum = 0;
  67. $totalCost = 0;
  68. $totalPrice = 0;
  69. if (!empty($list)) {
  70. foreach ($list as $order) {
  71. $addTime = $order['addTime'];
  72. $time = date("Ym", strtotime($addTime));
  73. $date = date("Y年n月", strtotime($addTime));
  74. $bigNum = $order['bigNum'] ?? 0;
  75. $cost = $order['cost'] ?? 0;
  76. $price = $order['price'] ?? 0;
  77. if (isset($arr[$time])) {
  78. $arr[$time]['num'] = bcadd($arr[$time]['num'], $bigNum);
  79. $arr[$time]['cost'] = bcadd($arr[$time]['cost'], $cost, 2);
  80. $arr[$time]['price'] = bcadd($arr[$time]['price'], $price, 2);
  81. $arr[$time]['time'] = $date;
  82. } else {
  83. $arr[$time]['num'] = $bigNum;
  84. $arr[$time]['cost'] = $cost;
  85. $arr[$time]['price'] = $price;
  86. $arr[$time]['time'] = $date;
  87. }
  88. $totalNum = bcadd($totalNum, $bigNum);
  89. $totalCost = bcadd($totalCost, $cost, 2);
  90. $totalPrice = bcadd($totalPrice, $price, 2);
  91. }
  92. }
  93. $totalCost = floatval($totalCost);
  94. $totalPrice = floatval($totalPrice);
  95. util::success(['list' => $arr, 'totalNum' => $totalNum, 'totalCost' => $totalCost, 'totalPrice' => $totalPrice]);
  96. }
  97. //损耗花材
  98. public function actionWastage()
  99. {
  100. $get = Yii::$app->request->get();
  101. $where = [];
  102. $where['mainId'] = $this->mainId;
  103. $searchTime = $get['searchTime'] ?? 'today';
  104. if (!empty($searchTime)) {
  105. $startTime = $get['startTime'] ?? '';
  106. $endTime = $get['endTime'] ?? '';
  107. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  108. $start = date("Y-m-d 00:00:00", strtotime($period['startTime']));
  109. $end = date("Y-m-d 23:59:59", strtotime($period['endTime']));
  110. $where['addTime'] = ['between', [$start, $end]];
  111. }
  112. $wastageList = StockWastageOrderItemClass::getAllByCondition($where, null, '*', null, true);
  113. $stat = [];
  114. $totalCost = 0;
  115. $totalNum = 0;
  116. if (!empty($wastageList)) {
  117. foreach ($wastageList as $waste) {
  118. $name = $waste->name ?? '';
  119. $shortCover = $waste->cover ?? '';
  120. $cover = imgUtil::groupImg($shortCover);
  121. $num = $waste->itemNum ?? 0;
  122. $cost = $waste->itemCost ?? 0;
  123. $currentCost = bcmul($cost, $num, 2);
  124. $productId = $waste->productId ?? 0;
  125. if (isset($stat[$productId]) == false) {
  126. $stat[$productId]['name'] = $name;
  127. $stat[$productId]['cover'] = $cover;
  128. $stat[$productId]['num'] = 0;
  129. $stat[$productId]['amount'] = 0;
  130. }
  131. $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2);
  132. $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $currentCost, 2);
  133. $totalNum = bcadd($totalNum, $num, 2);
  134. $totalCost = bcadd($totalCost, $currentCost, 2);
  135. }
  136. $stat = array_values($stat);
  137. $stat = arrayUtil::arraySort($stat, 'num');
  138. }
  139. util::success(['stat' => $stat, 'totalNum' => $totalNum, 'totalCost' => $totalCost]);
  140. }
  141. }