From 96d56d7d8dcadf06339b78f4d6bd34623a9cc202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E5=B3=B0?= <1feng.0595@gmail.com> Date: Mon, 14 Aug 2017 00:38:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Common/Helper.php | 26 +++ .../Controllers/Admin/GoodsController.php | 2 +- app/Http/Controllers/Api/BonusController.php | 158 +++++++++++++++ app/Http/Controllers/Api/CustomController.php | 56 ++++++ app/Http/Controllers/Api/GoodsController.php | 58 ++++++ app/Http/Controllers/Api/ImageController.php | 66 +++++++ app/Http/Controllers/Api/IndexController.php | 6 + app/Http/Controllers/Api/UserController.php | 133 ++----------- .../Controllers/Api/UserMoneyController.php | 1 + .../Controllers/Api/UserPointController.php | 1 + app/Http/Controllers/Home/IndexController.php | 4 +- app/Http/Model/Bonus.php | 83 ++++++++ app/Http/Model/Cart.php | 172 +++++++++++++++++ app/Http/Model/Goods.php | 182 +++++++++++++++++- app/Http/Model/GoodsType.php | 71 ++++++- app/Http/Model/Slide.php | 1 - app/Http/Model/UserBonus.php | 85 ++++++++ app/Http/Model/UserMoney.php | 5 +- app/Http/Model/UserPoint.php | 4 +- resources/views/home/index/test.blade.php | 8 + routes/web.php | 20 +- 21 files changed, 1008 insertions(+), 134 deletions(-) create mode 100644 app/Http/Controllers/Api/BonusController.php create mode 100644 app/Http/Controllers/Api/CustomController.php create mode 100644 app/Http/Controllers/Api/GoodsController.php create mode 100644 app/Http/Controllers/Api/ImageController.php create mode 100644 app/Http/Model/Bonus.php create mode 100644 app/Http/Model/Cart.php create mode 100644 app/Http/Model/UserBonus.php create mode 100644 resources/views/home/index/test.blade.php diff --git a/app/Common/Helper.php b/app/Common/Helper.php index 1717ca2..7b51d72 100644 --- a/app/Common/Helper.php +++ b/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; + } } \ No newline at end of file diff --git a/app/Http/Controllers/Admin/GoodsController.php b/app/Http/Controllers/Admin/GoodsController.php index 47ddd05..c1adc72 100644 --- a/app/Http/Controllers/Admin/GoodsController.php +++ b/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 //关键词 diff --git a/app/Http/Controllers/Api/BonusController.php b/app/Http/Controllers/Api/BonusController.php new file mode 100644 index 0000000..94df844 --- /dev/null +++ b/app/Http/Controllers/Api/BonusController.php @@ -0,0 +1,158 @@ +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); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Api/CustomController.php b/app/Http/Controllers/Api/CustomController.php new file mode 100644 index 0000000..714ca0b --- /dev/null +++ b/app/Http/Controllers/Api/CustomController.php @@ -0,0 +1,56 @@ +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); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Api/GoodsController.php b/app/Http/Controllers/Api/GoodsController.php new file mode 100644 index 0000000..25b407e --- /dev/null +++ b/app/Http/Controllers/Api/GoodsController.php @@ -0,0 +1,58 @@ +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); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Api/ImageController.php b/app/Http/Controllers/Api/ImageController.php new file mode 100644 index 0000000..09b9100 --- /dev/null +++ b/app/Http/Controllers/Api/ImageController.php @@ -0,0 +1,66 @@ + 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); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Api/IndexController.php b/app/Http/Controllers/Api/IndexController.php index 9221b56..1215b2f 100644 --- a/app/Http/Controllers/Api/IndexController.php +++ b/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')); + } + } diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index 7ab0aa6..f2cc784 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/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); - } } \ No newline at end of file diff --git a/app/Http/Controllers/Api/UserMoneyController.php b/app/Http/Controllers/Api/UserMoneyController.php index 32d4631..f02aa96 100644 --- a/app/Http/Controllers/Api/UserMoneyController.php +++ b/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) diff --git a/app/Http/Controllers/Api/UserPointController.php b/app/Http/Controllers/Api/UserPointController.php index 0fdf739..7196312 100644 --- a/app/Http/Controllers/Api/UserPointController.php +++ b/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) diff --git a/app/Http/Controllers/Home/IndexController.php b/app/Http/Controllers/Home/IndexController.php index 7ecae98..456a507 100644 --- a/app/Http/Controllers/Home/IndexController.php +++ b/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 ''; diff --git a/app/Http/Model/Bonus.php b/app/Http/Model/Bonus.php new file mode 100644 index 0000000..d1feb6e --- /dev/null +++ b/app/Http/Model/Bonus.php @@ -0,0 +1,83 @@ +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; + } +} \ No newline at end of file diff --git a/app/Http/Model/Cart.php b/app/Http/Model/Cart.php new file mode 100644 index 0000000..7900294 --- /dev/null +++ b/app/Http/Model/Cart.php @@ -0,0 +1,172 @@ +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; + } + } + } +} \ No newline at end of file diff --git a/app/Http/Model/Goods.php b/app/Http/Model/Goods.php index cefbf01..322814c 100644 --- a/app/Http/Model/Goods.php +++ b/app/Http/Model/Goods.php @@ -1,8 +1,6 @@ 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; + } + } + } +} \ No newline at end of file diff --git a/app/Http/Model/GoodsType.php b/app/Http/Model/GoodsType.php index b5de813..588b4a5 100644 --- a/app/Http/Model/GoodsType.php +++ b/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; + } +} \ No newline at end of file diff --git a/app/Http/Model/Slide.php b/app/Http/Model/Slide.php index 1d9fc5b..5dda011 100644 --- a/app/Http/Model/Slide.php +++ b/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 diff --git a/app/Http/Model/UserBonus.php b/app/Http/Model/UserBonus.php new file mode 100644 index 0000000..672b18f --- /dev/null +++ b/app/Http/Model/UserBonus.php @@ -0,0 +1,85 @@ +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; + } +} \ No newline at end of file diff --git a/app/Http/Model/UserMoney.php b/app/Http/Model/UserMoney.php index f16a1cf..6e1e95e 100644 --- a/app/Http/Model/UserMoney.php +++ b/app/Http/Model/UserMoney.php @@ -1,9 +1,6 @@ +笔记本电脑相关知识 +
{{ csrf_field() }} + + + +
+ \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 08ad983..85eb665 100644 --- a/routes/web.php +++ b/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'); //轮播图