123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- <?php
- namespace app\index\controller;
- use app\common\model\ActivityConfigModel;
- use app\common\model\CronTableModel;
- use app\common\model\GoodsOrderModel;
- use app\common\model\PackageMarketingModel;
- use app\common\model\PackageModel;
- use app\common\model\PackagePurchasedModel;
- use app\common\model\PayCodeModel;
- use app\common\model\PointsUpdateModel;
- use app\common\model\UserBodyDataModel;
- use app\common\model\UserCarDataModel;
- use app\common\model\UserCyclingDataModel;
- use app\common\model\UserCyclingDataStatistics;
- use app\common\model\UserFriendsModel;
- use app\common\model\UserModel;
- use app\common\service\helperService;
- use app\common\service\serviceSms;
- use think\Cache;
- use think\Config;
- use think\Controller;
- use think\Cookie;
- use think\image\Exception;
- use think\Session;
- use think\Validate;
- /**
- * 用于用户绑定基本信息
- * Class Bind
- * @package app\index\controller
- */
- class Bind extends Controller{
- public $user_no = null;
- protected function _initialize(){
- //user_id作为session的
- $this->user_no = Cookie::get('user_no');
- $action_name = $this->request->action();
- $allows = ['bindEmail','sendMobile','saveMobile','seeCode'];
- if(empty($this->user_no) && in_array($action_name,$allows)){
- $this->redirect('index/index/start');
- exit;
- }
- }
- /**
- * 商品兑换支付的回掉
- * @param $order_no
- * @param $out_trade_no
- * @param $total_price
- * @param $params
- * @return bool
- */
- private function wxGoodsOrder($order_no,$out_trade_no,$total_price,$params){
- $payCodeModel = new PayCodeModel();
- $goodsOrderModel = new GoodsOrderModel();
- $goodsOrder = $goodsOrderModel->getOne(['order_no'=>$order_no]);
- try{
- $res = $payCodeModel->saveData([
- 'order_no'=>$order_no,
- 'pay_type'=>1,
- 'pay_no'=>$out_trade_no,
- 'price'=>$total_price,
- 'add_ts'=>time(),
- 'status'=>1,
- 'note_json'=>json_encode($params),
- 'pathway'=>2,
- 'user_no'=>isset($goodsOrder['user_no'])?$goodsOrder['user_no']:'',
- ]);
- }catch (\Exception $ex){
- file_put_contents('wxNotifyPay.mp',"[1]",FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',json_encode($params),FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',$ex->getMessage(),FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',"\n",FILE_APPEND);
- return false;
- }
- if($res === false){
- file_put_contents('wxNotifyPay.mp',"[2]",FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',json_encode($params),FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',"\n",FILE_APPEND);
- return false;
- }
- $goodsOrderModel = new GoodsOrderModel();
- $result = $goodsOrderModel->saveData(['status'=>2],['order_no'=>"$order_no"]);
- $user_no = $goodsOrder['user_no'];
- $userModel = new UserModel();
- $user = $userModel->getOne(['user_no'=>"$user_no"]);
- serviceSms::exchangeSuccess($user['mobile']);
- if($result === false){
- file_put_contents('wxNotifyPay.mp',"[3]",FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',json_encode($params),FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',"\n",FILE_APPEND);
- return false;
- }
- return true;
- }
- /**
- * 套餐支付的回掉
- * @param $order_no
- * @param $out_trade_no
- * @param $total_price
- * @param $params
- * @return bool
- */
- private function wxPackagePurchased($order_no,$out_trade_no,$total_price,$params){
- $payCodeModel = new PayCodeModel();
- $packagePurchasedModel = new PackagePurchasedModel();
- $packagePurchased = $packagePurchasedModel->getOne(['package_purchased_no'=>"$order_no"]);
- try{
- $res = $payCodeModel->saveData([
- 'order_no'=>$order_no,
- 'pay_type'=>1,
- 'pay_no'=>$out_trade_no,
- 'price'=>$total_price,
- 'add_ts'=>time(),
- 'status'=>1,
- 'note_json'=>json_encode($params),
- 'pathway'=>1,
- 'user_no'=>isset($packagePurchased['user_no'])?$packagePurchased['user_no']:'',
- ]);
- }catch (\Exception $ex){
- file_put_contents('wxNotifyPay.mp',"[4]",FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',json_encode($params),FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',$ex->getMessage(),FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',"\n",FILE_APPEND);
- return false;
- }
- if($res === false){
- file_put_contents('wxNotifyPay.mp',"[5]",FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',json_encode($params),FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',"\n",FILE_APPEND);
- return false;
- }
- try {
- $packagePurchasedModel = new PackagePurchasedModel();
- $result = $packagePurchasedModel->saveData(['real_price' => $total_price, 'status' => 3], ['package_purchased_no' => $order_no, 'status' => 1]);
- if ($result === false) {
- file_put_contents('wxNotifyPay.mp', "[6]", FILE_APPEND);
- file_put_contents('wxNotifyPay.mp', json_encode($params), FILE_APPEND);
- file_put_contents('wxNotifyPay.mp', "\n", FILE_APPEND);
- return false;
- }
- //给自己添加优惠条件
- $num = $packagePurchased['num'];
- $activityConfigModel = new ActivityConfigModel();
- $activityConfigList = $activityConfigModel->getMulti(['buy_courses'=>['elt',$num]],"code <> 'NEW'");
- //获取优惠信息
- $this->getDiscountInformation($activityConfigList,$num,$packagePurchased['user_no']);
- $userModel = new UserModel();
- $friend_user_no = $packagePurchased['user_no'];
- $friend = $userModel->getOne(['user_no'=>"$friend_user_no"]);
- serviceSms::buyPackageSuccess($num,$friend['mobile']);
- //接下来给邀请码的人,进行一次加入次数
- $invite_code = $packagePurchased['invite_code'];
- if (empty($invite_code)) {
- return false;
- }
- $user = $userModel->getOne(['invite_code' => $invite_code]);
- if (empty($user)) {
- return false;
- }
- if(time()>strtotime('2018-01-01')){
- Config::set('converted_radix',Config::get('up2018_converted_radix'));
- }
- $give_times = floor($num / Config::get('converted_radix'));
- if($user['user_no'] != $friend['user_no']){
- $day = Config::get('invite')['day'];
- //赠送给邀请者的
- $packagePurchasedModel->saveData([
- 'package_purchased_no' => helperService::createOrderNum(),
- 'invite_code' => '',
- 'user_no' => "{$user['user_no']}",
- 'package_id' => 0,
- 'store_id' => Config::get('invite')['store_id'],
- 'num' => $give_times,
- 'total_price' => 0,
- 'status' => 3,
- 'day' => $day,
- 'expire_ts' => time() + 86400 * $day,
- 'real_price' => 0,
- 'add_ts' => time(),
- 'type' => 4
- ]);
- serviceSms::getGive($user['mobile'],$user['user_name'],$friend['user_name'],$num,$give_times);
- }
- //赠送给本人的
- $packagePurchasedModel->saveData([
- 'package_purchased_no' => helperService::createOrderNum(),
- 'invite_code' => '',
- 'user_no' => "{$friend_user_no}",
- 'package_id' => 0,
- 'store_id' => Config::get('invite')['store_id'],
- 'num' => $give_times,
- 'total_price' => 0,
- 'status' => 3,
- 'day' => $day,
- 'expire_ts' => time() + 86400 * $day,
- 'real_price' => 0,
- 'add_ts' => time(),
- 'type' => 4
- ]);
- serviceSms::myGive($friend['mobile'],$friend['user_name'],$num,$give_times);
- }catch (Exception $ex){
- file_put_contents('wxNotifyPay.mp',"[4]",FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',json_encode($params),FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',$ex->getMessage(),FILE_APPEND);
- file_put_contents('wxNotifyPay.mp',"\n",FILE_APPEND);
- return false;
- }
- return true;
- }
- /**
- * 授权信息获取
- */
- public function setCookie(){
- header("Content-Type: text/html; charset=utf-8");
- $params = $this->request->param();
- $openId = isset($params['openid'])?$params['openid']:'';
- $header_img = isset($params['headimgurl'])?$params['headimgurl']:'';
- $nick_name = isset($params['nickname'])?$params['nickname']:'';
- $userModel = new UserModel();
- $user = $userModel->getOne(['open_id'=>"$openId"]);
- if($user){
- Cookie::set('user_no',$user['user_no']);
- }else{
- $userNo = HelperService::createOrderNum();
- $data=[
- 'open_id'=>"$openId",
- 'user_no'=>"$userNo",
- 'head_img'=>"$header_img",
- 'user_name'=>$nick_name
- ];
- try {
- $userModel->saveData($data);
- }catch (\Exception $ex){
- file_put_contents('userInfo.wx',json_encode($data),FILE_APPEND);
- file_put_contents('userInfo.wx',"\n",FILE_APPEND);
- $data['user_name'] = 'xinyi'.rand(100,999);
- $userModel->saveData($data);
- }
- Cookie::set('user_no',$userNo);
- }
- $IndexHtml = 'http://'.$_SERVER['SERVER_NAME']."/index/index/index";
- if(Session::has('old_url')){
- $IndexHtml = Session::get('old_url');
- }
- header("HTTP/1.1 301 Moved Permanently");
- header("Location:$IndexHtml");
- exit;
- }
- /**
- * 解密参数
- * [加密规则,请求端 1、json_encode 2、openssl_public_encrypt 3、base64_encode]
- * [解密规则,服务端 1、base64_decode 2、openssl_private_decrypt 3、json_decode]
- * @param bool $is_get
- * @return array
- */
- private function decryptOpenssl($is_get=false){
- if($is_get == false){
- $data = file_get_contents("php://input");
- }else{
- $params = $this->request->param();
- if(!isset($params['encrypted'])){
- helperService::returnJson([],400,'encrypted is empty');
- }
- $data = $params['encrypted'];
- }
- $base64data = base64_decode($data);
- //私钥
- $privateKey = openssl_pkey_get_private(helperService::$private_key);
- $decrypted = '';
- foreach (str_split($base64data, 128) as $chunk) {
- openssl_private_decrypt($chunk, $decryptData, $privateKey); //私钥解密
- $decrypted .= $decryptData;
- }
- return json_decode($decrypted,true);
- }
- }
|