StatKhCgClass.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace biz\stat\classes;
  3. use biz\base\classes\BaseClass;
  4. class StatKhCgClass extends BaseClass
  5. {
  6. public static $baseFile = '\biz\stat\models\StatKhCg';
  7. //预订单数量减少
  8. public static function ghsBookOrderRefundNum($order, $num, $date = null)
  9. {
  10. $sjId = $order->sjId ?? 0;
  11. $shopId = $order->shopId ?? 0;
  12. $customId = $order->customId ?? 0;
  13. $time = $date == null ? date('Ymd') : $date;
  14. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
  15. if (empty($stat)) {
  16. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
  17. }
  18. $id = $stat->id;
  19. $unique = self::getLockById($id);
  20. $currentNum = bcadd($unique->refundNum, $num, 2);
  21. $unique->refundNum = $currentNum;
  22. $unique->save();
  23. StatKhCgMonthClass::ghsBookOrderRefundNum($order, $num, $time);
  24. }
  25. //供货商预订单退款,客户采购金额减少
  26. public static function ghsBookOrderChange($add, $order, $amount, $date = null)
  27. {
  28. $sjId = $order->sjId ?? 0;
  29. $shopId = $order->shopId ?? 0;
  30. $customId = $order->customId ?? 0;
  31. $time = $date == null ? date('Ymd') : $date;
  32. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
  33. if (empty($stat)) {
  34. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
  35. }
  36. $id = $stat->id;
  37. $unique = self::getLockById($id);
  38. if ($add == true) {
  39. $currentAmount = bcadd($unique->amount, $amount, 2);
  40. $unique->amount = $currentAmount;
  41. } else {
  42. $currentAmount = bcadd($unique->refundAmount, $amount, 2);
  43. $unique->refundAmount = $currentAmount;
  44. }
  45. $unique->save();
  46. StatKhCgMonthClass::ghsBookOrderChange($add, $order, $amount, $time);
  47. }
  48. //客户采购统计 ssh 2021012
  49. public static function replace($order, $amount, $date = null)
  50. {
  51. $sjId = $order->sjId ?? 0;
  52. $shopId = $order->shopId ?? 0;
  53. $customId = $order->customId ?? 0;
  54. $time = $date == null ? date('Ymd') : $date;
  55. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
  56. if (empty($stat)) {
  57. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
  58. }
  59. $id = $stat->id;
  60. $unique = self::getLockById($id);
  61. $num = $order->itemNum ?? 0;
  62. $currentNum = bcadd($unique->num, $num, 2);
  63. $unique->num = $currentNum;
  64. $currentAmount = bcadd($unique->amount, $amount, 2);
  65. $unique->amount = $currentAmount;
  66. $unique->save();
  67. StatKhCgMonthClass::replace($order, $amount, $time);
  68. }
  69. //客户退款统计
  70. public static function refundReplace($order, $date = null)
  71. {
  72. $sjId = $order->sjId ?? 0;
  73. $shopId = $order->shopId ?? 0;
  74. $customId = $order->customId ?? 0;
  75. $time = $date == null ? date('Ymd') : $date;
  76. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'customId' => $customId, 'time' => $time], true);
  77. if (empty($stat)) {
  78. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'time' => $time], true);
  79. }
  80. $id = $stat->id;
  81. $unique = self::getLockById($id);
  82. $num = $order->itemNum ?? 0;
  83. $refundPrice = $order->refundPrice ?? 0;
  84. $currentRefundNum = bcadd($unique->refundNum, $num, 2);
  85. $currentRefundAmount = bcadd($unique->refundAmount, $refundPrice, 2);
  86. $unique->refundNum = $currentRefundNum;
  87. $unique->refundAmount = $currentRefundAmount;
  88. $unique->save();
  89. StatKhCgMonthClass::refundReplace($order, $time);
  90. }
  91. }