Browse Source

优惠券

master
林一峰 7 years ago
parent
commit
96d56d7d8d
  1. 26
      app/Common/Helper.php
  2. 2
      app/Http/Controllers/Admin/GoodsController.php
  3. 158
      app/Http/Controllers/Api/BonusController.php
  4. 56
      app/Http/Controllers/Api/CustomController.php
  5. 58
      app/Http/Controllers/Api/GoodsController.php
  6. 66
      app/Http/Controllers/Api/ImageController.php
  7. 6
      app/Http/Controllers/Api/IndexController.php
  8. 133
      app/Http/Controllers/Api/UserController.php
  9. 1
      app/Http/Controllers/Api/UserMoneyController.php
  10. 1
      app/Http/Controllers/Api/UserPointController.php
  11. 4
      app/Http/Controllers/Home/IndexController.php
  12. 83
      app/Http/Model/Bonus.php
  13. 172
      app/Http/Model/Cart.php
  14. 182
      app/Http/Model/Goods.php
  15. 71
      app/Http/Model/GoodsType.php
  16. 1
      app/Http/Model/Slide.php
  17. 85
      app/Http/Model/UserBonus.php
  18. 5
      app/Http/Model/UserMoney.php
  19. 4
      app/Http/Model/UserPoint.php
  20. 8
      resources/views/home/index/test.blade.php
  21. 20
      routes/web.php

26
app/Common/Helper.php

@ -248,4 +248,30 @@ class Helper
return $ip;
}
/**
* 建立文件夹
*
* @param string $aimUrl
* @return viod
*/
public static function createDir($aimUrl)
{
$aimUrl = str_replace('', '/', $aimUrl);
$aimDir = '';
$arr = explode('/', $aimUrl);
$result = true;
foreach ($arr as $str)
{
$aimDir .= $str . '/';
if (!file_exists($aimDir))
{
$result = mkdir($aimDir);
}
}
return $result;
}
}

2
app/Http/Controllers/Admin/GoodsController.php

