Delivery.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\common\model;
  13. /**
  14. * 配送模板模型
  15. * Class Delivery
  16. * @package app\common\model
  17. */
  18. class Delivery extends BaseModel
  19. {
  20. // 定义表名
  21. protected $name = 'delivery';
  22. // 定义主键
  23. protected $pk = 'delivery_id';
  24. /**
  25. * 关联配送模板区域及运费
  26. * @return \think\model\relation\HasMany
  27. */
  28. public function rule()
  29. {
  30. return $this->hasMany('DeliveryRule');
  31. }
  32. /**
  33. * 运费模板详情
  34. * @param int $deliveryId
  35. * @param array $with
  36. * @return null|static
  37. */
  38. public static function detail(int $deliveryId, array $with = [])
  39. {
  40. return self::get($deliveryId, ['rule']);
  41. }
  42. /**
  43. * 获取列表(根据模板id集)
  44. * @param array $deliveryIds
  45. * @return \think\Collection
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function getListByIds(array $deliveryIds)
  51. {
  52. return $this->with(['rule'])
  53. ->where('delivery_id', 'in', $deliveryIds)
  54. ->order(['sort', $this->getPk()])
  55. ->select();
  56. }
  57. }