DepositOrder.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 DepositOrder extends Model
  7. {
  8. use ModelHelpers;
  9. const NO_TAG = 'Y';
  10. //押金订单表
  11. protected $table = "deposit_orders";
  12. protected $guarded = [];
  13. const STATUS_OK = 1;
  14. const STATUS_PAUSE = 0;
  15. public static $statusMaps = [
  16. self::STATUS_OK => '正常',
  17. self::STATUS_PAUSE => '暂停'
  18. ];
  19. const PAY_STATUS_OK = 1;
  20. const PAY_STATUS_NO = 0;
  21. public static $payStatusMaps = [
  22. self::PAY_STATUS_NO => '未支付',
  23. self::PAY_STATUS_OK => '缴纳成功'
  24. ];
  25. const PAY_TYPE_WECHAT = 0;
  26. public static $payTypeMaps = [
  27. self::PAY_TYPE_WECHAT => '微信支付'
  28. ];
  29. const REFUND_OK = 1;
  30. const REFUND_NO = 0;
  31. public static $refundMaps = [
  32. self::REFUND_OK => '已退款',
  33. self::REFUND_NO => '未退款'
  34. ];
  35. // 交易类型 用is_refund 判断
  36. public static $transactionTypeMaps = [
  37. self::REFUND_OK => '退还押金',
  38. self::REFUND_NO => '缴纳押金'
  39. ];
  40. public function depositRefund(){
  41. return $this->hasOne(DepositRefund::class,'deposit_id','id');
  42. }
  43. public function users(){
  44. return $this->belongsTo('App\Models\User','user_id','id');
  45. }
  46. public function area(){
  47. return $this->belongsTo(Area::class,'area_id','id');
  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. }