mirror of
https://github.com/crmeb/CRMEB.git
synced 2025-12-14 20:42:49 +00:00
小程序用户信息改为解密获取,修复打通版用户同步bug
This commit is contained in:
parent
6a85d51f73
commit
5e58dabe53
@ -58,6 +58,7 @@ function makePathToUrl($path,$type = 2)
|
||||
}else return '';
|
||||
|
||||
}
|
||||
|
||||
// 过滤掉emoji表情
|
||||
function filterEmoji($str)
|
||||
{
|
||||
@ -67,6 +68,43 @@ function filterEmoji($str)
|
||||
return strlen($match[0]) >= 4 ? '' : $match[0];
|
||||
},
|
||||
$str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
//可逆加密
|
||||
function encrypt($data, $key) {
|
||||
$prep_code = serialize($data);
|
||||
$block = mcrypt_get_block_size('des', 'ecb');
|
||||
if (($pad = $block - (strlen($prep_code) % $block)) < $block) {
|
||||
$prep_code .= str_repeat(chr($pad), $pad);
|
||||
}
|
||||
$encrypt = mcrypt_encrypt(MCRYPT_DES, $key, $prep_code, MCRYPT_MODE_ECB);
|
||||
return base64_encode($encrypt);
|
||||
}
|
||||
|
||||
//可逆解密
|
||||
function decrypt($str, $key) {
|
||||
$str = base64_decode($str);
|
||||
$str = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
|
||||
$block = mcrypt_get_block_size('des', 'ecb');
|
||||
$pad = ord($str[($len = strlen($str)) - 1]);
|
||||
if ($pad && $pad < $block && preg_match('/' . chr($pad) . '{' . $pad . '}$/', $str)) {
|
||||
$str = substr($str, 0, strlen($str) - $pad);
|
||||
}
|
||||
return unserialize($str);
|
||||
}
|
||||
//替换一部分字符
|
||||
/**
|
||||
* @param $string 需要替换的字符串
|
||||
* @param $start 开始的保留几位
|
||||
* @param $end 最后保留几位
|
||||
* @return string
|
||||
*/
|
||||
function strReplace($string,$start,$end)
|
||||
{
|
||||
$strlen = mb_strlen($string, 'UTF-8');//获取字符串长度
|
||||
$firstStr = mb_substr($string, 0, $start,'UTF-8');//获取第一位
|
||||
$lastStr = mb_substr($string, -1, $end, 'UTF-8');//获取最后一位
|
||||
return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($string, 'utf-8') -1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
|
||||
|
||||
}
|
||||
@ -8,6 +8,7 @@ use app\routine\model\routine\RoutineTemplate;
|
||||
use app\routine\model\store\StoreCombination;
|
||||
use service\JsonService;
|
||||
use service\GroupDataService;
|
||||
use service\MiniProgramService;
|
||||
use service\RoutineBizDataCrypt;
|
||||
use service\SystemConfigService;
|
||||
use service\UploadService;
|
||||
@ -60,9 +61,9 @@ class AuthApi extends AuthController{
|
||||
* 获取用户信息
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function get_user_info(){
|
||||
return JsonService::successful($this->userInfo);
|
||||
}
|
||||
// public function get_user_info(){
|
||||
// return JsonService::successful($this->userInfo);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取退款理由
|
||||
@ -291,6 +292,7 @@ class AuthApi extends AuthController{
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function confirm_order(Request $request){
|
||||
|
||||
$data = UtilService::postMore(['cartId'],$request);
|
||||
$cartId = $data['cartId'];
|
||||
if(!is_string($cartId) || !$cartId ) return JsonService::fail('请提交购买的商品');
|
||||
@ -375,20 +377,6 @@ class AuthApi extends AuthController{
|
||||
return JsonService::successful($this->userInfo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户签到
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function user_sign()
|
||||
{
|
||||
$signed = UserSign::checkUserSigned($this->userInfo['uid']);
|
||||
if($signed) return JsonService::fail('已签到');
|
||||
if(false !== $integral = UserSign::sign($this->userInfo))
|
||||
return JsonService::successful('签到获得'.floatval($integral).'积分');
|
||||
else
|
||||
return JsonService::fail('签到失败!');
|
||||
}
|
||||
/**
|
||||
* 过度查$uniqueId
|
||||
* @param string $productId
|
||||
@ -802,6 +790,7 @@ class AuthApi extends AuthController{
|
||||
$order = StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
|
||||
$order = $order->toArray();
|
||||
$order['add_time'] = date('Y-m-d H:i:s',$order['add_time']);
|
||||
$order['favourable_price'] = bcadd($order['deduction_price'],$order['coupon_price'],2);
|
||||
if(!$order) return JsonService::fail('订单不存在');
|
||||
return JsonService::successful(StoreOrder::tidyOrder($order,true));
|
||||
}
|
||||
@ -839,10 +828,16 @@ class AuthApi extends AuthController{
|
||||
public function pay_order($uni = '',$paytype='weixin')
|
||||
{
|
||||
if(!$uni) return JsonService::fail('参数错误!');
|
||||
$order= StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
|
||||
$order = StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
|
||||
if(!$order) return JsonService::fail('订单不存在!');
|
||||
if($order['paid']) return JsonService::fail('该订单已支付!');
|
||||
if($order['pink_id']) if(StorePink::isPinkStatus($order['pink_id'])) return JsonService::fail('该订单已失效!');
|
||||
$cartInfoId = $order['cart_id'];
|
||||
$resCartProductStatus = true;
|
||||
foreach ($cartInfoId as $key=>&$item){
|
||||
$resCartProductStatus = $resCartProductStatus && StoreCart::decideCartProductOverdue($item);
|
||||
}
|
||||
if(!$resCartProductStatus) return JsonService::fail(StoreCart::getErrorInfo('订单产品已失效,请重新下单'));
|
||||
$order['pay_type'] = $paytype;//重新支付选择支付方式
|
||||
if($order['pay_type'] == 'weixin'){
|
||||
try{
|
||||
@ -1040,9 +1035,9 @@ class AuthApi extends AuthController{
|
||||
public function get_spread_list($first = 0,$limit = 20)
|
||||
{
|
||||
$list = User::where('spread_uid',$this->userInfo['uid'])->field('uid,nickname,avatar,add_time')->limit($first,$limit)->order('add_time DESC')->select()->toArray();
|
||||
foreach ($list as $k=>$user){
|
||||
$list[$k]['add_time'] = date('Y/m/d',$user['add_time']);
|
||||
$list[$k]['price'] = StoreOrder::getUserPrice($user['uid']);
|
||||
foreach ($list as $k=>&$user){
|
||||
$user['add_time'] = date('Y/m/d',$user['add_time']);
|
||||
$user['price'] = StoreOrder::getUserPrice($user['uid']);
|
||||
}
|
||||
$count = User::where('spread_uid',$this->userInfo['uid'])->field('uid,nickname,avatar,add_time')->count();
|
||||
$data['count'] = $count;
|
||||
@ -1059,9 +1054,9 @@ class AuthApi extends AuthController{
|
||||
public function get_spread_list_two($two_uid=0,$first = 0,$limit = 20)
|
||||
{
|
||||
$list = User::where('spread_uid',$two_uid)->field('uid,nickname,avatar,add_time')->limit($first,$limit)->order('add_time DESC')->select()->toArray();
|
||||
foreach ($list as $k=>$user){
|
||||
$list[$k]['add_time'] = date('Y/m/d',$user['add_time']);
|
||||
$list[$k]['price'] = StoreOrder::getUserPrice($user['uid']);
|
||||
foreach ($list as $k=>&$user){
|
||||
$user['add_time'] = date('Y/m/d',$user['add_time']);
|
||||
$user['price'] = StoreOrder::getUserPrice($user['uid']);
|
||||
}
|
||||
$count = User::where('spread_uid',$two_uid)->field('uid,nickname,avatar,add_time')->count();
|
||||
$data['count'] = $count;
|
||||
@ -1152,114 +1147,6 @@ class AuthApi extends AuthController{
|
||||
return JsonService::successful();
|
||||
}
|
||||
|
||||
/**
|
||||
* 客服提醒
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function refresh_msn(Request $request)
|
||||
{
|
||||
$params = $request->post();
|
||||
$remind_where = "mer_id = ".$params["mer_id"]." AND uid = ".$params["uid"]." AND to_uid = ".$params["to_uid"]." AND type = 0 AND remind = 0";
|
||||
$remind_list = StoreServiceLog::where($remind_where)->order("add_time asc")->select();
|
||||
foreach ($remind_list as $key => $value) {
|
||||
if(time() - $value["add_time"] > 3){
|
||||
StoreServiceLog::edit(array("remind"=>1),$value["id"]);
|
||||
$now_user = StoreService::field("uid,nickname")->where(array("uid"=>$params["uid"]))->find();
|
||||
if(!$now_user)$now_user = User::field("uid,nickname")->where(array("uid"=>$params["uid"]))->find();
|
||||
if($params["to_uid"]) {
|
||||
$head = '您有新的消息,请注意查收!';
|
||||
$head .= $params["mer_id"] > 0 ? "\n商户名称:".Merchant::where('id',$params["mer_id"])->value('mer_name') : '';
|
||||
WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($params["to_uid"]),WechatTemplateService::SERVICE_NOTICE,[
|
||||
'first'=>$head,
|
||||
'keyword1'=>$now_user["nickname"],
|
||||
'keyword2'=>"客服提醒",
|
||||
'keyword3'=> preg_replace('/<img.*? \/>/','[图片]',$value["msn"]),
|
||||
'keyword4'=>date('Y-m-d H:i:s',time()),
|
||||
'remark'=>'点击立即查看消息'
|
||||
],Url::build('service/service_ing',['to_uid'=>$now_user["uid"],'mer_id'=>$params["mer_id"]],true,true));
|
||||
}
|
||||
}
|
||||
}
|
||||
$where = "mer_id = ".$params["mer_id"]." AND uid = ".$params["to_uid"]." AND to_uid = ".$params["uid"]." AND type = 0";
|
||||
$list = StoreServiceLog::where($where)->order("add_time asc")->select()->toArray();
|
||||
$ids = [];
|
||||
foreach ($list as $key => $value) {
|
||||
//设置发送人与接收人区别
|
||||
if($value["uid"] == $params["uid"])
|
||||
$list[$key]['my'] = "my";
|
||||
else
|
||||
$list[$key]['my'] = "to";
|
||||
|
||||
array_push($ids,$value["id"]);
|
||||
}
|
||||
|
||||
//设置这些消息为已读
|
||||
StoreServiceLog::where(array("id"=>array("in",$ids)))->update(array("type"=>1,"remind"=>1));
|
||||
return JsonService::successful($list);
|
||||
}
|
||||
|
||||
public function add_msn(Request $request){
|
||||
$params = $request->post();
|
||||
if($params["type"] == "html")
|
||||
$data["msn"] = htmlspecialchars_decode($params["msn"]);
|
||||
else
|
||||
$data["msn"] = $params["msn"];
|
||||
$data["uid"] = $params["uid"];
|
||||
$data["to_uid"] = $params["to_uid"];
|
||||
$data["mer_id"] = $params["mer_id"] > 0 ? $params["mer_id"] : 0;
|
||||
$data["add_time"] = time();
|
||||
StoreServiceLog::set($data);
|
||||
return JsonService::successful();
|
||||
}
|
||||
|
||||
public function get_msn(Request $request){
|
||||
$params = $request->post();
|
||||
$size = 10;
|
||||
$page = $params["page"]>=0 ? $params["page"] : 1;
|
||||
$where = "(mer_id = ".$params["mer_id"]." AND uid = ".$params["uid"]." AND to_uid = ".$params["to_uid"].") OR (mer_id = ".$params["mer_id"]." AND uid = ".$params["to_uid"]." AND to_uid = ".$params["uid"].")";
|
||||
$list = StoreServiceLog::where($where)->limit(($page-1)*$size,$size)->order("add_time desc")->select()->toArray();
|
||||
foreach ($list as $key => $value) {
|
||||
//设置发送人与接收人区别
|
||||
if($value["uid"] == $params["uid"])
|
||||
$list[$key]['my'] = "my";
|
||||
else
|
||||
$list[$key]['my'] = "to";
|
||||
|
||||
//设置这些消息为已读
|
||||
if($value["uid"] == $params["to_uid"] && $value["to_uid"] == $params["uid"])StoreServiceLog::edit(array("type"=>1,"remind"=>1),$value["id"]);
|
||||
}
|
||||
$list=array_reverse($list);
|
||||
return JsonService::successful($list);
|
||||
}
|
||||
|
||||
public function refresh_msn_new(Request $request){
|
||||
$params = $request->post();
|
||||
$now_user = User::getUserInfo($this->userInfo['uid']);
|
||||
if($params["last_time"] > 0)
|
||||
$where = "(uid = ".$now_user["uid"]." OR to_uid = ".$now_user["uid"].") AND add_time>".$params["last_time"];
|
||||
else
|
||||
$where = "uid = ".$now_user["uid"]." OR to_uid = ".$now_user["uid"];
|
||||
|
||||
|
||||
$msn_list = StoreServiceLog::where($where)->order("add_time desc")->select()->toArray();
|
||||
$info_array = $list = [];
|
||||
foreach ($msn_list as $key => $value){
|
||||
$to_uid = $value["uid"] == $now_user["uid"] ? $value["to_uid"] : $value["uid"];
|
||||
if(!in_array(["to_uid"=>$to_uid,"mer_id"=>$value["mer_id"]],$info_array)){
|
||||
$info_array[count($info_array)] = ["to_uid"=>$to_uid,"mer_id"=>$value["mer_id"]];
|
||||
|
||||
$to_user = StoreService::field("uid,nickname,avatar")->where(array("uid"=>$to_uid))->find();
|
||||
if(!$to_user)$to_user = User::field("uid,nickname,avatar")->where(array("uid"=>$to_uid))->find();
|
||||
$to_user["mer_id"] = $value["mer_id"];
|
||||
$to_user["mer_name"] = $value["mer_id"] > 0 ? "[".Merchant::where('id',$value["mer_id"])->value('mer_name')."]" : '';
|
||||
$value["to_info"] = $to_user;
|
||||
$value["count"] = StoreServiceLog::where(array("mer_id"=>$value["mer_id"],"uid"=>$to_uid,"to_uid"=>$now_user["uid"],"type"=>0))->count();
|
||||
$list[count($list)] = $value;
|
||||
}
|
||||
}
|
||||
return JsonService::successful($list);
|
||||
}
|
||||
|
||||
public function get_user_brokerage_list($uid, $first = 0,$limit = 8)
|
||||
{
|
||||
@ -1449,6 +1336,33 @@ class AuthApi extends AuthController{
|
||||
return JsonService::successful($domain.$picname);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取分销二维码不存入小程序二维码表中
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function get_routine_code(){
|
||||
header('content-type:image/jpg');
|
||||
if(!$this->userInfo['uid']) return JsonService::fail('授权失败,请重新授权');
|
||||
$path = makePathToUrl('routine/code');
|
||||
if($path == '')
|
||||
return JsonService::fail('生成上传目录失败,请检查权限!');
|
||||
$picname = $path.'/'.$this->userInfo['uid'].'.jpg';
|
||||
$domain = SystemConfigService::get('site_url').'/';
|
||||
$domainTop = substr($domain,0,5);
|
||||
if($domainTop != 'https') $domain = 'https:'.substr($domain,5,strlen($domain));
|
||||
if(file_exists($picname)) return JsonService::successful($domain.$picname);
|
||||
else{
|
||||
// $res = RoutineCode::getRoutineCode($this->userInfo['uid']);
|
||||
$res = MiniProgramService::appCodeUnlimitService($this->userInfo['uid'])->__toString();
|
||||
if($res){
|
||||
file_put_contents($picname,$res);
|
||||
}else return JsonService::fail('二维码生成失败');
|
||||
}
|
||||
return JsonService::successful($domain.$picname);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 绑定推荐人
|
||||
* @param Request $request
|
||||
@ -1594,7 +1508,7 @@ class AuthApi extends AuthController{
|
||||
if(!$bargainId || !$bargainUserId) return JsonService::fail('参数错误');
|
||||
$res = StoreBargainUserHelp::setBargainUserHelp($bargainId,$bargainUserId,$this->userInfo['uid']);
|
||||
if($res) {
|
||||
if(!StoreBargainUserHelp::getSurplusPrice($bargainId,$bargainUserId)){
|
||||
if(StoreBargainUserHelp::getSurplusPrice($bargainId,$bargainUserId) <= 0){
|
||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
|
||||
$bargain = StoreBargain::where('id',$bargainId)->find()->toArray();
|
||||
$bargainUser = StoreBargainUser::where('id',$bargainUserTableId)->find()->toArray();
|
||||
@ -1642,7 +1556,7 @@ class AuthApi extends AuthController{
|
||||
*/
|
||||
public function is_bargain_user_help($bargainId = 0,$bargainUserId = 0){
|
||||
if(!$bargainId || !$bargainUserId) return JsonService::fail('参数错误');
|
||||
if(StoreBargainUserHelp::isBargainUserHelpCount($bargainId,$bargainUserId,$this->userInfo['uid'])) return JsonService::successful('请稍后在帮助好友砍价');
|
||||
if(StoreBargainUserHelp::isBargainUserHelpCount($bargainId,$bargainUserId,$this->userInfo['uid'])) return JsonService::successful('请稍后再帮助好友砍价');
|
||||
else return JsonService::fail('您不能再帮忙砍价了');
|
||||
}
|
||||
|
||||
@ -1712,7 +1626,7 @@ class AuthApi extends AuthController{
|
||||
* @param string $formId
|
||||
*/
|
||||
public function get_form_id($formId = ''){
|
||||
if((int)$formId == '' || $formId == 'the formId is a mock one') return JsonService::fail('no');
|
||||
if(!strlen(trim($formId)) || $formId == 'the formId is a mock one') return JsonService::fail('no');
|
||||
$data['form_id'] = $formId;
|
||||
$data['uid'] = $this->userInfo['uid'];
|
||||
$data['status'] = 1;
|
||||
@ -1979,35 +1893,40 @@ class AuthApi extends AuthController{
|
||||
}
|
||||
|
||||
|
||||
public function poster($id = 0){
|
||||
/**
|
||||
* TODO 产品海报二维码 不存入小程序二维码表中
|
||||
* @param int $id
|
||||
*/
|
||||
public function product_promotion_routine_code($id = 0){
|
||||
if(!$id) return JsonService::fail('参数错误');
|
||||
$productInfo = StoreProduct::getValidProduct($id,'store_name,id,price,image,code_path');
|
||||
if(empty($productInfo)) return JsonService::fail('参数错误');
|
||||
if(strlen($productInfo['code_path'])< 10) {
|
||||
$path = 'public'.DS.'uploads'.DS.'codepath'.DS.'product';
|
||||
$codePath = $path.DS.$productInfo['id'].'.jpg';
|
||||
if(!file_exists($codePath)){
|
||||
if(!is_dir($path)) mkdir($path,0777,true);
|
||||
$res = file_put_contents($codePath,RoutineCode::getPages('pages/product-con/index?id='.$productInfo['id']));
|
||||
}
|
||||
$res = StoreProduct::edit(['code_path'=>$codePath],$id);
|
||||
if($res) $productInfo['code_path'] = $codePath;
|
||||
else return JsonService::fail('没有查看权限');
|
||||
$count = StoreProduct::validWhere()->count();
|
||||
if(!$count) return JsonService::fail('参数错误');
|
||||
$path = UPLOAD_PATH.'/codepath/product/';
|
||||
$codePath = $path.$id.'_'.$this->userInfo['uid'].'.jpg';
|
||||
$domain = SystemConfigService::get('site_url').'/';
|
||||
if(!file_exists($codePath)){
|
||||
if(!is_dir($path)) mkdir($path,0777,true);
|
||||
$res = RoutineCode::getRoutineCode($this->userInfo['uid'],'pages/product-con/index',$id);
|
||||
if($res){
|
||||
$resStatus = json_decode($res,true);
|
||||
if(is_array($resStatus)) return JsonService::fail('错误码:'.$resStatus['errcode']);
|
||||
else file_put_contents($codePath,$res);
|
||||
}else return JsonService::fail('二维码生成失败');
|
||||
}
|
||||
$posterPath = createPoster($productInfo);
|
||||
return JsonService::successful($posterPath);
|
||||
return JsonService::successful($domain.$codePath);
|
||||
}
|
||||
|
||||
|
||||
// public function poster($id = 0){
|
||||
// if(!$id) return JsonService::fail('参数错误');
|
||||
// $productInfo = StoreProduct::getValidProduct($id,'store_name,id,price,image,code_path');
|
||||
// if(empty($productInfo)) return JsonService::fail('参数错误');
|
||||
// if($productInfo['code_path'] == '') {
|
||||
// if(strlen($productInfo['code_path'])< 10) {
|
||||
// $path = 'public'.DS.'uploads'.DS.'codepath'.DS.'product';
|
||||
// $codePath = $path.DS.$productInfo['id'].'.jpg';
|
||||
// if(!file_exists($codePath)){
|
||||
// //$dir = iconv("UTF-8", "GBK", "public".DS."uploads".DS."codepath".DS."product");
|
||||
// if(!is_dir($path))
|
||||
// mkdir($path,0777,true);
|
||||
// file_put_contents($codePath,RoutineCode::getPages('pages/product-con/index?id='.$productInfo['id']));
|
||||
// if(!is_dir($path)) mkdir($path,0777,true);
|
||||
//// $res = file_put_contents($codePath,RoutineCode::getPages('pages/product-con/index?id='.$productInfo['id']));
|
||||
// }
|
||||
// $res = StoreProduct::edit(['code_path'=>$codePath],$id);
|
||||
// if($res) $productInfo['code_path'] = $codePath;
|
||||
@ -2015,9 +1934,142 @@ class AuthApi extends AuthController{
|
||||
// }
|
||||
// $posterPath = createPoster($productInfo);
|
||||
// return JsonService::successful($posterPath);
|
||||
//
|
||||
// }
|
||||
/**
|
||||
* TODO 获取用户信息
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function get_user_info($is_sign = '',$discount = ''){
|
||||
if(is_object($this->userInfo)) $this->userInfo = $this->userInfo->toArray();
|
||||
if($is_sign){
|
||||
$this->userInfo['is_sign'] = UserSign::checkUserSigned($this->userInfo['uid']) ? true : false;
|
||||
$this->userInfo['sign_count'] = UserSign::userSignedCount($this->userInfo['uid']);
|
||||
// if(!User::where(['uid'=>$this->userInfo['uid'],'status'=>1])->whereTime('sign_time','yesterday')->count() && $this->userInfo['is_sign']==false){
|
||||
// User::update(['sign_num'=>0],['uid'=>$this->userInfo['uid']]);
|
||||
// $this->userInfo['sign_num']=0;
|
||||
// }
|
||||
}
|
||||
if($discount){
|
||||
list($grade_name,$discount_num,$sign_grade,$pic)=UserSign::getdiscount($this->get_sign_list(true,'sign_deploy'),$this->userInfo['integral']);
|
||||
$this->userInfo['grade_name']=$grade_name;
|
||||
$this->userInfo['pic']=$pic;
|
||||
$rank=User::where(['status'=>1])->where('uid','<>',$this->userInfo['uid'])->where('integral',$this->userInfo['integral'])->count();
|
||||
$this->userInfo['ranking']=User::where(['status'=>1])->where('integral','>',$this->userInfo['integral'])->count() +$rank +1;
|
||||
$count=User::where(['status'=>1])->count();
|
||||
$ranking=bcsub($count,$this->userInfo['ranking']);
|
||||
$this->userInfo['ratio']=bcdiv($ranking,$count,2) * 100;
|
||||
if($this->userInfo['ranking'] == 1)
|
||||
$this->userInfo['differ']=0;
|
||||
else{
|
||||
$integral=User::where(['status'=>1])->order('integral asc')->where('integral','>',$this->userInfo['integral'])->value('integral');
|
||||
$this->userInfo['differ']=$integral-$this->userInfo['integral'];
|
||||
}
|
||||
$this->userInfo['notice'] = UserNotice::getNotice($this->userInfo['uid']);
|
||||
}
|
||||
return JsonService::successful($this->userInfo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 用户签到
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function user_sign()
|
||||
{
|
||||
$signed = UserSign::checkUserSigned($this->userInfo['uid']);
|
||||
if($signed) return JsonService::fail('已签到');
|
||||
if(false !== $integral = UserSign::sign($this->userInfo))
|
||||
return JsonService::successful('签到获得'.floatval($integral).'积分');
|
||||
// if(false !== $integral = UserSign::signFoodie($this->userInfo['uid'],$this->get_sign_list(true)))
|
||||
// return JsonService::successful('签到获得'.floatval($integral).'积分');
|
||||
else
|
||||
return JsonService::fail('签到失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 判断用户是否签到
|
||||
*/
|
||||
public function user_sign_status()
|
||||
{
|
||||
$signed = UserSign::checkUserSigned($this->userInfo['uid']);
|
||||
if($signed) return JsonService::successful('ok');
|
||||
else return JsonService::fail('no');
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO 获取系统配置签到列表
|
||||
* */
|
||||
public function get_sign_list($isarray = false,$data_key = 'sign_day_num'){
|
||||
$sign_day_num = GroupDataService::getData($data_key) ? :[];
|
||||
if($isarray === true) return $sign_day_num;
|
||||
return JsonService::successful($sign_day_num);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取签到记录
|
||||
*/
|
||||
public function get_sign_log(){
|
||||
$where = UtilService::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['uid',$this->userInfo['uid']],
|
||||
['group',''],
|
||||
]);
|
||||
if($where['group'])
|
||||
return JsonService::successful(UserSign::getSignLog($where,true));
|
||||
else
|
||||
return JsonService::successful(UserSign::getSignLog($where));
|
||||
}
|
||||
|
||||
/* 2.5.36 修改问题 */
|
||||
public function again_order($uni = ''){
|
||||
if(!$uni) return JsonService::fail('参数错误!');
|
||||
$order = StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
|
||||
if(!$order) return JsonService::fail('订单不存在!');
|
||||
$order = StoreOrder::tidyOrder($order,true);
|
||||
$res = array();
|
||||
foreach ($order['cartInfo'] as $v) {
|
||||
if($v['combination_id']) return JsonService::fail('拼团产品不能再来一单,请在拼团产品内自行下单!');
|
||||
else if($v['bargain_id']) return JsonService::fail('砍价产品不能再来一单,请在砍价产品内自行下单!');
|
||||
else $res[] = StoreCart::setCart($this->userInfo['uid'], $v['product_id'], $v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', 'product', 0, 0);
|
||||
}
|
||||
$cateId = [];
|
||||
foreach ($res as $v){
|
||||
if(!$v) return JsonService::fail('再来一单失败,请重新下单!');
|
||||
$cateId[] = $v['id'];
|
||||
}
|
||||
return JsonService::successful('ok',implode(',',$cateId));
|
||||
}
|
||||
/**
|
||||
* 获取用户手机号码
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function bind_mobile(Request $request){
|
||||
$data = UtilService::postMore([['info',[]]],$request);
|
||||
$data = $data['info'];
|
||||
unset($data['info']);
|
||||
//解密获取用户信息
|
||||
$data['iv'] = urldecode(urlencode($data['iv']));
|
||||
try{
|
||||
$userInfo = MiniProgramService::encryptor($data['session_key'], $data['iv'], $data['encryptedData']);
|
||||
if(!empty($userInfo['purePhoneNumber'])){
|
||||
if(User::edit(['phone'=>$userInfo['purePhoneNumber']],$this->userInfo['uid']))
|
||||
return JsonService::success('绑定成功');
|
||||
else
|
||||
return JsonService::fail('绑定失败');
|
||||
}else
|
||||
return JsonService::fail('获取手机号失败');
|
||||
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail('error',$e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 刷新数据缓存
|
||||
*/
|
||||
|
||||
@ -20,7 +20,6 @@ class AuthController extends Controller
|
||||
protected function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
|
||||
if(!empty(input('openid'))){
|
||||
$uid = WechatUser::openidTouid(input('openid'));
|
||||
|
||||
@ -7,6 +7,7 @@ use app\routine\model\routine\RoutineServer;
|
||||
use app\routine\model\user\RoutineUser;
|
||||
use service\JsonService;
|
||||
use service\UtilService;
|
||||
use service\MiniProgramService;
|
||||
use think\Controller;
|
||||
use think\Request;
|
||||
|
||||
@ -22,8 +23,12 @@ class Login extends Controller{
|
||||
|
||||
public function index(Request $request){
|
||||
$data = UtilService::postMore([['info',[]]],$request);//获取前台传的code
|
||||
// var_dump($data);
|
||||
// var_dump(MiniProgramService::encryptor($data->code));
|
||||
$data = $data['info'];
|
||||
unset($data['info']);
|
||||
// var_dump(MiniProgramService::getUserInfo($data['code']));
|
||||
|
||||
$res = $this->setCode($data['code']);
|
||||
if(!isset($res['openid'])) return JsonService::fail('openid获取失败');
|
||||
if(isset($res['unionid'])) $data['unionid'] = $res['unionid'];
|
||||
|
||||
114
application/routine/controller/Logins.php
Normal file
114
application/routine/controller/Logins.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace app\routine\controller;
|
||||
|
||||
use app\admin\model\system\SystemConfig;
|
||||
use app\routine\model\routine\RoutineServer;
|
||||
use app\routine\model\user\RoutineUser;
|
||||
use service\JsonService;
|
||||
use service\UtilService;
|
||||
use service\MiniProgramService;
|
||||
use think\Controller;
|
||||
use think\Request;
|
||||
|
||||
class Logins extends Controller{
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index(Request $request){
|
||||
$data = UtilService::postMore([['info',[]]],$request);//获取前台传的code
|
||||
$data = $data['info'];
|
||||
unset($data['info']);
|
||||
//解密获取用户信息
|
||||
$iv = urlencode($data['iv']);
|
||||
$data['iv'] = urldecode($iv);
|
||||
try{
|
||||
$userInfo = $this->decryptCode($data['session_key'], $data['iv'], $data['encryptedData']);
|
||||
if(!isset($userInfo['openId'])) return JsonService::fail('openid获取失败');
|
||||
if(!isset($userInfo['unionId'])) $userInfo['unionid'] = '';
|
||||
$userInfo['session_key'] = $data['session_key'];
|
||||
$userInfo['spid'] = $data['spid'];//推广人ID
|
||||
$userInfo['spreadid'] = (int)$data['spreadid'];//推广人ID 2.5.36
|
||||
$dataOauthInfo = RoutineUser::routineOauthnew($userInfo);
|
||||
$userInfo['uid'] = $dataOauthInfo['uid'];
|
||||
$userInfo['page'] = $dataOauthInfo['page'];
|
||||
$userInfo['status'] = RoutineUser::isUserStatus($userInfo['uid']);
|
||||
$userInfo['uidShare'] = RoutineUser::isUserShare($userInfo['uid']);//我的推广二维码ID
|
||||
return JsonService::successful($userInfo);
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail('error',$e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据前台传code 获取 openid 和 session_key //会话密匙
|
||||
* @param string $code
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function setCode(Request $request){
|
||||
$data = UtilService::postMore([['info', []]], $request);//获取前台传的code
|
||||
// var_dump($data);die;
|
||||
$code = '';
|
||||
if(isset($data['info']['code']))
|
||||
$code = $data['info']['code'];
|
||||
else
|
||||
JsonService::fail('未获取到code');
|
||||
if($code == '') return [];
|
||||
$info = MiniProgramService::getUserInfo($code);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密数据
|
||||
* @param string $code
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function decryptCode($session = '', $iv = '', $encryptData = '')
|
||||
{
|
||||
if (!$session) return JsonService::fail('session参数错误');
|
||||
if (!$iv) return JsonService::fail('iv参数错误');
|
||||
if (!$encryptData) return JsonService::fail('encryptData参数错误');
|
||||
return MiniProgramService::encryptor($session, $iv, $encryptData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取网站logo
|
||||
*/
|
||||
public function get_enter_logo(){
|
||||
$siteLogo = SystemConfig::getValue('routine_logo');
|
||||
$siteName = SystemConfig::getValue('routine_name');
|
||||
$data['site_logo'] = $siteLogo;
|
||||
$data['site_name'] = $siteName;
|
||||
return JsonService::successful($data);
|
||||
}
|
||||
/**
|
||||
* 获取网站顶部颜色
|
||||
*/
|
||||
public function get_routine_config(){
|
||||
$routineConfig = SystemConfig::getMore('site_name,site_logo,site_url,site_close,site_service_phone,routine_logo,routine_name,routine_style');
|
||||
$data['routine_config'] = $routineConfig;
|
||||
return JsonService::successful($data);
|
||||
}
|
||||
/**
|
||||
* 获取网站顶部颜色
|
||||
*/
|
||||
public function get_routine_style(){
|
||||
$routineStyle = SystemConfig::getValue('routine_style');
|
||||
$data['routine_style'] = $routineStyle;
|
||||
return JsonService::successful($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客服电话
|
||||
*/
|
||||
public function get_site_service_phone(){
|
||||
$siteServicePhone = SystemConfig::getValue('site_service_phone');
|
||||
$data['site_service_phone'] = $siteServicePhone;
|
||||
return JsonService::successful($data);
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,6 @@
|
||||
<?php
|
||||
namespace app\routine\controller;
|
||||
use behavior\wechat\PaymentBehavior;
|
||||
use service\HookService;
|
||||
use service\RoutineNotify;
|
||||
use service\MiniProgramService;
|
||||
|
||||
|
||||
/**
|
||||
@ -17,8 +15,7 @@ class Routine
|
||||
*/
|
||||
public function notify()
|
||||
{
|
||||
$result = RoutineNotify::notify();
|
||||
if($result) HookService::listen('wechat_pay_success_'.strtolower($result['attach']),$result['out_trade_no'],$result,true,PaymentBehavior::class);
|
||||
MiniProgramService::handleNotify();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,33 @@ namespace app\routine\model\routine;
|
||||
|
||||
class RoutineCode{
|
||||
|
||||
|
||||
/**
|
||||
* TODO 获取分销二维码 2.5.36更新
|
||||
* @param int $uid
|
||||
* @param string $page
|
||||
* @param int $productId
|
||||
* @param array $color
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function getRoutineCode($uid = 0,$page = '',$productId = 0,$color = array()){
|
||||
$accessToken = RoutineServer::get_access_token();
|
||||
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$accessToken;
|
||||
$data['scene'] = $uid.'-'.$productId;
|
||||
if(empty($color)){
|
||||
$color['r'] = 0;
|
||||
$color['g'] = 0;
|
||||
$color['b'] = 0;
|
||||
}
|
||||
$data['page'] = $page;
|
||||
$data['width'] = 430;
|
||||
$data['auto_color'] = false;
|
||||
$data['line_color'] = $color;
|
||||
$data['is_hyaline'] = false;
|
||||
$resCode = RoutineServer::curlPost($url,json_encode($data));
|
||||
if($resCode) return $resCode;
|
||||
else return false;
|
||||
}
|
||||
/**
|
||||
* 获取分销二维码
|
||||
* @param int $uid yonghuID
|
||||
@ -12,7 +39,7 @@ class RoutineCode{
|
||||
*/
|
||||
public static function getCode($uid = 0,$imgUrl = '',$color = array(),$page = '',$thirdType = 'spread'){
|
||||
$accessToken = RoutineServer::get_access_token();
|
||||
$res = RoutineQrcode::setRoutineQrcodeForever($uid,$thirdType,$page,$imgUrl);
|
||||
$res = RoutineQrcode::getRoutineQrCode($uid,$thirdType,$page,$imgUrl);
|
||||
if($res){
|
||||
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$accessToken;
|
||||
if($uid) $data['scene'] = $res->id;
|
||||
|
||||
@ -66,6 +66,56 @@ class RoutineUser extends ModelBasic
|
||||
return $data;
|
||||
}
|
||||
|
||||
/** 新授权函数
|
||||
* @param $routine
|
||||
* @return mixed
|
||||
*/
|
||||
public static function routineOauthnew($routine){
|
||||
$routineInfo['nickname'] = filterEmoji($routine['nickName']);//姓名
|
||||
$routineInfo['sex'] = $routine['gender'];//性别
|
||||
$routineInfo['language'] = $routine['language'];//语言
|
||||
$routineInfo['city'] = $routine['city'];//城市
|
||||
$routineInfo['province'] = $routine['province'];//省份
|
||||
$routineInfo['country'] = $routine['country'];//国家
|
||||
$routineInfo['headimgurl'] = $routine['avatarUrl'];//头像
|
||||
// $routineInfo[''] = $routine['code'];//临时登录凭证 是获取用户openid和session_key(会话密匙)
|
||||
$routineInfo['routine_openid'] = $routine['openId'];//openid
|
||||
$routineInfo['spreadid'] = $routine['spreadid'];//spreadid
|
||||
$routineInfo['session_key'] = $routine['session_key'];//会话密匙
|
||||
$routineInfo['unionid'] = isset($routine['unionId'])?$routine['unionId']:'';//用户在开放平台的唯一标识符
|
||||
$routineInfo['user_type'] = 'routine';//用户类型
|
||||
$page = '';//跳转小程序的页面
|
||||
$spid = 0;//绑定关系uid
|
||||
//获取是否有扫码进小程序
|
||||
if($routine['spid']){
|
||||
$info = RoutineQrcode::getRoutineQrcodeFindType($routine['spid']);
|
||||
if($info){
|
||||
$spid = $info['third_id'];
|
||||
$page = $info['page'];
|
||||
}
|
||||
}
|
||||
// 判断unionid 存在根据unionid判断
|
||||
if($routineInfo['unionid'] != '' && WechatUser::be(['unionid'=>$routineInfo['unionid']])){
|
||||
WechatUser::edit($routineInfo,$routineInfo['unionid'],'unionid');
|
||||
$uid = WechatUser::where('unionid',$routineInfo['unionid'])->value('uid');
|
||||
User::updateWechatUser($routineInfo,$uid);
|
||||
}else if(WechatUser::be(['routine_openid'=>$routineInfo['routine_openid']])){ //根据小程序openid判断
|
||||
WechatUser::edit($routineInfo,$routineInfo['routine_openid'],'routine_openid');
|
||||
$uid = WechatUser::where('routine_openid',$routineInfo['routine_openid'])->value('uid');
|
||||
User::updateWechatUser($routineInfo,$uid);
|
||||
}else{
|
||||
if($routineInfo['spreadid']) $spid = $routineInfo['spreadid'];
|
||||
$routineInfo['add_time'] = time();//用户添加时间
|
||||
$routineInfo = WechatUser::set($routineInfo);
|
||||
if(User::isUserSpread($spid)) {
|
||||
$res = User::setRoutineUser($routineInfo,$spid); //用户上级
|
||||
}else $res = User::setRoutineUser($routineInfo);
|
||||
$uid = $res->uid;
|
||||
}
|
||||
$data['page'] = $page;
|
||||
$data['uid'] = $uid;
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* 判断是否是小程序用户
|
||||
* @param int $uid
|
||||
@ -76,9 +126,28 @@ class RoutineUser extends ModelBasic
|
||||
return WechatUser::where('uid',$uid)->where('user_type','routine')->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @return int
|
||||
*/
|
||||
public static function isUserStatus($uid = 0){
|
||||
if(!$uid) return 0;
|
||||
$user = User::getUserInfo($uid);
|
||||
return $user['status'];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取分销编号
|
||||
* @param int $uid
|
||||
* @return int
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public static function isUserShare($uid = 0){
|
||||
if(!$uid) return 0;
|
||||
$userQrCodeInfo = RoutineQrcode::getRoutineQrCode($uid,'spread');
|
||||
if($userQrCodeInfo) return $userQrCodeInfo->id;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -107,10 +107,12 @@ class User extends ModelBasic
|
||||
$cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
|
||||
if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
|
||||
$brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
|
||||
//返佣之后余额
|
||||
$balance = bcsub($userInfo['now_money'],$brokeragePrice,2);
|
||||
if($brokeragePrice <= 0) return true;
|
||||
$mark = $userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
|
||||
self::beginTrans();
|
||||
$res1 = UserBill::income('获得推广佣金',$userInfo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],0,$mark);
|
||||
$res1 = UserBill::income('获得推广佣金',$userInfo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],$balance,$mark);
|
||||
$res2 = self::bcInc($userInfo['spread_uid'],'now_money',$brokeragePrice,'uid');
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
@ -136,13 +138,26 @@ class User extends ModelBasic
|
||||
$cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
|
||||
if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
|
||||
$brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
|
||||
//返佣之后余额
|
||||
$balance = bcsub($userInfo['now_money'],$brokeragePrice,2);
|
||||
if($brokeragePrice <= 0) return true;
|
||||
$mark = '二级推广人'.$userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
|
||||
self::beginTrans();
|
||||
$res1 = UserBill::income('获得推广佣金',$userInfoTwo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],0,$mark);
|
||||
$res1 = UserBill::income('获得推广佣金',$userInfoTwo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],$balance,$mark);
|
||||
$res2 = self::bcInc($userInfoTwo['spread_uid'],'now_money',$brokeragePrice,'uid');
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 订单删除 恢复对应的积分
|
||||
* @param $uid
|
||||
* @param $integral
|
||||
* @return bool
|
||||
*/
|
||||
public static function recoverOrderIntegral($uid, $integral)
|
||||
{
|
||||
return self::bcInc($uid,'integral',$integral,'uid');
|
||||
}
|
||||
}
|
||||
@ -108,10 +108,12 @@ class User extends ModelBasic
|
||||
$cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
|
||||
if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
|
||||
$brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
|
||||
//返佣之后余额
|
||||
$balance = bcsub($userInfo['now_money'],$brokeragePrice,2);
|
||||
if($brokeragePrice <= 0) return true;
|
||||
$mark = $userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
|
||||
self::beginTrans();
|
||||
$res1 = UserBill::income('获得推广佣金',$userInfo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],0,$mark);
|
||||
$res1 = UserBill::income('获得推广佣金',$userInfo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],$balance,$mark);
|
||||
$res2 = self::bcInc($userInfo['spread_uid'],'now_money',$brokeragePrice,'uid');
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
@ -137,10 +139,12 @@ class User extends ModelBasic
|
||||
$cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
|
||||
if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
|
||||
$brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
|
||||
//返佣之后余额
|
||||
$balance = bcsub($userInfo['now_money'],$brokeragePrice,2);
|
||||
if($brokeragePrice <= 0) return true;
|
||||
$mark = '二级推广人'.$userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
|
||||
self::beginTrans();
|
||||
$res1 = UserBill::income('获得推广佣金',$userInfoTwo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],0,$mark);
|
||||
$res1 = UserBill::income('获得推广佣金',$userInfoTwo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],$balance,$mark);
|
||||
$res2 = self::bcInc($userInfoTwo['spread_uid'],'now_money',$brokeragePrice,'uid');
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
|
||||
@ -39,6 +39,13 @@ class WechatUser extends ModelBasic
|
||||
if(!isset($userInfo['subscribe']) || !$userInfo['subscribe'] || !isset($userInfo['openid']))
|
||||
exception('请关注公众号!');
|
||||
$userInfo['tagid_list'] = implode(',',$userInfo['tagid_list']);
|
||||
//判断 unionid 是否存在
|
||||
if(isset($userInfo['unionid'])){
|
||||
$wechatInfo = self::where('unionid',$userInfo['unionid'])->find();
|
||||
if($wechatInfo){
|
||||
return self::edit($userInfo,$userInfo['unionid'],'unionid');
|
||||
}
|
||||
}
|
||||
self::beginTrans();
|
||||
$wechatUser = self::set($userInfo);
|
||||
if(!$wechatUser){
|
||||
@ -54,6 +61,9 @@ class WechatUser extends ModelBasic
|
||||
return $wechatUser;
|
||||
}
|
||||
|
||||
/**关注送优惠券
|
||||
* @param $openid
|
||||
*/
|
||||
public static function userFirstSubGiveCoupon($openid)
|
||||
{
|
||||
$couponId = SystemConfigService::get('wechat_first_sub_give_coupon');
|
||||
|
||||
307
extend/service/MiniProgramService.php
Normal file
307
extend/service/MiniProgramService.php
Normal file
@ -0,0 +1,307 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/23
|
||||
*/
|
||||
|
||||
namespace service;
|
||||
|
||||
use behavior\wechat\PaymentBehavior;
|
||||
use EasyWeChat\Foundation\Application;
|
||||
use EasyWeChat\Payment\Order;
|
||||
use think\Url;
|
||||
|
||||
/**微信小程序接口
|
||||
* Class WechatMinService
|
||||
* @package service
|
||||
*/
|
||||
class MiniProgramService
|
||||
{
|
||||
private static $instance = null;
|
||||
|
||||
public static function options()
|
||||
{
|
||||
$wechat = SystemConfigService::more(['site_url','routine_appId','routine_appsecret']);
|
||||
$payment = SystemConfigService::more(['pay_routine_mchid','pay_routine_key','pay_routine_client_cert','pay_routine_client_key','pay_weixin_open']);
|
||||
$config = [];
|
||||
$config['mini_program'] = [
|
||||
'app_id'=>isset($wechat['routine_appId']) ? $wechat['routine_appId']:'',
|
||||
'secret'=>isset($wechat['routine_appsecret']) ? $wechat['routine_appsecret']:'',
|
||||
'token'=>isset($wechat['wechat_token']) ? $wechat['wechat_token']:'',
|
||||
'aes_key'=> isset($wechat['wechat_encodingaeskey']) ? $wechat['wechat_encodingaeskey']:''
|
||||
];
|
||||
if(isset($payment['pay_weixin_open']) && $payment['pay_weixin_open'] == 1){
|
||||
$config['payment'] = [
|
||||
'app_id'=>isset($wechat['routine_appId']) ? $wechat['routine_appId']:'',
|
||||
'merchant_id'=>$payment['pay_routine_mchid'],
|
||||
'key'=>$payment['pay_routine_key'],
|
||||
'cert_path'=>realpath('.'.$payment['pay_routine_client_cert']),
|
||||
'key_path'=>realpath('.'.$payment['pay_routine_client_key']),
|
||||
'notify_url'=>$wechat['site_url'].Url::build('/routine/Routine/notify')
|
||||
];
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
public static function application($cache = false)
|
||||
{
|
||||
(self::$instance === null || $cache === true) && (self::$instance = new Application(self::options()));
|
||||
return self::$instance;
|
||||
}
|
||||
/**
|
||||
* 小程序接口
|
||||
* @return \EasyWeChat\MiniProgram\MiniProgram
|
||||
*/
|
||||
public static function miniprogram()
|
||||
{
|
||||
return self::application()->mini_program;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得用户信息 根据code 获取session_key
|
||||
* @param array|string $openid
|
||||
* @return $userInfo
|
||||
*/
|
||||
public static function getUserInfo($code)
|
||||
{
|
||||
$userInfo = self::miniprogram()->sns->getSessionKey($code);
|
||||
return $userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密数据解密
|
||||
* @param $sessionKey
|
||||
* @param $iv
|
||||
* @param $encryptData
|
||||
* @return $userInfo
|
||||
*/
|
||||
public static function encryptor($sessionKey, $iv, $encryptData){
|
||||
return self::miniprogram()->encryptor->decryptData($sessionKey, $iv, $encryptData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传临时素材接口
|
||||
* @return \EasyWeChat\Material\Temporary
|
||||
*/
|
||||
public static function materialTemporaryService()
|
||||
{
|
||||
return self::miniprogram()->material_temporary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客服消息接口
|
||||
* @param null $to
|
||||
* @param null $message
|
||||
*/
|
||||
public static function staffService()
|
||||
{
|
||||
return self::miniprogram()->staff;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信小程序二维码生成接口
|
||||
* @return \EasyWeChat\QRCode\QRCode
|
||||
*/
|
||||
public static function qrcodeService()
|
||||
{
|
||||
return self::miniprogram()->qrcode;
|
||||
}
|
||||
|
||||
/**微信小程序二维码生成接口不限量永久
|
||||
* @param $scene
|
||||
* @param null $page
|
||||
* @param null $width
|
||||
* @param null $autoColor
|
||||
* @param array $lineColor
|
||||
* @return \Psr\Http\Message\StreamInterface
|
||||
*/
|
||||
public static function appCodeUnlimitService($scene, $page = null, $width = 430, $autoColor = false, $lineColor = ['r' => 0, 'g' => 0, 'b' => 0])
|
||||
{
|
||||
return self::qrcodeService()->appCodeUnlimit($scene,$page,$width,$autoColor,$lineColor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 模板消息接口
|
||||
* @return \EasyWeChat\Notice\Notice
|
||||
*/
|
||||
public static function noticeService()
|
||||
{
|
||||
return self::miniprogram()->notice;
|
||||
}
|
||||
|
||||
/**发送小程序模版消息
|
||||
* @param $openid
|
||||
* @param $templateId
|
||||
* @param array $data
|
||||
* @param null $url
|
||||
* @param null $defaultColor
|
||||
* @return mixed
|
||||
*/
|
||||
public static function sendTemplate($openid,$templateId,array $data,$form_id,$link = null,$defaultColor = null)
|
||||
{
|
||||
$notice = self::noticeService()->to($openid)->template($templateId)->formId($form_id)->andData($data);
|
||||
$message = [];
|
||||
if($link !== null) $message = ['page'=>$link];
|
||||
if($defaultColor !== null) $notice->defaultColor($defaultColor);
|
||||
return $notice->send($message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付
|
||||
* @return \EasyWeChat\Payment\Payment
|
||||
*/
|
||||
public static function paymentService()
|
||||
{
|
||||
return self::application()->payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成支付订单对象
|
||||
* @param $openid
|
||||
* @param $out_trade_no
|
||||
* @param $total_fee
|
||||
* @param $attach
|
||||
* @param $body
|
||||
* @param string $detail
|
||||
* @param string $trade_type
|
||||
* @param array $options
|
||||
* @return Order
|
||||
*/
|
||||
protected static function paymentOrder($openid,$out_trade_no,$total_fee,$attach,$body,$detail='',$trade_type='JSAPI',$options = [])
|
||||
{
|
||||
$total_fee = bcmul($total_fee,100,0);
|
||||
$order = array_merge(compact('openid','out_trade_no','total_fee','attach','body','detail','trade_type'),$options);
|
||||
if($order['detail'] == '') unset($order['detail']);
|
||||
return new Order($order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得下单ID
|
||||
* @param $openid
|
||||
* @param $out_trade_no
|
||||
* @param $total_fee
|
||||
* @param $attach
|
||||
* @param $body
|
||||
* @param string $detail
|
||||
* @param string $trade_type
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public static function paymentPrepare($openid, $out_trade_no, $total_fee, $attach, $body, $detail='', $trade_type='JSAPI', $options = [])
|
||||
{
|
||||
$order = self::paymentOrder($openid,$out_trade_no,$total_fee,$attach,$body,$detail,$trade_type,$options);
|
||||
$result = self::paymentService()->prepare($order);
|
||||
if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS'){
|
||||
try{
|
||||
HookService::listen('wechat_payment_prepare_program',$order,$result->prepay_id,false,PaymentBehavior::class);
|
||||
}catch (\Exception $e){}
|
||||
return $result->prepay_id;
|
||||
}else{
|
||||
if($result->return_code == 'FAIL'){
|
||||
exception('微信支付错误返回:'.$result->return_msg);
|
||||
}else if(isset($result->err_code)){
|
||||
exception('微信支付错误返回:'.$result->err_code_des);
|
||||
}else{
|
||||
exception('没有获取微信支付的预支付ID,请重新发起支付!');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得jsSdk支付参数
|
||||
* @param $openid
|
||||
* @param $out_trade_no
|
||||
* @param $total_fee
|
||||
* @param $attach
|
||||
* @param $body
|
||||
* @param string $detail
|
||||
* @param string $trade_type
|
||||
* @param array $options
|
||||
* @return array|string
|
||||
*/
|
||||
public static function jsPay($openid, $out_trade_no, $total_fee, $attach, $body, $detail='', $trade_type='JSAPI', $options = [])
|
||||
{
|
||||
return self::paymentService()->configForJSSDKPayment(self::paymentPrepare($openid,$out_trade_no,$total_fee,$attach,$body,$detail,$trade_type,$options));
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用商户订单号退款
|
||||
* @param $orderNo
|
||||
* @param $refundNo
|
||||
* @param $totalFee
|
||||
* @param null $refundFee
|
||||
* @param null $opUserId
|
||||
* @param string $refundReason
|
||||
* @param string $type
|
||||
* @param string $refundAccount
|
||||
*/
|
||||
public static function refund($orderNo, $refundNo, $totalFee, $refundFee = null, $opUserId = null, $refundReason = '' , $type = 'out_trade_no', $refundAccount = 'REFUND_SOURCE_UNSETTLED_FUNDS')
|
||||
{
|
||||
$totalFee = floatval($totalFee);
|
||||
$refundFee = floatval($refundFee);
|
||||
return self::paymentService()->refund($orderNo,$refundNo,$totalFee,$refundFee,$opUserId,$type,$refundAccount,$refundReason);
|
||||
}
|
||||
|
||||
/** 根据订单号退款
|
||||
* @param $orderNo
|
||||
* @param array $opt
|
||||
* @return bool
|
||||
*/
|
||||
public static function payOrderRefund($orderNo, array $opt)
|
||||
{
|
||||
if(!isset($opt['pay_price'])) exception('缺少pay_price');
|
||||
$totalFee = floatval(bcmul($opt['pay_price'],100,0));
|
||||
$refundFee = isset($opt['refund_price']) ? floatval(bcmul($opt['refund_price'],100,0)) : null;
|
||||
$refundReason = isset($opt['desc']) ? $opt['desc'] : '';
|
||||
$refundNo = isset($opt['refund_id']) ? $opt['refund_id'] : $orderNo;
|
||||
$opUserId = isset($opt['op_user_id']) ? $opt['op_user_id'] : null;
|
||||
$type = isset($opt['type']) ? $opt['type'] : 'out_trade_no';
|
||||
/*仅针对老资金流商户使用
|
||||
REFUND_SOURCE_UNSETTLED_FUNDS---未结算资金退款(默认使用未结算资金退款)
|
||||
REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款*/
|
||||
$refundAccount = isset($opt['refund_account']) ? $opt['refund_account'] : 'REFUND_SOURCE_UNSETTLED_FUNDS';
|
||||
try{
|
||||
$res = (self::refund($orderNo,$refundNo,$totalFee,$refundFee,$opUserId,$refundReason,$type,$refundAccount));
|
||||
if($res->return_code == 'FAIL') exception('退款失败:'.$res->return_msg);
|
||||
if(isset($res->err_code)) exception('退款失败:'.$res->err_code_des);
|
||||
}catch (\Exception $e){
|
||||
exception($e->getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信支付成功回调接口
|
||||
*/
|
||||
public static function handleNotify()
|
||||
{
|
||||
self::paymentService()->handleNotify(function($notify, $successful){
|
||||
if($successful && isset($notify->out_trade_no)){
|
||||
return HookService::listen('wechat_pay_success',$notify,null,true,PaymentBehavior::class);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 作为客服消息发送
|
||||
* @param $to
|
||||
* @param $message
|
||||
* @return bool
|
||||
*/
|
||||
public static function staffTo($to, $message)
|
||||
{
|
||||
$staff = self::staffService();
|
||||
$staff = is_callable($message) ? $staff->message($message()) : $staff->message($message);
|
||||
$res = $staff->to($to)->send();
|
||||
HookService::afterListen('wechat_staff_to',compact('to','message'),$res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -44,9 +44,20 @@ Page({
|
||||
onLoad: function (options) {
|
||||
app.setBarColor();
|
||||
var that = this;
|
||||
if (options.spid){
|
||||
app.globalData.spid = options.spid
|
||||
if (app.globalData.config !=null){
|
||||
wx.setNavigationBarTitle({
|
||||
title: app.globalData.config.routine_name,
|
||||
})
|
||||
}else{
|
||||
wx.setNavigationBarTitle({
|
||||
title: '商城首页',
|
||||
})
|
||||
}
|
||||
|
||||
// if (options.spid){
|
||||
// app.globalData.spid = options.spid;
|
||||
// console.log(options);
|
||||
// }
|
||||
app.setUserInfo();
|
||||
that.getIndexInfo();
|
||||
},
|
||||
@ -153,8 +164,8 @@ Page({
|
||||
onShareAppMessage: function () {
|
||||
var that = this;
|
||||
return {
|
||||
title: '小程序',
|
||||
path: '/pages/index/index?spid=' + app.globalData.uid,
|
||||
title: app.globalData.config.routine_name,
|
||||
path: '/pages/index/index?scene=' + app.globalData.uid,
|
||||
// imageUrl: that.data.url + that.data.product.image,
|
||||
success: function () {
|
||||
wx.showToast({
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "商城首页"
|
||||
"navigationBarTitleText": "加载中..."
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
<!--banner-->
|
||||
<view class='swiper_banner'>
|
||||
<swiper class="swiper-box" style="height:400rpx" indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" indicator-color="{{indicatorColor}}" indicator-active-color="{{indicatorActivecolor}}">
|
||||
<block wx:for="{{imgUrls}}">
|
||||
<block wx:for="{{imgUrls}}" wx:key="key">
|
||||
<swiper-item>
|
||||
<image bindtap='goUrl' data-url="{{item.url}}" src="{{item.pic}}" class="slide-image"/>
|
||||
</swiper-item>
|
||||
@ -10,7 +10,7 @@
|
||||
</view>
|
||||
<!-- 导航 -->
|
||||
<view class='nav flex'>
|
||||
<block wx:for="{{menus}}">
|
||||
<block wx:for="{{menus}}" wx:key="key">
|
||||
<view class='nav-item'>
|
||||
<navigator class='flex' hover-class="none" url='{{item.url}}' wx:if="{{item.show == '是'}}" open-type='switchTab'>
|
||||
<image src='{{item.pic}}'></image>
|
||||
@ -32,7 +32,7 @@
|
||||
</view>
|
||||
<view class='scroll-product'>
|
||||
<scroll-view class="scroll-view_x" scroll-x style="width: auto;overflow:hidden;">
|
||||
<block wx:for="{{recommendList}}">
|
||||
<block wx:for="{{recommendList}}" wx:key="key">
|
||||
<view class='item'>
|
||||
<navigator hover-class="none" url="/pages/product-con/index?id={{item.id}}">
|
||||
<view class='img-box'><image src='{{url}}{{item.image}}'></image></view>
|
||||
@ -54,7 +54,7 @@
|
||||
<navigator hover-class="none" bindtap='torday' class='flex'><text>更多新品</text><text class='iconfont icon-xiala'></text></navigator>
|
||||
</view>
|
||||
<view class='new-pro-wrapper'>
|
||||
<block wx:for="{{newList}}">
|
||||
<block wx:for="{{newList}}" wx:key="key">
|
||||
<view class='item'>
|
||||
<navigator class='flex' hover-class="none" url="/pages/product-con/index?id={{item.id}}">
|
||||
<view class='text-box flex'>
|
||||
@ -76,7 +76,7 @@
|
||||
</view>
|
||||
<view class='scroll-product2'>
|
||||
<scroll-view class="scroll-view_x" scroll-x style="width: auto;overflow:hidden;">
|
||||
<block wx:for="{{hotList}}">
|
||||
<block wx:for="{{hotList}}" wx:key="key">
|
||||
<view class='item'>
|
||||
<navigator hover-class="none" url="/pages/product-con/index?id={{item.id}}">
|
||||
<view class='img-box'><image src='{{url}}{{item.image}}'></image></view>
|
||||
@ -98,7 +98,7 @@
|
||||
<navigator hover-class="none" bindtap='torday' class='flex'><text>更多新品</text><text class='iconfont icon-xiala'></text></navigator>
|
||||
</view>
|
||||
<view class='new-pro-wrapper2'>
|
||||
<block wx:for="{{benefitList}}">
|
||||
<block wx:for="{{benefitList}}" wx:key="key">
|
||||
<view class='item'>
|
||||
<navigator class='flex' hover-class="none" url="/pages/product-con/index?id={{item.id}}">
|
||||
<view class='text-box flex'>
|
||||
@ -115,7 +115,7 @@
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
<block wx:for="{{lovely}}" wx:if="{{index < 1}}">
|
||||
<block wx:for="{{lovely}}" wx:if="{{index < 1}}" wx:key="key">
|
||||
<view class='hot-banner'>
|
||||
<image src='{{url}}{{item.img}}'></image>
|
||||
</view>
|
||||
@ -127,7 +127,7 @@
|
||||
<text>猜你喜欢</text>
|
||||
</view>
|
||||
<view class='like-box flex'>
|
||||
<block wx:for="{{likeList}}">
|
||||
<block wx:for="{{likeList}}" wx:key="key">
|
||||
<view class='item'>
|
||||
<navigator hover-class="none" url="/pages/product-con/index?id={{item.id}}">
|
||||
<view class='img-box'><image src='{{url}}{{item.image}}'></image></view>
|
||||
|
||||
@ -49,7 +49,7 @@
|
||||
.scroll-product2 .item .img-box image{width: 100%; height: 304rpx;border-radius:20rpx 20rpx 0 0;}
|
||||
.scroll-product2 .item .pro-info .price-small{color: #ff3d3d;font-size:26rpx;
|
||||
margin-top:10rpx;text-align:center;}
|
||||
.scroll-product2 .item .pro-info .pro-title{text-align:center;margin-top:25rpx;}
|
||||
.scroll-product2 .item .pro-info .pro-title{text-align:center;margin-top:25rpx;overflow:hidden;padding:0 10rpx;}
|
||||
.scroll-product2 .item .pro-info .buy{width:250rpx;height:54rpx;background-color:#e6413a;border-radius:50rpx;font-size:24rpx;color:#fff;align-items:center;justify-content:center;margin:17rpx auto 25rpx auto;}
|
||||
.scroll-product2 .item .pro-info .buy image{width:27rpx;height:26rpx;margin-right:12rpx;}
|
||||
|
||||
|
||||
@ -4,59 +4,37 @@ Page({
|
||||
logo: '',
|
||||
name: '',
|
||||
url: app.globalData.url,
|
||||
code:'',
|
||||
userInfo:'',
|
||||
},
|
||||
onLoad: function (options) {
|
||||
var that = this;
|
||||
that.getEnterLogo();
|
||||
app.setBarColor();
|
||||
},
|
||||
getEnterLogo: function () {
|
||||
var that = this;
|
||||
wx.request({
|
||||
url: app.globalData.url + '/routine/login/get_enter_logo',
|
||||
method: 'post',
|
||||
dataType : 'json',
|
||||
success: function (res) {
|
||||
that.setData({
|
||||
logo: res.data.data.site_logo,
|
||||
name: res.data.data.site_name
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
//获取用户信息并且授权
|
||||
//首次点击允许获取用户信息并且授权
|
||||
getUserInfo: function(e){
|
||||
var that = this;
|
||||
var userInfo = e.detail.userInfo;
|
||||
userInfo.spid = app.globalData.spid;
|
||||
userInfo.spreadid = app.globalData.spreadid;//获取推广人ID 2.5.36
|
||||
wx.login({
|
||||
success: function (res) {
|
||||
// console.log(res);//获取code
|
||||
if (res.code) {
|
||||
userInfo.code = res.code;
|
||||
wx.request({
|
||||
url: app.globalData.url + '/routine/login/index',
|
||||
url: app.globalData.url + '/routine/logins/setCode',
|
||||
method: 'post',
|
||||
dataType : 'json',
|
||||
data: {
|
||||
info: userInfo
|
||||
},
|
||||
success: function (res) {
|
||||
app.globalData.uid = res.data.data.uid;
|
||||
app.globalData.openid = res.data.data.routine_openid;
|
||||
if (app.globalData.openPages != '' && app.globalData.openPages != undefined) {//跳转到指定页面
|
||||
wx.navigateTo({
|
||||
url: app.globalData.openPages
|
||||
})
|
||||
} else {//跳转到首页
|
||||
if(res.data.data.page){
|
||||
wx.navigateTo({
|
||||
url: res.data.data.page
|
||||
})
|
||||
}else{
|
||||
wx.reLaunch({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}
|
||||
}
|
||||
// console.log(res);//根据code 获取openid session_key unionid(未试过用相关连应用无法获取unionid)
|
||||
wx.setStorageSync('session_key', res.data.session_key);//保存小程序缓存中
|
||||
wx.navigateTo({
|
||||
url: '/pages/loading/loading',
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@ -64,5 +42,5 @@ Page({
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
})
|
||||
@ -1,7 +1,5 @@
|
||||
// pages/load/load.js
|
||||
var app = getApp();
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
@ -9,52 +7,107 @@ Page({
|
||||
logo: '',
|
||||
name: '',
|
||||
url: app.globalData.url,
|
||||
is_login:true,
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
var that = this;
|
||||
app.setBarColor();
|
||||
if (options.scene) app.globalData.spid = options.scene;
|
||||
that.setSetting();
|
||||
that.auth();
|
||||
},
|
||||
|
||||
setSetting: function () {
|
||||
//授权判断
|
||||
auth: function () {
|
||||
var that = this;
|
||||
wx.checkSession({
|
||||
success: function (res) {
|
||||
wx.getSetting({
|
||||
success(res) {
|
||||
//第一次弹窗允许授权
|
||||
if (!res.authSetting['scope.userInfo'] || !wx.getStorageSync('session_key')) {
|
||||
that.showlogin(false, 2500);
|
||||
} else {
|
||||
//第二次直接调用获取用户信息
|
||||
that.getUserInfoBydecryptCode();
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
fail: function (res) {
|
||||
that.showlogin(false,2500);
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
//首次点击允许获取用户信息并且授权
|
||||
getUserInfo: function (e) {
|
||||
var that = this;
|
||||
wx.getSetting({
|
||||
success(res) {
|
||||
if (!res.authSetting['scope.userInfo']){
|
||||
wx.navigateTo({
|
||||
url: '/pages/load/load',
|
||||
var userInfo = e.detail.userInfo;
|
||||
userInfo.spid = app.globalData.spid;
|
||||
userInfo.spreadid = app.globalData.spreadid;//获取推广人ID 2.5.36
|
||||
wx.login({
|
||||
success: function (res) {
|
||||
// console.log(res);//获取code
|
||||
if (res.code) {
|
||||
userInfo.code = res.code;
|
||||
wx.request({
|
||||
url: app.globalData.url + '/routine/logins/setCode',
|
||||
method: 'post',
|
||||
dataType : 'json',
|
||||
data: {
|
||||
info: userInfo
|
||||
},
|
||||
success: function (res) {
|
||||
// console.log(res);//根据code 获取openid session_key unionid(未试过用相关连应用无法获取unionid)
|
||||
wx.setStorageSync('session_key', res.data.session_key);//保存小程序缓存中
|
||||
that.showlogin(false);
|
||||
//解密获取用户信息
|
||||
that.getUserInfoBydecryptCode();
|
||||
},
|
||||
fail: function () {
|
||||
that.showlogin(false);
|
||||
},
|
||||
})
|
||||
}else{
|
||||
that.getUserInfo();
|
||||
} else {
|
||||
that.showlogin(false);
|
||||
console.log('登录失败!' + res.errMsg)
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
getUserInfo: function () {
|
||||
//解密获取用户信息
|
||||
getUserInfoBydecryptCode: function (e) {
|
||||
var that = this;
|
||||
wx.getUserInfo({
|
||||
lang: 'zh_CN',
|
||||
success: function (res) {
|
||||
var userInfo = res.userInfo
|
||||
wx.login({
|
||||
success: function (res) {
|
||||
if (res.code) {
|
||||
userInfo.code = res.code;
|
||||
userInfo.spid = app.globalData.spid;
|
||||
wx.request({
|
||||
url: app.globalData.url + '/routine/login/index',
|
||||
method: 'post',
|
||||
dataType : 'json',
|
||||
data: {
|
||||
info: userInfo
|
||||
},
|
||||
success: function (res) {
|
||||
app.globalData.uid = res.data.data.uid;
|
||||
// console.log(res);//第二次获取用户信息获得iv和encryptedData
|
||||
var pdata = res;
|
||||
pdata.userInfo = res.userInfo;
|
||||
pdata.spid = app.globalData.spid;//获取推广人ID
|
||||
pdata.spreadid = app.globalData.spreadid;//获取推广人ID 2.5.36
|
||||
if (res.iv) {
|
||||
pdata.iv = encodeURI(res.iv);
|
||||
pdata.encryptedData = res.encryptedData;
|
||||
pdata.session_key = wx.getStorageSync('session_key');//获取上一步获取的session_key
|
||||
wx.request({
|
||||
url: app.globalData.url + '/routine/logins/index',
|
||||
method: 'post',
|
||||
dataType : 'json',
|
||||
data: {
|
||||
info: pdata
|
||||
},
|
||||
success: function (res) {
|
||||
console.log(res);
|
||||
|
||||
if (res.data.data == 'ILLEGAL_BUFFER'){
|
||||
wx.setStorageSync('session_key','');
|
||||
that.auth();
|
||||
}else{
|
||||
app.globalData.uid = res.data.data.uid;
|
||||
if (!app.globalData.uid || app.globalData.uid == 'undefined') {
|
||||
that.showlogin(true);
|
||||
} else {
|
||||
if (app.globalData.openPages != '' && app.globalData.openPages != undefined) {//跳转到指定页面
|
||||
wx.navigateTo({
|
||||
url: app.globalData.openPages
|
||||
@ -64,24 +117,26 @@ Page({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
} else {
|
||||
console.log('登录失败!' + res.errMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function () {
|
||||
},
|
||||
})
|
||||
|
||||
})
|
||||
} else {
|
||||
console.log('登录失败!' + res.errMsg)
|
||||
}
|
||||
},
|
||||
fail: function () {
|
||||
},
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow: function () {
|
||||
|
||||
},
|
||||
//是否显示登录授权框
|
||||
showlogin:function(ishouw,times = 1500){
|
||||
var that = this;
|
||||
setTimeout(function () {
|
||||
that.setData({
|
||||
is_login: ishouw
|
||||
})
|
||||
}, times)
|
||||
}
|
||||
})
|
||||
@ -1,3 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "引导页"
|
||||
"navigationBarTitleText": "加载中"
|
||||
}
|
||||
@ -2,3 +2,11 @@
|
||||
<image src='/images/long.gif'></image>
|
||||
<!-- <view>正在加载中...</view> -->
|
||||
</view>
|
||||
<view class="warrant" wx:if="{{!is_login}}">
|
||||
<view class='white'>
|
||||
<view class='pictrue'></view>
|
||||
<view class='tip'>您的信息和数据将受到保护</view>
|
||||
<button class='but' type="primary" open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="getUserInfo">授权并登录</button>
|
||||
</view>
|
||||
<view class='mask'></view>
|
||||
</view>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user