RechargeOrder.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. const PAY_TYPE_SYSTERM = 2;
  24. public static $payTypeMaps = [
  25. self::PAY_TYPE_NO => '待支付',
  26. self::PAY_TYPE_WECHAT => '微信支付',
  27. self::PAY_TYPE_SYSTERM => '系统赠送',
  28. ];
  29. /**
  30. * 生成订单号
  31. * @return bool|string
  32. * User: Mead
  33. */
  34. public static function makeNo()
  35. {
  36. // 订单流水号前缀
  37. $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
  38. for ($i = 0; $i < 10; $i++) {
  39. // 随机生成 6 位的数字
  40. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  41. // 判断是否已经存在
  42. if (!static::query()->where('no', $no)->exists()) {
  43. return $no;
  44. }
  45. }
  46. Log::warning('find order no failed');
  47. return false;
  48. }
  49. /**
  50. * 充值成功回调
  51. * @return bool
  52. * User: Mead
  53. */
  54. public function pay_order_callback()
  55. {
  56. // 修改用户钱包
  57. 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);
  58. $config = js2php($this->attributes['recharge_config']);
  59. if (count($config) !== 0) {
  60. //检查用户是否满足充值赠送活动
  61. 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);
  62. }
  63. return true;
  64. }
  65. }