GoodsImage.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\store\model;
  13. use app\common\model\GoodsImage as GoodsImageModel;
  14. /**
  15. * 商品图片模型
  16. * Class GoodsImage
  17. * @package app\store\model
  18. */
  19. class GoodsImage extends GoodsImageModel
  20. {
  21. /**
  22. * 批量写入商品图片记录
  23. * @param int $goodsId
  24. * @param array $imageIds
  25. * @return array|false
  26. */
  27. public static function increased(int $goodsId, array $imageIds)
  28. {
  29. $dataset = [];
  30. foreach ($imageIds as $imageId) {
  31. $dataset[] = [
  32. 'image_id' => $imageId,
  33. 'goods_id' => $goodsId,
  34. 'store_id' => self::$storeId
  35. ];
  36. }
  37. return (new static)->addAll($dataset);
  38. }
  39. /**
  40. * 更新关系记录
  41. * @param int $goodsId
  42. * @param array $imageIds 新的图片集
  43. * @return array|false
  44. */
  45. public static function updates(int $goodsId, array $imageIds)
  46. {
  47. // 删除所有的sku记录
  48. static::deleteAll(['goods_id' => $goodsId]);
  49. // 批量写入商品图片记录
  50. return static::increased($goodsId, $imageIds);
  51. }
  52. }