StatCgGhsClass.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace biz\stat\classes;
  3. use biz\base\classes\BaseClass;
  4. class StatCgGhsClass extends BaseClass
  5. {
  6. public static $baseFile = '\biz\stat\models\StatCgGhs';
  7. //花店采购统计 ssh 20220402
  8. public static function hdCgGhsReplace($add, $cgInfo, $amount, $num, $date = null)
  9. {
  10. $sjId = $cgInfo->sjId ?? 0;
  11. $mainId = $cgInfo->mainId ?? 0;
  12. $ghsId = $cgInfo->ghsId ?? 0;
  13. $time = $date == null ? date('Ymd') : $date;
  14. $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'time' => $time], true);
  15. if (empty($stat)) {
  16. $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time], true);
  17. }
  18. $id = $stat->id;
  19. $unique = self::getLockById($id);
  20. if ($add) {
  21. $currentAmount = bcadd($unique->amount, $amount, 2);
  22. $unique->amount = $currentAmount;
  23. } else {
  24. $currentAmount = bcsub($unique->refundAmount, $amount, 2);
  25. $unique->refundAmount = $currentAmount;
  26. }
  27. $unique->num = bcadd($unique->num, $num);
  28. $unique->save();
  29. StatCgGhsMonthClass::hdCgGhsReplace($add, $cgInfo, $amount, $num, $time);
  30. }
  31. //城市批发商采购统计 ssh 2021012
  32. public static function ghsReplace($cgInfo, $date = null)
  33. {
  34. $sjId = $cgInfo->sjId ?? 0;
  35. $mainId = $cgInfo->mainId ?? 0;
  36. $ghsId = $cgInfo->ghsId ?? 0;
  37. $time = $date == null ? date('Ymd') : $date;
  38. $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'time' => $time], true);
  39. if (empty($stat)) {
  40. $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time], true);
  41. }
  42. $id = $stat->id;
  43. $amount = $cgInfo->price ?? 0;
  44. $totalFreight = $cgInfo->totalFreight ?? 0;
  45. if ($totalFreight > 0) {
  46. $amount = bcadd($totalFreight, $amount, 2);
  47. }
  48. $unique = self::getLockById($id);
  49. $num = $cgInfo->itemNum ?? 0;
  50. $currentNum = bcadd($unique->num, $num, 2);
  51. $unique->num = $currentNum;
  52. $currentAmount = bcadd($unique->amount, $amount, 2);
  53. $unique->amount = $currentAmount;
  54. $unique->save();
  55. StatCgGhsMonthClass::ghsReplace($cgInfo, $time);
  56. }
  57. //退款统计
  58. public static function ghsRefundReplace($cgInfo, $date = null)
  59. {
  60. $sjId = $cgInfo->sjId ?? 0;
  61. $shopId = $cgInfo->shopId ?? 0;
  62. $ghsId = $cgInfo->ghsId ?? 0;
  63. $time = $date == null ? date('Ymd') : $date;
  64. $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'ghsId' => $ghsId, 'time' => $time], true);
  65. if (empty($stat)) {
  66. $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time], true);
  67. }
  68. $id = $stat->id;
  69. $unique = self::getLockById($id);
  70. $num = $cgInfo->itemNum ?? 0;
  71. $refundPrice = $cgInfo->refundPrice ?? 0;
  72. $currentRefundNum = bcadd($unique->refundNum, $num, 2);
  73. $currentRefundAmount = bcadd($unique->refundAmount, $refundPrice, 2);
  74. $unique->refundNum = $currentRefundNum;
  75. $unique->refundAmount = $currentRefundAmount;
  76. $unique->save();
  77. StatCgGhsMonthClass::ghsRefundReplace($cgInfo, $time);
  78. }
  79. }