Delivery.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\common\model;
  3. use think\Request;
  4. /**
  5. * 配送模板模型
  6. * Class Delivery
  7. * @package app\common\model
  8. */
  9. class Delivery extends BaseModel
  10. {
  11. protected $name = 'delivery';
  12. /**
  13. * 关联配送模板区域及运费
  14. * @return \think\model\relation\HasMany
  15. */
  16. public function rule()
  17. {
  18. return $this->hasMany('DeliveryRule');
  19. }
  20. /**
  21. * 计费方式
  22. * @param $value
  23. * @return mixed
  24. */
  25. public function getMethodAttr($value)
  26. {
  27. $method = [10 => '按件数', 20 => '按重量'];
  28. return ['text' => $method[$value], 'value' => $value];
  29. }
  30. /**
  31. * 获取全部
  32. * @return mixed
  33. */
  34. public static function getAll()
  35. {
  36. $model = new static;
  37. return $model->order(['sort' => 'asc', $model->getPk() => 'desc'])->select();
  38. }
  39. /**
  40. * 获取列表
  41. * @return \think\Paginator
  42. * @throws \think\exception\DbException
  43. */
  44. public function getList()
  45. {
  46. return $this->with(['rule'])
  47. ->order(['sort' => 'asc', $this->getPk() => 'desc'])
  48. ->paginate(15, false, [
  49. 'query' => Request::instance()->request()
  50. ]);
  51. }
  52. /**
  53. * 运费模板详情
  54. * @param $delivery_id
  55. * @return null|static
  56. * @throws \think\exception\DbException
  57. */
  58. public static function detail($delivery_id)
  59. {
  60. return self::get($delivery_id, ['rule']);
  61. }
  62. /**
  63. * 获取列表(根据模板id集)
  64. * @param $deliveryIds
  65. * @return false|\PDOStatement|string|\think\Collection
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. */
  70. public function getListByIds($deliveryIds)
  71. {
  72. return $this->with(['rule'])
  73. ->where('delivery_id', 'in', $deliveryIds)
  74. ->order(['sort' => 'asc', $this->getPk() => 'desc'])
  75. ->select();
  76. }
  77. }