where('id',$user_info['id'])->find(); $referral_code = $user_info['referral_code']; $user_info['account_type'] = $account_type; // 推广链接 $tables = Db::connect('DB2')->name('table')->where(array('status' => 1))->order('game_id asc')->select(); $wt_agent = Db::connect('DB2')->name('table')->where(array('status' => 1))->order('id asc')->limit(1)->value('wt_agent'); $agent_list = Config::get('wt_list'); $serverName = WT_STATIC_DOMAIN; if(!$wt_agent){ $marketingUrl = '(请先请选择运行路线)'; }else{ $wt_agent_info = Db::name('user')->where(['username'=>$wt_agent])->find(); if($wt_agent_info['referral_code']){ $marketingUrl = $serverName.'?referral_code='.$wt_agent_info['referral_code']; }else{ $referral_code = getRandCode(); $marketingUrl = $serverName.'?referral_code='.$referral_code; Db::name('user')->where(['username'=>$wt_agent])->update(['referral_code'=>$referral_code]); } // if(!$wt_agent_info['line_url']){ // // 推广链接 // $ask = array(); // $ask['appid'] = 139663876; // $ask['appkey'] = 'f6d0f6090f7652bf509e96c51189298f'; // $ask['type'] = 'add'; // $ask['url'] = $marketingUrl; // $ask['visit_type'] = 'jump'; // $url = 'https://wechaturl.us/api/SingleShortUrl.json'; // $postdata = @http_build_query($ask); // $options = array( // 'http' => array( // 'method' => 'POST', // 'header' => 'Content-type:application/x-www-form-urlencoded', // 'content' => $postdata, // 'timeout' => 15 * 60 // 超时时间(单位:s) // ) // ); // $context = stream_context_create($options); // $result = file_get_contents($url, false, $context); // $result = json_decode($result); // $result = ((array)$result); // if($result['code'] == 1){ // $resultdata = ((array)$result['data']); // $marketingUrl = $resultdata['weibo_shorturl']; // DB::name('user')->where('id',$wt_agent_info['id'])->update(['line_url' => $marketingUrl]); // }else{ // return '生成推广码失败,请稍后再试'; // } // }else{ // $marketingUrl = $wt_agent_info['line_url']; // } } // 渲染 $this->assign('user_info',$user_info); $this->assign('wt_agent',$wt_agent); $this->assign('agent_list',$agent_list); $this->assign('tables',$tables); $this->assign('marketingUrl',$marketingUrl); return $this->fetch(); } public function do_wt_table(){ $table_str = Request::instance()->post('table_str'); Db::name('table')->where('is_wt',1)->update(['is_wt' => 0]); if($table_str){ $table_str = rtrim($table_str, ','); $table_arr = explode(",", $table_str); Db::name('table')->whereIn('id',$table_arr)->update(['is_wt' => 1]); } return json(array('Success' => 0, 'Msg' => '修改成功')); } public function do_wt_agent(){ $wt_agent = Request::instance()->post('wt_agent'); if($wt_agent == '0'){ return json(array('Success' => 0, 'Msg' => '请选择运行路线')); }else{ $serverName = WT_STATIC_DOMAIN; $wt_agent_info = Db::name('user')->where(['username'=>$wt_agent])->find(); if($wt_agent_info['referral_code']){ $marketingUrl = $serverName.'?referral_code='.$wt_agent_info['referral_code']; }else{ $referral_code = getRandCode(); $marketingUrl = $serverName.'?referral_code='.$referral_code; Db::name('user')->where(['username'=>$wt_agent])->update(['referral_code'=>$referral_code]); } Db::name('table')->where(array('status' => 1))->update(['wt_agent' => $wt_agent]); // if(!$wt_agent_info['line_url']){ // // 推广链接 // $ask = array(); // $ask['appid'] = 139663876; // $ask['appkey'] = 'f6d0f6090f7652bf509e96c51189298f'; // $ask['type'] = 'add'; // $ask['url'] = $marketingUrl; // $ask['visit_type'] = 'jump'; // $url = 'https://wechaturl.us/api/SingleShortUrl.json'; // $postdata = @http_build_query($ask); // $options = array( // 'http' => array( // 'method' => 'POST', // 'header' => 'Content-type:application/x-www-form-urlencoded', // 'content' => $postdata, // 'timeout' => 15 * 60 // 超时时间(单位:s) // ) // ); // $context = stream_context_create($options); // $result = file_get_contents($url, false, $context); // $result = json_decode($result); // $result = ((array)$result); // if($result['code'] == 1){ // $resultdata = ((array)$result['data']); // $marketingUrl = $resultdata['weibo_shorturl']; // DB::name('user')->where('id',$wt_agent_info['id'])->update(['line_url' => $marketingUrl]); // }else{ // return '生成推广码失败,请稍后再试'; // } // }else{ // $marketingUrl = $wt_agent_info['line_url']; // } return json(array('Success' => 1, 'Msg' => '修改成功','url' => $marketingUrl)); } } public function line_marketing(){ // 登录用户信息 $user_info = Session::get('user_info'); $account_type = $user_info['account_type']; $user_info = Db::name('user')->where('id',$user_info['id'])->find(); $referral_code = $user_info['referral_code']; $user_info['account_type'] = $account_type; if(!$user_info['referral_code']){//没有推荐码则补充 $referral_code = getRandCode(); Db::name('user')->where(['id'=>$user_info['id']])->update(['referral_code'=>$referral_code]); } $user_info['referral_code'] = $referral_code; $serverName = WT_STATIC_DOMAIN; $marketingUrl = $serverName.'?referral_code='.$referral_code; // if(!$user_info['line_url']){ // // 推广链接 // $serverName = WT_STATIC_DOMAIN; // $marketingUrl = $serverName.'?referral_code='.$referral_code; // $ask = array(); // $ask['appid'] = 139663876; // $ask['appkey'] = 'f6d0f6090f7652bf509e96c51189298f'; // $ask['type'] = 'add'; // $ask['url'] = $marketingUrl; // $ask['visit_type'] = 'jump'; // $url = 'https://wechaturl.us/api/SingleShortUrl.json'; // $postdata = @http_build_query($ask); // $options = array( // 'http' => array( // 'method' => 'POST', // 'header' => 'Content-type:application/x-www-form-urlencoded', // 'content' => $postdata, // 'timeout' => 15 * 60 // 超时时间(单位:s) // ) // ); // $context = stream_context_create($options); // $result = file_get_contents($url, false, $context); // $result = json_decode($result); // $result = ((array)$result); // if($result['code'] == 1){ // $resultdata = ((array)$result['data']); // $marketingUrl = $resultdata['weibo_shorturl']; // DB::name('user')->where('id',$user_info['id'])->update(['line_url' => $marketingUrl]); // }else{ // return '生成推广码失败,请稍后再试'; // } // }else{ // $marketingUrl = $user_info['line_url']; // } // 渲染 $this->assign('user_info',$user_info); $this->assign('marketingUrl',$marketingUrl); return $this->fetch(); } }