StatItemClass.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 StatItemClass extends BaseClass
  7. {
  8. public static $baseFile = '\biz\stat\models\StatItem';
  9. //预订单到货之后退货数
  10. public static function ghsBookOrderRefundNum($order, $info, $num, $date = null)
  11. {
  12. $sjId = $order->sjId ?? 0;
  13. $shopId = $order->shopId ?? 0;
  14. $productId = $info->productId ?? 0;
  15. $time = $date == null ? date('Ymd') : $date;
  16. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'itemId' => $productId, 'time' => $time], true);
  17. if (empty($stat)) {
  18. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'itemId' => $productId, 'time' => $time], true);
  19. }
  20. $id = $stat->id;
  21. $unique = self::getLockById($id);
  22. $currentNum = bcadd($unique->refundNum, $num, 2);
  23. $unique->refundNum = $currentNum;
  24. $unique->save();
  25. StatItemMonthClass::ghsBookOrderRefundNum($order, $info, $num, $time);
  26. }
  27. //每日花材统计 ssh 2021012
  28. public static function replace($item, $date = null)
  29. {
  30. $sjId = $item['sjId'] ?? 0;
  31. $mainId = $item['mainId'] ?? 0;
  32. $itemId = $item['itemId'] ?? 0;
  33. $time = $date == null ? date('Ymd') : $date;
  34. $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'itemId' => $itemId, 'time' => $time], true);
  35. if (empty($stat)) {
  36. $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'itemId' => $itemId, 'time' => $time], true);
  37. }
  38. $id = $stat->id;
  39. $unique = self::getLockById($id);
  40. $amount = $item['price'] ?? 0;
  41. $num = $item['num'] ?? 0;
  42. $currentNum = bcadd($unique->num, $num, 2);
  43. $unique->num = $currentNum;
  44. $currentAmount = bcadd($unique->amount, $amount, 2);
  45. $unique->amount = $currentAmount;
  46. $unique->save();
  47. StatItemMonthClass::replace($item, $time);
  48. }
  49. //退款花材
  50. public static function refundReplace($item, $date = null)
  51. {
  52. $mainId = $item['mainId'] ?? 0;
  53. $productId = $item['productId'] ?? 0;
  54. $time = $date == null ? date('Ymd') : $date;
  55. $stat = self::getByCondition(['mainId' => $mainId, 'itemId' => $productId, 'time' => $time], true);
  56. if (empty($stat)) {
  57. $stat = self::add(['mainId' => $mainId, 'itemId' => $productId, 'time' => $time], true);
  58. }
  59. $id = $stat->id;
  60. $unique = self::getLockById($id);
  61. $num = $item['itemNum'] ?? 0;
  62. $unitePrice = $item['itemPrice'] ?? 0;
  63. $price = bcmul($unitePrice, $num, 2);
  64. $currentRefundNum = bcadd($unique->refundNum, $num, 2);
  65. $currentRefundAmount = bcadd($unique->refundAmount, $price, 2);
  66. $unique->refundNum = $currentRefundNum;
  67. $unique->refundAmount = $currentRefundAmount;
  68. $unique->save();
  69. StatItemMonthClass::refundReplace($item, $time);
  70. }
  71. }