diff --git a/app/Http/Controllers/Admin/GoodsController.php b/app/Http/Controllers/Admin/GoodsController.php index c1adc72..b7912ab 100644 --- a/app/Http/Controllers/Admin/GoodsController.php +++ b/app/Http/Controllers/Admin/GoodsController.php @@ -77,7 +77,10 @@ class GoodsController extends CommonController unset($_POST["_token"]); if(isset($_POST['editorValue'])){unset($_POST['editorValue']);} - + if(isset($_POST['promote_start_date'])){$_POST['promote_start_date'] = strtotime($_POST['promote_start_date']);} + if(isset($_POST['promote_end_date'])){$_POST['promote_end_date'] = strtotime($_POST['promote_end_date']);} + if(empty($_POST['promote_price'])){unset($_POST['promote_price']);} + if(DB::table('goods')->insert(array_filter($_POST))) { success_jump('添加成功!', route('admin_goods')); @@ -93,7 +96,11 @@ class GoodsController extends CommonController if(!empty($_GET["id"])){$id = $_GET["id"];}else {$id="";}if(preg_match('/[0-9]*/',$id)){}else{exit;} $data['id'] = $id; - $data['post'] = object_to_array(DB::table('goods')->where('id', $id)->first(), 1); + $goods = DB::table('goods')->where('id', $id)->first(); + if($goods->promote_start_date != 0){$goods->promote_start_date = date('Y-m-d H:i:s',$goods->promote_start_date);} + if($goods->promote_end_date != 0){$goods->promote_end_date = date('Y-m-d H:i:s',$goods->promote_end_date);} + + $data['post'] = object_to_array($goods, 1); return view('admin.goods.edit', $data); } @@ -125,7 +132,10 @@ class GoodsController extends CommonController unset($_POST["_token"]); if(isset($_POST['editorValue'])){unset($_POST['editorValue']);} - + if(isset($_POST['promote_start_date'])){$_POST['promote_start_date'] = strtotime($_POST['promote_start_date']);} + if(isset($_POST['promote_end_date'])){$_POST['promote_end_date'] = strtotime($_POST['promote_end_date']);} + if(empty($_POST['promote_price'])){unset($_POST['promote_price']);} + if(DB::table('goods')->where('id', $id)->update($_POST)) { success_jump('修改成功!', route('admin_goods')); diff --git a/app/Http/Controllers/Api/UserGoodsHistoryController.php b/app/Http/Controllers/Api/UserGoodsHistoryController.php new file mode 100644 index 0000000..8fae967 --- /dev/null +++ b/app/Http/Controllers/Api/UserGoodsHistoryController.php @@ -0,0 +1,86 @@ +input('limit', 10); + $data['offset'] = $request->input('offset', 0); + + $data['user_id'] = Token::$uid; + + $res = UserGoodsHistory::getList($data); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //我的足迹添加 + public function userGoodsHistoryAdd(Request $request) + { + //参数 + $data['goods_id'] = $request->input('goods_id',null); + $data['user_id'] = Token::$uid; + + if($data['goods_id']===null || $data['user_id']===null) + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + + $res = UserGoodsHistory::add($data); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //删除一条我的足迹 + public function userGoodsHistoryDelete(Request $request) + { + //参数 + $id = $request->input('id',null); + + $res = UserGoodsHistory::remove($id,Token::$uid); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //清空我的足迹 + public function userGoodsHistoryClear(Request $request) + { + //参数 + $user_id = Token::$uid; + + $res = UserGoodsHistory::remove($user_id); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Weixin/ArticleController.php b/app/Http/Controllers/Weixin/ArticleController.php new file mode 100644 index 0000000..cb95c33 --- /dev/null +++ b/app/Http/Controllers/Weixin/ArticleController.php @@ -0,0 +1,53 @@ + $cat + ); + $url = env('APP_API_URL')."/arctype_detail"; + $arctype_detail = curl_request($url,$postdata,'GET'); + $data['post'] = $arctype_detail['data']; + + //文章列表 + $postdata = array( + 'limit' => 10, + 'offset' => 0 + ); + $url = env('APP_API_URL')."/article_list"; + $article_list = curl_request($url,$postdata,'GET'); + $data['article_list'] = $article_list['data']['list']; + + return view('weixin.article.category', $data); + } + + //文章详情页 + public function detail($id) + { + //最新资讯 + $postdata = array( + 'id' => $id + ); + $url = env('APP_API_URL')."/article_detail"; + $article_detail = curl_request($url,$postdata,'GET'); + if(empty($article_detail['data'])){return redirect()->route('weixin_page404');} + $article_detail['data']['body'] = preg_replace('/src=\"\/uploads\/allimg/',"src=\"".env('APP_URL')."/uploads/allimg",$article_detail['data']['body']); + $data['post'] = $article_detail['data']; + + return view('weixin.article.detail', $data); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Weixin/CommonController.php b/app/Http/Controllers/Weixin/CommonController.php index 975937b..4d282f1 100644 --- a/app/Http/Controllers/Weixin/CommonController.php +++ b/app/Http/Controllers/Weixin/CommonController.php @@ -9,4 +9,58 @@ class CommonController extends Controller { parent::__construct(); } + + /** + * 操作错误跳转的快捷方法 + * @access protected + * @param string $msg 错误信息 + * @param string $url 页面跳转地址 + * @param mixed $time 当数字时指定跳转时间 + * @return void + */ + public function error_jump($msg='', $url='', $time=3) + { + if ($url=='' && isset($_SERVER["HTTP_REFERER"])) + { + $url = $_SERVER["HTTP_REFERER"]; + } + + if(!headers_sent()) + { + header("Location:".route('weixin_jump')."?error=$msg&url=$url&time=$time"); + exit(); + } + else + { + $str = ""; + exit($str); + } + } + + /** + * 操作成功跳转的快捷方法 + * @access protected + * @param string $msg 提示信息 + * @param string $url 页面跳转地址 + * @param mixed $time 当数字时指定跳转时间 + * @return void + */ + public function success_jump($msg='', $url='', $time=1) + { + if ($url=='' && isset($_SERVER["HTTP_REFERER"])) + { + $url = $_SERVER["HTTP_REFERER"]; + } + + if(!headers_sent()) + { + header("Location:".route('weixin_jump')."?message=$msg&url=$url&time=$time"); + exit(); + } + else + { + $str = ""; + exit($str); + } + } } diff --git a/app/Http/Controllers/Weixin/GoodsController.php b/app/Http/Controllers/Weixin/GoodsController.php index 5e47be5..89d8762 100644 --- a/app/Http/Controllers/Weixin/GoodsController.php +++ b/app/Http/Controllers/Weixin/GoodsController.php @@ -32,7 +32,6 @@ class GoodsController extends CommonController $goods_list = curl_request($url,$postdata,'GET'); $data['goods_list'] = $goods_list['data']['list']; - return view('weixin.index.goodslist', $data); + return view('weixin.goods.goodslist', $data); } - } \ No newline at end of file diff --git a/app/Http/Controllers/Weixin/IndexController.php b/app/Http/Controllers/Weixin/IndexController.php index 8a68c33..0c3db28 100644 --- a/app/Http/Controllers/Weixin/IndexController.php +++ b/app/Http/Controllers/Weixin/IndexController.php @@ -11,6 +11,12 @@ class IndexController extends CommonController { parent::__construct(); } + + //页面跳转 + public function jump() + { + return view('weixin.index.jump'); + } //首页 public function index() @@ -45,44 +51,6 @@ class IndexController extends CommonController return view('weixin.index.index',$data); } - //列表页 - public function category($cat) - { - //文章分类 - $postdata = array( - 'id' => $cat - ); - $url = env('APP_API_URL')."/arctype_detail"; - $arctype_detail = curl_request($url,$postdata,'GET'); - $data['post'] = $arctype_detail['data']; - - //文章列表 - $postdata = array( - 'limit' => 10, - 'offset' => 0 - ); - $url = env('APP_API_URL')."/article_list"; - $article_list = curl_request($url,$postdata,'GET'); - $data['article_list'] = $article_list['data']['list']; - - return view('weixin.index.category', $data); - } - - //文章详情页 - public function detail($id) - { - //最新资讯 - $postdata = array( - 'id' => $id - ); - $url = env('APP_API_URL')."/article_detail"; - $article_detail = curl_request($url,$postdata,'GET'); - if(empty($article_detail['data'])){return redirect()->route('weixin_page404');} - $data['post'] = $article_detail['data']; - - return view('weixin.index.detail', $data); - } - //标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述 public function tag($tag, $page=0) { diff --git a/app/Http/Controllers/Weixin/UserController.php b/app/Http/Controllers/Weixin/UserController.php index 6638239..b2cfded 100644 --- a/app/Http/Controllers/Weixin/UserController.php +++ b/app/Http/Controllers/Weixin/UserController.php @@ -13,7 +13,7 @@ class UserController extends CommonController //个人中心 public function index(Request $request) - { + {$_SESSION['weixin_user_info']['access_token'] = '72d623d26a1a6d61186a97f9ccf752f7'; if($request->input('typeid', '') != ''){$data['typeid'] = $request->input('typeid');} if($request->input('tuijian', '') != ''){$data['tuijian'] = $request->input('tuijian');} if($request->input('keyword', '') != ''){$data['keyword'] = $request->input('keyword');} @@ -38,23 +38,15 @@ class UserController extends CommonController //浏览记录 public function userGoodsHistory(Request $request) { - if($request->input('typeid', '') != ''){$data['typeid'] = $request->input('typeid');} - if($request->input('tuijian', '') != ''){$data['tuijian'] = $request->input('tuijian');} - if($request->input('keyword', '') != ''){$data['keyword'] = $request->input('keyword');} - if($request->input('status', '') != ''){$data['status'] = $request->input('status');} - if($request->input('is_promote', '') != ''){$data['is_promote'] = $request->input('is_promote');} - if($request->input('orderby', '') != ''){$data['orderby'] = $request->input('orderby');} - if($request->input('max_price', '') != ''){$data['max_price'] = $request->input('max_price');}else{$data['max_price'] = 99999;} - if($request->input('min_price', '') != ''){$data['min_price'] = $request->input('min_price');}else{$data['min_price'] = 0;} - //商品列表 $postdata = array( 'limit' => 10, - 'offset' => 0 + 'offset' => 0, + 'access_token' => $_SESSION['weixin_user_info']['access_token'] ); - $url = env('APP_API_URL')."/goods_list"; - $goods_list = curl_request($url,$postdata,'GET'); - $data['goods_list'] = $goods_list['data']['list']; + $url = env('APP_API_URL')."/user_goods_history_list"; + $res = curl_request($url,$postdata,'GET'); + $data['user_goods_history'] = $res['data']['list']; return view('weixin.user.userGoodsHistory', $data); } diff --git a/app/Http/Model/Goods.php b/app/Http/Model/Goods.php index 388f2c4..1266d72 100644 --- a/app/Http/Model/Goods.php +++ b/app/Http/Model/Goods.php @@ -31,9 +31,9 @@ class Goods extends BaseModel //protected $connection = 'connection-name'; //常用字段 - protected static $common_field = [ + protected static $common_field = array( 'id', 'typeid', 'tuijian', 'click', 'title', 'sn', 'price','litpic', 'pubdate', 'add_time', 'market_price', 'goods_number', 'sale', 'comments','promote_start_date','promote_price','promote_end_date','goods_img','spec','point' - ]; + ); const STATUS = 0; //商品是否删除,0未删除 @@ -110,13 +110,20 @@ class Goods extends BaseModel return $res; } - public static function getOne($id) + public static function getOne(array $param) { - if(isset($status)){$where['status'] = $status;}else{$where['status'] = self::STATUS;} + extract($param); + + $model = new Goods; + $where['id'] = $id; - $goods = self::where($where)->first(); + if(isset($where)){$model = $model->where($where);} + if(isset($field)){$model = $model->select($field);} + + $goods = $model->first(); + $goods['goods_detail_url'] = route('weixin_goods_detail',array('id'=>$goods->id)); $goods['price'] = self::get_final_price($id); return $goods; diff --git a/app/Http/Model/UserGoodsHistory.php b/app/Http/Model/UserGoodsHistory.php index 77057ed..36f6004 100644 --- a/app/Http/Model/UserGoodsHistory.php +++ b/app/Http/Model/UserGoodsHistory.php @@ -36,6 +36,16 @@ class UserGoodsHistory extends BaseModel if($res['count']>0) { $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get(); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $goods = Goods::getOne(array('id'=>$v['goods_id'],'field'=>array('id', 'typeid', 'tuijian', 'click', 'title', 'sn', 'price','litpic', 'pubdate', 'add_time', 'market_price', 'goods_number', 'sale', 'comments','promote_start_date','promote_price','promote_end_date','goods_img','spec','point'))); + + $res['list'][$k]['goods'] = $goods; + } + } } else { @@ -77,9 +87,9 @@ class UserGoodsHistory extends BaseModel } //删除一条记录 - public static function remove($id) + public static function remove($id,$user_id) { - if (self::whereIn('id', explode(',', $id))->delete() === false) + if (self::whereIn('id', explode(',', $id))->where('user_id',$user_id)->delete() === false) { return false; } diff --git a/resources/views/admin/goods/edit.blade.php b/resources/views/admin/goods/edit.blade.php index 3b9fc70..04e7536 100644 --- a/resources/views/admin/goods/edit.blade.php +++ b/resources/views/admin/goods/edit.blade.php @@ -2,6 +2,7 @@ @section('title', '商品信息修改') @section('content') +