/**
  * default action 'index'
  *
  * @param Request $request
  * @param Response $response
  */
 public function index(Request $request, Response $response)
 {
     $t = $request->arg(1);
     $wx = new Weixin([], $t);
     if (!isset($_GET['echostr'])) {
         if ($wx->checkSignature()) {
             //签名检测
             $wx->responseMsg();
         } else {
             echo '';
         }
     } else {
         //接口验证
         $wx->valid();
     }
     exit;
 }
Beispiel #2
0
 /**
  * 提交地址
  * 
  * @param Request $request
  * @param Response $response
  */
 function post_address(Request $request, Response $response)
 {
     $uid = $GLOBALS['user']->uid;
     if ($request->is_post()) {
         //送花奖励阶梯
         $sendmoney_phases = [30, 50, 100];
         $address_id = $request->post('address_id', 0);
         $match_id = $request->post('match_id', 0);
         $player_id = $request->post('player_id', 0);
         $order_id = $request->post('order_id', 0);
         $sendmoney = $request->post('sendmoney', 0);
         $backurl = $request->post('backurl', 0);
         $consignee = $request->post('consignee', '');
         $mobile = $request->post('mobile', '');
         $province = $request->post('province', 0);
         $city = $request->post('city', 0);
         $address = $request->post('address', '');
         $zipcode = $request->post('zipcode', '');
         $res = ['flag' => 'FAIL', 'msg' => '', 'match_id' => $match_id, 'backurl' => $backurl];
         if (empty($uid)) {
             $res['msg'] = '未登录,请先登录';
             $response->sendJSON($res);
         }
         if ('' == $consignee) {
             $res['msg'] = '姓名不能为空';
             $response->sendJSON($res);
         }
         if ('' == $mobile) {
             $res['msg'] = '手机不能为空';
             $response->sendJSON($res);
         } elseif (!preg_match('/^\\d{11,14}$/', $mobile)) {
             $res['msg'] = '手机号码不正确';
             $response->sendJSON($res);
         }
         if (empty($province)) {
             $res['msg'] = '身份地址不能为空';
             $response->sendJSON($res);
         }
         $province_name = Match_Model::getLocationName($province);
         if (empty($city)) {
             $res['msg'] = '城市地址不能为空';
             $response->sendJSON($res);
         }
         $city_name = Match_Model::getLocationName($city);
         if ('' == $address) {
             $res['msg'] = '详细地址不能为空';
             $response->sendJSON($res);
         }
         if ('' != $zipcode && !preg_match('/^\\d{6}$/', $zipcode)) {
             $res['msg'] = '邮政编码不正确';
             $response->sendJSON($res);
         }
         $tbname = 'member_address';
         $tbdata = ['address_name' => '', 'user_id' => $uid, 'consignee' => $consignee, 'country' => 2, 'country_name' => '中国', 'province' => $province, 'province_name' => $province_name, 'city' => $city, 'city_name' => $city_name, 'district' => 0, 'district_name' => '', 'address' => $address, 'zipcode' => $zipcode, 'mobile' => $mobile];
         if (!$address_id) {
             // Insert mode
             $address_id = D()->insert($tbname, $tbdata);
         } else {
             // Edit mode
             D()->update($tbname, $tbdata, ['address_id' => $address_id]);
         }
         //送奖品记录
         if ($address_id && $sendmoney >= $sendmoney_phases[0] && $player_id && $order_id) {
             $phasemoney = $sendmoney_phases[0];
             if ($sendmoney >= $sendmoney_phases[1] && $sendmoney < $sendmoney_phases[2]) {
                 $phasemoney = $sendmoney_phases[1];
             } elseif ($sendmoney >= $sendmoney_phases[2]) {
                 $phasemoney = $sendmoney_phases[2];
             }
             $tbdata = ['user_id' => $uid, 'address_id' => $address_id, 'player_id' => $player_id, 'order_id' => $order_id, 'phase_money' => $phasemoney, 'true_money' => $sendmoney, 'timeline' => simphp_time()];
             $rid = D()->from("member_giftpay")->where("`user_id`=%d AND `player_id`=%d AND `order_id`=%d", $uid, $player_id, $order_id)->select('`rid`')->result();
             if (!$rid) {
                 //一个订单只有没有生成过记录时才记录,避免重复
                 D()->insert('member_giftpay', $tbdata);
             } else {
                 $res['flag'] = 'SUC';
                 $res['msg'] = '当前订单之前申请过礼物,不能重复申请';
                 $response->sendJSON($res);
             }
         }
         $res['flag'] = 'SUC';
         $res['msg'] = '地址保存成功!';
         $response->sendJSON($res);
     } else {
         $this->v->set_tplname('mod_match_post_address');
         $this->v->set_page_render_mode(View::RENDER_MODE_GENERAL);
         $this->nav_flag1 = 'match_address';
         $this->topnav_no = 1;
         $match_id = $request->arg(1);
         $sendmoney = $request->get('sendmoney', 0);
         $player_id = $request->get('player_id', 0);
         $order_id = $request->get('order_id', 0);
         $backurl = $request->get('backurl', '');
         $this->v->assign('match_id', $match_id);
         $this->v->assign('player_id', $player_id);
         $this->v->assign('order_id', $order_id);
         $this->v->assign('sendmoney', $sendmoney);
         $this->v->assign('backurl', $backurl);
         $player_info = Match_Model::getPlayerInfo($player_id);
         $this->v->assign('player_info', $player_info);
         $user_address = Match_Model::getUserAddress($uid);
         $this->v->assign('user_address', $user_address);
         $province = Match_Model::getProvinces();
         $this->v->assign('province', $province);
         $city_html = '<option value="0">选择城市▼</option>';
         if (!empty($user_address)) {
             $cities = Match_Model::getCities($user_address['province']);
             $selected = '';
             foreach ($cities as $loc) {
                 if ($loc['locaid'] == $user_address['city']) {
                     $selected = ' selected="selected"';
                 } else {
                     $selected = '';
                 }
                 $city_html .= '<option value="' . $loc['locaid'] . '"' . $selected . '>' . $loc['location'] . '</option>';
             }
         }
         $this->v->assign('city_html', $city_html);
         $seo = ['title' => '地址上传', 'keyword' => '', 'desc' => ''];
         $this->v->assign('seo', $seo);
         $response->send($this->v);
     }
 }
