RefundBalanceOrder.php 1.6 KB

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