StatKindController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\goods\classes\KindClass;
  4. use bizHd\item\classes\ItemClass;
  5. use bizHd\order\classes\OrderClass;
  6. use bizHd\order\classes\OrderGoodsClass;
  7. use bizHd\part\classes\PartClass;
  8. use bizHd\part\classes\PartItemClass;
  9. use bizHd\work\classes\WorkClass;
  10. use common\components\dateUtil;
  11. use Yii;
  12. use common\components\util;
  13. class StatKindController extends BaseController
  14. {
  15. //各渠道收入 ssh 20220711
  16. public function actionProfile()
  17. {
  18. $get = Yii::$app->request->get();
  19. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  20. $startTime = $get['startTime'] ?? '';
  21. $endTime = $get['endTime'] ?? '';
  22. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  23. $start = $period['startTime'];
  24. $end = $period['endTime'];
  25. $currentStartDate = date('Y-m-d', strtotime($start));
  26. $currentEndDate = date('Y-m-d', strtotime($end));
  27. $currentStartTime = $currentStartDate . ' 00:00:00';
  28. $currentEndTime = $currentEndDate . ' 23:59:59';
  29. $mainId = $this->mainId;
  30. $kindList = KindClass::getAllByCondition(['mainId' => $mainId, 'flower' => 1, 'delStatus' => 0, 'status' => 1], null, '*', 'id');
  31. $kindStat = [];
  32. $where = ['mainId' => $mainId, 'status' => 1];
  33. $where['finishTime'] = ['between', [$currentStartTime, $currentEndTime]];
  34. $workList = WorkClass::getAllByCondition($where, null, '*', null, true);
  35. if (!empty($workList)) {
  36. foreach ($workList as $work) {
  37. $kindId = $work->kindId ?? 0;
  38. if (empty($kindId)) {
  39. continue;
  40. }
  41. $kindName = $kindList[$kindId]['name'] ?? '';
  42. $num = $work->num ?? 0;
  43. $flowerNum = $work->flowerNum ?? 0;
  44. $totalFlowerNum = bcmul($flowerNum, $num);
  45. if (isset($kindStat[$kindId]['makeNum'])) {
  46. $kindStat[$kindId]['makeNum'] = bcadd($kindStat[$kindId]['makeNum'], $num);
  47. $kindStat[$kindId]['flowerNum'] = bcadd($totalFlowerNum, $kindStat[$kindId]['flowerNum']);
  48. } else {
  49. $kindStat[$kindId]['makeNum'] = $num;
  50. $kindStat[$kindId]['flowerNum'] = $totalFlowerNum;
  51. $kindStat[$kindId]['kindName'] = $kindName;
  52. }
  53. }
  54. }
  55. $where = ['mainId' => $mainId, 'payStatus' => 1, 'payTime' => ['between', [$currentStartTime, $currentEndTime]]];
  56. $orderList = OrderClass::getAllByCondition($where, null, '*', null, true);
  57. if (!empty($orderList)) {
  58. foreach ($orderList as $order) {
  59. $orderSn = $order->orderSn ?? '';
  60. $sonList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  61. if (!empty($sonList)) {
  62. foreach ($sonList as $son) {
  63. $flower = $son->flower ?? 0;
  64. if ($flower == 0) {
  65. continue;
  66. }
  67. $kindId = $son->kindId ?? 0;
  68. if (empty($kindId)) {
  69. continue;
  70. }
  71. $num = $son->num ?? 0;
  72. $kindName = $kindList[$kindId]['name'] ?? '';
  73. if (isset($kindStat[$kindId]['saleNum'])) {
  74. $kindStat[$kindId]['saleNum'] = bcadd($kindStat[$kindId]['saleNum'], $num);
  75. } else {
  76. $kindStat[$kindId]['saleNum'] = $num;
  77. $kindStat[$kindId]['kindName'] = $kindName;
  78. }
  79. }
  80. }
  81. }
  82. }
  83. $itemList = ItemClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, 'id,name,mainId,delStatus,ratio', 'id');
  84. $partStat = [];
  85. $partList = PartClass::getAllByCondition(['mainId' => $mainId, 'addTime' => ['between', [$currentStartTime, $currentEndTime]]], null, '*', null, true);
  86. if (!empty($partList)) {
  87. foreach ($partList as $part) {
  88. $orderSn = $part->orderSn ?? '';
  89. $partItemList = PartItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  90. if (!empty($partItemList)) {
  91. foreach ($partItemList as $pItem) {
  92. $productId = $pItem->productId ?? 0;
  93. $ratio = $itemList[$productId]['ratio'] ?? 10;
  94. $ratioType = $itemList[$productId]['ratioType'] ?? 0;
  95. if ($ratioType == 1) {
  96. continue;
  97. }
  98. $name = $itemList[$productId]['name'] ?? '';
  99. $num = $pItem->itemNum ?? 0;
  100. $smallNum = bcmul($ratio, $num);
  101. if (isset($partStat[$productId]['num'])) {
  102. $partStat[$productId]['num'] = bcadd($partStat[$productId]['num'], $num);
  103. $partStat[$productId]['smallNum'] = bcadd($partStat[$productId]['smallNum'], $smallNum);
  104. } else {
  105. $partStat[$productId]['num'] = $num;
  106. $partStat[$productId]['smallNum'] = $smallNum;
  107. $partStat[$productId]['name'] = $name;
  108. }
  109. }
  110. }
  111. }
  112. }
  113. util::success(['kindStat' => $kindStat, 'partStat' => $partStat]);
  114. }
  115. }