From 5e58dabe53231b57ffb64c7fbf256c46fc72c387 Mon Sep 17 00:00:00 2001 From: sugar1569 Date: Tue, 2 Apr 2019 17:28:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=94=B9=E4=B8=BA=E8=A7=A3=E5=AF=86=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=89=93=E9=80=9A=E7=89=88?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8C=E6=AD=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common.php | 40 +- application/routine/controller/AuthApi.php | 362 ++++++++++-------- .../routine/controller/AuthController.php | 1 - application/routine/controller/Login.php | 5 + application/routine/controller/Logins.php | 114 ++++++ application/routine/controller/Routine.php | 7 +- .../routine/model/routine/RoutineCode.php | 29 +- .../routine/model/user/RoutineUser.php | 69 ++++ application/routine/model/user/User.php | 19 +- application/wap/model/user/User.php | 8 +- application/wap/model/user/WechatUser.php | 10 + extend/service/MiniProgramService.php | 307 +++++++++++++++ view/crmebN/pages/index/index.js | 19 +- view/crmebN/pages/index/index.json | 2 +- view/crmebN/pages/index/index.wxml | 16 +- view/crmebN/pages/index/index.wxss | 2 +- view/crmebN/pages/load/load.js | 48 +-- view/crmebN/pages/loading/loading.js | 145 ++++--- view/crmebN/pages/loading/loading.json | 2 +- view/crmebN/pages/loading/loading.wxml | 8 + view/crmebN/pages/loading/loading.wxss | 10 +- 21 files changed, 960 insertions(+), 263 deletions(-) create mode 100644 application/routine/controller/Logins.php create mode 100644 extend/service/MiniProgramService.php diff --git a/application/common.php b/application/common.php index 08eae7aa..93730f1d 100644 --- a/application/common.php +++ b/application/common.php @@ -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; + } \ No newline at end of file diff --git a/application/routine/controller/AuthApi.php b/application/routine/controller/AuthApi.php index a5828e0a..38ad2d2f 100644 --- a/application/routine/controller/AuthApi.php +++ b/application/routine/controller/AuthApi.php @@ -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('//','[图片]',$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()); + } + + } + + + /** * 刷新数据缓存 */ diff --git a/application/routine/controller/AuthController.php b/application/routine/controller/AuthController.php index 3b45df5a..80773128 100644 --- a/application/routine/controller/AuthController.php +++ b/application/routine/controller/AuthController.php @@ -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')); diff --git a/application/routine/controller/Login.php b/application/routine/controller/Login.php index 249cb3ba..86c287f8 100644 --- a/application/routine/controller/Login.php +++ b/application/routine/controller/Login.php @@ -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']; diff --git a/application/routine/controller/Logins.php b/application/routine/controller/Logins.php new file mode 100644 index 00000000..e329afc2 --- /dev/null +++ b/application/routine/controller/Logins.php @@ -0,0 +1,114 @@ +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); + } +} \ No newline at end of file diff --git a/application/routine/controller/Routine.php b/application/routine/controller/Routine.php index c0c360b8..bb48e8e6 100644 --- a/application/routine/controller/Routine.php +++ b/application/routine/controller/Routine.php @@ -1,8 +1,6 @@ id; diff --git a/application/routine/model/user/RoutineUser.php b/application/routine/model/user/RoutineUser.php index f2b1bd09..8e65cdb6 100644 --- a/application/routine/model/user/RoutineUser.php +++ b/application/routine/model/user/RoutineUser.php @@ -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; + } + + } \ No newline at end of file diff --git a/application/routine/model/user/User.php b/application/routine/model/user/User.php index e339374e..e02025c4 100644 --- a/application/routine/model/user/User.php +++ b/application/routine/model/user/User.php @@ -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'); + } } \ No newline at end of file diff --git a/application/wap/model/user/User.php b/application/wap/model/user/User.php index 8b9199c7..0fa8a212 100644 --- a/application/wap/model/user/User.php +++ b/application/wap/model/user/User.php @@ -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); diff --git a/application/wap/model/user/WechatUser.php b/application/wap/model/user/WechatUser.php index dcf4e623..703cdd48 100644 --- a/application/wap/model/user/WechatUser.php +++ b/application/wap/model/user/WechatUser.php @@ -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'); diff --git a/extend/service/MiniProgramService.php b/extend/service/MiniProgramService.php new file mode 100644 index 00000000..5d429f3f --- /dev/null +++ b/extend/service/MiniProgramService.php @@ -0,0 +1,307 @@ + + * @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; + } + + + + +} \ No newline at end of file diff --git a/view/crmebN/pages/index/index.js b/view/crmebN/pages/index/index.js index fd4025bb..4d2d9bc4 100644 --- a/view/crmebN/pages/index/index.js +++ b/view/crmebN/pages/index/index.js @@ -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({ diff --git a/view/crmebN/pages/index/index.json b/view/crmebN/pages/index/index.json index d98d12dd..53323405 100644 --- a/view/crmebN/pages/index/index.json +++ b/view/crmebN/pages/index/index.json @@ -1,3 +1,3 @@ { - "navigationBarTitleText": "商城首页" + "navigationBarTitleText": "加载中..." } \ No newline at end of file diff --git a/view/crmebN/pages/index/index.wxml b/view/crmebN/pages/index/index.wxml index 8702266e..429bba41 100644 --- a/view/crmebN/pages/index/index.wxml +++ b/view/crmebN/pages/index/index.wxml @@ -1,7 +1,7 @@ - + @@ -10,7 +10,7 @@ - + @@ -32,7 +32,7 @@ - + @@ -54,7 +54,7 @@ 更多新品 - + @@ -76,7 +76,7 @@ - + @@ -98,7 +98,7 @@ 更多新品 - + @@ -115,7 +115,7 @@ - + @@ -127,7 +127,7 @@ 猜你喜欢