| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace biz\renew\classes;
- use biz\base\classes\BaseClass;
- use biz\shop\classes\ShopClass;
- use biz\sj\classes\SjClass;
- use bizHd\saas\classes\ApplyClass;
- use bizHd\shop\classes\MainInviteClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\util;
- use Yii;
- class RenewClass extends BaseClass
- {
- public static $baseFile = '\biz\renew\models\Renew';
- public static function getRenewList($where)
- {
- $data = self::getList('*', $where, 'addTime DESC');
- return $data;
- }
- /**
- * 是否已有 xhRenew 付费成功记录(同一 main/shop 仅首次付费享受邀请减免与佣金)
- */
- public static function hasPaidMemberRenew(int $mainId, int $shopId = 0): bool
- {
- $ptStyle = dict::getDict('ptStyle', 'hd');
- if ($mainId > 0) {
- $row = self::getByCondition(['mainId' => $mainId, 'status' => 1, 'ptStyle' => $ptStyle], false);
- if (!empty($row)) {
- return true;
- }
- }
- if ($shopId > 0) {
- $row = self::getByCondition(['shopId' => $shopId, 'status' => 1, 'ptStyle' => $ptStyle], false);
- return !empty($row);
- }
- return false;
- }
- /**
- * 除当前订单外是否已有付费成功的 xhRenew(回调写佣金时用)
- */
- public static function hasOtherPaidMemberRenew(int $mainId, string $excludeOrderSn = ''): bool
- {
- if ($mainId <= 0) {
- return false;
- }
- $ptStyle = dict::getDict('ptStyle', 'hd');
- $list = self::getAllByCondition(['mainId' => $mainId, 'status' => 1, 'ptStyle' => $ptStyle]);
- if (empty($list)) {
- return false;
- }
- foreach ($list as $item) {
- $sn = is_array($item) ? (string) ($item['orderSn'] ?? '') : (string) ($item->orderSn ?? '');
- if ($excludeOrderSn !== '' && $sn !== $excludeOrderSn) {
- return true;
- }
- }
- return false;
- }
- public static function thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId)
- {
- $renew = self::getByCondition(['orderSn' => $orderSn], true);
- if (empty($renew)) {
- $msg = "没有找到续费订单 orderSn:{$orderSn}";
- noticeUtil::push($msg, '15280215347');
- util::fail($msg);
- }
- if ($renew->actPrice != $totalFee) {
- $msg = "续费订单金额与回调通知金额不一致 orderSn:{$orderSn} {$renew->actPrice} {$totalFee}";
- noticeUtil::push($msg, '15280215347');
- util::fail($msg);
- }
- if ($renew->status == 1) {
- $msg = '续费订单已付款,重复通知 orderSn:' . $orderSn;
- noticeUtil::push($msg, '15280215347');
- util::fail($msg);
- }
- $attachParams = [];
- if (!empty($attach)) {
- parse_str($attach, $attachParams);
- }
- $applyId = (int) ($attachParams['applyId'] ?? 0);
- $isRegisterMember = $applyId > 0;
- $shopId = $renew->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- $msg = '续费订单没有找到门店 orderSn:' . $orderSn;
- noticeUtil::push($msg, '15280215347');
- util::fail($msg);
- }
- $mainId = $shop->mainId ?? 0;
- $before = $shop->deadline ?? '';
- $beforeTime = strtotime($before);
- if ($renew->type == 2) {
- //购买设备,不需要有操作
- } else {
- //每次续费一年
- $time = $beforeTime + 31536000;
- $newDate = date("Y-m-d H:i:s", $time);
- $renew->deadline = $newDate;
- $renew->beforeDeadline = $before;
- $shopList = ShopClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
- if (!empty($shopList)) {
- foreach ($shopList as $myShop) {
- $myShop->beforeDeadline = $before;
- $myShop->deadline = $newDate;
- $myShop->hasRenew = 1;
- $myShop->needRenew = 0;
- $myShop->save();
- }
- }
- }
- $renew->returnCode = $transactionId;
- $renew->payTime = date("Y-m-d H:i:s");
- $renew->status = 1;
- $renew->save();
- if ($isRegisterMember && !self::hasOtherPaidMemberRenew((int) $mainId, (string) $orderSn)) {
- $apply = ApplyClass::getById($applyId);
- if (!empty($apply)) {
- try {
- MainInviteClass::grantInviterCommission(
- $apply,
- (int) $mainId,
- trim((string) ($apply['name'] ?? '')),
- trim((string) ($apply['mobile'] ?? '')),
- round((float) ($renew->prePrice ?? 0), 2),
- round((float) ($renew->actPrice ?? 0), 2)
- );
- } catch (\Throwable $e) {
- $msg = '邀请发佣失败 orderSn:' . $orderSn . ' ' . $e->getMessage();
- noticeUtil::push($msg, '15280215347');
- }
- }
- }
- return true;
- }
- }
|