This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
yoshop/source/application/common/model/Delivery.php
2020-08-28 10:38:52 +08:00

88 lines
2.0 KiB
PHP

<?php
namespace app\common\model;
use think\Request;
/**
* 配送模板模型
* Class Delivery
* @package app\common\model
*/
class Delivery extends BaseModel
{
protected $name = 'delivery';
/**
* 关联配送模板区域及运费
* @return \think\model\relation\HasMany
*/
public function rule()
{
return $this->hasMany('DeliveryRule');
}
/**
* 计费方式
* @param $value
* @return mixed
*/
public function getMethodAttr($value)
{
$method = [10 => '按件数', 20 => '按重量'];
return ['text' => $method[$value], 'value' => $value];
}
/**
* 获取全部
* @return mixed
*/
public static function getAll()
{
$model = new static;
return $model->order(['sort' => 'asc', $model->getPk() => 'desc'])->select();
}
/**
* 获取列表
* @return \think\Paginator
* @throws \think\exception\DbException
*/
public function getList()
{
return $this->with(['rule'])
->order(['sort' => 'asc', $this->getPk() => 'desc'])
->paginate(15, false, [
'query' => Request::instance()->request()
]);
}
/**
* 运费模板详情
* @param $delivery_id
* @return null|static
* @throws \think\exception\DbException
*/
public static function detail($delivery_id)
{
return self::get($delivery_id, ['rule']);
}
/**
* 获取列表(根据模板id集)
* @param $deliveryIds
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getListByIds($deliveryIds)
{
return $this->with(['rule'])
->where('delivery_id', 'in', $deliveryIds)
->order(['sort' => 'asc', $this->getPk() => 'desc'])
->select();
}
}