RechargeOrder.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 RechargeOrder extends Model
  7. {
  8. //
  9. use ModelHelpers;
  10. protected $table = "recharge_orders";
  11. const NO_TAG = 'C';
  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_NO = 0;
  26. const PAY_TYPE_WECHAT = 1;
  27. const PAY_TYPE_SYSTERM = 2;
  28. public static $payTypeMaps = [
  29. self::PAY_TYPE_NO => '待支付',
  30. self::PAY_TYPE_WECHAT => '微信支付',
  31. self::PAY_TYPE_SYSTERM => '系统赠送',
  32. ];
  33. /**
  34. * 生成订单号
  35. * @return bool|string
  36. * User: Mead
  37. */
  38. public static function makeNo()
  39. {
  40. // 订单流水号前缀
  41. $prefix = config('bike.no_tag') . self::NO_TAG . date('YmdHis');
  42. for ($i = 0; $i < 10; $i++) {
  43. // 随机生成 6 位的数字
  44. $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
  45. // 判断是否已经存在
  46. if (!static::query()->where('no', $no)->exists()) {
  47. return $no;
  48. }
  49. }
  50. Log::warning('find order no failed');
  51. return false;
  52. }
  53. public function users()
  54. {
  55. return $this->belongsTo(User::class, 'user_id', 'id');
  56. }
  57. public function areas()
  58. {
  59. return $this->belongsTo(Area::class, 'area_id', 'id');
  60. }
  61. }