Delivery.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 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. use think\model\relation\HasMany;
  15. /**
  16. * 配送模板模型
  17. * Class Delivery
  18. * @package app\common\model
  19. */
  20. class Delivery extends BaseModel
  21. {
  22. // 定义表名
  23. protected $name = 'delivery';
  24. // 定义主键
  25. protected $pk = 'delivery_id';
  26. /**
  27. * 关联配送模板区域及运费
  28. * @return HasMany
  29. */
  30. public function rule(): HasMany
  31. {
  32. return $this->hasMany('DeliveryRule');
  33. }
  34. /**
  35. * 运费模板详情
  36. * @param int $deliveryId
  37. * @param array $with
  38. * @return static|array|null
  39. */
  40. public static function detail(int $deliveryId, array $with = [])
  41. {
  42. return self::get($deliveryId, ['rule']);
  43. }
  44. /**
  45. * 获取列表(根据模板id集)
  46. * @param array $deliveryIds
  47. * @return \think\Collection
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function getListByIds(array $deliveryIds): \think\Collection
  53. {
  54. return $this->with(['rule'])
  55. ->where('delivery_id', 'in', $deliveryIds)
  56. ->order(['sort', $this->getPk()])
  57. ->select();
  58. }
  59. /**
  60. * 验证模板ID是否存在
  61. * @param int $deliveryId 模板ID
  62. * @param int|null $storeId 商城ID
  63. * @return bool
  64. */
  65. public static function checkDeliveryId(int $deliveryId, int $storeId = null): bool
  66. {
  67. return (bool)(new static)->where('delivery_id', '=', $deliveryId)
  68. ->where('is_delete', '=', 0)
  69. ->where('store_id', '=', $storeId)
  70. ->value('delivery_id');
  71. }
  72. }