Service.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\api\model\goods;
  13. use app\common\model\goods\Service as ServiceModel;
  14. use app\api\model\goods\ServiceRel as ServiceRelModel;
  15. /**
  16. * 商品服务与承诺模型
  17. * Class Service
  18. */
  19. class Service extends ServiceModel
  20. {
  21. // 隐藏的字段
  22. protected $hidden = [
  23. 'is_default',
  24. 'status',
  25. 'sort',
  26. 'is_delete',
  27. 'store_id',
  28. 'update_time',
  29. ];
  30. /**
  31. * 获取指定商品的服务与承诺
  32. * @param int $goodsId
  33. * @return \think\Collection
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public function getListByGoods(int $goodsId)
  39. {
  40. // 获取指定商品的服务承诺id集
  41. $serviceIds = ServiceRelModel::getServiceIds($goodsId);
  42. // 获取服务与承诺列表
  43. return $this->where('service_id', 'in', $serviceIds)
  44. ->where('status', '=', 1)
  45. ->where('is_delete', '=', 0)
  46. ->order(['sort', $this->getPk()])
  47. ->select();
  48. }
  49. }