CommentImage.php 1.8 KB

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