<?php

namespace app\common\model\shops;

use app\common\model\BaseModel;
use app\common\model\dict\DictData;
use think\facade\Cache;

class ShopOrderLogistic extends BaseModel
{
    protected $name = 'shop_order_logistic';

    public function express(){
        return $this->belongsTo(ShopExpress::class, 'express_id', 'id');
    }

    public function getLogisticStatusTextAttr($value,$data)
    {
        $default = Cache::get('LOGISTIC_STATUS');
        if (!$default) {
            $status = DictData::whereIn('type_value', 'logistic_status')->column('name','value');
            Cache::set('LOGISTIC_STATUS', json_encode($status,true),5);
        } else {
            $status = json_decode($default,true);
        }
        return $status[$data['logistic_status']] ?? '';
    }
}