Delivery.php 2.0 KB

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