@ -56,7 +56,7 @@ class GoodsController extends CommonController
{
$litpic="";if(!empty($_POST["litpic"])){$litpic = $_POST["litpic"];}else{$_POST['litpic']="";} //缩略图
if(empty($_POST["description"])){if(!empty($_POST["body"])){$_POST['description']=cut_str($_POST["body"]);}} //description
$_POST['addtime'] = $_POST['pubdate'] = time(); //添加&更新时间
$_POST['add_time'] = $_POST['pubdate'] = time(); //添加&更新时间
$_POST['user_id'] = $_SESSION['admin_user_info']['id']; // 发布者id
//关键词

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

@ -0,0 +1,158 @@
<?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\Bonus;
use App\Http\Model\UserBonus;
class BonusController extends CommonController
{
public function __construct()
{
parent::__construct();
}
//可用获取的优惠券列表
public function bonusList(Request $request)
{
//参数
$data['limit'] = $request->input('limit', 10);
$data['offset'] = $request->input('offset', 0);
$data['user_id'] = Token::$uid;
$res = Bonus::getList($data);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//添加优惠券
public function bonusAdd(Request $request)
{
//参数
$data['name'] = $request->input('name',null);
$data['money'] = $request->input('money',null);
$data['min_amount'] = $request->input('min_amount',null);
$data['start_time'] = $request->input('start_time',null);
$data['end_time'] = $request->input('end_time',null);
if($request->input('point', null) !== null){$data['point'] = $request->input('point');}
if($request->input('status', null) !== null){$data['status'] = $request->input('status');}
$data['add_time'] = time();
if($data['name']===null || $data['money']===null || $data['min_amount']===null || $data['start_time']===null || $data['end_time']===null)
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
if($data['start_time'] >= $data['end_time'])
{
return ReturnData::create(ReturnData::PARAMS_ERROR,null,'有效期错误');
}
//正则验证时间格式,未作
$res = Bonus::add($data);
if($res !== true)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//修改优惠券
public function bonusUpdate(Request $request)
{
//参数
$id = $request->input('id',null);
$data['name'] = $request->input('name',null);
$data['money'] = $request->input('money',null);
$data['min_amount'] = $request->input('min_amount',null);
$data['start_time'] = $request->input('start_time',null);
$data['end_time'] = $request->input('end_time',null);
if($request->input('point', null) !== null){$data['point'] = $request->input('point');}
if($request->input('status', null) !== null){$data['status'] = $request->input('status');}
if($id===null || $data['name']===null || $data['money']===null || $data['min_amount']===null || $data['start_time']===null || $data['end_time']===null)
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
if($data['start_time'] >= $data['end_time'])
{
return ReturnData::create(ReturnData::PARAMS_ERROR,null,'有效期错误');
}
//正则验证时间格式,未作
$res = Bonus::modify(array('id'=>$id),$data);
if($res !== true)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//删除优惠券
public function bonusDelete(Request $request)
{
//参数
$id = $request->input('id',null);
if($id===null)
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
$res = Bonus::remove($id);
if($res !== true)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res);
}
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);
}
}

56
app/Http/Controllers/Api/CustomController.php

@ -0,0 +1,56 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Common\Token;
class CustomController extends CommonController
{
public function __construct()
{
parent::__construct();
}
public function userMoneyList(Request $request)
{
//参数
$data['limit'] = $request->input('limit', 10);
$data['offset'] = $request->input('offset', 0);
if($request->input('type', null) !== null){$data['type'] = $request->input('type');}
$res = UserMoney::getList($data);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//添加余额明细
public function userMoneyAdd(Request $request)
{
//参数
$data['type'] = $request->input('type',null);
$data['money'] = $request->input('money',null);
$data['des'] = $request->input('des',null);
if($request->input('user_money', null) !== null){$data['user_money'] = $request->input('user_money');}
$data['add_time'] = time();
$data['user_id'] = Token::$uid;
if($data['type']===null || $data['money']===null || $data['des']===null)
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
$res = UserMoney::add($data);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
}

58
app/Http/Controllers/Api/GoodsController.php

@ -0,0 +1,58 @@
<?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\Goods;
class GoodsController extends CommonController
{
public function __construct()
{
parent::__construct();
}
public function goodsList(Request $request)
{
//参数
$data['limit'] = $request->input('limit', 10);
$data['offset'] = $request->input('offset', 0);
if($request->input('type', null) !== null){$data['type'] = $request->input('type');}
$data['user_id'] = Token::$uid;
$res = Goods::getList($data);
if($res === false)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//添加余额明细
public function userMoneyAdd(Request $request)
{
//参数
$data['type'] = $request->input('type',null);
$data['money'] = $request->input('money',null);
$data['des'] = $request->input('des',null);
if($request->input('user_money', null) !== null){$data['user_money'] = $request->input('user_money');}
$data['add_time'] = time();
$data['user_id'] = Token::$uid;
if($data['type']===null || $data['money']===null || $data['des']===null)
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
$res = UserMoney::add($data);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
}

66
app/Http/Controllers/Api/ImageController.php

@ -0,0 +1,66 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\CommonController;
use Illuminate\Http\Request;
use App\Common\ReturnData;
use App\Common\Helper;
class ImageController extends CommonController
{
public function __construct()
{
parent::__construct();
}
//文件上传,成功返回路径,不含域名
public function imageUpload(Request $request)
{
$file = $_FILES['file'];//得到传输的数据
$type = strtolower(substr(strrchr($file["name"], '.'), 1)); //文件后缀
$image_path = '/uploads/'.date('Y/m',time()).'/'.date('Ymdhis',time()).rand(1000,9999).'.'.$type;
$uploads_path = '/uploads/'.date('Y/m',time()); //存储路径
$allow_type = array('jpg','jpeg','gif','png','doc','docx','txt'); //定义允许上传的类型
//判断文件类型是否被允许上传
if(!in_array($type, $allow_type))
{
//如果不被允许,则直接停止程序运行
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'文件格式不正确');
}
//判断是否是通过HTTP POST上传的
if(!is_uploaded_file($file['tmp_name']))
{
//如果不是通过HTTP POST上传的
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
//文件小于1M
if ($file["size"] < 102400)
{
if ($file["error"] > 0)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$file["error"]);
}
else
{
if(!file_exists($uploads_path))
{
Helper::createDir($uploads_path); //创建文件夹;
}
move_uploaded_file($file["tmp_name"], base_path('public').$image_path);
}
}
else
{
return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'文件不得超过1M');
}
return ReturnData::create(ReturnData::SUCCESS,$image_path);
}
}

6
app/Http/Controllers/Api/IndexController.php

@ -28,5 +28,11 @@ class IndexController extends CommonController
return ReturnData::create(ReturnData::SUCCESS, $res);
}
//关于
public function about(Request $request)
{
return ReturnData::create(ReturnData::SUCCESS,array('url'=>'http://www.baidu.com'));
}
}

