time()) { throw new \Exception('评论时间不能超过当前时间'); } $goods = Goods::findOrEmpty($params['goods_id']); if ($goods->isEmpty()) { throw new \Exception('商品不存在'); } $virtual = [ 'sn' => create_user_sn(), 'avatar' => FileService::setFileUrl($params['avatar']), 'nickname' => $params['nickname'], 'level_id' => $params['level_id'], 'goods_name' => $goods['name'], 'goods_image' => $goods['image'] ]; $item = GoodsItem::where('goods_id', $params['goods_id'])->findOrEmpty(); $commentData = [ 'goods_id' => $params['goods_id'], 'item_id' => $item['id'], 'spec_value_str' => $item['spec_value_str'], 'user_id' => 0, 'order_goods_id' => 0, 'goods_comment' => $params['goods_comment'], 'service_comment' => $params['goods_comment'], 'description_comment' => $params['goods_comment'], 'express_comment' => $params['goods_comment'], 'comment' => $params['comment'], 'status' => YesNoEnum::YES, 'virtual' => json_encode($virtual), 'create_time' => $commentTime ]; $newComment = GoodsComment::create($commentData); $commentImagesData = []; if (isset($params['comment_images']) && is_array($params['comment_images'])) { foreach($params['comment_images'] as $item) { $commentImagesData[] = [ 'comment_id' => $newComment['id'], 'uri' => FileService::setFileUrl($item), ]; } } if (count($commentImagesData)) { $goodsCommentImage = new GoodsCommentImage(); $goodsCommentImage->saveAll($commentImagesData); } Db::commit(); return true; } catch(\Exception $e) { Db::rollback(); self::$error = $e->getMessage(); return false; } } }