diff --git a/app/Http/Controllers/Api/PaymentController.php b/app/Http/Controllers/Api/PaymentController.php new file mode 100644 index 0000000..ce36ed3 --- /dev/null +++ b/app/Http/Controllers/Api/PaymentController.php @@ -0,0 +1,31 @@ +input('status', -1); + + $res = Payment::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/UserAddressController.php b/app/Http/Controllers/Api/UserAddressController.php index af8177b..a6c889b 100644 --- a/app/Http/Controllers/Api/UserAddressController.php +++ b/app/Http/Controllers/Api/UserAddressController.php @@ -135,4 +135,16 @@ class UserAddressController extends CommonController return ReturnData::create(ReturnData::SUCCESS,$res); } + + //获取用户默认地址 + public function userDefaultAddress(Request $request) + { + $res = UserAddress::userDefaultAddress(Token::$uid); + 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/UserRechargeController.php b/app/Http/Controllers/Api/UserRechargeController.php new file mode 100644 index 0000000..550ed0a --- /dev/null +++ b/app/Http/Controllers/Api/UserRechargeController.php @@ -0,0 +1,82 @@ +input('limit', 10); + $data['offset'] = $request->input('offset', 0); + $data['status'] = $request->input('status', -1); + + $data['user_id'] = Token::$uid; + + $res = UserRecharge::getList($data); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //添加充值记录 + public function userRechargeAdd(Request $request) + { + //参数 + $data['money'] = $request->input('money',''); + if($request->input('status', '') != ''){$data['status'] = $request->input('status');} + if($request->input('pay_type', '') != ''){$data['pay_type'] = $request->input('pay_type');} + $data['user_id'] = Token::$uid; + + if($data['money']=='') + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + + $res = UserRecharge::add($data); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + //修改充值记录 + public function userRechargeUpdate(Request $request) + { + //参数 + $id = $request->input('id',''); + $data['trade_no'] = $request->input('trade_no',''); + $data['pay_time'] = $request->input('pay_time',''); + $data['status'] = UserRecharge::COMPLETE_PAY; + $data['updated_at'] = date('Y-m-d H:i:s',time()); + + if($id=='' || $data['trade_no']=='' || $data['pay_time']=='') + { + return ReturnData::create(ReturnData::PARAMS_ERROR); + } + + $res = UserRecharge::modify(array('id'=>$id,'user_id'=>Token::$uid),$data); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Weixin/CartController.php b/app/Http/Controllers/Weixin/CartController.php index a22f33c..caddf7a 100644 --- a/app/Http/Controllers/Weixin/CartController.php +++ b/app/Http/Controllers/Weixin/CartController.php @@ -38,6 +38,7 @@ class CartController extends CommonController //购物车结算 public function cartCheckout($ids) { + //购物车结算商品列表 $postdata = array( 'ids' => $ids, 'access_token' => $_SESSION['weixin_user_info']['access_token'] @@ -46,6 +47,23 @@ class CartController extends CommonController $res = curl_request($url,$postdata,'GET'); $data['list'] = $res['data']['list']; + //支付方式列表 + $postdata = array( + 'status' => 1, + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/payment_list"; + $res = curl_request($url,$postdata,'GET'); + $data['payment_list'] = $res['data']['list']; + + //支付方式列表 + $postdata = array( + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/user_default_address"; + $res = curl_request($url,$postdata,'GET'); + $data['user_default_address'] = $res['data']; + return view('weixin.cart.cartCheckout', $data); } } \ No newline at end of file diff --git a/app/Http/Controllers/Weixin/UserController.php b/app/Http/Controllers/Weixin/UserController.php index 7232f7f..25a734f 100644 --- a/app/Http/Controllers/Weixin/UserController.php +++ b/app/Http/Controllers/Weixin/UserController.php @@ -55,6 +55,12 @@ class UserController extends CommonController return view('weixin.user.userAccount', $data); } + //用户充值 + public function userRecharge(Request $request) + { + return view('weixin.user.userRecharge'); + } + //余额明细 public function userMoneyList(Request $request) { diff --git a/app/Http/Model/Payment.php b/app/Http/Model/Payment.php new file mode 100644 index 0000000..36e0a46 --- /dev/null +++ b/app/Http/Model/Payment.php @@ -0,0 +1,80 @@ +where($where);} + + $res['count'] = $model->count(); + $res['list'] = array(); + + if($res['count']>0) + { + $res['list'] = $model->orderBy('listorder','desc')->get(); + } + + return $res; + } + + public static function getOne($where) + { + return self::where($where)->first(); + } + + public static function add(array $data) + { + if(self::where(array('pay_code'=>$data['pay_code']))->first()){return ReturnData::create(ReturnData::PARAMS_ERROR,null,'支付方式已存在');} + + if ($id = self::insertGetId($data)) + { + return ReturnData::create(ReturnData::SUCCESS,$id); + } + + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + 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/UserAddress.php b/app/Http/Model/UserAddress.php index 8a969c8..b88788c 100644 --- a/app/Http/Model/UserAddress.php +++ b/app/Http/Model/UserAddress.php @@ -18,6 +18,8 @@ class UserAddress extends BaseModel */ protected $guarded = array(); + const IS_DEFAULT = 1; //是默认地址 + //获取列表 public static function getList(array $param) { @@ -62,15 +64,6 @@ class UserAddress extends BaseModel if ($address_id) { $arr = self::where('id',$address_id)->first(); - - if($arr) - { - $arr->country_name = Region::getRegionName($arr->country); - $arr->province_name = Region::getRegionName($arr->province); - $arr->city_name = Region::getRegionName($arr->city); - $arr->district_name = Region::getRegionName($arr->district); - } - return $arr; } @@ -80,14 +73,14 @@ class UserAddress extends BaseModel $arr = self::join('user','user_address.id', '=', 'user.address_id') ->where('user.id',$user_id)->select('user_address.id','user_address.name','country','province','city','district','address','user_address.mobile','zipcode') ->first(); - - if($arr) - { - $arr->country_name = Region::getRegionName($arr->country); - $arr->province_name = Region::getRegionName($arr->province); - $arr->city_name = Region::getRegionName($arr->city); - $arr->district_name = Region::getRegionName($arr->district); - } + } + + if($arr) + { + $arr->country_name = Region::getRegionName($arr->country); + $arr->province_name = Region::getRegionName($arr->province); + $arr->city_name = Region::getRegionName($arr->city); + $arr->district_name = Region::getRegionName($arr->district); } return $arr; @@ -207,4 +200,26 @@ class UserAddress extends BaseModel return false; } + + // 获取默认地址 + public static function userDefaultAddress($user_id) + { + $arr = ''; + $arr = self::where(array('user_id'=>$user_id,'is_default'=>self::IS_DEFAULT))->first(); + + if (!$arr) + { + $arr = self::where(array('user_id'=>$user_id))->first(); + } + + if($arr) + { + $arr->country_name = Region::getRegionName($arr->country); + $arr->province_name = Region::getRegionName($arr->province); + $arr->city_name = Region::getRegionName($arr->city); + $arr->district_name = Region::getRegionName($arr->district); + } + + return $arr; + } } \ No newline at end of file diff --git a/app/Http/Model/UserBonus.php b/app/Http/Model/UserBonus.php index 1cfecd9..7bcf5d6 100644 --- a/app/Http/Model/UserBonus.php +++ b/app/Http/Model/UserBonus.php @@ -13,7 +13,7 @@ class UserBonus extends BaseModel * * @var array */ - protected $guarded = []; + protected $guarded = array(); //获取列表 public static function getList(array $param) diff --git a/app/Http/Model/UserMoney.php b/app/Http/Model/UserMoney.php index 6e1e95e..329b99f 100644 --- a/app/Http/Model/UserMoney.php +++ b/app/Http/Model/UserMoney.php @@ -13,7 +13,7 @@ class UserMoney extends BaseModel * * @var array */ - protected $guarded = []; + protected $guarded = array(); //获取列表 public static function getList(array $param) @@ -35,7 +35,7 @@ class UserMoney extends BaseModel if($res['count']>0) { - $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray(); + $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get(); } else { @@ -47,7 +47,7 @@ class UserMoney extends BaseModel public static function getOne($id) { - return self::where('id', $id)->first()->toArray(); + return self::where('id', $id)->first(); } public static function add(array $data) diff --git a/app/Http/Model/UserPoint.php b/app/Http/Model/UserPoint.php index 05bc1f0..f9e8f3e 100644 --- a/app/Http/Model/UserPoint.php +++ b/app/Http/Model/UserPoint.php @@ -13,7 +13,7 @@ class UserPoint extends BaseModel * * @var array */ - protected $guarded = []; + protected $guarded = array(); //获取列表 public static function getList(array $param) @@ -35,7 +35,7 @@ class UserPoint extends BaseModel if($res['count']>0) { - $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray(); + $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get(); } else { @@ -47,7 +47,7 @@ class UserPoint extends BaseModel public static function getOne($id) { - return self::where('id', $id)->first()->toArray(); + return self::where('id', $id)->first(); } public static function add(array $data) diff --git a/app/Http/Model/UserRecharge.php b/app/Http/Model/UserRecharge.php new file mode 100644 index 0000000..514cf91 --- /dev/null +++ b/app/Http/Model/UserRecharge.php @@ -0,0 +1,86 @@ +where($where); + + $res['count'] = $model->count(); + $res['list'] = array(); + + if($res['count']>0) + { + $res['list'] = $model->skip($offset)->take($limit)->orderBy('id','desc')->get(); + } + else + { + return false; + } + + return $res; + } + + public static function getOne($where) + { + return self::where($where)->first(); + } + + 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) === false) + { + return false; + } + + return true; + } + + //删除一条记录 + 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/resources/views/weixin/address/index.blade.php b/resources/views/weixin/address/index.blade.php index a7654ef..94bf61d 100644 --- a/resources/views/weixin/address/index.blade.php +++ b/resources/views/weixin/address/index.blade.php @@ -9,16 +9,8 @@