StatKhCgMonthClass.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 StatKhCgMonthClass extends BaseClass
  7. {
  8. public static $baseFile = '\biz\stat\models\StatKhCgMonth';
  9. public static function ghsBookOrderRefundNum($order, $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. $customId = $order->customId ?? 0;
  24. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
  25. if (empty($stat)) {
  26. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, '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. $unique->save();
  34. }
  35. //供货商预订单退款,客户采购金额减少
  36. public static function ghsBookOrderChange($add, $order, $amount, $date = null)
  37. {
  38. if ($date == null) {
  39. $time = date('Ym');
  40. $year = date('Y');
  41. $month = date('m');
  42. } else {
  43. $timestamp = strtotime($date);
  44. $time = date('Ym', $timestamp);
  45. $year = date('Y', $timestamp);
  46. $month = date('m', $timestamp);
  47. }
  48. $sjId = $order->sjId ?? 0;
  49. $shopId = $order->shopId ?? 0;
  50. $customId = $order->customId ?? 0;
  51. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
  52. if (empty($stat)) {
  53. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time, 'year' => $year, 'month' => $month], true);
  54. }
  55. $id = $stat->id;
  56. $unique = self::getLockById($id);
  57. if ($add == true) {
  58. $currentAmount = bcadd($unique->amount, $amount, 2);
  59. $unique->amount = $currentAmount;
  60. } else {
  61. $currentAmount = bcadd($unique->refundAmount, $amount, 2);
  62. $unique->refundAmount = $currentAmount;
  63. }
  64. $unique->save();
  65. }
  66. //每月客户采购统计 ssh 20211012
  67. public static function replace($order, $amount, $date = null)
  68. {
  69. if ($date == null) {
  70. $time = date('Ym');
  71. $year = date('Y');
  72. $month = date('m');
  73. } else {
  74. $timestamp = strtotime($date);
  75. $time = date('Ym', $timestamp);
  76. $year = date('Y', $timestamp);
  77. $month = date('m', $timestamp);
  78. }
  79. $sjId = $order->sjId ?? 0;
  80. $shopId = $order->shopId ?? 0;
  81. $customId = $order->customId ?? 0;
  82. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
  83. if (empty($stat)) {
  84. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time, 'year' => $year, 'month' => $month], true);
  85. }
  86. $id = $stat->id;
  87. $unique = self::getLockById($id);
  88. $num = $order->itemNum ?? 0;
  89. $currentNum = bcadd($unique->num, $num, 2);
  90. $unique->num = $currentNum;
  91. $currentAmount = bcadd($unique->amount, $amount, 2);
  92. $unique->amount = $currentAmount;
  93. $unique->save();
  94. }
  95. //客户退款
  96. public static function refundReplace($order, $date = null)
  97. {
  98. if ($date == null) {
  99. $time = date('Ym');
  100. $year = date('Y');
  101. $month = date('m');
  102. } else {
  103. $timestamp = strtotime($date);
  104. $time = date('Ym', $timestamp);
  105. $year = date('Y', $timestamp);
  106. $month = date('m', $timestamp);
  107. }
  108. $sjId = $order['sjId'] ?? 0;
  109. $shopId = $order['shopId'] ?? 0;
  110. $customId = $order['customId'] ?? 0;
  111. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
  112. if (empty($stat)) {
  113. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time, 'year' => $year, 'month' => $month], true);
  114. }
  115. $id = $stat->id;
  116. $unique = self::getLockById($id);
  117. $num = $order->itemNum ?? 0;
  118. $currentRefundNum = bcadd($unique->refundNum, $num, 2);
  119. $refundPrice = $order->refundPrice ?? 0;
  120. $currentRefundAmount = bcadd($unique->refundAmount, $refundPrice, 2);
  121. $unique->refundNum = $currentRefundNum;
  122. $unique->refundAmount = $currentRefundAmount;
  123. $unique->save();
  124. }
  125. }