RechargeOrder.php 2.1 KB

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