Beispiel #3
0
 /**
  * action 'oauth', the OAuth callback
  * 
  * @param Request $request
  * @param Response $response
  */
 public function oauth(Request $request, Response $response)
 {
     //trace_debug('weixin_oauth2_callback_doing', $_GET);
     $code = $request->get('code', '');
     if ('' != $code) {
         //授权通过
         $state = $request->get('state', '');
         $refer = $request->get('refer', '/');
         $from = $request->arg(2);
         if (empty($from)) {
             $from = 'weixin';
         }
         $auth_action = $request->get('act', '');
         $refer = rawurldecode($refer);
         //收获地址base oauth回调
         if ('jsapi_address' == $auth_action) {
             $response->redirect($refer . '&code=' . $code . '&state=' . $state);
         }
         //授权出错
         if (!in_array($state, array('base', 'detail'))) {
             Fn::show_error_message('授权出错,不能访问应用!');
         }
         $wx = new Weixin();
         //用code换取access token
         $code_ret = $wx->request_access_token($code);
         if (!empty($code_ret['errcode'])) {
             Fn::show_error_message('微信授权错误<br/>' . $code_ret['errcode'] . '(' . $code_ret['errmsg'] . ')');
         }
         //获取到openid
         $openid = $code_ret['openid'];
         $uid = 0;
         $auth_method = 'oauth2_' . $state;
         //认证方式
         //查询本地是否存在对应openid的用户
         $uinfo_bd = Member::getTinyInfoByOpenid($openid, $from);
         if (empty($uinfo_bd)) {
             //用户不存在,则要尝试建立
             //保存微信用户信息到本地库
             $udata = ['openid' => $openid, 'auth_method' => $auth_method];
             $uid = Member::createUser($udata, $from);
             $uinfo_bd = ['uid' => $uid];
         } else {
             //用户已存在,对state='base',则仅需设置登录状态;而对state='detail',需保存或更新用户数据
             $uid = intval($uinfo_bd['uid']);
         }
         //detail认证模式,需更新用户数据
         if ('detail' == $state && empty($uinfo_bd['nickname'])) {
             $uinfo_wx = $wx->userInfoByOAuth2($openid, $code_ret['access_token']);
             if (!empty($uinfo_wx['errcode'])) {
                 //失败!则报错
                 Fn::show_error_message('微信获取用户信息出错!<br/>' . $uinfo_wx['errcode'] . '(' . $uinfo_wx['errmsg'] . ')');
             }
             //保存微信用户信息到本地库
             $udata = ['unionid' => isset($uinfo_wx['unionid']) ? $uinfo_wx['unionid'] : '', 'subscribe' => isset($uinfo_wx['subscribe']) ? $uinfo_wx['subscribe'] : 0, 'subscribe_time' => isset($uinfo_wx['subscribe_time']) ? $uinfo_wx['subscribe_time'] : 0, 'nickname' => isset($uinfo_wx['nickname']) ? $uinfo_wx['nickname'] : '', 'logo' => isset($uinfo_wx['headimgurl']) ? $uinfo_wx['headimgurl'] : '', 'sex' => isset($uinfo_wx['sex']) ? $uinfo_wx['sex'] : 0, 'lang' => isset($uinfo_wx['language']) ? $uinfo_wx['language'] : '', 'country' => isset($uinfo_wx['country']) ? $uinfo_wx['country'] : '', 'province' => isset($uinfo_wx['province']) ? $uinfo_wx['province'] : '', 'city' => isset($uinfo_wx['city']) ? $uinfo_wx['city'] : '', 'auth_method' => $auth_method];
             Member::updateUser($udata, $openid, $from);
             //尝试用基本型接口获取用户信息,以便确认用户是否已经关注(基本型接口存在 50000000次/日 调用限制,且仅对关注者有效)
             if (FALSE && !$uinfo_bd['subscribe'] && !$udata['subscribe']) {
                 $uinfo_wx = $wx->userInfo($openid);
                 //trace_debug('weixin_basic_userinfo', $uinfo_wx);
                 if (!empty($uinfo_wx['errcode'])) {
                     //失败!说明很可能没关注,维持现状不处理
                 } else {
                     //成功!说明之前已经关注,得更新关注标记
                     $udata = ['subscribe' => isset($uinfo_wx['subscribe']) ? $uinfo_wx['subscribe'] : 0, 'subscribe_time' => isset($uinfo_wx['subscribe_time']) ? $uinfo_wx['subscribe_time'] : 0];
                     Member::updateUser($udata, $openid, $from);
                 }
             }
         }
         //End: if ('detail'===$state)
         //设置本地登录状态
         if ('login' == $auth_action) {
             if (empty($uid)) {
                 Fn::show_error_message('微信授权登录失败!');
             }
             Member::setLocalLogin($uid);
         }
         //跳转
         $response->redirect($refer);
     } else {
         //授权未通过
         Fn::show_error_message('未授权,不能访问应用!');
     }
 }
