diff --git a/app/Common/function.php b/app/Common/function.php index 412fa81..dd04082 100644 --- a/app/Common/function.php +++ b/app/Common/function.php @@ -18,7 +18,6 @@ if (! function_exists('curl_request')) case 'POST' : curl_setopt($curl, CURLOPT_POST, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS, $params); - break; case 'PUT' : curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); diff --git a/app/Http/Controllers/Api/CommentController.php b/app/Http/Controllers/Api/CommentController.php index e2c4983..192d737 100644 --- a/app/Http/Controllers/Api/CommentController.php +++ b/app/Http/Controllers/Api/CommentController.php @@ -15,17 +15,19 @@ class CommentController extends CommonController parent::__construct(); } - public function goodsCommentList(Request $request) + public function commentList(Request $request) { //参数 $data['limit'] = $request->input('limit', 10); $data['offset'] = $request->input('offset', 0); $data['user_id'] = Token::$uid; $data['comment_type'] = $request->input('comment_type', 0); //0商品评价,1文章评价 - if($request->input('comment_rank', null) !== null){$data['comment_rank'] = $request->input('comment_rank');} + if($request->input('comment_rank', '') != ''){$data['comment_rank'] = $request->input('comment_rank');} + if($request->input('id_value', '') != ''){$data['id_value'] = $request->input('id_value');} + if($request->input('parent_id', '') != ''){$data['parent_id'] = $request->input('parent_id');} $res = Comment::getList($data); - if($res !== true) + if($res === false) { return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res); } @@ -33,16 +35,14 @@ class CommentController extends CommonController return ReturnData::create(ReturnData::SUCCESS,$res); } - //添加评价 - public function goodsCommentAdd(Request $request) + //添加一条评价 + public function commentAdd(Request $request) { //参数 $data['comment_type'] = $request->input('comment_type',0); $data['id_value'] = $request->input('id_value',null); $data['content'] = $request->input('content',null); $data['comment_rank'] = $request->input('comment_rank',null); - if($request->input('email', null) !== null){$data['email'] = $request->input('email');} - if($request->input('user_name', null) !== null){$data['user_name'] = $request->input('user_name');} if($request->input('ip_address', null) !== null){$data['ip_address'] = $request->input('ip_address');} if($request->input('parent_id', null) !== null){$data['parent_id'] = $request->input('parent_id');} $data['add_time'] = time(); @@ -54,47 +54,50 @@ class CommentController extends CommonController return ReturnData::create(ReturnData::PARAMS_ERROR); } - $res = Comment::add($data); - if($res !== true) - { - return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res); - } + 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 ReturnData::create(ReturnData::SUCCESS,$res); + return Comment::batchAdd($comment); } - public function goodsCommentUpdate(Request $request) + public function commentUpdate(Request $request) { //参数 $id = $request->input('id',null); - $data['comment_type'] = $request->input('comment_type',0); - $data['id_value'] = $request->input('id_value',null); - $data['content'] = $request->input('content',null); - $data['comment_rank'] = $request->input('comment_rank',null); - if($request->input('email', null) !== null){$data['email'] = $request->input('email');} - if($request->input('user_name', null) !== null){$data['user_name'] = $request->input('user_name');} + if($request->input('content', null) !== null){$data['content'] = $request->input('content');} + if($request->input('comment_rank', null) !== null){$data['comment_rank'] = $request->input('comment_rank');} if($request->input('ip_address', null) !== null){$data['ip_address'] = $request->input('ip_address');} if($request->input('parent_id', null) !== null){$data['parent_id'] = $request->input('parent_id');} - $data['add_time'] = time(); - $data['user_id'] = Token::$uid; - $data['ip_address'] = Helper::getRemoteIp(); + if($id===null) { return ReturnData::create(ReturnData::PARAMS_ERROR); } - $res = Comment::modify(array('id'=>$id),$data); - if($res !== true) - { - return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res); - } + if(isset($data)) + { + $data['user_id'] = Token::$uid; + Comment::modify(array('id'=>$id),$data); + } - return ReturnData::create(ReturnData::SUCCESS,$res); + return ReturnData::create(ReturnData::SUCCESS); } //删除评价 - public function goodsCommentDelete(Request $request) + public function commentDelete(Request $request) { //参数 $data['comment_type'] = $request->input('comment_type',null); @@ -107,7 +110,7 @@ class CommentController extends CommonController } $res = Comment::remove($data); - if($res !== true) + if($res === false) { return ReturnData::create(ReturnData::SYSTEM_FAIL,null,$res); } diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index 2cb2213..065519f 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use App\Common\ReturnData; use App\Common\Token; use App\Http\Model\Order; +use DB; class OrderController extends CommonController { @@ -19,7 +20,7 @@ class OrderController extends CommonController { //参数 $data['user_id'] = Token::$uid; - $data['status'] = $request->input('status',''); + $data['status'] = $request->input('status',-1); return Order::getList($data); } @@ -32,6 +33,7 @@ class OrderController extends CommonController $data['order_id'] = $request->input('order_id',''); if($request->input('order_status','') != ''){$data['order_status'] = $request->input('order_status');} if($request->input('pay_status','') != ''){$data['pay_status'] = $request->input('pay_status');} + if($request->input('refund_status','') != ''){$data['refund_status'] = $request->input('refund_status');} if($data['order_id']=='') { @@ -64,6 +66,148 @@ class OrderController extends CommonController return Order::add($data); } + //订单修改 + public function orderUpdate(Request $request) + { + if($request->input('id', '')!=''){$where['id'] = $request->input('id');} + if($request->input('order_sn', '')!=''){$where['order_sn'] = $request->input('order_sn');} + + if($request->input('order_amount', '')!=''){$data['order_amount'] = $request->input('order_amount');} + if($request->input('out_trade_no', '')!=''){$data['out_trade_no'] = $request->input('out_trade_no');} + if($request->input('shipping_name', '')!=''){$data['shipping_name'] = $request->input('shipping_name');} + if($request->input('shipping_id', '')!=''){$data['shipping_id'] = $request->input('shipping_id');} + if($request->input('shipping_sn', '')!=''){$data['shipping_sn'] = $request->input('shipping_sn');} + if($request->input('shipping_fee', '')!=''){$data['shipping_fee'] = $request->input('shipping_fee');} + if($request->input('shipping_time', '')!=''){$data['shipping_time'] = $request->input('shipping_time');} + if($request->input('name', '')!=''){$data['name'] = $request->input('name');} + if($request->input('province', '')!=''){$data['province'] = $request->input('province');} + if($request->input('city', '')!=''){$data['city'] = $request->input('city');} + if($request->input('district', '')!=''){$data['district'] = $request->input('district');} + if($request->input('address', '')!=''){$data['address'] = $request->input('address');} + if($request->input('zipcode', '')!=''){$data['zipcode'] = $request->input('zipcode');} + if($request->input('mobile', '')!=''){$data['mobile'] = $request->input('mobile');} + if($request->input('message', '')!=''){$data['message'] = $request->input('message');} + if($request->input('is_comment', '')!=''){$data['is_comment'] = $request->input('is_comment');} + if($request->input('is_delete', '')!=''){$data['is_delete'] = $request->input('is_delete');} + if($request->input('to_buyer', '')!=''){$data['to_buyer'] = $request->input('to_buyer');} + if($request->input('invoice', '')!=''){$data['invoice'] = $request->input('invoice');} + if($request->input('invoice_title', '')!=''){$data['invoice_title'] = $request->input('invoice_title');} + if($request->input('invoice_taxpayer_number', '')!=''){$data['invoice_taxpayer_number'] = $request->input('invoice_taxpayer_number');} + + if(!isset($where)){return ReturnData::create(ReturnData::PARAMS_ERROR);} + + if (isset($data)) + { + $where['user_id'] = Token::$uid; + Order::modify($where,$data); + } + + return ReturnData::create(ReturnData::SUCCESS); + } + + //订单状态修改 + public function orderStatusUpdate(Request $request) + { + $type = $request->input('type',''); + if($request->input('id', '')!=''){$where['id'] = $request->input('id');} + $where['user_id'] = Token::$uid; + + if($type=='' || $where['id'] =='') + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + + //修改订单状态,1设为支付,2设为取消,3设为确认收货,4设为退款退货,5设为删除,6设为已评价 + if($type == 1) + { + //判断订单是否存在或本人 + $where['order_status'] = 0; + $where['pay_status'] = 0; + $order = Order::where($where)->first(); + if(!$order){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'订单不存在');} + + //判断用户余额是否足够 + $user_money = DB::table('user')->where(array('id'=>Token::$uid))->value('money'); + if($order['order_amount']>$user_money){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'余额不足');} + + $data['pay_status'] = 1; + $data['pay_money'] = $order['order_amount']; //支付金额 + $data['pay_id'] = $request->input('pay_id',''); + $data['pay_time'] = $request->input('pay_time',time()); + if($request->input('pay_name', '')!=''){$data['pay_name'] = $request->input('pay_name');} + + //扣除用户余额 + if($data['pay_money']<=0 || !DB::table('user')->where(array('id'=>Token::$uid))->decrement('money', $data['pay_money'])) + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + + //增加用户余额记录 + DB::table('user_money')->insert(array('user_id'=>Token::$uid,'type'=>1,'money'=>$data['pay_money'],'des'=>'订单余额支付','user_money'=>DB::table('user')->where(array('id'=>Token::$uid))->value('money'),'add_time'=>time())); + } + elseif($type == 2) + { + //判断订单是否存在或本人 + $where['order_status'] = 0; + $where['pay_status'] = 0; + $order = Order::where($where)->first(); + if(!$order){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'订单不存在');} + + $data['order_status'] = 1; + } + elseif($type == 3) + { + //判断订单是否存在或本人 + $where['order_status'] = 0; + $where['refund_status'] = 0; + $where['pay_status'] = 1; + $order = Order::where($where)->first(); + if(!$order){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'订单不存在');} + + $data['order_status'] = 3; + $data['shipping_status'] = 2; + $data['refund_status'] = 0; + $data['is_comment'] = 0; + } + elseif($type == 4) + { + //判断订单是否存在或本人 + $where['order_status'] = 3; + $where['refund_status'] = 0; + $where['shipping_status'] = 2; + $order = Order::where($where)->first(); + if(!$order){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'订单不存在');} + + $data['refund_status'] = 1; + } + elseif($type == 5) + { + //判断订单是否存在或本人 + $order = Order::where(array('order_status'=>3,'refund_status'=>0))->orWhere(array('order_status'=>1))->orWhere(array('order_status'=>2))->first(); + if(!$order){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'订单不存在');} + + $data['is_delete'] = 1; + } + elseif($type == 6) + { + //判断订单是否存在或本人 + $where['order_status'] = 3; + $where['refund_status'] = 0; + $order = Order::where($where)->first(); + if(!$order){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'订单不存在');} + + $data['is_comment'] = 1; + } + + //修改订单状态 + if (isset($data)) + { + Order::modify($where,$data); + } + + return ReturnData::create(ReturnData::SUCCESS); + } + //删除订单 public function orderDelete(Request $request) { diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index b9b89a4..23b8c65 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -34,12 +34,13 @@ class UserController extends CommonController if($request->input('user_name', null)!==null) { $data['user_name'] = $request->input('user_name'); - + if(User::getOneUser($data)) { return ReturnData::create(ReturnData::PARAMS_ERROR,null,'用户名已存在'); } } + 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');} @@ -63,7 +64,26 @@ class UserController extends CommonController return ReturnData::create(ReturnData::SUCCESS); } - + + //修改用户余额 + public function userMoneyUpdate(Request $request) + { + $data['money'] = $request->input('money',''); + + if($data['money'] == '' || $data['money'] <= 0) + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + + $user = User::getOneUser(array('id'=>Token::$uid)); + $data['money'] = $user['money'] - $data['money']; + + if(User::modify(array('id'=>Token::$uid),$data)) + { + return ReturnData::create(ReturnData::SUCCESS); + } + } + //修改用户密码、支付密码 public function userPasswordUpdate(Request $request) { diff --git a/app/Http/Controllers/Api/UserWithdrawController.php b/app/Http/Controllers/Api/UserWithdrawController.php index ba35b30..480b36a 100644 --- a/app/Http/Controllers/Api/UserWithdrawController.php +++ b/app/Http/Controllers/Api/UserWithdrawController.php @@ -40,14 +40,16 @@ class UserWithdrawController extends CommonController $data['method'] = $request->input('method',''); $data['money'] = $request->input('money',''); $data['account'] = $request->input('account',''); + $data['name'] = $request->input('name',''); if($request->input('note', '') != ''){$data['note'] = $request->input('note');} if($request->input('status', '') != ''){$data['status'] = $request->input('status');} if($request->input('bank_name', '') != ''){$data['bank_name'] = $request->input('bank_name');} if($request->input('bank_place', '') != ''){$data['bank_place'] = $request->input('bank_place');} $data['add_time'] = time(); $data['user_id'] = Token::$uid; + $data['pay_password'] = $request->input('pay_password',''); - if($data['method']=='' || $data['money']=='' || $data['account']=='') + if($data['method']=='' || $data['money']=='' || $data['account']=='' || $data['name']=='' || $data['pay_password']=='') { return ReturnData::create(ReturnData::PARAMS_ERROR); } @@ -57,13 +59,7 @@ class UserWithdrawController extends CommonController return ReturnData::create(ReturnData::PARAMS_ERROR); } - $res = UserWithdraw::add($data); - if(!$res) - { - return ReturnData::create(ReturnData::SYSTEM_FAIL); - } - - return ReturnData::create(ReturnData::SUCCESS,$res); + return UserWithdraw::add($data); } //修改提现 diff --git a/app/Http/Controllers/Weixin/OrderController.php b/app/Http/Controllers/Weixin/OrderController.php index ba6dd80..6c2afb1 100644 --- a/app/Http/Controllers/Weixin/OrderController.php +++ b/app/Http/Controllers/Weixin/OrderController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Weixin; use App\Http\Controllers\Weixin\CommonController; use Illuminate\Http\Request; use App\Common\ReturnData; +use App\Common\Helper; class OrderController extends CommonController { @@ -20,7 +21,7 @@ class OrderController extends CommonController if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;} - $status = $request->input('status',''); + $status = $request->input('status',-1); $postdata = array( 'limit' => $pagesize, @@ -72,7 +73,63 @@ class OrderController extends CommonController return view('weixin.order.orderDetail', $data); } - + + //订单评价 + public function orderComment(Request $request) + { + if(Helper::isPostRequest()) + { + if($_POST['comment']) + { + foreach($_POST['comment'] as $k=>$v) + { + $_POST['comment'][$k]['comment_type'] = 0; + $_POST['comment'][$k]['comment_rank'] = 5; + } + } + else + { + $this->error_jump('评论失败'); + } + + $postdata = array( + 'order_id' => $_POST['order_id'], + 'comment' => json_encode($_POST['comment']), + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/comment_batch_add"; + $res = curl_request($url,$postdata,'POST'); + if($res['code']!=0){$this->error_jump('评论失败');} + + //订单状态设为已评价 + $postdata = array( + 'id' => $_POST['order_id'], + 'type' => 6, + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/order_status_update"; + $res = curl_request($url,$postdata,'POST'); + + $this->success_jump('评论成功',route('weixin_order_list')); + } + + $id = $request->input('id',''); + if($id==''){$this->error_jump('您访问的页面不存在或已被删除!');} + + $postdata = array( + 'order_id' => $id, + 'order_status' => 3, + 'refund_status' => 0, + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/order_detail"; + $res = curl_request($url,$postdata,'GET'); + $data['post'] = $res['data']; + if(empty($data['post'])){$this->error_jump('您访问的页面不存在或已被删除!');} + + return view('weixin.order.orderComment', $data); + } + //订单支付 public function pay($id) { @@ -138,6 +195,49 @@ class OrderController extends CommonController } } + //订单余额支付 + public function orderYuepay(Request $request) + { + $order_id = $request->input('order_id',''); + + //获取订单详情 + $postdata = array( + 'order_id' => $order_id, //要支付的订单id + 'order_status' => 0, + 'pay_status' => 0, + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/order_detail"; + $res = curl_request($url,$postdata,'GET'); + $order_detail = $res['data']; + if($res['code']!=0){$this->error_jump('订单不存在或已过期');} + + //获取会员信息 + $postdata = array( + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/user_info"; + $res = curl_request($url,$postdata,'GET'); + $user_info = $res['data']; + + if($order_detail['order_amount']>$user_info['money']){$this->error_jump('余额不足');} + + //修改订单状态 + $postdata = array( + 'id' => $order_detail['id'], + 'type' => 1, + 'pay_id' => 1, + 'pay_name' => '余额支付', + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/order_status_update"; + $res = curl_request($url,$postdata,'POST'); + if($res['code']!=0){$this->error_jump('支付失败');} + + $this->success_jump('支付成功',route('weixin_order_list')); + } + + //订单余额支付 public function orderWxpay(Request $request) { $order_id = $request->input('order_id',''); @@ -153,7 +253,6 @@ class OrderController extends CommonController $res = curl_request($url,$postdata,'GET'); $data['order_detail'] = $res['data']; $data['order_id'] = $order_id; - if($res['code']!=0){$this->error_jump('订单不存在或已过期');} //微信支付-start diff --git a/app/Http/Controllers/Weixin/UserController.php b/app/Http/Controllers/Weixin/UserController.php index 5455cf7..a449917 100644 --- a/app/Http/Controllers/Weixin/UserController.php +++ b/app/Http/Controllers/Weixin/UserController.php @@ -109,6 +109,64 @@ class UserController extends CommonController return view('weixin.user.userAccount', $data); } + //提现 + public function userWithdraw(Request $request) + { + $postdata = array( + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/user_info"; + $res = curl_request($url,$postdata,'GET'); + $data['user_info'] = $res['data']; + $data['is_withdraw'] = 0; //是否达到可提现要求,0否 + $data['min_withdraw_money'] = sysconfig('CMS_MIN_WITHDRAWAL_MONEY'); //最低可提现金额 + + if($data['user_info']['money']>=$data['min_withdraw_money']){$data['is_withdraw'] = 1;} + + return view('weixin.user.userWithdraw', $data); + } + + //提现明细 + public function userWithdrawList(Request $request) + { + $pagesize = 10; + $offset = 0; + if(isset($_REQUEST['page'])){$offset = ($_REQUEST['page']-1)*$pagesize;} + + $postdata = array( + 'limit' => $pagesize, + 'offset' => $offset, + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/user_withdraw_list"; + $res = curl_request($url,$postdata,'GET'); + $data['list'] = $res['data']['list']; + + $data['totalpage'] = ceil($res['data']['count']/$pagesize); + + if(isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax']==1) + { + $html = ''; + + if($res['data']['list']) + { + foreach($res['data']['list'] as $k => $v) + { + $html .= '
提现
'; + $html .= '收款账号:'.$v['name'].' ,提现方式:'.$v['method'].' ,姓名:'.$v['name'].'
状态:'.$v['status_text'].'
'.date('Y-m-d H:i:s',$v['add_time']).'
订单状态: