StatCgGhsMonthClass.php 3.9 KB

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