| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace addons\HiGo\common\logic\notify;
- use addons\HiGo\common\enums\HiGoEnum;
- use addons\HiGo\common\logic\WalletLogic;
- use addons\HiGo\common\models\HigoRechargeOrders;
- use common\helpers\LockHelper;
- use common\traits\ErrorTrait;
- use Exception;
- class RechargeNotify
- {
- const LOCK = 'update_user_higo_recharge_order_status';
- use ErrorTrait;
- public function notify($order_info): bool
- {
- $lock_key = self::LOCK . $order_info['order_no'];
- $identification = uniqid();
- try {
- //加锁
- $res = LockHelper::lock($lock_key, $identification, 100, 100);
- if (!$res) throw new Exception('获取锁失败');
- $order = HigoRechargeOrders::findOne(['order_no' => $order_info['order_no']]);
- $order->is_pay = $order_info['is_pay'];
- $order->pay_at = $order_info['updated_at'];
- if (!$order->save()) {
- throw new Exception(HigoRechargeOrders::getStaticError());
- }
- $wallet_text = HiGoEnum::getHigoWalletText($order->mall_id);
- $hi_bei_name = $wallet_text[HiGoEnum::WALLET_TYPE_HI_BEI];
- $desc = $hi_bei_name . '充值';
- if ($order_info['is_pay'] == HigoRechargeOrders::IS_PAY) {
- $wallet_log = [
- 'mall_id' => $order->mall_id,
- 'user_id' => $order->user_id,
- 'change_num' => $order->hi_bei,
- 'desc' => $desc,
- 'source_table' => HigoRechargeOrders::tableName(),
- 'source_table_id' => $order->id,
- 'from_type' => HiGoEnum::FROM_TYPE_USER_RECHARGE,
- 'wallet_type' => HiGoEnum::WALLET_TYPE_HI_BEI,
- 'is_send' => true
- ];
- $result = WalletLogic::handleInQueue($wallet_log);
- if ($result === false) {
- throw new Exception('系统繁忙,请稍后再试');
- }
- }
- //unlock
- LockHelper::uLock($lock_key, $identification);
- return true;
- } catch (Exception $e) {
- echo 'Higo充值失败Message: ' . $e->getMessage() . $e->getFile() . $e->getLine();
- LockHelper::uLock($lock_key, $identification);
- $this->setStaticError($e->getMessage());
- return false;
- }
- }
- }
|