PunishmentOrder.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 PunishmentOrder extends Model
  7. {
  8. use ModelHelpers;
  9. //
  10. const NO_TAG = 'P';
  11. protected $table = 'punishment_orders';
  12. protected $guarded = [];
  13. const PAY_TYPE_NO = 0;
  14. const PAY_TYPE_WECHAT = 1;
  15. const PAY_TYPE_ACCOUNT = 2;
  16. public static $payTypeMaps = [
  17. self::PAY_TYPE_NO => '待支付',
  18. self::PAY_TYPE_WECHAT => '微信支付',
  19. self::PAY_TYPE_ACCOUNT => '余额支付'
  20. ];
  21. const PAY_STATUS_OK = 1;
  22. const PAY_STATUS_NO = 0;
  23. public static $payStatusMaps = [
  24. self::PAY_STATUS_NO => '未支付',
  25. self::PAY_STATUS_OK => '已支付'
  26. ];
  27. public function users()
  28. {
  29. return $this->belongsTo(User::class, 'user_id', 'id');
  30. }
  31. public function bikes()
  32. {
  33. return $this->belongsTo(Bike::class, 'bike_id', 'id');
  34. }
  35. public function area()
  36. {
  37. return $this->belongsTo(Area::class, 'area_id', 'id');
  38. }
  39. /**
  40. * 生成订单号
  41. * @return bool|string
  42. * User: Mead
  43. */
  44. public static function makeNo()
  45. {
  46. // 订单流水号前缀
  47. $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
  48. for ($i = 0; $i < 10; $i++) {
  49. // 随机生成 6 位的数字
  50. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  51. // 判断是否已经存在
  52. if (!static::query()->where('no', $no)->exists()) {
  53. return $no;
  54. }
  55. }
  56. Log::warning('find order no failed');
  57. return false;
  58. }
  59. }