12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class OrderW extends Model{
- use SoftDeletes;
- protected $connection = 'mysql_w';
- protected $table='order';
- protected $fillable=['order_no','store_id','user_id','address_id',
- 'self_receive','remark','account','status','is_help','op_id','op_name',
- 'is_pay','pay_money','pay_type','pay_no','pay_at', 'express_no',
- 'express_company','express_state','address_id','is_tip_send',
- 'tip_send_at','is_comment','wechat_pay_no','total','pay_open_id','pay_user_id',
- 'express_time','express_receive_time','order_status','signature','rand_no','vip','snapshot','zbs_yb','recomer_status'];
- public static function order_no($type)
- {
- if($type=='th'){
- $prefix = 'TH';
- }else{
- $prefix = 'DD';
- }
- $timestamp=date('ymdHis') . substr(microtime(), 2, 6);
- $rand=mt_rand(10000, 99999);
- $order_no=$prefix . $timestamp . $rand;
- if(self::where('order_no',$order_no)->first()){
- self::order_no();
- }else{
- return $order_no;
- }
- }
- public function user()
- {
- return $this->belongsTo(UserW::class,'user_id');
- }
- public function address()
- {
- return $this->belongsTo(AddressW::class,'address_id')->withTrashed();
- }
- public function order_cancel()
- {
- return $this->hasOne(OrderCancelW::class,'order_id');
- }
- public function store()
- {
- return $this->hasOne(Store::class,'id','store_id');
- }
- public function refund()
- {
- return $this->hasMany(OrderRefundW::class,'order_no','order_no');
- }
- public function getAccountAttribute($value){
- return round($value);
- }
- }
|