Browse Source

个人中心-优惠券

master
林一峰 7 years ago
parent
commit
5e80de7594
  1. 3
      .gitignore
  2. 37
      app/Http/Controllers/Api/BonusController.php
  3. 73
      app/Http/Controllers/Api/UserBonusController.php
  4. 42
      app/Http/Controllers/Weixin/UserController.php
  5. 3
      app/Http/Model/User.php
  6. 21
      app/Http/Model/UserBonus.php
  7. 2
      resources/views/weixin/common/footer.blade.php
  8. 6
      resources/views/weixin/goods/goodsDetail.blade.php
  9. 4
      resources/views/weixin/user/index.blade.php
  10. 91
      resources/views/weixin/user/userBonusList.blade.php
  11. 8
      routes/web.php

3
.gitignore

@ -10,3 +10,6 @@ Homestead.json
Homestead.yaml
npm-debug.log
.env
/.svn
/build
/.project

37
app/Http/Controllers/Api/BonusController.php

@ -118,41 +118,4 @@ class BonusController extends CommonController
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//用户获取优惠券
public function userGetBonus(Request $request)
{
//参数
$data['bonus_id'] = $request->input('bonus_id',null);
if($data['bonus_id']===null)
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
$data['user_id'] = Token::$uid;
$res = UserBonus::add($data);
if($res !== true)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//用户优惠券列表
public function userBonusList(Request $request)
{
//参数
$data['used_time'] = 0;
$data['user_id'] = Token::$uid;
$res = UserBonus::getList($data);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
}

73
app/Http/Controllers/Api/UserBonusController.php

@ -0,0 +1,73 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Common\Token;
use App\Http\Model\UserBonus;
class UserBonusController extends CommonController
{
public function __construct()
{
parent::__construct();
}
public function userBonusList(Request $request)
{
//参数
$data['limit'] = $request->input('limit', 10);
$data['offset'] = $request->input('offset', 0);
if($request->input('status', '') != ''){$data['status'] = $request->input('status');}
$data['user_id'] = Token::$uid;
$res = UserBonus::getList($data);
if($res == false)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//用户获取优惠券
public function userBonusAdd(Request $request)
{
//参数
$data['bonus_id'] = $request->input('bonus_id','');
$data['get_time'] = time();
$data['user_id'] = Token::$uid;
if($data['bonus_id']=='')
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
$res = UserBonus::add($data);
if($res == false)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//用户删除优惠券
public function userBonusDelete(Request $request)
{
$id = $request->input('id','');
if($id=='')
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
$res = UserBonus::remove($id);
if($res == false)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
}

42
app/Http/Controllers/Weixin/UserController.php

@ -149,6 +149,48 @@ class UserController extends CommonController
return view('weixin.user.userPointList', $data);
}
//用户优惠券列表
public function userBonusList(Request $request)
{
//商品列表
$pagesize = 1;
$offset = 0;
if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;}
$postdata = array(
'limit' => $pagesize,
'offset' => $offset,
'status' => 0,
'access_token' => $_SESSION['weixin_user_info']['access_token']
);
$url = env('APP_API_URL')."/user_bonus_list";
$res = curl_request($url,$postdata,'GET');
$data['list'] = $res['data']['list'];
$data['totalpage'] = ceil($res['data']['count']/$pagesize);
if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1)
{
$html = '';
if($res['data']['list'])
{
foreach($res['data']['list'] as $k => $v)
{
$html .= '<div class="flow-have-adr">';
$html .= '<p class="f-h-adr-title">'.$v['bonus']['name'].'</label><span class="ect-colory fr"><small>¥</small>'.$v['bonus']['money'].'</span><div class="cl"></div></p>';
$html .= '<p class="f-h-adr-con">有效期至'.$v['bonus']['end_time'].' <span class="fr">满'.$v['bonus']['min_amount'].'可用</span></p>';
//$html .= '<div class="adr-edit-del">说明</div>';
$html .= '</div>';
}
}
exit(json_encode($html));
}
return view('weixin.user.userBonusList', $data);
}
//浏览记录
public function userGoodsHistory(Request $request)
{

3
app/Http/Model/User.php

@ -134,7 +134,8 @@ class User extends BaseModel
if(!$user){return false;}
$user->reciever_address = UserAddress::getOne($user->address_id);
$user->collect_goods_count = CollectGoods::where('user_id', $user_id)->count();
$user->bonus_count = UserBonus::where(array('user_id'=>$user_id,'status'=>0))->count();
$userinfo = $user->makeVisible(array('pay_password'))->toArray();
$user->pay_password = 0;
if($userinfo['pay_password']){$user->pay_password = 1;}

21
app/Http/Model/UserBonus.php

@ -26,7 +26,7 @@ class UserBonus extends BaseModel
$model = new UserBonus;
if(isset($used_time)){$where['used_time'] = $used_time;}
if(isset($status)){$where['status'] = $status;}
$model = $model->where($where);
@ -35,7 +35,13 @@ class UserBonus extends BaseModel
if($res['count']>0)
{
$res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray();
$bonus_list = $model->skip($offset)->take($limit)->orderBy('id','desc')->get();
foreach($bonus_list as $k=>$v)
{
$bonus_list[$k]->bonus = Bonus::where('id',$v->bonus_id)->first();
}
$res['list'] = $bonus_list;
}
else
{
@ -45,18 +51,21 @@ class UserBonus extends BaseModel
return $res;
}
public static function getOne($id)
public static function getOne($where)
{
return self::where('id', $id)->first()->toArray();
$res = self::where($where)->first();
if($res){$res->bonus = Bonus::where('id',$res->bonus_id)->first();}
return $res;
}
public static function add(array $data)
{
if(self::where($data)->first()){return '亲,您已获取!';}
if(self::where(['bonus_id'=>$data['bonus_id'],'user_id'=>$data['user_id']])->first()){return '亲,您已获取!';}
if ($id = self::insertGetId($data))
{
return true;
return $id;
}
return false;

2
resources/views/weixin/common/footer.blade.php

@ -4,7 +4,7 @@
<ul>
<?php $current_url = url()->current(); ?>
<a href="<?php echo route('weixin'); ?>"><li<?php if(route('weixin') == $current_url){echo ' class="on"';} ?>><img src="<?php echo env('APP_URL'); ?>/images/weixin/home_icon<?php if(route('weixin') == $current_url){echo '2';} ?>.png"><p>首页</p></li></a>
<a href="categoryList.html"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/brand_icon.png"><p>分类</p></li></a>
<a href="<?php echo route('weixin_category'); ?>"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/brand_icon.png"><p>分类</p></li></a>
<a href="<?php echo route('weixin_cart'); ?>"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/car_icon.png"><p>购物车</p></li></a>
<a href="<?php echo route('weixin_user'); ?>"><li<?php if(route('weixin_user') == $current_url){echo ' class="on"';} ?>><img src="<?php echo env('APP_URL'); ?>/images/weixin/center_icon<?php if(route('weixin_user') == $current_url){echo '2';} ?>.png"><p>个人中心</p></li></a></ul>
</div>

6
resources/views/weixin/goods/goodsDetail.blade.php

@ -13,9 +13,9 @@
<div class="nav_list">
<ul>
<a href="<?php echo route('weixin'); ?>"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/home_icon.png"><p>首页</p></li></a>
<a href="/Weixin/index.php?m=Store&amp;a=index"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/brand_icon.png"><p>分类</p></li></a>
<a href="/Weixin/index.php?m=Cart&amp;a=index"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/car_icon.png"><p>购物车</p></li></a>
<a href="/Weixin/index.php?m=User&amp;a=index"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/center_icon.png"><p>个人中心</p></li></a></ul>
<a href="<?php echo route('weixin_category'); ?>"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/brand_icon.png"><p>分类</p></li></a>
<a href="<?php echo route('weixin_cart'); ?>"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/car_icon.png"><p>购物车</p></li></a>
<a href="<?php echo route('weixin_user'); ?>"><li><img src="<?php echo env('APP_URL'); ?>/images/weixin/center_icon.png"><p>个人中心</p></li></a></ul>
<div class="cl"></div>
</div>
</div>

4
resources/views/weixin/user/index.blade.php

@ -121,8 +121,8 @@
</a>
</li>
<li>
<a href="/index.php/Mobile/User/coupon.html">
<div class="tit">0</div>
<a href="<?php echo route('weixin_user_bonus_list'); ?>">
<div class="tit"><?php echo $user_info['bonus_count']; ?></div>
<p>优惠券</p>
</a>
</li>

91
resources/views/weixin/user/userBonusList.blade.php

@ -0,0 +1,91 @@
<!DOCTYPE html><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>我的优惠券</title><meta name="keywords" content=""><meta name="description" content=""><meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
<link href="<?php echo env('APP_URL'); ?>/css/weixin/style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/weixin/mobile.js"></script></head><body style="background-color:#f1f1f1;">
<div class="classreturn loginsignup">
<div class="ds-in-bl return"><a href="javascript:history.back(-1);"><img src="<?php echo env('APP_URL'); ?>/images/weixin/return.png" alt="返回"></a></div>
<div class="ds-in-bl tit center"><span>我的优惠券</span></div>
</div>
<script type="text/javascript" src="<?php echo env('APP_URL'); ?>/js/layer/mobile/layer.js"></script>
<style>
.bonus_list .flow-have-adr{padding:10px;margin:10px;background-color:#fff;}
.bonus_list .f-h-adr-title .ect-colory{color:#f45239;font-size:32px;}
.bonus_list .f-h-adr-title label{font-size:18px;color:#2e2e2e;margin-right:5px;}
.bonus_list .f-h-adr-con{color:#616161;margin-top:5px;margin-bottom:5px;font-size:14px;}
.bonus_list .adr-edit-del{margin-top:10px;padding-top:8px;border-top:1px dashed #ddd;line-height:22px;color:#a0a0a0;font-size:14px;}
</style>
<div class="bonus_list">
<?php if($list){foreach($list as $k=>$v){ ?>
<div class="flow-have-adr">
<p class="f-h-adr-title"><label><?php echo $v['bonus']['name']; ?></label><span class="ect-colory fr"><small>¥</small><?php echo $v['bonus']['money']; ?></span><div class="cl"></div></p>
<p class="f-h-adr-con">有效期至<?php echo $v['bonus']['end_time']; ?> <span class="fr">满<?php echo $v['bonus']['min_amount']; ?>可用</span></p>
<!-- <div class="adr-edit-del">说明</div> -->
</div>
<?php }} ?>
</div>
<script>
$(function(){
var ajaxload = false;
var maxpage = false;
var startpage = 1;
var totalpage = <?php echo $totalpage; ?>;
var tmp_url = window.location.href;
msg = tmp_url.split("#");
tmp_url = msg[0];
$(window).scroll(function ()
{
var listheight = $(".bonus_list").outerHeight();
if ($(document).scrollTop() + $(window).height() >= listheight)
{
if(startpage >= totalpage)
{
//$("#submit_bt_one").html("已是最后一页,没有更多数据!");
return false;
}
if(!ajaxload && !maxpage)
{
ajaxload = true;
//$("#submit_bt_one").html("努力加载中...");
var url = tmp_url;
var nextpage = startpage+1;
$.get(url,{page_ajax:1,page:nextpage},function(res)
{
if(res)
{
$(".bonus_list").append(res);
startpage++;
if(startpage >= totalpage)
{
maxpage = true;
//$("#submit_bt_one").html("已是最后一页,没有更多数据!");
}
else
{
//$("#submit_bt_one").html("点击加载更多");
}
ajaxload = false;
}
else
{
//$("#submit_bt_one").html("请求失败,请稍候再试!");
ajaxload = false;
}
},'json');
}
}
});
});
</script>
@include('weixin.common.footer')
</body></html>

8
routes/web.php

@ -75,13 +75,15 @@ Route::group(['prefix' => 'weixin', 'namespace' => 'Weixin'], function () {
//微信路由,需登录,全局
Route::group(['prefix' => 'weixin', 'namespace' => 'Weixin', 'middleware' => ['web','wxlogin']], function () {
Route::get('/category', 'CartController@index')->name('weixin_category');
//个人中心
Route::get('/user', 'UserController@index')->name('weixin_user');
Route::get('/userinfo', 'UserController@userinfo')->name('weixin_userinfo');
Route::get('/user_account', 'UserController@userAccount')->name('weixin_user_account');
Route::get('/user_money_list', 'UserController@userMoneyList')->name('weixin_user_money_list');
Route::get('/user_point_list', 'UserController@userPointList')->name('weixin_user_point_list');
//优惠券、红包
Route::get('/user_bonus_list', 'UserController@userBonusList')->name('weixin_user_bonus_list');
//浏览记录
Route::get('/user_goods_history', 'UserController@userGoodsHistory')->name('weixin_user_goods_history');
Route::get('/user_goods_history_delete', 'UserController@userGoodsHistoryDelete')->name('weixin_user_goods_history_delete');
@ -164,8 +166,8 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
Route::get('/user_point_list', 'UserPointController@userPointList'); //用户积分列表
Route::post('/user_point_add', 'UserPointController@userPointAdd');
//优惠券
Route::get('/user_bonus_list', 'BonusController@userBonusList'); //用户优惠券列表
Route::post('/user_get_bonus', 'BonusController@userGetBonus'); //用户获取优惠券
Route::get('/user_bonus_list', 'UserBonusController@userBonusList'); //用户优惠券列表
Route::post('/user_bonus_add', 'UserBonusController@userBonusAdd'); //用户获取优惠券
Route::get('/bonus_list', 'BonusController@bonusList'); //可用获取的优惠券列表
Route::post('/bonus_add', 'BonusController@bonusAdd'); //添加优惠券
Route::post('/bonus_update', 'BonusController@bonusUpdate'); //修改优惠券

Loading…
Cancel
Save