Delivery.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. use cores\BaseModel;
  14. /**
  15. * 配送模板模型
  16. * Class Delivery
  17. * @package app\common\model
  18. */
  19. class Delivery extends BaseModel
  20. {
  21. // 定义表名
  22. protected $name = 'delivery';
  23. // 定义主键
  24. protected $pk = 'delivery_id';
  25. /**
  26. * 关联配送模板区域及运费
  27. * @return \think\model\relation\HasMany
  28. */
  29. public function rule()
  30. {
  31. return $this->hasMany('DeliveryRule');
  32. }
  33. /**
  34. * 运费模板详情
  35. * @param int $deliveryId
  36. * @param array $with
  37. * @return null|static
  38. */
  39. public static function detail(int $deliveryId, array $with = [])
  40. {
  41. return self::get($deliveryId, ['rule']);
  42. }
  43. /**
  44. * 获取列表(根据模板id集)
  45. * @param array $deliveryIds
  46. * @return \think\Collection
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function getListByIds(array $deliveryIds)
  52. {
  53. return $this->with(['rule'])
  54. ->where('delivery_id', 'in', $deliveryIds)
  55. ->order(['sort', $this->getPk()])
  56. ->select();
  57. }
  58. }