From 178fa1352ec0b827978ee9fa766c3d76d7397ba1 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: Thu, 24 May 2018 00:22:12 +0800 Subject: [PATCH] collectGoods --- .../Api/CollectGoodsController.php | 104 +++++++----- .../Controllers/Api/CommentController.php | 133 ++++++++++++--- app/Http/Controllers/Api/OrderController.php | 89 +++++++++++ app/Http/Controllers/Api/UserController.php | 114 +++++++++++-- .../Controllers/Weixin/OrderController.php | 4 +- app/Http/Logic/CollectGoodsLogic.php | 9 ++ app/Http/Logic/UserLogic.php | 14 ++ app/Http/Model/Cart.php | 151 ------------------ app/Http/Model/CollectGoods.php | 84 ---------- app/Http/Model/User.php | 55 +------ app/Http/Requests/ArticleRequest.php | 2 +- app/Http/Requests/CollectGoodsRequest.php | 4 +- app/Http/Requests/UserRequest.php | 148 +++++++++++++++-- routes/web.php | 2 +- 14 files changed, 542 insertions(+), 371 deletions(-) diff --git a/app/Http/Controllers/Api/CollectGoodsController.php b/app/Http/Controllers/Api/CollectGoodsController.php index 75ced80..642ed38 100644 --- a/app/Http/Controllers/Api/CollectGoodsController.php +++ b/app/Http/Controllers/Api/CollectGoodsController.php @@ -1,11 +1,13 @@ input('limit', 10); - $data['offset'] = $request->input('offset', 0); - $data['user_id'] = Token::$uid; + $limit = $request->input('limit', 10); + $offset = $request->input('offset', 0); + $where['user_id'] = Token::$uid; + if($request->input('is_attention', null) !== null){$where['is_attention'] = $request->input('is_attention');} - $res = CollectGoods::getList($data); - if(!$res) - { - return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res); - } + $res = $this->getLogic()->getList($where, array('id', 'desc'), '*', $offset, $limit); + + /* if($res['count']>0) + { + foreach($res['list'] as $k=>$v) + { + + } + } */ return ReturnData::create(ReturnData::SUCCESS,$res); } - //收藏商品 - public function collectGoodsAdd(Request $request) + public function collectGoodsDetail(Request $request) { //参数 - $data['goods_id'] = $request->input('goods_id',null); - if($request->input('is_attention', null) !== null){$data['is_attention'] = $request->input('is_attention');} - $data['add_time'] = time(); - $data['user_id'] = Token::$uid; + if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $id = $request->input('id'); + $where['id'] = $id; - if($data['goods_id']===null) - { - return ReturnData::create(ReturnData::PARAMS_ERROR); - } - - $res = CollectGoods::add($data); - if($res !== true) + $res = $this->getLogic()->getOne($where); + if(!$res) { - return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res); + return ReturnData::create(ReturnData::RECORD_NOT_EXIST); } return ReturnData::create(ReturnData::SUCCESS,$res); } + //收藏商品 + public function collectGoodsAdd(Request $request) + { + if(Helper::isPostRequest()) + { + $_POST['user_id'] = Token::$uid; + + return $this->getLogic()->add($_POST); + } + } + + //修改 + public function collectGoodsUpdate(Request $request) + { + if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $id = $request->input('id'); + + if(Helper::isPostRequest()) + { + unset($_POST['id']); + $where['id'] = $id; + $where['user_id'] = Token::$uid; + + return $this->getLogic()->edit($_POST,$where); + } + } + //取消收藏商品 public function collectGoodsDelete(Request $request) - { - //参数 - $data['goods_id'] = $request->input('goods_id',null); - $data['user_id'] = Token::$uid; + { + if(!checkIsNumber($request->input('goods_id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $goods_id = $request->input('goods_id'); - if($data['goods_id']===null) - { - return ReturnData::create(ReturnData::PARAMS_ERROR); + if(Helper::isPostRequest()) + { + $where['goods_id'] = $goods_id; + $where['user_id'] = Token::$uid; + + return $this->getLogic()->del($where); } - - $res = CollectGoods::remove($data); - if($res !== true) - { - 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/CommentController.php b/app/Http/Controllers/Api/CommentController.php index 2109e0e..abda5e7 100644 --- a/app/Http/Controllers/Api/CommentController.php +++ b/app/Http/Controllers/Api/CommentController.php @@ -1,12 +1,13 @@ input('limit', 10); + $offset = $request->input('offset', 0); + $where['user_id'] = Token::$uid; + $where['comment_type'] = $request->input('comment_type', 0); //0商品评价,1文章评价 + if($request->input('comment_rank', '') != ''){$where['comment_rank'] = $request->input('comment_rank');} + if($request->input('id_value', '') != ''){$where['id_value'] = $request->input('id_value');} + if($request->input('parent_id', '') != ''){$where['parent_id'] = $request->input('parent_id');} + + $res = $this->getLogic()->getList($where, array('id', 'desc'), '*', $offset, $limit); + + /* if($res['count']>0) + { + foreach($res['list'] as $k=>$v) + { + + } + } */ + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + public function commentDetail(Request $request) + { + //参数 + if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $id = $request->input('id'); + + $where['id'] = $id; + + $res = $this->getLogic()->getOne($where); + if(!$res) + { + return ReturnData::create(ReturnData::RECORD_NOT_EXIST); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //添加 + public function commentAdd(Request $request) + { + if(Helper::isPostRequest()) + { + $_POST['user_id'] = Token::$uid; + $_POST['add_time'] = time(); + + return $this->getLogic()->add($_POST); + } + } + + //评价批量添加 + public function commentBatchAdd(Request $request) + { + if($request->input('comment',null)===null){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $comment = json_decode($request->input('comment'),true); + foreach($comment as $k=>$v) + { + $comment[$k]['user_id'] = Token::$uid; + $comment[$k]['ip_address'] = Helper::getRemoteIp(); + $comment[$k]['add_time'] = time(); + } + + return Comment::batchAdd($comment); + } + + //修改 + public function commentUpdate(Request $request) + { + if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $id = $request->input('id'); + + if(Helper::isPostRequest()) + { + unset($_POST['id']); + $where['id'] = $id; + $where['user_id'] = Token::$uid; + + return $this->getLogic()->edit($_POST,$where); + } + } + + //删除 + public function commentDelete(Request $request) + { + if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $id = $request->input('id'); + + if(Helper::isPostRequest()) + { + $where['id'] = $id; + //$where['user_id'] = Token::$uid; + + return $this->getLogic()->del($where); + } + } + + + + + + + /* public function commentList(Request $request) { //参数 $data['limit'] = $request->input('limit', 10); @@ -56,21 +166,6 @@ class CommentController extends CommonController return Comment::add($data); } - //评价批量添加 - public function commentBatchAdd(Request $request) - { - if($request->input('comment',null)===null){return ReturnData::create(ReturnData::PARAMS_ERROR);} - $comment = json_decode($request->input('comment'),true); - foreach($comment as $k=>$v) - { - $comment[$k]['user_id'] = Token::$uid; - $comment[$k]['ip_address'] = Helper::getRemoteIp(); - $comment[$k]['add_time'] = time(); - } - - return Comment::batchAdd($comment); - } - public function commentUpdate(Request $request) { //参数 @@ -115,5 +210,5 @@ class CommentController extends CommonController } return ReturnData::create(ReturnData::SUCCESS,$res); - } + } */ } \ No newline at end of file diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index f20d293..f2823ad 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -222,4 +222,93 @@ class OrderController extends CommonController return Order::remove($id,Token::$uid); } + + //商城支付宝app支付 + public function orderAlipayApp(Request $request) + { + $id = $request->input('id',null); + if($id===null){return ReturnCode::create(ReturnCode::PARAMS_ERROR);} + + $order = DB::table('order')->where(['id'=>$id,'status'=>0,'user_id'=>Token::$uid])->first(); + if(!$order){return ReturnCode::create(ReturnCode::PARAMS_ERROR);} + + $order_pay = DB::table('order_pay')->where(['id'=>$order->pay_id])->first(); + if(!$order_pay){return ReturnCode::create(ReturnCode::PARAMS_ERROR);} + + require_once base_path('resources/org/alipay_app').'/AopClient.php'; + require_once base_path('resources/org/alipay_app').'/AlipayTradeAppPayRequest.php'; + + $aop = new \AopClient; + $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; + $aop->appId = config('alipay.app_alipay.appId'); + $aop->rsaPrivateKey = config('alipay.app_alipay.rsaPrivateKey'); + $aop->format = "json"; + $aop->charset = "UTF-8"; + $aop->signType = "RSA2"; + $aop->alipayrsaPublicKey = config('alipay.app_alipay.alipayrsaPublicKey'); + //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay + $request = new \AlipayTradeAppPayRequest(); + //SDK已经封装掉了公共参数,这里只需要传入业务参数 + $bizcontent = "{\"body\":\"订单支付\"," + . "\"subject\": \"订单支付\"," + . "\"out_trade_no\": \"".$order_pay->sn."\"," + . "\"total_amount\": \"".$order_pay->pay_amount."\"," + . "\"timeout_express\": \"30m\"," + . "\"product_code\":\"QUICK_MSECURITY_PAY\"" + . "}"; + $request->setNotifyUrl(config('app.url.apiDomain') . '/payment/notify/order_alipay/'); + $request->setBizContent($bizcontent); + //这里和普通的接口调用不同,使用的是sdkExecute + $response = $aop->sdkExecute($request); + //htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题 + return ReturnCode::create(ReturnCode::SUCCESS,$response);//就是orderString 可以直接给客户端请求,无需再做处理。 + } + + //商城微信app支付 + public function orderWxpayApp(Request $request) + { + //参数 + $id = $request->input('id',null); + if($id===null){return ReturnCode::create(ReturnCode::PARAMS_ERROR);} + + $order_info = DB::table('order')->where(['id'=>$id,'status'=>0,'user_id'=>Token::$uid])->first(); + if(!$order_info){return ReturnCode::create(ReturnCode::PARAMS_ERROR);} + + $order_pay = DB::table('order_pay')->where(['id'=>$order_info->pay_id])->first(); + if(!$order_pay){return ReturnCode::create(ReturnCode::PARAMS_ERROR);} + + //1.配置 + $options = config('weixin.app'); + + $app = new \EasyWeChat\Foundation\Application($options); + $payment = $app->payment; + $out_trade_no = $order_pay->sn; + + //2.创建订单 + $attributes = [ + 'trade_type' => 'APP', // JSAPI,NATIVE,APP... + 'body' => '订单支付', + 'detail' => '订单支付', + 'out_trade_no' => $out_trade_no, + 'total_fee' => $order_pay->pay_amount*100, // 单位:分 + 'notify_url' => config('app.url.apiDomain').'payment/notify/app_order_weixin_pay/', // 支付结果通知网址,如果不设置则会使用配置里的默认地址 + //'openid' => '当前用户的 openid', // trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识, + // ... + ]; + + $order = new \EasyWeChat\Payment\Order($attributes); + + //3.统一下单 + $result = $payment->prepare($order); + + if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') + { + $prepayId = $result->prepay_id; + $res = $payment->configForAppPayment($prepayId); + } + + $res['out_trade_no'] = $out_trade_no; + + return ReturnCode::create(ReturnCode::SUCCESS,$res); + } } \ No newline at end of file diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index 1396f26..0a6fe4c 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -1,13 +1,13 @@ input('limit', 10); + $offset = $request->input('offset', 0); + + $where = []; + if($request->input('parent_id', '')!=''){$where['parent_id'] = $request->input('parent_id');} + if($request->input('group_id', '')!=''){$where['group_id'] = $request->input('group_id');} + if($request->input('sex', '')!=''){$where['sex'] = $request->input('sex');} + + $res = $this->getLogic()->getList($where, array('id', 'desc'), '*', $offset, $limit); + + /* if($res['count']>0) + { + foreach($res['list'] as $k=>$v) + { + + } + } */ + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + public function userDetail(Request $request) + { + //参数 + if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $id = $request->input('id'); + $where['id'] = $id; + + $res = $this->getLogic()->getOne($where); + if(!$res) { - return ReturnData::create(ReturnData::SUCCESS, $user); + return ReturnData::create(ReturnData::RECORD_NOT_EXIST); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //添加 + public function userAdd(Request $request) + { + if(Helper::isPostRequest()) + { + return $this->getLogic()->add($_POST); } - else - { - return ReturnData::create(ReturnData::RECORD_NOT_EXIST); + } + + //修改 + public function userUpdate(Request $request) + { + if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $id = $request->input('id'); + + if(Helper::isPostRequest()) + { + unset($_POST['id']); + $where['id'] = $id; + //$where['user_id'] = Token::$uid; + + return $this->getLogic()->edit($_POST,$where); + } + } + + //删除 + public function userDelete(Request $request) + { + if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $id = $request->input('id'); + + if(Helper::isPostRequest()) + { + $where['id'] = $id; + //$where['user_id'] = Token::$uid; + + return $this->getLogic()->del($where); } } + //用户信息 + public function userInfo(Request $request) + { + $where['id'] = Token::$uid; + + $res = $this->getLogic()->getOne($where); + if(!$res) + { + return ReturnData::create(ReturnData::RECORD_NOT_EXIST); + } + + if($res->pay_password){$res->pay_password = 1;}else{$res->pay_password = 0;} + unset($res->password); + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + /* //修改用户信息 public function userInfoUpdate(Request $request) { @@ -487,5 +577,5 @@ class UserController extends CommonController MallDataManager::tokenDelete(['uid'=>Token::$uid]); return ReturnCode::create(ReturnCode::SUCCESS); - } + } */ } \ No newline at end of file diff --git a/app/Http/Controllers/Weixin/OrderController.php b/app/Http/Controllers/Weixin/OrderController.php index 6c802a1..2db307d 100644 --- a/app/Http/Controllers/Weixin/OrderController.php +++ b/app/Http/Controllers/Weixin/OrderController.php @@ -279,13 +279,13 @@ class OrderController extends CommonController //noncestr已填,商户无需重复填写 //spbill_create_ip已填,商户无需重复填写 //sign已填,商户无需重复填写 - $unifiedOrder->setParameter("openid","$openid");//微信用户 + $unifiedOrder->setParameter("openid","$openid");//微信用户openid,trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识, $unifiedOrder->setParameter("body","$body");//商品描述 $unifiedOrder->setParameter("out_trade_no","$out_trade_no");//商户订单号 $unifiedOrder->setParameter("total_fee","$total_fee");//总金额 $unifiedOrder->setParameter("attach","$attach"); //附加数据,选填,在查询API和支付通知中原样返回,可作为自定义参数使用,示例:a=1&b=2 $unifiedOrder->setParameter("notify_url","$notify_url");//通知地址 - $unifiedOrder->setParameter("trade_type","JSAPI");//交易类型 + $unifiedOrder->setParameter("trade_type","JSAPI");//交易类型,JSAPI,NATIVE,APP... $prepay_id = $unifiedOrder->getPrepayId(); //=========步骤3:使用jsapi调起支付============ $jsApi->setPrepayId($prepay_id); diff --git a/app/Http/Logic/CollectGoodsLogic.php b/app/Http/Logic/CollectGoodsLogic.php index c350c7b..6f04c63 100644 --- a/app/Http/Logic/CollectGoodsLogic.php +++ b/app/Http/Logic/CollectGoodsLogic.php @@ -34,6 +34,9 @@ class CollectGoodsLogic extends BaseLogic foreach($res['list'] as $k=>$v) { $res['list'][$k] = $this->getDataView($v); + + $goods = logic('Goods')->getOne(array('id'=>$v->goods_id)); + $res['list'][$k]->goods = $goods; } } @@ -80,9 +83,13 @@ class CollectGoodsLogic extends BaseLogic { if(empty($data)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + $data['add_time'] = time(); + $validator = $this->getValidate($data, 'add'); if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());} + if($this->getModel()->getOne(array('user_id'=>$data['user_id'],'goods_id'=>$data['goods_id']))){return '亲,您已经收藏啦!';} + $res = $this->getModel()->add($data,$type); if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} @@ -111,6 +118,8 @@ class CollectGoodsLogic extends BaseLogic $validator = $this->getValidate($where,'del'); if ($validator->fails()){return ReturnData::create(ReturnData::PARAMS_ERROR, null, $validator->errors()->first());} + if(!$this->getModel()->getOne(array('user_id'=>$where['user_id'],'goods_id'=>$where['goods_id']))){return '商品未收藏';} + $res = $this->getModel()->del($where); if($res === false){return ReturnData::create(ReturnData::SYSTEM_FAIL);} diff --git a/app/Http/Logic/UserLogic.php b/app/Http/Logic/UserLogic.php index 5c0da15..ab1de1e 100644 --- a/app/Http/Logic/UserLogic.php +++ b/app/Http/Logic/UserLogic.php @@ -34,6 +34,8 @@ class UserLogic extends BaseLogic foreach($res['list'] as $k=>$v) { $res['list'][$k] = $this->getDataView($v); + + //$res['list'][$k]->user_name = !empty($res['list'][$k]->mobile) ? $res['list'][$k]->mobile : $res['list'][$k]->user_name; } } @@ -72,6 +74,10 @@ class UserLogic extends BaseLogic $res = $this->getDataView($res); + $res->reciever_address = model('UserAddress')->getOne(['id'=>$res->address_id]); + $res->collect_goods_count = model('CollectGoods')->getDb()->where(['user_id'=>$where['id']])->count(); + $res->bonus_count = model('UserBonus')->getDb()->where(array('user_id'=>$where['id'],'status'=>0))->count(); + return $res; } @@ -126,4 +132,12 @@ class UserLogic extends BaseLogic { return getDataAttr($this->getModel(),$data); } + + //获取用户信息 + public function getUserInfo($user_id) + { + $user = self::where('id', $user_id)->first(); + if(!$user){return false;} + + } } \ No newline at end of file diff --git a/app/Http/Model/Cart.php b/app/Http/Model/Cart.php index 438acb0..fd1bc91 100644 --- a/app/Http/Model/Cart.php +++ b/app/Http/Model/Cart.php @@ -181,157 +181,6 @@ class Cart extends BaseModel return $res; } - /* - //获取列表 - public static function getList(array $param) - { - extract($param); //参数:limit,offset - - $model = self::join('goods', 'goods.id', '=', 'cart.goods_id') - ->where('cart.user_id', $user_id) - ->where('goods.status', Goods::STATUS) - ->select('cart.*','goods.id as goods_id','goods.title','goods.sn','goods.price as goods_price','goods.market_price','goods.litpic','goods.goods_number as stock','goods.promote_start_date','goods.promote_price','goods.promote_end_date'); - - $res['count'] = $model->count(); - $res['list'] = array(); - - if($res['count']>0) - { - $res['list'] = $model->get(); - - foreach ($res['list'] as $k => $v) - { - $res['list'][$k]->is_promote = 0; - if(Goods::bargain_price($v->goods_price,$v->promote_start_date,$v->promote_end_date) > 0){$res['list'][$k]->is_promote = 1;} - - //订货数量大于0 - if ($v->goods_number > 0) - { - $res['list'][$k]->final_price = Goods::get_final_price($v->goods_id); //商品最终价格 - $res['list'][$k]->goods_detail_url = route('weixin_goods_detail',array('id'=>$v->goods_id)); - - //更新购物车中的商品数量 - //self::where('id', $v->id)->update(array('price' => $goods_price)); - } - } - } - else - { - return false; - } - - return $res; - } - - public static function getOne($where) - { - $goods = self::where($where)->first(); - - 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,$user_id) - { - if(!is_array($id)){$id = explode(',', $id);} - if (self::whereIn('id', $id)->where('user_id',$user_id)->delete() === false) - { - return false; - } - - return true; - } - */ - - /** - * 添加商品到购物车 - * - * @access public - * @param integer $goods_id 商品编号 - * @param integer $goods_number 商品数量 - * @param json $property 规格值对应的id json数组 - * @return boolean - */ - public function cartAdd(array $attributes) - { - extract($attributes); - - //获取商品信息 - $goods = Goods::where(['id' => $goods_id, 'status' => Goods::GOODS_NORMAL_STATUS])->first(); - - if (!$goods) - { - return ReturnData::create(ReturnData::PARAMS_ERROR,null,'商品不存在'); - } - - //判断库存 是否足够 - if($goods['goods_number']<$goods_number) - { - return ReturnData::create(ReturnData::PARAMS_ERROR,null,'库存不足'); - } - - //判断购物车商品数 - if(Cart::where(['user_id'=>$user_id])->count() >= 20) - { - return ReturnData::create(ReturnData::PARAMS_ERROR,null,'购物车商品最多20件'); - } - - //查看是否已经有购物车插入记录 - $where = array( - 'user_id' => $user_id, - 'goods_id' => $goods_id - ); - - $cart = Cart::where($where)->first(); - - if($cart) - { - //更新购物车 - $updateArr = array( - 'goods_number' => $goods_number, - 'add_time' => time(), - ); - - self::where(array('id'=>$cart->id))->update($updateArr); - - $cart_id = $cart->id; - } - else - { - //添加购物车 - $cartInsert = array( - 'user_id' => $user_id, - 'goods_id' => $goods_id, - 'goods_number' => $goods_number, - 'add_time' => time(), - ); - - $cart_id = self::insertGetId($cartInsert); - } - - return ReturnData::create(ReturnData::SUCCESS,$cart_id,'购物车添加成功'); - } - /** * 用户购物车商品总数量 * diff --git a/app/Http/Model/CollectGoods.php b/app/Http/Model/CollectGoods.php index 2d584c9..023e61e 100644 --- a/app/Http/Model/CollectGoods.php +++ b/app/Http/Model/CollectGoods.php @@ -168,88 +168,4 @@ class CollectGoods extends BaseModel return $res; } - /* - //获取列表 - public static function getList(array $param) - { - extract($param); //参数:limit,offset - - $where['user_id'] = Token::$uid; - $limit = isset($limit) ? $limit : 10; - $offset = isset($offset) ? $offset : 0; - - $model = new CollectGoods; - - if(isset($type)){$where['type'] = $type;} - - $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(); - - if($res['list']) - { - foreach($res['list'] as $k=>$v) - { - $goods = Goods::getOne(array('id'=>$v['goods_id'],'field'=>array('id', 'typeid', 'tuijian', 'click', 'title', 'sn', 'price','litpic', 'pubdate', 'add_time', 'market_price', 'goods_number', 'sale', 'comments','promote_start_date','promote_price','promote_end_date','goods_img','spec','point'))); - - $res['list'][$k]['goods'] = $goods; - } - } - } - else - { - return false; - } - - return $res; - } - - public static function getOne(array $param) - { - extract($param); //参数 - - $where['id'] = $id; - - return self::where($where)->first(); - } - - public static function add(array $data) - { - if(self::where(array('user_id'=>$data['user_id'],'goods_id'=>$data['goods_id']))->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(array $data) - { - if(!self::where(array('user_id'=>$data['user_id'],'goods_id'=>$data['goods_id']))->first()){return '商品未收藏';} - - if (!self::where(array('user_id'=>$data['user_id'],'goods_id'=>$data['goods_id']))->delete()) - { - return false; - } - - return true; - } */ } \ No newline at end of file diff --git a/app/Http/Model/User.php b/app/Http/Model/User.php index 835ea62..37d83fd 100644 --- a/app/Http/Model/User.php +++ b/app/Http/Model/User.php @@ -272,14 +272,6 @@ class User extends BaseModel return true; } */ - //获取一条用户信息 - public static function getOneUser($where) - { - $user = self::where($where)->first(); - if(!$user){return false;} - - return $user; - } //获取用户信息 public static function getUserInfo($user_id) @@ -377,50 +369,17 @@ class User extends BaseModel return $res; } - //获取性别文字:0未知,1男,2女 - public static function getSexText($where) - { - $res = ''; - if($where['sex'] === 0) - { - $res = '未知'; - } - elseif($where['sex'] === 1) - { - $res = '男'; - } - elseif($where['sex'] === 2) - { - $res = '女'; - } - - return $res; - } - - //描述-文字 + //性别1男2女 public function getSexAttr($data) { - $arr = [0 => '不限', 1 => '黑色', 2 => '白色', 3 => '银色', 4 => '橙色', 5 => '绿色', 6 => '红色', 7 => '蓝色', 8 => '紫色', 9 => '黄色', 10 => '香槟色', 11 => '咖啡色']; - return $arr[$data['des']]; + $arr = [0 => '未知', 1 => '男', 2 => '女']; + return $arr[$data->sex]; } - //获取用户状态文字:1正常 2 删除 3锁定 - public static function getStatusText($where) + //用户状态 1正常状态 2 删除至回收站 3锁定 + public function getStatusAttr($data) { - $res = ''; - if($where['status'] === 1) - { - $res = '正常'; - } - elseif($where['status'] === 2) - { - $res = '删除'; - } - elseif($where['status'] === 3) - { - $res = '锁定'; - } - - return $res; + $arr = [1 => '正常', 2 => '删除', 3 => '锁定']; + return $arr[$data->status]; } } \ No newline at end of file diff --git a/app/Http/Requests/ArticleRequest.php b/app/Http/Requests/ArticleRequest.php index 259166f..3acf1b8 100644 --- a/app/Http/Requests/ArticleRequest.php +++ b/app/Http/Requests/ArticleRequest.php @@ -31,7 +31,7 @@ class ArticleRequest extends BaseRequest 'tuijian.integer' => '推荐等级必须是数字', 'click.required' => '点击量必填', 'click.integer' => '点击量必须为数字', - 'title.max' => '标题不能大于150个字', + 'title.max' => '标题不能大于150个字符', 'title.required' => '必须填写标题', 'writer.max' => '作者不能超过20个字符', 'source.max' => '来源不能超过30个字符', diff --git a/app/Http/Requests/CollectGoodsRequest.php b/app/Http/Requests/CollectGoodsRequest.php index ce8eac7..fe04262 100644 --- a/app/Http/Requests/CollectGoodsRequest.php +++ b/app/Http/Requests/CollectGoodsRequest.php @@ -29,8 +29,8 @@ class CollectGoodsRequest extends BaseRequest //场景验证规则 protected $scene = [ 'add' => ['user_id', 'goods_id', 'add_time', 'is_attention'], - 'edit' => ['user_id', 'goods_id', 'add_time', 'is_attention'] - 'del' => ['id'], + 'edit' => ['user_id', 'goods_id', 'add_time', 'is_attention'], + 'del' => ['user_id', 'goods_id'], ]; /** diff --git a/app/Http/Requests/UserRequest.php b/app/Http/Requests/UserRequest.php index 673b2f9..3eccff5 100644 --- a/app/Http/Requests/UserRequest.php +++ b/app/Http/Requests/UserRequest.php @@ -1,21 +1,145 @@ 'required|integer', + 'email' => 'max:60', + 'user_name' => 'required|max:60', + 'password' => 'required|max:50', + 'pay_password' => 'max:50', + 'head_img' => 'max:255', + 'sex' => 'integer|between:0,2', + 'birthday' => 'date_format:"Y-m-d"', + 'commission' => ['regex:/^\d{0,10}(\.\d{0,2})?$/'], + 'money' => ['regex:/^\d{0,10}(\.\d{0,2})?$/'], + 'frozen_money' => ['regex:/^\d{0,10}(\.\d{0,2})?$/'], + 'point' => 'integer', + 'rank_points' => 'integer', + 'address_id' => 'integer', + 'add_time' => 'integer', + 'user_rank' => 'integer|between:0,99999', + 'parent_id' => 'integer', + 'nickname' => 'max:30', + 'mobile' => 'max:20', + 'status' => 'integer|between:0,5', + 'group_id' => 'integer|between:0,99999', + 'updated_at' => 'integer', + 'signin_time' => 'date_format:"Y-m-d H:i:s"', + 'openid' => 'max:100', + 'unionid' => 'max:128', + 'push_id' => 'max:30', + 'refund_account' => 'max:30', + 'refund_name' => 'max:20', + 'consumption_money' => ['regex:/^\d{0,10}(\.\d{0,2})?$/'], + ]; + + //总的自定义错误信息 + protected $messages = [ + 'id.required' => 'ID必填', + 'id.integer' => 'ID必须为数字', + 'email.max' => 'email不能大于60个字符', + 'user_name.required' => '用户名必填', + 'user_name.max' => '用户名不能大于60个字符', + 'password.required' => '密码必填', + 'password.max' => '密码不能大于50个字符', + 'pay_password.max' => '支付密码不能大于50个字符', + 'head_img.max' => '头像不能大于255个字符', + 'sex.integer' => '性别必须为数字', + 'sex.between' => '性别1男2女', + 'birthday.date_format' => '生日格式不正确', + 'commission.regex' => '累积佣金格式不正确,累积佣金只能带2位小数的数字', + 'money.regex' => '用户余额格式不正确,用户余额只能带2位小数的数字', + 'frozen_money.regex' => '用户冻结资金格式不正确,用户冻结资金只能带2位小数的数字', + 'point.integer' => '用户积分必须为数字', + 'rank_points.integer' => '会员等级积分必须为数字', + 'address_id.integer' => '默认收货地址ID必须为数字', + 'add_time.integer' => '注册时间必须为数字', + 'user_rank.integer' => '用户等级必须为数字', + 'user_rank.between' => '用户等级只能1-99999', + 'parent_id.integer' => '推荐人ID必须为数字', + 'nickname.max' => '昵称不能大于30个字符', + 'mobile.max' => '手机号不能大于20个字符', + 'status.integer' => '用户状态必须为数字', + 'status.between' => '用户状态 1正常状态 2 删除至回收站 3锁定', + 'group_id.integer' => '分组必须为数字', + 'group_id.between' => '分组只能1-99999', + 'updated_at.integer' => '更新时间必须为数字', + 'signin_time.date_format' => '签到时间格式不正确', + 'openid.max' => 'openid不能大于100个字符', + 'unionid.max' => 'unionid不能大于120个字符', + 'push_id.max' => 'push_id不能大于30个字符', + 'refund_account.max' => '退款账户不能大于30个字符', + 'refund_name.max' => '退款姓名不能大于20个字符', + 'consumption_money.regex' => '累计消费金额格式不正确,只能带2位小数的数字', ]; + //场景验证规则 protected $scene = [ - 'add' => ['user_name', 'text', 'status', 'result'], + 'add' => ['email', 'user_name', 'password', 'pay_password', 'head_img', 'sex', 'birthday', 'commission', 'money', 'frozen_money', 'point', 'rank_points', 'address_id', 'add_time', 'user_rank', 'parent_id', 'nickname', 'mobile', 'status', 'group_id', 'updated_at', 'signin_time', 'openid', 'unionid', 'push_id', 'refund_account', 'refund_name', 'consumption_money'], + 'edit' => ['email', 'user_name', 'password', 'pay_password', 'head_img', 'sex', 'birthday', 'commission', 'money', 'frozen_money', 'point', 'rank_points', 'address_id', 'add_time', 'user_rank', 'parent_id', 'nickname', 'mobile', 'status', 'group_id', 'updated_at', 'signin_time', 'openid', 'unionid', 'push_id', 'refund_account', 'refund_name', 'consumption_money'], 'del' => ['id'], ]; + + /** + * Determine if the user is authorized to make this request. + * + * @return bool + */ + public function authorize() + { + return true; //修改为true + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return $this->rules; + } + + /** + * 获取被定义验证规则的错误消息. + * + * @return array + */ + public function messages() + { + return $this->messages; + } + + //获取场景验证规则 + public function getSceneRules($name, $fields = null) + { + $res = array(); + + if(!isset($this->scene[$name])) + { + return false; + } + + $scene = $this->scene[$name]; + if($fields != null && is_array($fields)) + { + $scene = $fields; + } + + foreach($scene as $k=>$v) + { + if(isset($this->rules[$v])){$res[$v] = $this->rules[$v];} + } + + return $res; + } + + //获取场景验证规则自定义错误信息 + public function getSceneRulesMessages() + { + return $this->messages; + } } \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index d9dde11..caa9529 100644 --- a/routes/web.php +++ b/routes/web.php @@ -173,7 +173,7 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web //用户中心 Route::post('/user_signin', 'UserController@signin'); //签到 Route::get('/user_info', 'UserController@userInfo'); //用户详细信息 - Route::post('/user_info_update', 'UserController@userInfoUpdate'); //修改用户信息 + Route::post('/user_info_update', 'UserController@userUpdate'); //修改用户信息 Route::post('/user_password_update', 'UserController@userPasswordUpdate'); //修改用户密码、支付密码 Route::get('/user_list', 'UserController@userList'); //用户列表 Route::post('/user_money_update', 'UserController@userMoneyUpdate'); //修改用户余额