123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?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();
- }
- }
|