OrderW.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. class OrderW extends Model{
  6. use SoftDeletes;
  7. protected $connection = 'mysql_w';
  8. protected $table='order';
  9. protected $fillable=['order_no','store_id','user_id','address_id',
  10. 'self_receive','remark','account','status','is_help','op_id','op_name',
  11. 'is_pay','pay_money','pay_type','pay_no','pay_at', 'express_no',
  12. 'express_company','express_state','address_id','is_tip_send',
  13. 'tip_send_at','is_comment','wechat_pay_no','total','pay_open_id','pay_user_id',
  14. 'express_time','express_receive_time','order_status','signature','rand_no','vip','snapshot','zbs_yb','recomer_status'];
  15. public static function order_no($type)
  16. {
  17. if($type=='th'){
  18. $prefix = 'TH';
  19. }else{
  20. $prefix = 'DD';
  21. }
  22. $timestamp=date('ymdHis') . substr(microtime(), 2, 6);
  23. $rand=mt_rand(10000, 99999);
  24. $order_no=$prefix . $timestamp . $rand;
  25. if(self::where('order_no',$order_no)->first()){
  26. self::order_no();
  27. }else{
  28. return $order_no;
  29. }
  30. }
  31. public function user()
  32. {
  33. return $this->belongsTo(UserW::class,'user_id');
  34. }
  35. public function address()
  36. {
  37. return $this->belongsTo(AddressW::class,'address_id')->withTrashed();
  38. }
  39. public function order_cancel()
  40. {
  41. return $this->hasOne(OrderCancelW::class,'order_id');
  42. }
  43. public function store()
  44. {
  45. return $this->hasOne(Store::class,'id','store_id');
  46. }
  47. public function refund()
  48. {
  49. return $this->hasMany(OrderRefundW::class,'order_no','order_no');
  50. }
  51. public function getAccountAttribute($value){
  52. return round($value);
  53. }
  54. }