## 1、前台页面添加新的页面教程 >[info]控制器中添加如下代码 public function test() { $this->initTheme('apple');//主题初始化 $this->theme->setTitle('我的回答');//设置页面头部标题 return $this->theme->scope('user.test')->render(); } >[info]在public/themes/default/views/user/目录下添加test.blade.php模板,定义好路由就能访问前台测试页面了示例以发布商品为例,添加路由 //商品管理信息 Route::get('/goodsShop', 'GoodsController@shopGoods')->name('shopGoods'); //店铺编辑商品页面 Route::get('/editGoods/{id}', 'GoodsController@editGoods')->name('editGoods'); //店铺商品编辑保存信息 Route::post('/postEditGoods', 'GoodsController@postEditGoods')->name('postEditGoods'); ![](https://box.kancloud.cn/7fe144364bab4922e953f707b551fc5c_1121x723.png) >[info]然后访问kppw.io//user/goodsShop就能访问商品列表页面, ![](https://box.kancloud.cn/99358508258d733946034c479374f7a6_1062x969.png) >[info]访问http://kppw.io/user/pubGoods访问发布作品页面 ![](https://box.kancloud.cn/b2436e7bfbea68f5bc6c914b52cd48be_1447x860.png) >[info]控制器示例,在如下路径添加控制器 ![](https://box.kancloud.cn/a2bfdf3c87bc72032dd1120025882737_1093x728.png) >[info]控制器源代码 //商品列表 public function shopGoods(Request $request) { $uid = Auth::id(); //判断店铺是否开启 $isOpenShop = ShopModel::isOpenShop($uid); //店铺id $shopId = ShopModel::getShopIdByUid($uid); $merge = $request->all(); $uid = Auth::id(); $shopGoods = GoodsModel::getGoodsListByUid($uid,$merge); $goodsStatistics = GoodsModel::goodsStatistics($uid); $data = array( 'goods_list' => $shopGoods, 'merge' => $merge, 'goods_statistics' => $goodsStatistics, 'is_open_shop' => $isOpenShop, 'shop_id' => $shopId ); $this->theme->setTitle('我发布的作品'); $this->theme->set('TYPE',3); return $this->theme->scope('user.usershopspgl',$data)->render(); } /** * 编辑或重新编辑商品视图 * @param $id 商品id * @return mixed */ public function editGoods($id) { $id = intval($id); $uid = Auth::id(); //查询商品状态 $status = GoodsModel::getGoodsStatus($id); //审核失败编辑 if($status == 3){ $type = 1; }else{ $type = 2; } //查询商品详情 $goodsInfo = GoodsModel::getGoodsInfoById($id); //一级行业 $cateFirst = TaskCateModel::findByPid([0],['id','name']); if(!empty($goodsInfo->cate_pid)){ //二级行业 $cateSecond = TaskCateModel::findByPid([$goodsInfo->cate_pid],['id','name']); }else{ $cateSecond = TaskCateModel::findByPid([$cateFirst[0]['id']],['id','name']); } //商品的附件 $attachment = UnionAttachmentModel::where('object_id', $id)->where('object_type',4) ->lists('attachment_id')->toArray(); $attachmentIds = array_flatten($attachment); $attachmentData = AttachmentModel::whereIn('id', $attachmentIds)->get(); $domain = \CommonClass::getDomain(); //查询是否购买增值服务 $isService = ShopOrderModel::isBuy($uid,$goodsInfo->id,3); //查询是否开启推荐商品增值工具 $isOpenArr = ServiceModel::where('identify','ZUOPINTUIJIAN')->first(); if(!empty($isOpenArr) && $isOpenArr->status == 1){ $isOpen = 1; $price = $isOpenArr->price; }else{ $isOpen = 2; $price = 0.00; } //查询推荐增值服务有效期 $unitAbout = ConfigModel::getConfigByAlias('recommend_goods_unit'); if(!empty($unitAbout)){ $recommendUnit = $unitAbout->rule; }else{ $recommendUnit = ''; } //查询商品最小金额 $minPriceArr = ConfigModel::getConfigByAlias('min_price'); if(!empty($minPriceArr)){ $minPrice = $minPriceArr->rule; }else{ $minPrice = 0; } $data = array( 'type' => $type, 'goods_info' => $goodsInfo, 'cate_first' => $cateFirst, 'cate_second' => $cateSecond, 'attachment_data' => $attachmentData, 'domain' => $domain, 'is_service' => $isService, 'is_open' => $isOpen, 'price' => $price, 'recommend_unit' => $recommendUnit, 'min_price' => $minPrice ); $this->theme->setTitle('编辑作品'); $this->theme->set('TYPE',3); return $this->theme->scope('user.editgoods', $data)->render(); } /** * 保存编辑商品信息 * @param PubGoodsRequest $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function postEditGoods(PubGoodsRequest $request) { $uid = Auth::id(); //判断配置项商品上架是否需要审核 $config = ConfigModel::getConfigByAlias('goods_check'); if(!empty($config) && $config->rule == 1){ $goodsCheck = 0; }else{ $goodsCheck = 1; } $data = $request->except('_token'); //查询商品最小金额 $minPriceArr = ConfigModel::getConfigByAlias('min_price'); if(!empty($minPriceArr)){ $minPrice = $minPriceArr->rule; }else{ $minPrice = 0; } if($minPrice > 0 && $data['cash'] < $minPrice){ $error['cash'] = '作品金额设定错误'; if (!empty($error)) { return redirect('/user/editGoods/'.$data['id'])->withErrors($error); } } $data['cate_id'] = $data['second_cate']; $goodsInfo = GoodsModel::where('id',$data['id'])->first(); if (isset($data['is_recommend'])){ $is_service = true; } else { $is_service = false; } //处理封面 if (!empty($data['cover'])){ $cover = $request->file('cover'); $result = \FileClass::uploadFile($cover,'sys'); if ($result){ $result = json_decode($result, true); $data['cover'] = $result['data']['url']; } }else{ $data['cover'] = $goodsInfo->cover; } //审核失败的重新发布新商品 if($request->get('status') == 3){ $goodsArr = array( 'uid' => $uid, 'shop_id' => $goodsInfo->shop_id, 'cate_id' => $data['cate_id'], 'title' => $data['title'], 'desc' => $data['desc'], 'unit' => $data['unit'], 'type' => 1, 'cash' => $data['cash'], 'cover' => $data['cover'], 'status' => $goodsCheck, 'is_recommend' => 0, ); $goods = GoodsModel::create($goodsArr); //处理附件 if (!empty($data['file_id'])){ $arrAttachment = []; foreach ($data['file_id'] as $v){ $arrAttachment[] = [ 'object_id' => $goods->id, 'object_type' => 4, 'attachment_id' => $v, 'created_at' => date('Y-m-d H:i:s', time()) ]; } UnionAttachmentModel::insert($arrAttachment); } //购买推荐增值服务 if ($is_service){ return redirect('finance/getpay/' . $goods->id); } if ($goods && $goodsCheck == 0){ return redirect('user/waitGoodsHandle/'.$goods->id); }else{ return redirect('user/goodsShop'); } }else{ //编辑商品信息 $goodsArr = array( 'cate_id' => $data['cate_id'], 'title' => $data['title'], 'desc' => $data['desc'], 'unit' => $data['unit'], 'cash' => $data['cash'], 'cover' => $data['cover'], ); $goods = GoodsModel::where('id',$data['id'])->update($goodsArr); if (!empty($data['file_id'])) { //查询商品的附件记录,排除掉商品删除的附件记录 $fileAbleIds = AttachmentModel::fileAble($data['file_id']); $fileAbleIds = array_flatten($fileAbleIds); //先删除旧的附件关联信息 UnionAttachmentModel::where('object_id',$data['id'])->where('object_type',4)->delete(); foreach ($fileAbleIds as $v) { $attachmentData = [ 'object_id' => $data['id'], 'object_type' => 4, 'attachment_id' => $v, 'created_at' => date('Y-m-d H:i:s', time()) ]; UnionAttachmentModel::create($attachmentData); } //修改附件的发布状态 $attachmentModel = new AttachmentModel(); $attachmentModel->statusChange($fileAbleIds); } //购买推荐增值服务 if ($is_service){ return redirect('finance/getpay/' . $data['id']); } if ($goods) return redirect('user/goodsShop'); } }