Browse Source

slide

master
ZLW-PC\Administrator 7 years ago
parent
commit
b396765de6
  1. 17
      app/Common/function.php
  2. 3
      app/Http/Controllers/Api/ArctypeController.php
  3. 3
      app/Http/Controllers/Api/ArticleController.php
  4. 83
      app/Http/Controllers/Api/SlideController.php
  5. 18
      app/Http/Controllers/Home/IndexController.php
  6. 7
      app/Http/Model/Arctype.php
  7. 2
      app/Http/Model/Article.php
  8. 4
      app/Http/Model/Cart.php
  9. 43
      app/Http/Model/Goods.php
  10. 187
      app/Http/Model/Slide.php
  11. 2
      resources/views/weixin/article/detail.blade.php

17
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;
}

3
app/Http/Controllers/Api/ArctypeController.php

@ -1,7 +1,6 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use Log;
use App\Common\ReturnData;
@ -35,7 +34,7 @@ class ArctypeController extends CommonController
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
foreach($res as $k=>$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));

3
app/Http/Controllers/Api/ArticleController.php

@ -1,11 +1,11 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use Log;
use DB;
use App\Common\ReturnData;
use App\Common\Helper;
use App\Http\Model\Article;
use App\Http\Logic\ArticleLogic;
@ -61,6 +61,7 @@ class ArticleController extends CommonController
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//添加
public function articleAdd(Request $request)
{

83
app/Http/Controllers/Api/SlideController.php

@ -1,11 +1,12 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Common\Helper;
use App\Http\Model\Slide;
use App\Http\Logic\SlideLogic;
class SlideController extends CommonController
{
@ -13,21 +14,89 @@ class SlideController extends CommonController
{
parent::__construct();
}
public function getLogic()
{
return new SlideLogic();
}
public function slideList(Request $request)
{
//参数
$data['limit'] = $request->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;
}
}
}

18
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";

7
app/Http/Model/Arctype.php

@ -1,9 +1,8 @@
<?php
namespace App\Http\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
class Arctype extends Model
class Arctype extends BaseModel
{
//文章分类模型
@ -13,7 +12,7 @@ class Arctype extends Model
* @var string
*/
protected $table = 'arctype';
const TABLE_NAME = 'article';
const TABLE_NAME = 'arctype';
/**
* 表明模型是否应该被打上时间戳

2
app/Http/Model/Article.php

@ -225,7 +225,7 @@ class Article extends BaseModel
*/
public static function edit($data, $where = array())
{
if (self::where($where)->update(parent::filterTableColumn($data,self::TABLE_NAME)) !== false)
if (self::where($where)->update(parent::filterTableColumn($data, self::TABLE_NAME)) !== false)
{
return true;
}

4
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();
}
//购物车商品总数量

43
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;
}
/**
* 判断某个商品是否正在特价促销期
*

187
app/Http/Model/Slide.php

@ -1,87 +1,176 @@
<?php
namespace App\Http\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
use DB;
class Slide extends Model
class Slide extends BaseModel
{
//轮播图
protected $table = 'slide';
const TABLE_NAME = 'slide';
public $timestamps = false;
protected $guarded = []; //$guarded包含你不想被赋值的字段数组。
const UN_SHOW = 1; // 不显示
const IS_SHOW = 0; // 显示
public static function getList(array $param)
public static function getDb()
{
extract($param); //参数:group_id,limit,offset
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$where['is_show'] = self::IS_SHOW;
$model = new Slide;
if(isset($group_id)){$where['group_id'] = $group_id;}
if(isset($type)){$where['type'] = $type;}
return DB::table(self::TABLE_NAME);
}
/**
* 列表
* @param array $where 查询条件
* @param string $order 排序
* @param string $field 字段
* @param int $offset 偏移量
* @param int $limit 取多少条
* @return array
*/
public static function getList($where = array(), $order = '', $field = '*', $offset = 0, $limit = 10)
{
$model = self::getDb();
if($where){$model = $model->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)
{

2
resources/views/weixin/article/detail.blade.php

@ -14,7 +14,7 @@
<h1 class="arc_tit"><?php echo $post['title']; ?></h1>
<div class="arc_content box">
<div class="ainfo"><?php echo $post['pubdate']; ?> <a style="color:#ee5b03;" href="<?php echo route('weixin_article_category',array('cat'=>$post['typeid'])); ?>"><?php echo $post['type_name']; ?></a></div>
<div class="ainfo"><?php echo $post['pubdate']; ?> <a style="color:#ee5b03;" href="<?php echo route('weixin_article_category',array('cat'=>$post['typeid'])); ?>"><?php echo $post['typename']; ?></a></div>
<?php echo $post['body']; ?>
<div class="arcnext cl mb10" style="margin-top:10px;color:#999;">阅读 <?php echo $post['click']; ?><!-- <a class="red" href="" rel="prev"></a> --></div></div>

Loading…
Cancel
Save