RechargeNotify.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace addons\HiGo\common\logic\notify;
  3. use addons\HiGo\common\enums\HiGoEnum;
  4. use addons\HiGo\common\logic\WalletLogic;
  5. use addons\HiGo\common\models\HigoRechargeOrders;
  6. use common\helpers\LockHelper;
  7. use common\traits\ErrorTrait;
  8. use Exception;
  9. class RechargeNotify
  10. {
  11. const LOCK = 'update_user_higo_recharge_order_status';
  12. use ErrorTrait;
  13. public function notify($order_info): bool
  14. {
  15. $lock_key = self::LOCK . $order_info['order_no'];
  16. $identification = uniqid();
  17. try {
  18. //加锁
  19. $res = LockHelper::lock($lock_key, $identification, 100, 100);
  20. if (!$res) throw new Exception('获取锁失败');
  21. $order = HigoRechargeOrders::findOne(['order_no' => $order_info['order_no']]);
  22. $order->is_pay = $order_info['is_pay'];
  23. $order->pay_at = $order_info['updated_at'];
  24. if (!$order->save()) {
  25. throw new Exception(HigoRechargeOrders::getStaticError());
  26. }
  27. $wallet_text = HiGoEnum::getHigoWalletText($order->mall_id);
  28. $hi_bei_name = $wallet_text[HiGoEnum::WALLET_TYPE_HI_BEI];
  29. $desc = $hi_bei_name . '充值';
  30. if ($order_info['is_pay'] == HigoRechargeOrders::IS_PAY) {
  31. $wallet_log = [
  32. 'mall_id' => $order->mall_id,
  33. 'user_id' => $order->user_id,
  34. 'change_num' => $order->hi_bei,
  35. 'desc' => $desc,
  36. 'source_table' => HigoRechargeOrders::tableName(),
  37. 'source_table_id' => $order->id,
  38. 'from_type' => HiGoEnum::FROM_TYPE_USER_RECHARGE,
  39. 'wallet_type' => HiGoEnum::WALLET_TYPE_HI_BEI,
  40. 'is_send' => true
  41. ];
  42. $result = WalletLogic::handleInQueue($wallet_log);
  43. if ($result === false) {
  44. throw new Exception('系统繁忙,请稍后再试');
  45. }
  46. }
  47. //unlock
  48. LockHelper::uLock($lock_key, $identification);
  49. return true;
  50. } catch (Exception $e) {
  51. echo 'Higo充值失败Message: ' . $e->getMessage() . $e->getFile() . $e->getLine();
  52. LockHelper::uLock($lock_key, $identification);
  53. $this->setStaticError($e->getMessage());
  54. return false;
  55. }
  56. }
  57. }