Beispiel #4
0
 /**
  * action 'import'
  * @param Request $request
  * @param Response $response
  */
 public function import(Request $request, Response $response)
 {
     if ($request->is_post()) {
         $source_id = $request->post('source_id');
         $source_url = $request->post('source_url');
         $ret = ['flag' => 'ERR', 'msg' => ''];
         if (!$source_id || !in_array($source_id, Node_Model::getSourceList('music', true))) {
             $ret['msg'] = '请选择有效的来源';
             $response->sendJSON($ret);
         }
         if (!$source_url || !preg_match('!^http://.{4,}!i', $source_url)) {
             $ret['msg'] = '请输入有效的URL地址';
             $response->sendJSON($ret);
         }
         Node_Model::importMusic($source_id, $source_url);
         $ret = ['flag' => 'OK', 'msg' => '导入成功!'];
         $response->sendJSON($ret);
     } else {
         // Node Info
         $import_ntype = $request->arg(2);
         $this->v->assign('nav_second', $import_ntype);
         // Music Source List
         $sourceList = Node_Model::getSourceList('music');
         $this->v->set_tplname('mod_node_import');
         $this->v->assign('sourceList', $sourceList);
         $response->send($this->v);
     }
 }
 /**
  * action 'player_edit'
  * @param Request $request
  * @param Response $response
  */
 public function player_edit(Request $request, Response $response)
 {
     if ($request->is_post()) {
         $ret = ['flag' => 'ERR', 'msg' => ''];
         $player_id = $request->post('player_id', 0);
         $truename = $request->post('truename', '');
         $mobile = $request->post('mobile', '');
         $weixin = $request->post('weixin', '');
         $idcard = $request->post('idcard', '');
         $video = $request->post('video', '');
         $province = $request->post('province', 0);
         $city = $request->post('city', 0);
         $inc_vote = $request->post('inc_vote', 0);
         $inc_flower = $request->post('inc_flower', 0);
         $cover_pic_id = $request->post('cover_pic_id', 0);
         $imgs = $request->post('imgs', []);
         $player_info = Member_Model::getPlayerInfo($player_id);
         if (empty($player_info)) {
             $ret['msg'] = '参赛者不存在';
             $response->sendJSON($ret);
         }
         $uid = 10000;
         //10000 为系统管理员帐号
         $ret['flag'] = 'SUC';
         $ret['msg'] = '更新成功';
         $data = ['cover_pic_id' => $cover_pic_id];
         if ('' != $truename) {
             $data['truename'] = $truename;
         }
         if ('' != $mobile) {
             $data['mobile'] = $mobile;
         }
         if ('' != $weixin) {
             $data['weixin'] = $weixin;
         }
         if ('' != $idcard && strlen($idcard) <= 18) {
             $data['idcard'] = $idcard;
         }
         if ('' != $video && preg_match('/^http(s?):\\/\\//', $video)) {
             $data['video'] = $video;
         }
         //将省份、城市平均成: "40:北京"这样的结构
         if ($province) {
             $loc = Member_Model::getLocationName($province);
             if ($loc) {
                 $province = $province . ':' . $loc;
             }
         } else {
             $province = '';
         }
         if ($city) {
             $loc = Member_Model::getLocationName($city);
             if ($loc) {
                 $city = $city . ':' . $loc;
             }
         } else {
             $city = '';
         }
         $data['province'] = $province;
         $data['city'] = $city;
         //更新pic_cover_id
         D()->update("player", $data, ['player_id' => $player_id]);
         //更新图片
         if (!empty($imgs) && is_array($imgs)) {
             //! 务必检查严格
             $imgs_idstr = implode(',', $imgs);
             $existed_rids = D()->from("player_gallery")->where("`rid` IN(%s)", $imgs_idstr)->select("`rid`")->fetch_column('rid');
             if (!empty($existed_rids)) {
                 //! 务必检查严格,否则容易出现丢失图片数据
                 //先将原有的记录的player_id设为0
                 D()->query("UPDATE `{player_gallery}` SET `old_player_id`=`player_id`,`player_id`=0 WHERE `player_id`=%d", $player_id);
                 //紧接着重新关联新的记录
                 D()->query("UPDATE `{player_gallery}` SET `player_id`=%d,`old_player_id`=%d WHERE `rid` IN(%s)", $player_id, $player_id, $imgs_idstr);
                 //更新排序
                 $o = 1;
                 foreach ($imgs as $rid) {
                     D()->query("UPDATE `{player_gallery}` SET `sortorder`=%d WHERE `rid`=%d", $o, $rid);
                     $o++;
                 }
             }
         }
         if ($inc_vote) {
             $action_id = Node::action('vote', $player_id, $uid, $inc_vote, TRUE, FALSE, ['from' => 'admin']);
             $ret['msg'] .= ',增加了' . $inc_vote . '票';
         }
         if ($inc_flower) {
             $action_id = Node::action('flower', $player_id, $uid, $inc_flower);
             $ret['msg'] .= ',增加了' . $inc_flower . '花';
         }
         $response->sendJSON($ret);
     } else {
         // GET request
         $this->_nav_second = 'player';
         $this->v->set_tplname('mod_member_player_edit');
         // Player Info
         $player_id = $request->arg(2);
         $player_id = intval($player_id);
         $is_edit = $player_id ? TRUE : FALSE;
         $player_info = $is_edit ? Member_Model::getPlayerInfo($player_id) : [];
         $player_gallery = [];
         if (!empty($player_info)) {
             $player_gallery = Member_Model::getPlayerGalleryAll($player_info['player_id'], $player_info['cover_pic_id']);
             if (!empty($player_info['province'])) {
                 $player_info['province'] = preg_replace('/(:.*)$/', '', $player_info['province']);
             }
             if (!empty($player_info['city'])) {
                 $player_info['city'] = preg_replace('/(:.*)$/', '', $player_info['city']);
             }
         }
         $province = Member_Model::getProvinces();
         $this->v->assign('province', $province);
         $this->v->assign('player_info', $player_info)->assign('player_gallery', $player_gallery)->assign('is_edit', $is_edit);
         $response->send($this->v);
     }
 }
