RenewClass.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace biz\renew\classes;
  3. use biz\base\classes\BaseClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\sj\classes\SjClass;
  6. use bizHd\saas\classes\ApplyClass;
  7. use bizHd\shop\classes\MainInviteClass;
  8. use common\components\noticeUtil;
  9. use common\components\util;
  10. use Yii;
  11. class RenewClass extends BaseClass
  12. {
  13. public static $baseFile = '\biz\renew\models\Renew';
  14. public static function getRenewList($where)
  15. {
  16. $data = self::getList('*', $where, 'addTime DESC');
  17. return $data;
  18. }
  19. public static function thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId)
  20. {
  21. $renew = self::getByCondition(['orderSn' => $orderSn], true);
  22. if (empty($renew)) {
  23. $msg = "没有找到续费订单 orderSn:{$orderSn}";
  24. noticeUtil::push($msg, '15280215347');
  25. util::fail($msg);
  26. }
  27. if ($renew->actPrice != $totalFee) {
  28. $msg = "续费订单金额与回调通知金额不一致 orderSn:{$orderSn} {$renew->actPrice} {$totalFee}";
  29. noticeUtil::push($msg, '15280215347');
  30. util::fail($msg);
  31. }
  32. if ($renew->status == 1) {
  33. $msg = '续费订单已付款,重复通知 orderSn:' . $orderSn;
  34. noticeUtil::push($msg, '15280215347');
  35. util::fail($msg);
  36. }
  37. $attachParams = [];
  38. if (!empty($attach)) {
  39. parse_str($attach, $attachParams);
  40. }
  41. $applyId = (int) ($attachParams['applyId'] ?? 0);
  42. $isRegisterMember = $applyId > 0;
  43. $shopId = $renew->shopId ?? 0;
  44. $shop = ShopClass::getById($shopId, true);
  45. if (empty($shop)) {
  46. $msg = '续费订单没有找到门店 orderSn:' . $orderSn;
  47. noticeUtil::push($msg, '15280215347');
  48. util::fail($msg);
  49. }
  50. $mainId = $shop->mainId ?? 0;
  51. $before = $shop->deadline ?? '';
  52. $beforeTime = strtotime($before);
  53. if ($renew->type == 2) {
  54. //购买设备,不需要有操作
  55. } else {
  56. //每次续费一年
  57. $time = $beforeTime + 31536000;
  58. $newDate = date("Y-m-d H:i:s", $time);
  59. $renew->deadline = $newDate;
  60. $renew->beforeDeadline = $before;
  61. $shopList = ShopClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  62. if (!empty($shopList)) {
  63. foreach ($shopList as $myShop) {
  64. $myShop->beforeDeadline = $before;
  65. $myShop->deadline = $newDate;
  66. $myShop->hasRenew = 1;
  67. $myShop->needRenew = 0;
  68. $myShop->save();
  69. }
  70. }
  71. }
  72. $renew->returnCode = $transactionId;
  73. $renew->payTime = date("Y-m-d H:i:s");
  74. $renew->status = 1;
  75. $renew->save();
  76. if ($isRegisterMember) {
  77. $apply = ApplyClass::getById($applyId);
  78. if (!empty($apply)) {
  79. MainInviteClass::grantInviterCommission(
  80. $apply,
  81. (int) $mainId,
  82. trim((string) ($apply['name'] ?? '')),
  83. trim((string) ($apply['mobile'] ?? '')),
  84. round((float) ($renew->prePrice ?? 0), 2),
  85. round((float) ($renew->actPrice ?? 0), 2)
  86. );
  87. }
  88. }
  89. return true;
  90. }
  91. }