| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace biz\recharge\classes;
- use biz\base\classes\BaseClass;
- use biz\ghs\classes\GhsClass;
- use biz\shop\classes\ShopCouponClass;
- use biz\sj\classes\SjClass;
- use bizHd\merchant\classes\ShopClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\orderSn;
- class RechargeClass extends BaseClass
- {
- public static $baseFile = '\biz\recharge\models\Recharge';
- const PAY_STATUS_UN_PAY = 1;
- const PAY_STATUS_HAS_PAY = 2;
- //充值记录 ssh 2021.2.21
- public static function getRechargeList($where)
- {
- $data = self::getList('*', $where, 'addTime DESC');
- return $data;
- }
- //创建订单 ssh 2021.2.21
- public static function addOrder($data, $returnObj = false)
- {
- $data['orderSn'] = orderSn::getRechargeSn();
- return self::add($data, $returnObj);
- }
- //处理充值流程 ssh 2021.2.21
- public static function complete($recharge, $payWay, $rechargeRenew = 0, $ghsId = 0)
- {
- $recharge->payWay = $payWay;
- $recharge->payStatus = self::PAY_STATUS_HAS_PAY;
- $orderSn = $recharge->orderSn;
- $shopId = $recharge->shopId;
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- noticeUtil::push("充值支付回调通知,没有找到门店 orderSn:{$orderSn}");
- return false;
- }
- $amount = $recharge->amount;
- $recharge->save();
- if (!empty($ghsId)) {
- $shop->fixGhsId = $ghsId;
- $shop->save();
- }
- //门店和平台余额增加
- $tx = dict::getDict('yeTx', 'canNot');
- $capitalType = dict::getDict('capitalType', 'xhRecharge');
- //余额是否指定门店使用
- $fix = false;
- //免费续期功能暂时关闭
- // if ($rechargeRenew == 1) {
- // $sjId = $recharge->sjId;
- // SjClass::renewOneYear($sjId, 2, ['amount' => $recharge->amount, 'orderSn' => $orderSn]);
- // $fix = true;
- //
- // if (!empty($ghsId)) {
- // $ghs = GhsClass::getById($ghsId);
- // $ghsName = $ghs['name'] ?? '';
- // $customName = $shop->shopName ?? '';
- // noticeUtil::push("客户[{$customName}]在供货商[{$ghsName}]充值花款{$recharge->amount}元,免费续期一年", '15280215347');
- // }
- // }
- //充值发红包
- if ($recharge->sjStyle == SjClass::STYLE_RETAIL && !empty($recharge->ghsId)) {
- ShopCouponClass::rechargeGiveCoupon($recharge);
- }
- \biz\shop\classes\ShopClass::rechargeAddBalance($shop, $amount, $recharge, $tx, $capitalType, $fix);
- }
- //第三支付后流程 ssh 2021.4.27
- public static function thirdPay($payWay, $orderSn, $totalFee, $attach)
- {
- $recharge = RechargeClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($recharge)) {
- noticeUtil::push('充值付款成功,收到回调,但没有找到充值记录,orderSn:' . $orderSn, '15280215347');
- return false;
- }
- if ($totalFee != $recharge->amount) {
- noticeUtil::push("充值付款成功,收到回调,但金额不一致 {$totalFee} {$recharge->amount},orderSn:" . $orderSn, '15280215347');
- return false;
- }
- if ($recharge->payStatus == RechargeClass::PAY_STATUS_HAS_PAY) {
- noticeUtil::push("充值付款成功,收到回调,但订单是已经支付过了,orderSn:" . $orderSn, '15280215347');
- return false;
- }
- //临时解决微信一秒内通知二次问题
- $id = $recharge->id;
- $recharge = RechargeClass::getLockById($id);
- parse_str($attach);
- //是否充值免费续期
- $rechargeRenew = isset($rechargeRenew) ? $rechargeRenew : 0;
- $ghsId = isset($ghsId) ? $ghsId : 0;
- //处理充值成功的流程
- self::complete($recharge, $payWay, $rechargeRenew, $ghsId);
- return $recharge;
- }
- }
|