<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 维修订单
 */
namespace app\bestbao\model;
use think\Model;

class BestbaoOrder extends Model{

    protected $autoWriteTimestamp = true;

    
    public function engineer(){
        return $this->hasOne('BestbaoEngineer','id','engineer_id');
    }

    public function user(){
        return $this->hasOne('app\common\model\SystemUser','id','uid');
    }

    public function process(){
        return $this->hasMany('BestbaoProcess','order_id','id');
    }

    public function product(){
        return $this->hasOne('BestbaoProduct','id','product_id');
    }

    //添加或编辑
    public static function edit($param){
        $data['title']     = $param['title'];
        $data['note']      = $param['note'];
        $data['picture']   = $param['picture'];
        $data['sort']      = $param['sort'];
        $data['update_time']  = time();
        if(isset($param['id'])){
            return self::update($data,['id'=>(int)$param['id']]);
        }else{
            $data['create_time']       = time();
            $data['member_miniapp_id'] = $param['member_miniapp_id'];
            return self::insert($data);
        }
    } 

    /**
     * 状态盘
     * @param [type] $param
     * @return void
     */
    public static function stateText($state,$engineer_id){
        switch ($state) {
            case 1:
                $stateText = '待付费';
                break;
            case 2:
                $stateText = '待评价';
                break;
            case 3:
                $stateText = '已关闭';
                break;
            default:
                if($engineer_id){
                    $stateText = '已接单';
                }else{
                    $stateText = '派单中';
                }
                break;
        }
        return $stateText;
    } 

    /**
     * 紧急程度
     * @param [type] $param
     * @return void
     */
    public static function urgentText($state){
        switch ($state) {
            case 1:
                $stateText = '中等';
                break;
            case 2:
                $stateText = '危险';
                break;
            case 3:
                $stateText = '超急';
                break;
            default:
                $stateText = '一般';
                break;
        }
        return $stateText;
    } 
    
}