Beispiel #6
0
 public function add(Request $request, Response $response)
 {
     if ($request->is_post()) {
         $nid = $request->post('nid', 0);
         $title = $request->post('title', '');
         $content = $request->post('content', '');
         $img = $request->post('img', '');
         $recommend = $request->post('recommend', 0);
         $sort = $request->post('sort', 0);
         $ret = ['flag' => 'ERR', 'msg' => ''];
         if ('' == $title) {
             $ret['msg'] = '新闻标题';
             $response->sendJSON($ret);
         }
         if ('' == $content) {
             $ret['msg'] = '新闻详情不能为空';
             $response->sendJSON($ret);
         }
         if ('' == $img) {
             $ret['msg'] = '封面不能空';
             $response->sendJSON($ret);
         }
         $info = [];
         if ($nid) {
             $info = News_Model::getInfo($nid);
         }
         $now = simphp_time();
         $uid = $_SESSION['logined_uid'];
         $params = ['title' => $title, 'content' => $content, 'img' => $img, 'recommend' => $recommend, 'sort' => $sort, 'createdby' => $uid, 'created' => $now, 'changedby' => $uid, 'changed' => $now, 'status' => 'R'];
         if (empty($info)) {
             // new insert
             $ninfo['nid'] = D()->insert('news', $params);
             $ret['flag'] = 'OK';
             $ret['msg'] = '添加成功!';
             $response->sendJSON($ret);
         } else {
             // edit
             unset($params['createdby'], $params['created'], $params['status']);
             D()->update('news', $params, ['nid' => $nid]);
             $ret['flag'] = 'OK';
             $ret['msg'] = '编辑成功!';
             $response->sendJSON($ret);
         }
     } else {
         //
         $nid = $request->arg(1);
         $nid = intval($nid);
         $is_edit = $nid ? TRUE : FALSE;
         $ainfo = $is_edit ? News_Model::getInfo($nid) : [];
         // Node Type
         $node_type = '';
         $this->v->assign('nav_second', $node_type);
         $this->v->set_tplname('mod_news_add');
         $this->v->assign('ninfo', $ainfo)->assign('is_edit', $is_edit);
         $response->send($this->v);
     }
 }