133
app/Http/Controllers/Api/UserController.php

@ -28,23 +28,31 @@ class UserController extends CommonController
}
//修改用户信息
public function updateUserInfo(Request $request)
public function userInfoUpdate(Request $request)
{
$data = $data2 = '';
if($request->input('sex', null)!=null){$data['sex'] = $request->input('sex');}
if($request->input('head_img', null)!=null){$data['head_img'] = $request->input('head_img');}
if($request->input('name', null)!=null){$data['name'] = $request->input('name');}
if($request->input('nickname', null)!=null){$data['nickname'] = $request->input('nickname');}
if($request->input('verify_mobile', null)!=null){$data['verify_mobile'] = $request->input('verify_mobile');}
if($request->input('community_id', null)!=null){$data['community_id'] = $request->input('community_id');}
if($request->input('address', null)!=null){$data['address'] = $request->input('address');}
$data = '';
if($request->input('user_name', null)!==null){$data['user_name'] = $request->input('user_name');}
if($request->input('email', null)!==null){$data['email'] = $request->input('email');}
if($request->input('sex', null)!==null){$data['sex'] = $request->input('sex');}
if($request->input('birthday', null)!==null){$data['birthday'] = $request->input('birthday');}
if($request->input('money', null)!==null){$data['money'] = $request->input('money');}
if($request->input('frozen_money', null)!==null){$data['frozen_money'] = $request->input('frozen_money');}
if($request->input('point', null)!==null){$data['point'] = $request->input('point');}
if($request->input('address_id', null)!==null){$data['address_id'] = $request->input('address_id');}
if($request->input('user_rank', null)!==null){$data['user_rank'] = $request->input('user_rank');}
if($request->input('parent_id', null)!==null){$data['parent_id'] = $request->input('parent_id');}
if($request->input('nickname', null)!==null){$data['nickname'] = $request->input('nickname');}
if($request->input('mobile', null)!==null){$data['mobile'] = $request->input('mobile');}
if($request->input('status', null)!==null){$data['status'] = $request->input('status');}
if($request->input('group_id', null)!==null){$data['group_id'] = $request->input('group_id');}
if($request->input('password', null)!==null){$data['password'] = $request->input('password');}
if ($data != '')
{
MallDataManager::userUpdate(['id'=>Token::$uid],$data);
User::modify(['id'=>Token::$uid],$data);
}
return ReturnCode::create(ReturnCode::SUCCESS);
return ReturnData::create(ReturnData::SUCCESS);
}
//用户列表
@ -347,30 +355,6 @@ class UserController extends CommonController
}
}
//用户意见反馈
public function feedback(Request $request)
{
$content = $request->input('content', null);
if(!$content)
return response(ReturnCode::create(ReturnCode::PARAMS_ERROR));
if ($user = MallDataManager::userFirst(['id'=>Token::$uid]))
{
$id = MallDataManager::mallFeedbackinsertGetId(['content' => $content, 'user_id' => Token::$uid]);
return response(ReturnCode::create(ReturnCode::SUCCESS,$id));
}
else
{
return response(ReturnCode::create(ReturnCode::AUTHORIZE_FAIL));
}
}
//关于
public function about(Request $request)
{
return response(ReturnCode::create(ReturnCode::SUCCESS,['url'=>'http://www.baidu.com']));
}
//修改手机号
public function changeMobile(Request $request)
{
@ -427,81 +411,4 @@ class UserController extends CommonController
return ReturnCode::create(ReturnCode::SUCCESS);
}
//添加收货地址
public function userAddressAdd(Request $request)
{
//参数
$data['name'] = $request->input('name',null);
$data['mobile'] = $request->input('mobile',null);
$data['country'] = $request->input('country',null);
$data['province'] = $request->input('province',null);
$data['city'] = $request->input('city',null);
$data['district'] = $request->input('district',null);
$data['address'] = $request->input('address',null);
if($request->input('telphone',null)!==null){$data['telphone'] = $request->input('telphone');}
if($request->input('zipcode',null)!==null){$data['zipcode'] = $request->input('zipcode');}
if($request->input('email',null)!==null){$data['email'] = $request->input('email');}
if($request->input('best_time',null)!==null){$data['best_time'] = $request->input('best_time');}
if($request->input('is_default',null)!==null){$data['is_default'] = $request->input('is_default');}
if($data['name']===null || $data['mobile']===null || $data['address']===null || $data['country']===null || $data['province']===null || $data['city']===null || $data['district']===null)
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
$res = UserAddress::add($data);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//修改收货地址
public function userAddressUpdate(Request $request)
{
//参数
$data['id'] = $request->input('id',null);
$data['name'] = $request->input('name',null);
$data['mobile'] = $request->input('mobile',null);
$data['country'] = $request->input('country',null);
$data['province'] = $request->input('province',null);
$data['city'] = $request->input('city',null);
$data['district'] = $request->input('district',null);
$data['address'] = $request->input('address',null);
if($request->input('telphone',null)!==null){$data['telphone'] = $request->input('telphone');}
if($request->input('zipcode',null)!==null){$data['zipcode'] = $request->input('zipcode');}
if($request->input('email',null)!==null){$data['email'] = $request->input('email');}
if($request->input('best_time',null)!==null){$data['best_time'] = $request->input('best_time');}
if($request->input('is_default',null)!==null){$data['is_default'] = $request->input('is_default');}
if($data['id']===null || $data['name']===null || $data['mobile']===null || $data['address']===null || $data['country']===null || $data['province']===null || $data['city']===null || $data['district']===null)
{
return ReturnData::create(ReturnData::PARAMS_ERROR);
}
$res = UserAddress::modify($data);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
//删除收货地址
public function userAddressDelete(Request $request)
{
//参数
$id = $request->input('id',null);
$res = UserAddress::remove($id);
if(!$res)
{
return ReturnData::create(ReturnData::SYSTEM_FAIL);
}
return ReturnData::create(ReturnData::SUCCESS,$res);
}
}

1
app/Http/Controllers/Api/UserMoneyController.php

@ -20,6 +20,7 @@ class UserMoneyController extends CommonController
$data['limit'] = $request->input('limit', 10);
$data['offset'] = $request->input('offset', 0);
if($request->input('type', null) !== null){$data['type'] = $request->input('type');}
$data['user_id'] = Token::$uid;
$res = UserMoney::getList($data);
if(!$res)

1
app/Http/Controllers/Api/UserPointController.php

@ -20,6 +20,7 @@ class UserPointController extends CommonController
$data['limit'] = $request->input('limit', 10);
$data['offset'] = $request->input('offset', 0);
if($request->input('type', null) !== null){$data['type'] = $request->input('type');};
$data['user_id'] = Token::$uid;
$res = UserPoint::getList($data);
if(!$res)

4
app/Http/Controllers/Home/IndexController.php

@ -258,8 +258,8 @@ class IndexController extends CommonController
//测试页面
public function test()
{
return base_path('resources/org');
{return view('home.index.test');
//return base_path('resources/org');
//$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
//return $qrcode->size(500)->generate('Make a qrcode without Laravel!');
//return '<img src="data:image/png;base64,'.base64_encode(\QrCode::format('png')->encoding('UTF-8')->size(200)->generate('http://www.72p.org/')).'">';

83
app/Http/Model/Bonus.php

@ -0,0 +1,83 @@
<?php
namespace App\Http\Model;
class Bonus extends BaseModel
{
//优惠券
protected $table = 'bonus';
public $timestamps = false;
/**
* 不能被批量赋值的属性
*
* @var array
*/
protected $guarded = [];
const STATUS = 0; // 优惠券可以
//获取列表
public static function getList(array $param)
{
extract($param); //参数:limit,offset
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$where['status'] = self::STATUS;
$model = new Bonus;
$model = $model->where($where);
$res['count'] = $model->count();
$res['list'] = array();
if($res['count']>0)
{
$res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray();
}
else
{
return false;
}
return $res;
}
public static function getOne($id)
{
return self::where('id', $id)->first()->toArray();
}
public static function add(array $data)
{
if ($id = self::insertGetId($data))
{
return true;
}
return false;
}
public static function modify($where, array $data)
{
if (self::where($where)->update($data)!==false)
{
return true;
}
return false;
}
//删除一条记录
public static function remove($id)
{
if (!self::whereIn('id', explode(',', $id))->delete())
{
return false;
}
return true;
}
}

172
app/Http/Model/Cart.php

@ -0,0 +1,172 @@
<?php
namespace App\Http\Model;
class Cart extends BaseModel
{
//产品模型
/**
* 关联到模型的数据表
*
* @var string
*/
protected $table = 'cart';
/**
* 表明模型是否应该被打上时间戳
* 默认情况下,Eloquent 期望 created_at 和updated_at 已经存在于数据表中,如果你不想要这些 Laravel 自动管理的数据列,在模型类中设置 $timestamps 属性为 false
*
* @var bool
*/
public $timestamps = false;
//protected $guarded = []; //$guarded包含你不想被赋值的字段数组。
//protected $fillable = ['name']; //定义哪些字段是可以进行赋值的,与$guarded相反
/**
* The connection name for the model.
* 默认情况下,所有的 Eloquent 模型使用应用配置中的默认数据库连接,如果你想要为模型指定不同的连接,可以通过 $connection 属性来设置
* @var string
*/
//protected $connection = 'connection-name';
const STATUS = 0; //商品是否删除,0未删除
//获取列表
public static function getList($uid)
{
$goods = self::join('goods', 'goods.id', '=', 'cart.goods_id')
->where('cart.user_id', $uid)
->where('goods.status', 0)
->select('cart.*')
->get();
if($goods)
{
foreach ($goods as $key => $value)
{
//订货数量大于0
if ($value->goods_number > 0)
{
$goods->goods_price = $goods_price = Goods::get_final_price($value->goods_id);
//更新购物车中的商品数量
self::where('id', $value->id)->update(array('goods_price' => $goods_price));
}
}
}
return $goods->toArray();
}
public static function getOne($id)
{
if(isset($status)){$where['status'] = $status;}else{$where['status'] = self::STATUS;}
$where['id'] = $id;
$goods = self::where($where)->first()->toArray();
$goods['price'] = get_final_price($id);
return $goods;
}
public static function add(array $data)
{
if ($id = self::insertGetId($data))
{
return $id;
}
return false;
}
public static function modify($where, array $data)
{
if (self::where($where)->update($data))
{
return true;
}
return false;
}
//删除一条记录
public static function remove($id)
{
if (!self::whereIn('id', explode(',', $id))->delete())
{
return false;
}
return true;
}
/**
* 取得商品最终使用价格
*
* @param string $goods_id 商品编号
* @param string $goods_num 购买数量
*
* @return 商品最终购买价格
*/
public static function get_final_price($goods_id)
{
$final_price = '0'; //商品最终购买价格
$promote_price = '0'; //商品促销价格
$user_price = '0'; //商品会员价格,预留
//取得商品促销价格列表
$goods = Goods::where('id',$goods_id)->where('status',0)->first(['promote_price','promote_start_date','promote_end_date','price']);
$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;
}
/**
* 判断某个商品是否正在特价促销期
*
* @access public
* @param float $price 促销价格
* @param string $start 促销开始日期
* @param string $end 促销结束日期
* @return float 如果还在促销期则返回促销价,否则返回0
*/
public static function bargain_price($price, $start, $end)
{
if ($price == 0)
{
return 0;
}
else
{
$time = time();
if ($time >= $start && $time <= $end)
{
return $price;
}
else
{
return 0;
}
}
}
}

182
app/Http/Model/Goods.php

@ -1,8 +1,6 @@
<?php
namespace App\Http\Model;
use App\Common\Token;
class Goods extends BaseModel
{
//产品模型
@ -32,6 +30,13 @@ class Goods extends BaseModel
*/
//protected $connection = 'connection-name';
//常用字段
protected $common_field = [
'id', 'typeid', 'tuijian', 'click', 'title', 'goods_sn', 'price','litpic', 'pubdate', 'addtime', 'market_price', 'goods_number', 'sale', 'comments','promote_start_date','promote_price','promote_end_date','goods_img','spec','point'
];
const STATUS = 0; //商品是否删除,0未删除
/**
* 获取关联到产品的分类
*/
@ -40,4 +45,175 @@ class Goods extends BaseModel
return $this->belongsTo(GoodsType::class, 'typeid', 'id');
}
}
//获取列表
public static function getList(array $param)
{
extract($param); //参数:limit,offset
$where = '';
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$model = new Goods;
if(isset($typeid)){$where['typeid'] = $typeid;}
if(isset($tuijian)){$where['tuijian'] = $tuijian;}
if(isset($status)){$where['status'] = $status;}else{$where['status'] = self::STATUS;}
if($where !== '')
{
$model = $model->where($where);
}
if(isset($keyword)){$model = $model->where("title", "like", "%$keyword%");} //关键词搜索
if(isset($goods_sn)){$model = $model->where("goods_sn", "like", "%$goods_sn%");} //货号搜索
if(isset($max_price) && isset($min_price)){$model = $model->where("price", ">=", $min_price)->where("price", "<=", $max_price);} //价格区间搜索
$res['count'] = $model->count();
$res['list'] = array();
//排序
if(isset($orderby))
{
switch ($orderby)
{
case 1:
$model = $model->orderBy('sale','desc'); //销量从高到低
break;
case 2:
$model = $model->orderBy('comments','desc'); //评论从高到低
break;
case 3:
$model = $model->orderBy('price','desc'); //价格从高到低
break;
case 4:
$model = $model->orderBy('price','asc'); //价格从低到高
break;
default:
$model = $model->orderBy('pubdate','desc'); //价格从低到高
}
}
if($res['count']>0)
{
$res['list'] = $model->select(self::$common_field)->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray();
}
else
{
return false;
}
return $res;
}
public static function getOne($id)
{
if(isset($status)){$where['status'] = $status;}else{$where['status'] = self::STATUS;}
$where['id'] = $id;
$goods = self::where($where)->first()->toArray();
$goods['price'] = get_final_price($id);
return $goods;
}
public static function add(array $data)
{
if ($id = self::insertGetId($data))
{
return $id;
}
return false;
}
public static function modify($where, array $data)
{
if (self::where($where)->update($data))
{
return true;
}
return false;
}
//删除一条记录
public static function remove($id)
{
if (!self::whereIn('id', explode(',', $id))->delete())
{
return false;
}
return true;
}
/**
* 取得商品最终使用价格
*
* @param string $goods_id 商品编号
* @param string $goods_num 购买数量
*
* @return 商品最终购买价格
*/
public static function get_final_price($goods_id)
{
$final_price = '0'; //商品最终购买价格
$promote_price = '0'; //商品促销价格
$user_price = '0'; //商品会员价格,预留
//取得商品促销价格列表
$goods = Goods::where('id',$goods_id)->where('status',0)->first(['promote_price','promote_start_date','promote_end_date','price']);
$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;
}
/**
* 判断某个商品是否正在特价促销期
*
* @access public
* @param float $price 促销价格
* @param string $start 促销开始日期
* @param string $end 促销结束日期
* @return float 如果还在促销期则返回促销价,否则返回0
*/
public static function bargain_price($price, $start, $end)
{
if ($price == 0)
{
return 0;
}
else
{
$time = time();
if ($time >= $start && $time <= $end)
{
return $price;
}
else
{
return 0;
}
}
}
}

71
app/Http/Model/GoodsType.php

@ -23,4 +23,73 @@ class GoodsType extends BaseModel
return $this->hasMany(GoodsType::class, 'typeid', 'id');
}
}
//获取列表
public static function getList(array $param)
{
extract($param); //参数:limit,offset
$where = '';
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$model = new GoodsType;
if(isset($pid)){$where['pid'] = $pid;}
if($where !== '')
{
$model = $model->where($where);
}
$res['count'] = $model->count();
$res['list'] = array();
if($res['count']>0)
{
$res['list'] = $model->skip($offset)->take($limit)->orderBy('listorder','desc')->get()->toArray();
}
else
{
return false;
}
return $res;
}
public static function getOne($id)
{
return self::where('id', $id)->first()->toArray();
}
public static function add(array $data)
{
if ($id = self::insertGetId($data))
{
return $id;
}
return false;
}
public static function modify($where, array $data)
{
if (self::where($where)->update($data))
{
return true;
}
return false;
}
//删除一条记录
public static function remove($id)
{
if (!self::whereIn('id', explode(',', $id))->delete())
{
return false;
}
return true;
}
}

