CardRidingOrder.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\Log;
  6. class CardRidingOrder extends Model
  7. {
  8. use ModelHelpers;
  9. const NO_TAG = 'R';
  10. //
  11. protected $table = "card_riding_orders";
  12. protected $guarded = [];
  13. public function areas()
  14. {
  15. return $this->belongsTo(Area::class, 'area_id', 'id');
  16. }
  17. public function users()
  18. {
  19. return $this->belongsTo(User::class, 'user_id', 'id');
  20. }
  21. public function cardRiding()
  22. {
  23. return $this->belongsTo(CardRiding::class, 'riding_card_id', 'id');
  24. }
  25. const PAY_TYPE_WECHAT = 1;
  26. const PAY_TYPE_ACCOUNT = 2;
  27. const PAY_TYPE_ADMIN_GIVE = 3;
  28. const PAY_TYPE_INVITE_NEW_USER_GIVE = 4;
  29. const PAY_TYPE_NEW_USER_OVER_AUTH_SERVER_GIVE = 5;
  30. public static $payTypeMaps = [
  31. self::PAY_TYPE_WECHAT => '微信支付',
  32. self::PAY_TYPE_ACCOUNT => '余额支付',
  33. self::PAY_TYPE_ADMIN_GIVE => '后台赠送',
  34. self::PAY_TYPE_INVITE_NEW_USER_GIVE => '邀请新用户赠送',
  35. self::PAY_TYPE_NEW_USER_OVER_AUTH_SERVER_GIVE => '新用户完成实名系统赠送'
  36. ];
  37. const PAY_STATUS_OK = 1;
  38. const PAY_STATUS_NO = 0;
  39. public static $payStatusMaps = [
  40. self::PAY_STATUS_OK => '支付成功',
  41. self::PAY_STATUS_NO => '支付失败',
  42. ];
  43. const STATUS_OK = 1;
  44. const STATUS_NO = 0;
  45. public static $statusMaps = [
  46. self::STATUS_OK => '支付成功',
  47. self::STATUS_NO => '支付失败'
  48. ];
  49. /**
  50. * 生成订单号
  51. * @return bool|string
  52. * User: Mead
  53. */
  54. public static function makeNo()
  55. {
  56. // 订单流水号前缀
  57. $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
  58. for ($i = 0; $i < 10; $i++) {
  59. // 随机生成 6 位的数字
  60. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  61. // 判断是否已经存在
  62. if (!static::query()->where('no', $no)->exists()) {
  63. return $no;
  64. }
  65. }
  66. Log::warning('find order no failed');
  67. return false;
  68. }
  69. }