RechargeOrder.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\Log;
  4. class RechargeOrder extends Model
  5. {
  6. protected $guarded = [];
  7. const NO_TAG = 'C';
  8. const STATUS_OK = 1;
  9. const STATUS_PAUSE = 0;
  10. public static $statusMaps = [
  11. self::STATUS_OK => '正常',
  12. self::STATUS_PAUSE => '暂停'
  13. ];
  14. const PAY_STATUS_OK = 1;
  15. const PAY_STATUS_NO = 0;
  16. public static $payStatusMaps = [
  17. self::PAY_STATUS_NO => '已支付',
  18. self::PAY_STATUS_OK => '未支付'
  19. ];
  20. const PAY_TYPE_NO = 0;
  21. const PAY_TYPE_WECHAT = 1;
  22. const PAY_TYPE_SYSTERM = 2;
  23. const PAY_TYPE_ALIPAYMINI = 3;
  24. public static $payTypeMaps = [
  25. self::PAY_TYPE_NO => '待支付',
  26. self::PAY_TYPE_WECHAT => '微信支付',
  27. self::PAY_TYPE_SYSTERM => '系统赠送',
  28. self::PAY_TYPE_ALIPAYMINI => '支付宝支付',
  29. ];
  30. /**
  31. * 生成订单号
  32. * @return bool|string
  33. * User: Mead
  34. */
  35. public static function makeNo($tag = null)
  36. {
  37. // 订单流水号前缀
  38. $prefix = $tag . self::NO_TAG . date('YmdHis');
  39. for ($i = 0; $i < 10; $i++) {
  40. // 随机生成 6 位的数字
  41. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  42. // 判断是否已经存在
  43. if (!static::query()->where('no', $no)->exists()) {
  44. return $no;
  45. }
  46. }
  47. Log::warning('find order no failed');
  48. return false;
  49. }
  50. /**
  51. * 充值成功回调
  52. * @return bool
  53. * User: Mead
  54. */
  55. public function pay_order_callback()
  56. {
  57. $payment_type = WalletLog::TYPE_ADD_WECHAT_PREFERENTIAL_TO_WALLET;
  58. // 修改用户钱包
  59. WalletLog::log(WalletLog::OPERATE_TYPE_ADD, $this->attributes['recharge_money'], $this->attributes['user_id'], $payment_type, $this->attributes['area_id'], $this->attributes['id'], RechargeOrder::class);
  60. $config = js2php($this->attributes['recharge_config']);
  61. if (count($config) !== 0) {
  62. //检查用户是否满足充值赠送活动
  63. WalletLog::log(WalletLog::OPERATE_TYPE_ADD, $config['give_money'], $this->attributes['user_id'], $payment_type, $this->attributes['area_id'], $this->attributes['id'], RechargeOrder::class);
  64. }
  65. return true;
  66. }
  67. }