StatController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\StockWastageOrderClass;
  4. use bizGhs\order\classes\StockWastageOrderItemClass;
  5. use bizGhs\stat\classes\StatSaleClass;
  6. use common\components\arrayUtil;
  7. use common\components\imgUtil;
  8. use Yii;
  9. use common\components\util;
  10. use common\components\dateUtil;
  11. class StatController extends BaseController
  12. {
  13. public function actionProfit()
  14. {
  15. ini_set('memory_limit', '2045M');
  16. set_time_limit(0);
  17. $shopAdmin = $this->shopAdmin;
  18. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  19. util::fail('超管才能查看');
  20. }
  21. //惠雅鲜花员工不能看利润表
  22. $shopAdmin = $this->shopAdmin;
  23. $adminId = $shopAdmin->adminId ?? 0;
  24. if (in_array($adminId, [2366, 2812, 4004, 3405, 3407])) {
  25. util::fail('暂无权限');
  26. }
  27. $mainId = $this->mainId;
  28. $respond = StatSaleClass::profile($mainId);
  29. $income = $respond['income'] ?? 0;
  30. $expend = $respond['expend'] ?? 0;
  31. $balance = $respond['balance'] ?? 0;
  32. util::success(['income' => $income, 'expend' => $expend, 'balance' => floatval($balance)]);
  33. }
  34. //按月统计损耗情况
  35. public function actionWaste()
  36. {
  37. ini_set('memory_limit', '2045M');
  38. set_time_limit(0);
  39. $list = StockWastageOrderClass::getAllByCondition(['mainId' => 742], null, '*');
  40. $arr = [];
  41. if (!empty($list)) {
  42. foreach ($list as $order) {
  43. $addTime = $order['addTime'];
  44. $time = date("Ym", strtotime($addTime));
  45. $bigNum = $order['bigNum'];
  46. $cost = $order['cost'];
  47. if (isset($arr[$time])) {
  48. $arr[$time]['num'] = bcadd($arr[$time]['num'], $bigNum);
  49. $arr[$time]['cost'] = bcadd($arr[$time]['cost'], $cost, 2);
  50. $arr[$time]['time'] = $time;
  51. } else {
  52. $arr[$time]['num'] = $bigNum;
  53. $arr[$time]['cost'] = $cost;
  54. $arr[$time]['time'] = $time;
  55. }
  56. }
  57. }
  58. util::success(['list' => $arr]);
  59. }
  60. //损耗花材
  61. public function actionWastage()
  62. {
  63. $get = Yii::$app->request->get();
  64. $where = [];
  65. $where['mainId'] = $this->mainId;
  66. $searchTime = $get['searchTime'] ?? 'today';
  67. if (!empty($searchTime)) {
  68. $startTime = $get['startTime'] ?? '';
  69. $endTime = $get['endTime'] ?? '';
  70. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  71. $start = date("Y-m-d 00:00:00", strtotime($period['startTime']));
  72. $end = date("Y-m-d 23:59:59", strtotime($period['endTime']));
  73. $where['addTime'] = ['between', [$start, $end]];
  74. }
  75. $wastageList = StockWastageOrderItemClass::getAllByCondition($where, null, '*', null, true);
  76. $stat = [];
  77. $totalCost = 0;
  78. $totalNum = 0;
  79. if (!empty($wastageList)) {
  80. foreach ($wastageList as $waste) {
  81. $name = $waste->name ?? '';
  82. $shortCover = $waste->cover ?? '';
  83. $cover = imgUtil::groupImg($shortCover);
  84. $num = $waste->itemNum ?? 0;
  85. $cost = $waste->itemCost ?? 0;
  86. $currentCost = bcmul($cost, $num, 2);
  87. $productId = $waste->productId ?? 0;
  88. if (isset($stat[$productId]) == false) {
  89. $stat[$productId]['name'] = $name;
  90. $stat[$productId]['cover'] = $cover;
  91. $stat[$productId]['num'] = 0;
  92. $stat[$productId]['amount'] = 0;
  93. }
  94. $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2);
  95. $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $currentCost, 2);
  96. $totalNum = bcadd($totalNum, $num, 2);
  97. $totalCost = bcadd($totalCost, $currentCost, 2);
  98. }
  99. $stat = array_values($stat);
  100. $stat = arrayUtil::arraySort($stat, 'num');
  101. }
  102. util::success(['stat' => $stat, 'totalNum' => $totalNum, 'totalCost' => $totalCost]);
  103. }
  104. }