Delivery.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\common\model\settings;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 配送模板模型
  6. */
  7. class Delivery extends BaseModel
  8. {
  9. protected $name = 'delivery';
  10. protected $pk = 'delivery_id';
  11. /**
  12. * 关联配送模板区域及运费
  13. */
  14. public function rule()
  15. {
  16. return $this->hasMany('DeliveryRule');
  17. }
  18. /**
  19. * 计费方式
  20. */
  21. public function getMethodAttr($value)
  22. {
  23. $method = [10 => '按件数', 20 => '按重量'];
  24. return ['text' => $method[$value], 'value' => $value];
  25. }
  26. /**
  27. * 获取全部
  28. */
  29. public static function getAll($shop_supplier_id = 0)
  30. {
  31. $model = new static;
  32. if($shop_supplier_id > 0){
  33. $model = $model->where('shop_supplier_id', '=', $shop_supplier_id);
  34. }
  35. return $model->order(['sort' => 'asc'])->select();
  36. }
  37. /**
  38. * 获取列表
  39. */
  40. public function getList($limit = 10,$shop_supplier_id=0)
  41. {
  42. $where = [];
  43. if($shop_supplier_id){
  44. $where['shop_supplier_id'] = $shop_supplier_id;
  45. }
  46. return $this->with(['rule'])
  47. ->where($where)
  48. ->order(['sort' => 'asc'])
  49. ->paginate($limit);
  50. }
  51. /**
  52. * 运费模板详情
  53. */
  54. public static function detail($delivery_id)
  55. {
  56. return (new static())->find($delivery_id, ['rule']);
  57. }
  58. }