123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace app\common\model\card;
- use app\common\enum\order\DeliveryStatus;
- use app\common\enum\order\ReceiptStatus;
- use app\common\model\BaseModel;
- use app\common\model\UploadFile;
- use app\common\model\chef\ChefAreas as RegionModel;
- /**
- * 米卡配送模型
- * @package app\common\model
- */
- class UserRiceDelivery extends BaseModel
- {
- protected $name = 'user_rice_delivery';
- /**
- * 追加字段
- * @var array
- */
- protected $append = ['region','status_text'];
- /**
- * 获取器:地区名称
- * @param $value
- * @param $data
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getRegionAttr($value, $data)
- {
- return [
- 'province' => RegionModel::getNameById($data['province_id']),
- 'city' => RegionModel::getNameById($data['city_id']),
- 'region' => RegionModel::getNameById($data['region_id'])
- ];
- }
- /**
- * 发货时间
- * @param $value
- * @return false|string
- */
- public function getDeliveryTimeAttr($value)
- {
- return format_time($value);
- }
- /**
- * 收货时间
- * @param $value
- * @return false|string
- */
- public function getReceiptTimeAttr($value)
- {
- return format_time($value);
- }
- /**
- * 一对一关联米卡
- */
- public function userRiceCard()
- {
- return $this->belongsTo('UserRiceCard', 'user_rice_card_id','id');
- }
- /**
- * 一对多关联配送物流表
- */
- public function userRiceDeliveryExpress()
- {
- return $this->hasMany('UserRiceDeliveryExpress', 'user_rice_delivery_id','id');
- }
- public function getStatusTextAttr($value,$data){
- if($data['delivery_status']==DeliveryStatus::NOT_DELIVERED){
- return ['code'=>1,'text'=>'待配送'];
- }elseif($data['delivery_status']==DeliveryStatus::DELIVERED && $data['receipt_status']==ReceiptStatus::NOT_RECEIVED){
- return ['code'=>2,'text'=>'配送中'];
- }elseif($data['receipt_status']==ReceiptStatus::RECEIVED){
- return ['code'=>3,'text'=>'配送完成'];
- }
- return ['code'=>1,'text'=>'配送完成'];
- }
- /**
- * 获取记录
- * @param int $id
- * @param array $with
- * @return static
- */
- public static function detail(int $id, array $with = [])
- {
- return static::get($id, $with);
- }
-
- }
|