StatKindController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\goods\classes\KindClass;
  4. use bizHd\goods\classes\PlantCgClass;
  5. use bizHd\goods\classes\PlantCgItemClass;
  6. use bizHd\item\classes\ItemClass;
  7. use bizHd\order\classes\OrderClass;
  8. use bizHd\order\classes\OrderGoodsClass;
  9. use bizHd\part\classes\PartClass;
  10. use bizHd\part\classes\PartItemClass;
  11. use bizHd\work\classes\WorkClass;
  12. use common\components\dateUtil;
  13. use Yii;
  14. use common\components\util;
  15. class StatKindController extends BaseController
  16. {
  17. //花束相关统计 ssh 20230320
  18. public function actionProfile()
  19. {
  20. $get = Yii::$app->request->get();
  21. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  22. $startTime = $get['startTime'] ?? '';
  23. $endTime = $get['endTime'] ?? '';
  24. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  25. $start = $period['startTime'];
  26. $end = $period['endTime'];
  27. $currentStartDate = date('Y-m-d', strtotime($start));
  28. $currentEndDate = date('Y-m-d', strtotime($end));
  29. $currentStartTime = $currentStartDate . ' 00:00:00';
  30. $currentEndTime = $currentEndDate . ' 23:59:59';
  31. $mainId = $this->mainId;
  32. $kindList = KindClass::getAllByCondition(['mainId' => $mainId, 'flower' => 1], null, '*', 'id');
  33. $kindStat = [];
  34. $workTotalUseSmallNum = 0;
  35. $where = ['mainId' => $mainId, 'status' => 1];
  36. $where['finishTime'] = ['between', [$currentStartTime, $currentEndTime]];
  37. $workList = WorkClass::getAllByCondition($where, null, '*', null, true);
  38. if (!empty($workList)) {
  39. foreach ($workList as $work) {
  40. $kindId = $work->kindId ?? 0;
  41. if (empty($kindId)) {
  42. continue;
  43. }
  44. $kindName = $kindList[$kindId]['name'] ?? '';
  45. $num = $work->num ?? 0;
  46. $smallNumber = $work->flowerNum ?? 0;
  47. $totalMakeSmallNum = bcmul($smallNumber, $num);
  48. $workTotalUseSmallNum = bcadd($workTotalUseSmallNum, $totalMakeSmallNum);
  49. if (isset($kindStat[$kindId]['makeNum'])) {
  50. $kindStat[$kindId]['makeNum'] = bcadd($kindStat[$kindId]['makeNum'], $num);
  51. $kindStat[$kindId]['makeSmallNum'] = bcadd($totalMakeSmallNum, $kindStat[$kindId]['makeSmallNum']);
  52. } else {
  53. $kindStat[$kindId]['makeNum'] = $num;
  54. $kindStat[$kindId]['makeSmallNum'] = $totalMakeSmallNum;
  55. $kindStat[$kindId]['kindName'] = $kindName;
  56. if (isset($kindStat[$kindId]['saleNum']) == false) {
  57. $kindStat[$kindId]['saleNum'] = 0;
  58. }
  59. }
  60. }
  61. }
  62. $where = ['mainId' => $mainId, 'payStatus' => 1, 'payTime' => ['between', [$currentStartTime, $currentEndTime]]];
  63. $orderList = OrderClass::getAllByCondition($where, null, '*', null, true);
  64. if (!empty($orderList)) {
  65. foreach ($orderList as $order) {
  66. $orderSn = $order->orderSn ?? '';
  67. $sonList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  68. if (!empty($sonList)) {
  69. foreach ($sonList as $son) {
  70. $flower = $son->flower ?? 0;
  71. if ($flower == 0) {
  72. continue;
  73. }
  74. $kindId = $son->kindId ?? 0;
  75. if (empty($kindId)) {
  76. continue;
  77. }
  78. $num = $son->num ?? 0;
  79. $kindName = $kindList[$kindId]['name'] ?? '';
  80. if (isset($kindStat[$kindId]['saleNum'])) {
  81. $kindStat[$kindId]['saleNum'] = bcadd($kindStat[$kindId]['saleNum'], $num);
  82. } else {
  83. $kindStat[$kindId]['saleNum'] = $num;
  84. $kindStat[$kindId]['kindName'] = $kindName;
  85. if (isset($kindStat[$kindId]['makeNum']) == false) {
  86. $kindStat[$kindId]['makeNum'] = 0;
  87. $kindStat[$kindId]['makeSmallNum'] = 0;
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. $itemList = ItemClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, 'id,name,mainId,delStatus,ratio', 'id');
  95. $partStat = [];
  96. $partTotalSmallNum = 0;
  97. $partTotalNum = 0;
  98. $partList = PartClass::getAllByCondition(['mainId' => $mainId, 'addTime' => ['between', [$currentStartTime, $currentEndTime]]], null, '*', null, true);
  99. if (!empty($partList)) {
  100. foreach ($partList as $part) {
  101. $orderSn = $part->orderSn ?? '';
  102. $partItemList = PartItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  103. if (!empty($partItemList)) {
  104. foreach ($partItemList as $pItem) {
  105. $productId = $pItem->productId ?? 0;
  106. $ratio = $itemList[$productId]['ratio'] ?? 10;
  107. $ratioType = $itemList[$productId]['ratioType'] ?? 0;
  108. if ($ratioType == 1) {
  109. continue;
  110. }
  111. $name = $itemList[$productId]['name'] ?? '';
  112. $num = $pItem->itemNum ?? 0;
  113. $num = floatval($num);
  114. $partTotalNum = bcadd($partTotalNum, $num);
  115. $smallNum = bcmul($ratio, $num);
  116. $partTotalSmallNum = bcadd($partTotalSmallNum, $smallNum);
  117. if (isset($partStat[$productId]['num'])) {
  118. $partStat[$productId]['num'] = bcadd($partStat[$productId]['num'], $num);
  119. $partStat[$productId]['smallNum'] = bcadd($partStat[$productId]['smallNum'], $smallNum);
  120. } else {
  121. $partStat[$productId]['num'] = $num;
  122. $partStat[$productId]['smallNum'] = $smallNum;
  123. $partStat[$productId]['name'] = $name;
  124. }
  125. }
  126. }
  127. }
  128. }
  129. util::success(['kindStat' => $kindStat, 'partStat' => $partStat, 'workTotalUseSmallNum' => $workTotalUseSmallNum, 'partTotalSmallNum' => $partTotalSmallNum, 'partTotalNum' => $partTotalNum]);
  130. }
  131. //绿植相关的统计 ssh 20230320
  132. public function actionLzProfile()
  133. {
  134. $get = Yii::$app->request->get();
  135. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  136. $startTime = $get['startTime'] ?? '';
  137. $endTime = $get['endTime'] ?? '';
  138. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  139. $start = $period['startTime'];
  140. $end = $period['endTime'];
  141. $currentStartDate = date('Y-m-d', strtotime($start));
  142. $currentEndDate = date('Y-m-d', strtotime($end));
  143. $currentStartTime = $currentStartDate . ' 00:00:00';
  144. $currentEndTime = $currentEndDate . ' 23:59:59';
  145. $mainId = $this->mainId;
  146. $kindList = KindClass::getAllByCondition(['mainId' => $mainId, 'flower' => 0], null, '*', 'id');
  147. $kindStat = [];
  148. $where = ['mainId' => $mainId, 'status' => 3];
  149. $where['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
  150. $lzList = PlantCgClass::getAllByCondition($where, null, '*', null, true);
  151. if (!empty($lzList)) {
  152. foreach ($lzList as $lz) {
  153. $orderSn = $lz->orderSn ?? '';
  154. $lzItemList = PlantCgItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  155. if (!empty($lzItemList)) {
  156. foreach ($lzItemList as $lzItem) {
  157. $kindId = $lzItem->kindId ?? 0;
  158. if (empty($kindId)) {
  159. continue;
  160. }
  161. $num = $lzItem->num ?? 0;
  162. $kindName = $kindList[$kindId]['name'] ?? '';
  163. if (isset($kindStat[$kindId]['cgNum'])) {
  164. $kindStat[$kindId]['cgNum'] = bcadd($kindStat[$kindId]['cgNum'], $num);
  165. } else {
  166. $kindStat[$kindId]['cgNum'] = $num;
  167. $kindStat[$kindId]['name'] = $kindName;
  168. if (isset($kindStat[$kindId]['saleNum']) == false) {
  169. $kindStat[$kindId]['saleNum'] = 0;
  170. }
  171. }
  172. }
  173. }
  174. }
  175. }
  176. $where = ['mainId' => $mainId, 'payStatus' => 1, 'payTime' => ['between', [$currentStartTime, $currentEndTime]]];
  177. $orderList = OrderClass::getAllByCondition($where, null, '*', null, true);
  178. if (!empty($orderList)) {
  179. foreach ($orderList as $order) {
  180. $orderSn = $order->orderSn ?? '';
  181. $sonList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  182. if (!empty($sonList)) {
  183. foreach ($sonList as $son) {
  184. $flower = $son->flower ?? 0;
  185. if ($flower == 1) {
  186. continue;
  187. }
  188. $kindId = $son->kindId ?? 0;
  189. if (empty($kindId)) {
  190. continue;
  191. }
  192. $num = $son->num ?? 0;
  193. $kindName = $kindList[$kindId]['name'] ?? '';
  194. if (isset($kindStat[$kindId]['saleNum'])) {
  195. $kindStat[$kindId]['saleNum'] = bcadd($kindStat[$kindId]['saleNum'], $num);
  196. } else {
  197. $kindStat[$kindId]['saleNum'] = $num;
  198. $kindStat[$kindId]['kindName'] = $kindName;
  199. if (isset($kindStat[$kindId]['cgNum']) == false) {
  200. $kindStat[$kindId]['cgNum'] = 0;
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. util::success(['kindStat' => $kindStat]);
  208. }
  209. }