<?php

namespace App\Models;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @description 订单列表
 * @author  system;
 * @version    1.0
 * @date 2018-07-12 08:32:14
 *
 */
class OrderInfoModel extends BaseModel
{
    use SoftDeletes;
    /**
     * 数据表名
     *
     * @var string
     *
     */
    protected $table = 'order_info';
    /**
     * 主键
     */
    protected $primaryKey = 'id';

    //分页
    protected $perPage = PAGE_NUMS;

    /**
     * 可以被集体附值的表的字段
     *
     * @var string
     */
    protected $fillable = [
        'out_trade_no',
        'username',
        'sex',
        'phone',
        'email',
        'store_id',
        'schedule_time',
        'status',
        'user_id',
        'comment',
        'product_id',
        'schedule_id',
        'price',
        'deposit'
    ];

  public function store(){
      return (new StoreInfoModel())->find($this->store_id)->name;
  }

    public function getstore(){
        return $this->belongsTo('App\Models\StoreInfoModel','store_id');
    }

  public function product(){
      return $this->belongsTo('App\Models\ProductInfoModel','product_id');
  }

  public function status(){
      switch ($this->status){
          case 1:
              return '已付款';
              break;
          case 2:
              return '已完成';
              break;
          case 3:
              return '已取消';
              break;
          default:
              return '未付款';
              break;

      }
  }

  public function paidinfo(){
      return $this->hasOne('App\Models\PaidInfoModel','order_id');
  }

    public function refundinfo(){
        return $this->hasOne('App\Models\RefundInfoModel','order_id');
    }
}