2020-04-25 22:20:29 +08:00
|
|
|
<?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;
|
2020-08-28 10:38:52 +08:00
|
|
|
return $model->order(['sort' => 'asc', $model->getPk() => 'desc'])->select();
|
2020-04-25 22:20:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取列表
|
|
|
|
* @return \think\Paginator
|
|
|
|
* @throws \think\exception\DbException
|
|
|
|
*/
|
|
|
|
public function getList()
|
|
|
|
{
|
|
|
|
return $this->with(['rule'])
|
2020-08-28 10:38:52 +08:00
|
|
|
->order(['sort' => 'asc', $this->getPk() => 'desc'])
|
2020-04-25 22:20:29 +08:00
|
|
|
->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)
|
2020-08-28 10:38:52 +08:00
|
|
|
->order(['sort' => 'asc', $this->getPk() => 'desc'])
|
2020-04-25 22:20:29 +08:00
|
|
|
->select();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|