$params['id']]) ->append(['goods_image']) ->field('id,name,price,duration,scribing_price,order_num+virtual_order_num as total_order_num,tags,content') ->findOrEmpty() ->toArray(); $goodsImage = array_column($detail['goods_image']->toArray(),'uri'); $detail['goods_image'] = $goodsImage; $detail['comment_count'] = GoodsComment::where(['goods_id'=>$params['id']])->count(); $detail['is_collect'] =Collect::where(['relation_id'=>$params['id'],'user_id'=>$params['user_id'],'type'=>2])->findOrEmpty()->toArray() ? 1 : 0;; $decorate = DecoratePage::where(['type'=>5,'source'=>1])->findOrEmpty()->toArray(); $decorateData = json_decode($decorate['data'],true); $commentNum = 0; $enabled = 1; foreach($decorateData as $data){ if('goods-comment' == $data['name']){ $commentNum = $data['content']['num'] ?? 0; $enabled = $data['content']['enabled'] ?? 0; } } $detail['comment_lists'] = []; if($commentNum > 0 && $enabled){ $goodsCommentLists = GoodsComment::alias('gc') ->leftjoin('goods_comment_image gci', 'gc.id = gci.comment_id') ->with(['goods_comment_image','user']) ->where(['gc.goods_id'=>$params['id']]) ->field('gc.id,gc.goods_id,gc.user_id,gc.service_comment,gc.comment,gc.reply,gc.create_time') ->append(['comment_level']) ->order('gc.id','desc') ->group('gc.id') ->limit($commentNum) ->select() ->toArray(); $detail['comment_lists'] = $goodsCommentLists; } return $detail; } /** * @notes 预约上门时间 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2022/3/11 2:32 下午 */ public function appointTime() { return [ 'order_time' => ConfigService::get('order_time','time',7), 'appoint_time' => OrderTime::order(['sort'=>'desc','id'=>'desc'])->field('start_time,end_time')->select()->toArray(), ]; } /** * @notes 收藏服务 * @param $params * @return bool * @author ljj * @date 2022/3/16 4:14 下午 */ public function collect($params) { if($params['is_collect']){ $goods_collect = GoodsCollect::where(['goods_id'=>$params['id'],'user_id'=>$params['user_id']])->findOrEmpty(); if(!$goods_collect->isEmpty()){ return true; } $goods_collect->goods_id = $params['id']; $goods_collect->user_id = $params['user_id']; $goods_collect->save(); }else { GoodsCollect::where(['goods_id'=>$params['id'],'user_id'=>$params['user_id']])->delete(); } return true; } }