1
app/Http/Model/Slide.php

@ -2,7 +2,6 @@
namespace App\Http\Model;
use Illuminate\Database\Eloquent\Model;
use App\Common\Token;
use DB;
class Slide extends Model

85
app/Http/Model/UserBonus.php

@ -0,0 +1,85 @@
<?php
namespace App\Http\Model;
class UserBonus extends BaseModel
{
//用户优惠券
protected $table = 'user_bonus';
public $timestamps = false;
/**
* 不能被批量赋值的属性
*
* @var array
*/
protected $guarded = [];
//获取列表
public static function getList(array $param)
{
extract($param); //参数:limit,offset
$where['user_id'] = $user_id;
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;
$model = new UserBonus;
if(isset($used_time)){$where['used_time'] = $used_time;}
$model = $model->where($where);
$res['count'] = $model->count();
$res['list'] = array();
if($res['count']>0)
{
$res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray();
}
else
{
return false;
}
return $res;
}
public static function getOne($id)
{
return self::where('id', $id)->first()->toArray();
}
public static function add(array $data)
{
if(self::where($data)->first()){return '亲,您已获取!';}
if ($id = self::insertGetId($data))
{
return true;
}
return false;
}
public static function modify($where, array $data)
{
if (self::where($where)->update($data))
{
return true;
}
return false;
}
//删除一条记录
public static function remove($id)
{
if (!self::whereIn('id', explode(',', $id))->delete())
{
return false;
}
return true;
}
}

