diff --git a/app/Common/function.php b/app/Common/function.php index d334e39..d30b44e 100644 --- a/app/Common/function.php +++ b/app/Common/function.php @@ -1186,6 +1186,23 @@ function getDataAttr($dataModel,$data = []) return $data; } +//判断是否为数字 +function checkIsNumber($data) +{ + if($data == '') + { + return false; + } + elseif($data === null) + { + return false; + } + elseif(preg_match("/^\d*$/",$data)) + { + return true; + } + return false; +} diff --git a/app/Http/Controllers/Api/ArctypeController.php b/app/Http/Controllers/Api/ArctypeController.php index 8e2d04b..ed122f5 100644 --- a/app/Http/Controllers/Api/ArctypeController.php +++ b/app/Http/Controllers/Api/ArctypeController.php @@ -1,7 +1,6 @@ $v) + foreach($res['list'] as $k=>$v) { $res['list'][$k]->addtime = date('Y-m-d H:i',$v->addtime); $res['list'][$k]->category_list_url = route('weixin_article_category',array('id'=>$v->id)); diff --git a/app/Http/Controllers/Api/ArticleController.php b/app/Http/Controllers/Api/ArticleController.php index ec52495..1aca700 100644 --- a/app/Http/Controllers/Api/ArticleController.php +++ b/app/Http/Controllers/Api/ArticleController.php @@ -1,11 +1,11 @@ input('limit', 10); - $data['offset'] = $request->input('offset', 0); - if($request->input('group_id', null) !== null){$data['group_id'] = $request->input('group_id');} - if($request->input('type', null) !== null){$data['type'] = $request->input('type');} + $where = array(); + $limit = $request->input('limit', 10); + $offset = $request->input('offset', 0); + if($request->input('group_id', null) !== null){$where['group_id'] = $request->input('group_id');} + if($request->input('type', null) !== null){$where['type'] = $request->input('type');} - $res = Slide::getList($data); + $res = $this->getLogic()->getList($where, array('id', 'desc'), '*', $offset, $limit); if($res == false) { return ReturnData::create(ReturnData::SYSTEM_FAIL); } + foreach($res['list'] as $k=>$v) + { + if(!empty($res['list'][$k]->pic)){$res['list'][$k]->pic = http_host().$v->pic;} + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //详情 + public function slideDetail(Request $request) + { + //参数 + if(!checkIsNumber($request->input('id', null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + $res = $this->getLogic()->getOne($where); + if(!$res){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + if(!empty($res->pic)){$res->pic = http_host().$res->pic;} + return ReturnData::create(ReturnData::SUCCESS,$res); } + + //添加 + public function slideAdd(Request $request) + { + if(Helper::isPostRequest()) + { + $res = $this->getLogic()->add($_POST); + + return $res; + } + } + + //修改 + public function slideUpdate(Request $request) + { + if(!checkIsNumber($request->input('id', null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + if(Helper::isPostRequest()) + { + unset($_POST['id']); + $where['id'] = $id; + + $res = $this->getLogic()->edit($_POST,$where); + + return $res; + } + } + + //删除 + public function slideDelete(Request $request) + { + if(!checkIsNumber($request->input('id', null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + if(Helper::isPostRequest()) + { + unset($_POST['id']); + $where['id'] = $id; + + $res = $this->getLogic()->del($where); + + return $res; + } + } } \ No newline at end of file diff --git a/app/Http/Controllers/Home/IndexController.php b/app/Http/Controllers/Home/IndexController.php index 1ed8e7f..03e5a51 100644 --- a/app/Http/Controllers/Home/IndexController.php +++ b/app/Http/Controllers/Home/IndexController.php @@ -95,19 +95,17 @@ class IndexController extends CommonController //商品列表页 public function goodslist(Request $request) { - $data['typeid'] = 0; - if($request->input('typeid', null) != null){$data['typeid'] = $request->input('typeid');} + if($request->input('typeid', null) != null){$postdata['typeid'] = $request->input('typeid');} + if($request->input('orderby', null) != null){$postdata['orderby'] = $request->input('orderby');} + if($request->input('tuijian', null) != null){$postdata['tuijian'] = $request->input('tuijian');} $pagesize = 15; $offset = 0; if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;} //商品列表 - $postdata = array( - 'typeid' => $data['typeid'], - 'limit' => $pagesize, - 'offset' => $offset - ); + $postdata['limit'] = $pagesize; + $postdata['offset'] = $offset; $url = env('APP_API_URL')."/goods_list"; $res = curl_request($url,$postdata,'GET'); $data['list'] = $res['data']['list']; @@ -225,10 +223,8 @@ class IndexController extends CommonController if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;} //文章列表 - $postdata2 = array( - 'limit' => $pagesize, - 'offset' => $offset - ); + $postdata2['limit'] = $limit; + $postdata2['offset'] = $offset; if($request->input('typeid', null) != null){$postdata2['typeid'] = $request->input('typeid');} $url = env('APP_API_URL')."/article_list"; diff --git a/app/Http/Model/Arctype.php b/app/Http/Model/Arctype.php index dce346b..6af296b 100644 --- a/app/Http/Model/Arctype.php +++ b/app/Http/Model/Arctype.php @@ -1,9 +1,8 @@ update(parent::filterTableColumn($data,self::TABLE_NAME)) !== false) + if (self::where($where)->update(parent::filterTableColumn($data, self::TABLE_NAME)) !== false) { return true; } diff --git a/app/Http/Model/Cart.php b/app/Http/Model/Cart.php index 1671e59..c8b1395 100644 --- a/app/Http/Model/Cart.php +++ b/app/Http/Model/Cart.php @@ -178,9 +178,7 @@ class Cart extends BaseModel */ public static function clearCart($user_id) { - self::where('user_id',$user_id)->delete(); - - return true; + return self::where('user_id',$user_id)->delete(); } //购物车商品总数量 diff --git a/app/Http/Model/Goods.php b/app/Http/Model/Goods.php index b4778bd..b5af220 100644 --- a/app/Http/Model/Goods.php +++ b/app/Http/Model/Goods.php @@ -117,7 +117,10 @@ class Goods extends BaseModel foreach($res['list'] as $k=>$v) { $res['list'][$k]->goods_detail_url = route('weixin_goods_detail',array('id'=>$v->id)); - $res['list'][$k]->price = self::get_final_price($v->id); + $res['list'][$k]->price = self::get_goods_final_price($v); + + if(!empty($res['list'][$k]->litpic)){$res['list'][$k]->litpic = http_host().$res['list'][$k]->litpic;} + $res['list'][$k]->is_promote_goods = self::bargain_price($v->promote_price,$v->promote_start_date,$v->promote_end_date); //is_promote_goods等于0,说明不是促销商品 } } @@ -142,7 +145,7 @@ class Goods extends BaseModel if($goods) { $goods['goods_detail_url'] = route('weixin_goods_detail',array('id'=>$goods->id)); - $goods['price'] = self::get_final_price($id); + $goods['price'] = self::get_goods_final_price($goods); $goods['is_promote_goods'] = self::bargain_price($goods->promote_price,$goods->promote_start_date,$goods->promote_end_date); //is_promote_goods等于0,说明不是促销商品 } @@ -228,6 +231,42 @@ class Goods extends BaseModel return $final_price; } + /** + * 取得商品最终使用价格 + * + * @param string $goods_id 商品编号 + * @param string $goods_num 购买数量 + * + * @return 商品最终购买价格 + */ + public static function get_goods_final_price($goods) + { + $final_price = '0'; //商品最终购买价格 + $promote_price = '0'; //商品促销价格 + $user_price = '0'; //商品会员价格,预留 + + //取得商品促销价格列表 + $final_price = $goods->price; + + // 计算商品的促销价格 + if ($goods->promote_price > 0) + { + $promote_price = self::bargain_price($goods->promote_price, $goods->promote_start_date, $goods->promote_end_date); + } + else + { + $promote_price = 0; + } + + if ($promote_price != 0) + { + $final_price = $promote_price; + } + + //返回商品最终购买价格 + return $final_price; + } + /** * 判断某个商品是否正在特价促销期 * diff --git a/app/Http/Model/Slide.php b/app/Http/Model/Slide.php index cb8e8b4..f07db5e 100644 --- a/app/Http/Model/Slide.php +++ b/app/Http/Model/Slide.php @@ -1,87 +1,176 @@ where($where);} - + $res['count'] = $model->count(); $res['list'] = array(); - - if($res['count']>0) - { - $res['list'] = $model->orderBy('id', 'desc')->skip($offset)->take($limit)->get()->toArray(); - } - else + + if($res['count'] > 0) { - return false; + if($field){if(is_array($field)){$model = $model->select($field);}else{$model = $model->select(\DB::raw($field));}} + if($order){$model = parent::getOrderByData($model, $order);} + if($offset){}else{$offset = 0;} + if($limit){}else{$limit = 10;} + + $res['list'] = $model->skip($offset)->take($limit)->get(); } - + + return $res; + } + + /** + * 分页,用于前端html输出 + * @param array $where 查询条件 + * @param string $order 排序 + * @param string $field 字段 + * @param int $limit 每页几条 + * @param int $page 当前第几页 + * @return array + */ + public static function getPaginate($where = array(), $order = '', $field = '*', $limit = '') + { + $res = self::getDb(); + + if($where){$res = $res->where($where);} + if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} + if($order){$res = parent::getOrderByData($res, $order);} + if($limit){}else{$limit = 10;} + + return $res->paginate($limit); + } + + /** + * 查询全部 + * @param array $where 查询条件 + * @param string $order 排序 + * @param string $field 字段 + * @param int $limit 取多少条 + * @return array + */ + public static function getAll($where = array(), $order = '', $field = '*', $limit = 10, $offset = 0) + { + $res = self::getDb(); + + if($where){$res = $res->where($where);} + if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} + if($order){$res = parent::getOrderByData($res, $order);} + if($offset){}else{$offset = 0;} + if($limit){}else{$limit = 10;} + + $res = $res->skip($offset)->take($limit)->get(); + return $res; } - - public static function getOne($id) + + /** + * 获取一条 + * @param array $where 条件 + * @param string $field 字段 + * @return array + */ + public static function getOne($where, $field = '*') { - return self::where('id', $id)->first()->toArray(); + $res = self::getDb(); + + if($where){$res = $res->where($where);} + if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} + + $res = $res->first(); + + return $res; } - - public static function add(array $data) + + /** + * 添加 + * @param array $data 数据 + * @return int + */ + public static function add(array $data,$type = 0) { - if ($id = DB::table(self::$table)->insertGetId($data)) + if($type==0) { - return $id; + // 新增单条数据并返回主键值 + return self::insertGetId(parent::filterTableColumn($data,self::TABLE_NAME)); + } + elseif($type==1) + { + /** + * 添加单条数据 + * $data = ['foo' => 'bar', 'bar' => 'foo']; + * 添加多条数据 + * $data = [ + * ['foo' => 'bar', 'bar' => 'foo'], + * ['foo' => 'bar1', 'bar' => 'foo1'], + * ['foo' => 'bar2', 'bar' => 'foo2'] + * ]; + */ + return self::insert($data); } - - return false; } - - public static function modify($where, array $data) + + /** + * 修改 + * @param array $data 数据 + * @param array $where 条件 + * @return bool + */ + public static function edit($data, $where = array()) { - $slide = DB::table(self::$table); - if ($slide->where($where)->update($data)) + if (self::where($where)->update(parent::filterTableColumn($data, self::TABLE_NAME)) !== false) { return true; } - + return false; } - + + /** + * 删除 + * @param array $where 条件 + * @return bool + */ + public static function del($where) + { + return self::where($where)->delete(); + } + //删除一条记录 public static function remove($id) { - if (!self::whereIn('id', explode(',', $id))->delete()) - { - return false; - } - - return true; + return self::whereIn('id', explode(',', $id))->delete(); } - + //获取显示平台文字:0pc,1weixin,2app,3wap public static function getTypeText($where) { diff --git a/resources/views/weixin/article/detail.blade.php b/resources/views/weixin/article/detail.blade.php index 4d61e93..0c6473b 100644 --- a/resources/views/weixin/article/detail.blade.php +++ b/resources/views/weixin/article/detail.blade.php @@ -14,7 +14,7 @@

-
+
阅读