PunishmentOrder.php 1.8 KB

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