ServiceRel.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\goods;
  13. use cores\BaseModel;
  14. /**
  15. * 商品服务与承诺模型
  16. * Class ServiceRel
  17. */
  18. class ServiceRel extends BaseModel
  19. {
  20. // 定义表名
  21. protected $name = 'goods_service_rel';
  22. // 定义主键
  23. protected $pk = 'id';
  24. protected $updateTime = false;
  25. /**
  26. * 获取商品服务与承诺ID集
  27. * @param int $goodsId
  28. * @return array
  29. */
  30. public static function getServiceIds(int $goodsId): array
  31. {
  32. return (new static)->where('goods_id', '=', $goodsId)->column('service_id');
  33. }
  34. /**
  35. * 批量写入商品服务记录
  36. * @param int $goodsId
  37. * @param array $serviceIds
  38. * @param int|null $storeId 商城ID
  39. * @return array|false
  40. */
  41. public static function increased(int $goodsId, array $serviceIds, int $storeId = null)
  42. {
  43. $dataset = [];
  44. foreach ($serviceIds as $serviceId) {
  45. $dataset[] = [
  46. 'service_id' => $serviceId,
  47. 'goods_id' => $goodsId,
  48. 'store_id' => $storeId ?: self::$storeId
  49. ];
  50. }
  51. return (new static)->addAll($dataset);
  52. }
  53. }