StatItemMonthClass.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace biz\stat\classes;
  3. use biz\base\classes\BaseClass;
  4. use biz\stat\models\StatCg;
  5. use common\components\util;
  6. class StatItemMonthClass extends BaseClass
  7. {
  8. public static $baseFile = '\biz\stat\models\StatItemMonth';
  9. public static function ghsBookOrderRefundNum($order, $info, $num, $date)
  10. {
  11. if ($date == null) {
  12. $time = date('Ym');
  13. $year = date('Y');
  14. $month = date('m');
  15. } else {
  16. $timestamp = strtotime($date);
  17. $time = date('Ym', $timestamp);
  18. $year = date('Y', $timestamp);
  19. $month = date('m', $timestamp);
  20. }
  21. $sjId = $order->sjId ?? 0;
  22. $shopId = $order->shopId ?? 0;
  23. $productId = $info->productId ?? 0;
  24. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'itemId' => $productId, 'time' => $time], true);
  25. if (empty($stat)) {
  26. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'itemId' => $productId, 'time' => $time, 'year' => $year, 'month' => $month], true);
  27. }
  28. $id = $stat->id;
  29. $unique = self::getLockById($id);
  30. $currentNum = bcadd($unique->refundNum, $num, 2);
  31. $unique->refundNum = $currentNum;
  32. $unique->save();
  33. }
  34. //每月花材统计 ssh 20211012
  35. public static function replace($item, $date = null)
  36. {
  37. if ($date == null) {
  38. $time = date('Ym');
  39. $year = date('Y');
  40. $month = date('m');
  41. } else {
  42. $timestamp = strtotime($date);
  43. $time = date('Ym', $timestamp);
  44. $year = date('Y', $timestamp);
  45. $month = date('m', $timestamp);
  46. }
  47. $sjId = $item['sjId'] ?? 0;
  48. $mainId = $item['mainId'] ?? 0;
  49. $itemId = $item['itemId'] ?? 0;
  50. $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'itemId' => $itemId, 'time' => $time], true);
  51. if (empty($stat)) {
  52. $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'itemId' => $itemId, 'time' => $time, 'year' => $year, 'month' => $month], true);
  53. }
  54. $id = $stat->id;
  55. $unique = self::getLockById($id);
  56. $amount = $item['price'] ?? 0;
  57. $num = $item['num'] ?? 0;
  58. $currentNum = bcadd($unique->num, $num, 2);
  59. $unique->num = $currentNum;
  60. $currentAmount = bcadd($unique->amount, $amount, 2);
  61. $unique->amount = $currentAmount;
  62. $unique->save();
  63. }
  64. //退款花材
  65. public static function refundReplace($item, $date = null)
  66. {
  67. if ($date == null) {
  68. $time = date('Ym');
  69. $year = date('Y');
  70. $month = date('m');
  71. } else {
  72. $timestamp = strtotime($date);
  73. $time = date('Ym', $timestamp);
  74. $year = date('Y', $timestamp);
  75. $month = date('m', $timestamp);
  76. }
  77. $sjId = $item['sjId'] ?? 0;
  78. $shopId = $item['shopId'] ?? 0;
  79. $productId = $item['productId'] ?? 0;
  80. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'itemId' => $productId, 'time' => $time], true);
  81. if (empty($stat)) {
  82. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'itemId' => $productId, 'time' => $time, 'year' => $year, 'month' => $month], true);
  83. }
  84. $id = $stat->id;
  85. $unique = self::getLockById($id);
  86. $num = $item['itemNum'] ?? 0;
  87. $unitePrice = $item['itemPrice'] ?? 0;
  88. $price = bcmul($unitePrice, $num, 2);
  89. $currentRefundNum = bcadd($unique->refundNum, $num, 2);
  90. $currentRefundAmount = bcadd($unique->refundAmount, $price, 2);
  91. $unique->refundNum = $currentRefundNum;
  92. $unique->refundAmount = $currentRefundAmount;
  93. $unique->save();
  94. }
  95. }