diff --git a/application/api/controller/Common.php b/application/api/controller/Common.php index cb2bf7d77150835d0101f668337daaca2c781626..51b3d547852e47eb92d6ff02529875da30bb5444 100755 --- a/application/api/controller/Common.php +++ b/application/api/controller/Common.php @@ -44,6 +44,11 @@ class Common extends Controller exit(json_encode(DataReturn('非法访问', -500))); } + // 输入参数 + $this->data_post = input('post.'); + $this->data_get = input('get.'); + $this->data_request = input(); + // 系统初始化 $this->SystemInit(); @@ -52,11 +57,6 @@ class Common extends Controller // 公共数据初始化 $this->CommonInit(); - - // 输入参数 - $this->data_post = input('post.'); - $this->data_get = input('get.'); - $this->data_request = input(); } /** @@ -118,7 +118,7 @@ class Common extends Controller // 用户数据 if(!empty($this->data_request['user_id'])) { - $this->user = UserService::UserLoginRecord($this->data_request['user_id']); + $this->user = UserService::UserLoginRecord($this->data_request['user_id'], true); } } diff --git a/application/api/controller/User.php b/application/api/controller/User.php new file mode 100644 index 0000000000000000000000000000000000000000..37d14478032d8c96156cdf0b64edcf7b7fb7ae13 --- /dev/null +++ b/application/api/controller/User.php @@ -0,0 +1,174 @@ +error('非法访问'); + } + + // 调用服务层 + $ret = UserService::AppReg(input('post.')); + return json($ret); + } + + /** + * [RegVerifySend 用户注册-验证码发送] + * @author Devil + * @blog http://gong.gg/ + * @version 0.0.1 + * @datetime 2017-03-05T19:17:10+0800 + */ + public function RegVerifySend() + { + // 是否ajax请求 + if(!IS_AJAX) + { + return $this->error('非法访问'); + } + + // 调用服务层 + $ret = UserService::AppUserBindVerifySend(input('post.')); + return json($ret); + } + + /** + * [GetAlipayUserInfo 获取支付宝用户信息] + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2017-09-23T21:52:49+0800 + */ + public function AlipayUserAuth() + { + // 参数 + if(empty($this->data_post['authcode'])) + { + return json(DataReturn('授权码不能为空', -1)); + } + + // 授权 + $result = (new \base\AlipayAuth())->GetAlipayUserInfo($this->data_post['authcode'], MyC('common_app_mini_alipay_appid')); + if($result === false) + { + return json(DataReturn('获取授权信息失败', -10)); + } else { + $result['openid'] = $result['user_id']; + $result['referrer']= isset($this->data_post['referrer']) ? intval($this->data_post['referrer']) : 0; + $ret = UserService::AuthUserProgram($result, 'alipay_openid'); + return json($ret); + } + } + + /** + * 百度小程序获取用户信息 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-11-06 + * @desc description + */ + public function BaiduUserAuth() + { + return json(DataReturn('暂未开放', -1)); + + $_POST['config'] = MyC('baidu_mini_program_config'); + $result = (new \Library\BaiduAuth())->GetAuthUserInfo($_POST); + if($result['status'] == 0) + { + $ret = UserService::AuthUserProgram($result, 'alipay_openid'); + return json($ret); + } else { + return json(DataReturn($result['msg'], -10)); + } + } + + /** + * [ClientCenter 用户中心] + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2018-05-21T15:21:52+0800 + */ + public function Center() + { + // 登录校验 + $this->Is_Login(); + + // 订单总数 + $where = ['user_id'=>$this->user['id'], 'is_delete_time'=>0, 'user_is_delete_time'=>0]; + $user_order_count = OrderService::OrderTotal($where); + + // 商品收藏总数 + $where = ['user_id'=>$this->user['id']]; + $user_goods_favor_count = GoodsService::GoodsFavorTotal($where); + + // 商品浏览总数 + $where = ['user_id'=>$this->user['id']]; + $user_goods_browse_count = GoodsService::GoodsBrowseTotal($where); + + // 未读消息总数 + $params = ['user'=>$this->user, 'is_more'=>1, 'is_read'=>0]; + $common_message_total = MessageService::UserMessageTotal($params); + $common_message_total = ($common_message_total > 99) ? '99+' : $common_message_total; + + // 用户订单状态 + $user_order_status = OrderService::OrderStatusStepTotal(['user_type'=>'user', 'user'=>$this->user, 'is_comments'=>1]); + + // 初始化数据 + $result = array( + 'integral' => (int) $this->user['integral'], + 'avatar' => $this->user['avatar'], + 'nickname' => $this->user['nickname'], + 'username' => $this->user['username'], + 'customer_service_tel' => MyC('common_app_customer_service_tel', null, true), + 'common_user_center_notice' => MyC('common_user_center_notice', null, true), + 'user_order_status' => $user_order_status['data'], + 'user_order_count' => $user_order_count, + 'user_goods_favor_count' => $user_goods_favor_count, + 'user_goods_browse_count' => $user_goods_browse_count, + 'common_message_total' => $common_message_total, + 'common_app_is_enable_answer' => (int) MyC('common_app_is_enable_answer', 0), + ); + + // 返回数据 + return json(DataReturn('success', 0, $result)); + } +} +?> \ No newline at end of file diff --git a/application/service/UserService.php b/application/service/UserService.php index 9fd86f107c89a56997680186ab90f9f0af6689a9..1fc9779d0016bf730ba26d7d22017fe020c34173 100755 --- a/application/service/UserService.php +++ b/application/service/UserService.php @@ -602,9 +602,10 @@ class UserService * @version 0.0.1 * @datetime 2017-03-09T11:37:43+0800 * @param [int] $user_id [用户id] + * @param [boolean] $is_app [是否为app] * @return [boolean] [记录成功true, 失败false] */ - public static function UserLoginRecord($user_id = 0) + public static function UserLoginRecord($user_id = 0, $is_app = false) { if(!empty($user_id)) { @@ -645,9 +646,14 @@ class UserService $user['avatar'] = config('images_host').'/static/index/'.strtolower(config('DEFAULT_THEME', 'default')).'/images/default-user-avatar.jpg'; } - // 存储session - session('user', $user); - return (session('user') !== null); + if($is_app == true) + { + return $user; + } else { + // 存储session + session('user', $user); + return (session('user') !== null); + } } } return false; @@ -1343,5 +1349,205 @@ class UserService return DataReturn('编辑失败或数据未改变', -100); } + /** + * 用户授权数据 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-11-06 + * @desc description + * @param [array] $params [用户数据] + * @param [string] $field [平台字段名称] + */ + public static function AuthUserProgram($params, $field) + { + $data = [ + $field => $params['openid'], + 'nickname' => empty($params['nick_name']) ? '' : $params['nick_name'], + 'avatar' => empty($params['avatar']) ? '' : $params['avatar'], + 'gender' => empty($params['gender']) ? 0 : ($params['gender'] == 'm') ? 2 : 1, + 'province' => empty($params['province']) ? '' : $params['province'], + 'city' => empty($params['city']) ? '' : $params['city'], + 'referrer' => isset($params['referrer']) ? intval($params['referrer']) : 0, + ]; + $where = [$field=>$params['openid'], 'is_delete_time'=>0]; + $user = Db::name('User')->where($where)->find(); + if(!empty($user)) + { + $data = $user; + } + + // 返回成功 + return DataReturn('授权成功', 0, $data); + } + + /** + * app用户注册 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-12-27 + * @desc description + * @param [array] $params [输入参数] + */ + public static function AppReg($params = []) + { + // 数据验证 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'mobile', + 'error_msg' => '手机号码不能为空', + ], + [ + 'checked_type' => 'empty', + 'key_name' => 'app_type', + 'error_msg' => '终端用户类型不能为空', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 手机号码格式 + if(!CheckMobile($params['mobile'])) + { + return DataReturn('手机号码格式错误', -2); + } + + // 验证码校验 + $verify_param = array( + 'key_prefix' => 'bind', + 'expire_time' => MyC('common_verify_expire_time') + ); + $obj = new \base\Sms($verify_param); + + // 是否已过期 + if(!$obj->CheckExpire()) + { + return DataReturn('验证码已过期', -10); + } + // 是否正确 + if(!$obj->CheckCorrect($params['verify'])) + { + return DataReturn('验证码错误', -11); + } + + // 用户信息 + $accounts_field = $params['app_type'].'_openid'; + if(empty($params[$accounts_field])) + { + return DataReturn('用户openid不能为空', -20); + } + $data = array( + $accounts_field => $params[$accounts_field], + 'mobile' => $params['mobile'], + ); + + // 获取用户信息 + $where = ['mobile'=>$data['mobile'], 'is_delete_time'=>0]; + $temp_user = Db::name('User')->where($where)->find(); + + // 额外信息 + if(empty($temp_user['nickname']) && !empty($params['nickname'])) + { + $data['nickname'] = $params['nickname']; + } + if(empty($temp_user['avatar']) && !empty($params['avatar'])) + { + $data['avatar'] = $params['avatar']; + } + if(empty($temp_user['province']) && !empty($params['province'])) + { + $data['province'] = $params['province']; + } + if(empty($temp_user['city']) && !empty($params['city'])) + { + $data['city'] = $params['city']; + } + if(empty($temp_user) && isset($params['gender'])) + { + $data['gender'] = intval($params['gender']); + } + + // 不存在添加/则更新 + if(empty($temp_user)) + { + $data['referrer'] = isset($params['referrer']) ? intval($params['referrer']) : 0; + $data['add_time'] = time(); + $user_id = Db::name('User')->insertGetId($data); + } else { + $data['upd_time'] = time(); + if(Db::name('User')->where($where)->update($data)) + { + $user_id = $temp_user['id']; + } + } + + if(isset($user_id) && $user_id > 0) + { + // 清除验证码 + $obj->Remove(); + + return DataReturn('绑定成功', 0, self::UserLoginRecord($user_id, true)); + } else { + return DataReturn('绑定失败', -100); + } + } + + /** + * app用户绑定验证码发送 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-12-27 + * @desc description + * @param [array] $params [输入参数] + */ + public static function AppUserBindVerifySend($params = []) + { + // 数据验证 + $p = [ + [ + 'checked_type' => 'empty', + 'key_name' => 'mobile', + 'error_msg' => '手机号码不能为空', + ], + [ + 'checked_type' => 'fun', + 'key_name' => 'mobile', + 'checked_data' => 'CheckMobile', + 'error_msg' => '手机号码格式错误', + ], + ]; + $ret = ParamsChecked($params, $p); + if($ret !== true) + { + return DataReturn($ret, -1); + } + + // 验证码公共基础参数 + $verify_param = array( + 'key_prefix' => 'bind', + 'expire_time' => MyC('common_verify_expire_time'), + 'time_interval' => MyC('common_verify_time_interval'), + ); + + // 发送验证码 + $obj = new \base\Sms($verify_param); + $code = GetNumberCode(6); + $status = $obj->SendCode($params['mobile'], $code, MyC('home_sms_user_mobile_binding')); + + // 状态 + if($status) + { + return DataReturn('发送成功', 0); + } else { + return DataReturn('发送失败'.'['.$obj->error.']', -100); + } + } + } ?> \ No newline at end of file diff --git a/public/appmini/old/alipay/app.js b/public/appmini/old/alipay/app.js index c8d3da263a7480ae8e80f7efd51ed8138d32441d..036e969a3394e9dd45dfae479203be3db87e9d1a 100755 --- a/public/appmini/old/alipay/app.js +++ b/public/appmini/old/alipay/app.js @@ -164,7 +164,6 @@ App({ var user = this.GetUserCacheInfo(); var app_client_user_id = user == false ? "" : user.alipay_openid; var user_id = user == false ? 0 : user.id; - var nickname = user == false ? "" : user.nickname; return ( this.data.request_url + "/" + m + "/" + c + "/" + a + @@ -172,8 +171,6 @@ App({ app_client_user_id + "&user_id=" + user_id + - "&nickname=" + - nickname + "&ajax=ajax" + params ); @@ -227,7 +224,7 @@ App({ success: res => { if (res.authCode) { my.httpRequest({ - url: this.get_request_url("GetAlipayUserInfo", "User"), + url: this.get_request_url("alipayuserauth", "user"), method: "POST", data: { authcode: res.authCode, diff --git a/public/appmini/old/alipay/pages/goods-detail/goods-detail.js b/public/appmini/old/alipay/pages/goods-detail/goods-detail.js index 71e93184a80141143c7564f4df314c07433ad9a2..60e522b0c71b56ff3c99854ff3c34dc883a00fa7 100755 --- a/public/appmini/old/alipay/pages/goods-detail/goods-detail.js +++ b/public/appmini/old/alipay/pages/goods-detail/goods-detail.js @@ -460,6 +460,11 @@ Page({ } if(spec.length <= 0 || active_count < sku_count) { + this.setData({ + goods_spec_base_price: this.data.goods.price, + goods_spec_base_original_price: this.data.goods.original_price, + goods_spec_base_inventory: this.data.goods.inventory, + }); return false; } @@ -471,7 +476,11 @@ Page({ dataType: 'json', success: (res) => { if (res.data.code == 0) { - + this.setData({ + goods_spec_base_price: res.data.data.price, + goods_spec_base_original_price: res.data.data.original_price, + goods_spec_base_inventory: res.data.data.inventory, + }); } else { my.showToast({ type: 'fail', diff --git a/public/appmini/old/alipay/pages/login/login.acss b/public/appmini/old/alipay/pages/login/login.acss index 43818b671e128781dade86bfb1ed5b229aa78fb7..c322498fcd1ca884dcfaf19b6ac9c8f146af26b8 100755 --- a/public/appmini/old/alipay/pages/login/login.acss +++ b/public/appmini/old/alipay/pages/login/login.acss @@ -12,7 +12,7 @@ page{ .content .mobile{ width: 100%; margin: 20rpx 0; - border-bottom: solid 1rpx #a6a6a6; + border-bottom: solid 1px #eee; } .content input{ font-size: 28rpx; @@ -22,13 +22,13 @@ page{ } .content .code{ margin: 20rpx 0; - border-bottom: solid 1rpx #a6a6a6; + border-bottom: solid 1px #eee; } .content .code .verify{ width: 63%; } .content .code .verify-sub{ - border: solid 1rpx #ff6482; + border: solid 1px #ff6482; color: #ff6482; width: 35%; height: 35px; @@ -36,7 +36,7 @@ page{ border-radius: 10rpx; } .content .code .verify-sub.sub-disabled{ - border: solid 1rpx #a6a6a6; + border: solid 1px #eee; color: #a6a6a6 } .content .submit{ diff --git a/public/appmini/old/alipay/pages/login/login.js b/public/appmini/old/alipay/pages/login/login.js index 5dfb655e41a92af13b0613cadfa69f8f71c72fb6..e962bfc193520f7130272932fdcfd78c07099506 100755 --- a/public/appmini/old/alipay/pages/login/login.js +++ b/public/appmini/old/alipay/pages/login/login.js @@ -46,7 +46,7 @@ Page({ this.setData({verify_submit_text: '发送中', verify_loading: true, verify_disabled: true}); my.httpRequest({ - url: app.get_request_url('RegVerifySend', 'User'), + url: app.get_request_url('regverifysend', 'user'), method: 'POST', data: {mobile: this.data.mobile}, dataType: 'json', @@ -115,7 +115,7 @@ Page({ // 网络请求 my.httpRequest({ - url: app.get_request_url('Reg', 'User'), + url: app.get_request_url('reg', 'user'), method: 'POST', data: e.detail.value, dataType: 'json',