5
app/Http/Model/UserMoney.php

@ -1,9 +1,6 @@
<?php
namespace App\Http\Model;
use App\Common\Token;
use DB;
class UserMoney extends BaseModel
{
//用户余额明细
@ -23,7 +20,7 @@ class UserMoney extends BaseModel
{
extract($param); //参数:limit,offset
$where['user_id'] = Token::$uid;
$where['user_id'] = $user_id;
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;

4
app/Http/Model/UserPoint.php

@ -1,8 +1,6 @@
<?php
namespace App\Http\Model;
use App\Common\Token;
class UserPoint extends BaseModel
{
//用户积分明细
@ -22,7 +20,7 @@ class UserPoint extends BaseModel
{
extract($param); //参数:limit,offset
$where['user_id'] = Token::$uid;
$where['user_id'] = $user_id;
$limit = isset($limit) ? $limit : 10;
$offset = isset($offset) ? $offset : 0;

8
resources/views/home/index/test.blade.php

@ -0,0 +1,8 @@
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /><meta http-equiv="Cache-Control" content="no-siteapp" /><meta http-equiv="Cache-Control" content="no-transform" /><meta name="mobile-agent" content="format=xhtml;url=http://m.bnbni.com/cat{dede:type}[field:id/]{/dede:type}/id{dede:field name='aid' /}">
<title>笔记本电脑相关知识</title></head><body><script>site();</script>
<form action="/dataapi/image_upload" name="form" method="post" enctype="multipart/form-data">{{ csrf_field() }}
<input type="file" name="file" />
<input type="submit" name="submit" value="上传" />
<input type="text" name="token" value="72d623d26a1a6d61186a97f9ccf752f7" />
</form>
</body></html>

20
routes/web.php

@ -187,10 +187,12 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
//接口路由,需token验证
Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web','token']], function () {
//用户中心
Route::post('/user_signin', 'UserController@signin');
Route::get('/user_info', 'UserController@userInfo');
Route::get('/user_list', 'UserController@userList');
Route::get('/user_money_list', 'UserMoneyController@userMoneyList'); //余额明细
Route::post('/user_signin', 'UserController@signin'); //签到
Route::get('/user_info', 'UserController@userInfo'); //用户详细信息
Route::post('/user_info_update', 'UserController@userInfoUpdate'); //修改用户信息
Route::get('/user_list', 'UserController@userList'); //用户列表
Route::get('/user_money_list', 'UserMoneyController@userMoneyList'); //用户余额明细
Route::post('/user_money_add', 'UserMoneyController@userMoneyAdd'); //添加余额明细
//浏览记录
//商品
@ -212,10 +214,15 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
//分销
//积分
Route::get('/user_point_list', 'UserPointController@userPointList');
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('/bonus_list', 'BonusController@bonusList'); //可用获取的优惠券列表
Route::post('/bonus_add', 'BonusController@bonusAdd'); //添加优惠券
Route::post('/bonus_update', 'BonusController@bonusUpdate'); //修改优惠券
Route::post('/bonus_delete', 'BonusController@bonusDelete'); //删除优惠券
//微信
//意见反馈
@ -226,6 +233,7 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
Route::get('/verifycode_check', 'VerifyCodeController@check'); //验证码校验
Route::get('/andriod_upgrade', 'IndexController@andriodUpgrade'); //安卓升级
//图片上传
Route::post('/image_upload', 'ImageController@imageUpload'); //普通文件/图片上传
//二维码
Route::get('/create_simple_qrcode', 'QrcodeController@createSimpleQrcode');
//轮播图

Loading…
Cancel
Save