DepositOrder.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\Log;
  5. class DepositOrder extends Model
  6. {
  7. protected $guarded = [];
  8. const NO_TAG = 'Y';
  9. const STATUS_OK = 1;
  10. const STATUS_PAUSE = 0;
  11. public static $statusMaps = [
  12. self::STATUS_OK => '正常',
  13. self::STATUS_PAUSE => '暂停'
  14. ];
  15. const PAY_STATUS_OK = 1;
  16. const PAY_STATUS_NO = 0;
  17. public static $payStatusMaps = [
  18. self::PAY_STATUS_NO => '已支付',
  19. self::PAY_STATUS_OK => '未支付'
  20. ];
  21. const PAY_TYPE_NO = 0;
  22. const PAY_TYPE_WECHAT = 1;
  23. public static $payTypeMaps = [
  24. self::PAY_TYPE_NO => '待支付',
  25. self::PAY_TYPE_WECHAT => '微信支付'
  26. ];
  27. const REFUND_OK = 1;
  28. const REFUND_NO = 0;
  29. public static $refundMaps = [
  30. self::REFUND_OK => '已退款',
  31. self::REFUND_NO => '未退款'
  32. ];
  33. /**
  34. * 生成订单号
  35. * @return bool|string
  36. * User: Mead
  37. */
  38. public static function makeNo()
  39. {
  40. // 订单流水号前缀
  41. $prefix = 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 pay_order_callback()
  54. {
  55. // 修改用户押金状态
  56. User::where('id', $this->attributes['user_id'])->update([
  57. 'deposit_money' => $this->attributes['money'],
  58. 'is_deposit' => User::DEPOSIT_OK
  59. ]);
  60. $this->save();
  61. return true;
  62. }
  63. }