Beispiel #7
0
 public function ad_list_edit(Request $request, Response $response)
 {
     $menu_name = 'ad';
     if ($request->is_post()) {
         $res = ['flag' => 'FAIL', 'msg' => ''];
         $ad_id = $request->post('ad_id', 0);
         $pic_id = $request->post('pic_id', 0);
         $title = $request->post('title', '');
         $link = $request->post('link', '');
         $pic_path = $request->post('pic_path', 0);
         $sort = $request->post('sort', 0);
         $ad_id = intval($ad_id);
         $pic_id = intval($pic_id);
         $sort = intval($sort);
         $data = ['title' => $title, 'link' => $link, 'pic_path' => $pic_path, 'ad_id' => $ad_id, 'sort' => $sort];
         if ($pic_id == 0) {
             //添加
             $cur_time = time();
             $data['created'] = $cur_time;
             $pic_id = Other_Model::addAdPic($data);
             if ($ad_id > 0) {
                 $res['flag'] = 'SUC';
                 $res['msg'] = '添加成功';
             } else {
                 $res['msg'] = '添加失败';
             }
             $response->sendJSON($res);
         } else {
             //编辑
             $affected = Other_Model::editAdPic($data, $pic_id);
             if ($affected > 0) {
                 $res['flag'] = 'SUC';
                 $res['msg'] = '更新成功';
             } else {
                 $res['msg'] = '更新失败';
             }
             $response->sendJSON($res);
         }
     } else {
         $ad_id = $request->arg(3);
         $ad_id = intval($ad_id);
         $pic_id = $request->arg(5);
         $pic_id = intval($pic_id);
         $is_edit = $pic_id ? TRUE : FALSE;
         $pic = $is_edit ? Other_Model::getAdPicInfo($pic_id) : [];
         $this->v->assign('pic', $pic);
     }
     $this->v->assign('ad_id', $ad_id);
     $this->v->assign('nav_second', $menu_name);
     $this->v->set_tplname('mod_other_ad_pic_add');
     $response->send($this->v);
 }
 /**
  * [subject description]
  * @param  Request  $request  [description]
  * @param  Response $response [description]
  * @return [type]             [description]
  */
 public function subject(Request $request, Response $response)
 {
     $context = '/mobiles/activity';
     $subid = $request->arg(2);
     $subid = intval($subid);
     $this->v->set_tplname('mod_activity_subject_' . $subid);
     $this->v->assign('nav_no', 0);
     $this->v->assign('context', $context);
     $response->send($this->v);
 }
 /**
  * 更新记录
  * @param  Request  $request  [description]
  * @param  Response $response [description]
  * @return [type]             [description]
  */
 public function relatedU(Request $request, Response $response)
 {
     if ($request->is_post()) {
         $aid = $request->arg(2);
         $ids = $request->post('rids', '');
         $act = $request->post('act', 0);
         $ret = Activity_Model::relatedUpdate($aid, $ids, $act);
         $response->sendJSON(['flag' => 'OK', 'rids' => $ret]);
     }
 }