/** * 提交地址 * * @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); } }
/** * 订单确认 * * @param Request $request * @param Response $response */ public function order_confirm(Request $request, Response $response) { $this->v->set_tplname('mod_trade_order_confirm'); $this->v->set_page_render_mode(View::RENDER_MODE_GENERAL); //改变默认的hashreq请求模式,改为普通页面请求(一次过render页面所有内容) $this->extra_css = 'fixmaxheight'; $this->nav_flag1 = 'order'; $this->nav_flag2 = 'order_confirm'; $this->nav_no = 0; if (1 || $request->is_hashreq()) { $goods_type = $request->get('goods', 'flower'); $player_id = $request->get('player_id', 0); $errmsg = ''; $this->v->add_render_filter(function (View $v) use(&$errmsg) { $v->assign('errmsg', $errmsg); }); //检查player是否存在 import('match/Match_Model'); $player_info = Match_Model::getPlayerInfo($player_id, false); if (empty($player_info)) { $errmsg = "参赛者不存在(player_id={$player_id})"; $response->send($this->v); } $this->v->assign('player_id', $player_id); $this->v->assign('player_info', $player_info); //商品类型 if (!in_array($goods_type, ['flower', 'kiss'])) { $goods_type = 'flower'; } $this->v->assign('goods_type', $goods_type); //起送数量 $amount_start = 1; if ($goods_type == 'kiss') { $amount_start = 2; } $this->v->assign('amount_start', $amount_start); $animate_num = config_get('flower_animate_num'); $this->v->assign('animate_num', $animate_num); //$_SESSION['animatenum_'.$player_id] = 100; } else { /* $code = $request->get('code', ''); if (''!=$code) { //微信base授权 $state = $request->get('state', ''); //授权出错 if (!in_array($state, array('base','detail'))) { Fn::show_error_message('授权出错,提交订单失败!', true); } $wx = new Weixin([Weixin::PLUGIN_JSADDR]); //用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'].')', true); } $accessToken = $code_ret['access_token']; $wxAddrJs = $wx->jsaddr->js($accessToken); $this->v->add_append_filter(function(PageView $v) use($wxAddrJs) { $v->append_to_foot_js .= $wxAddrJs; },'foot'); } else { //正常访问 if (Weixin::isWeixinBrowser()) { (new Weixin())->authorizing($request->url(), 'base'); //base授权获取access token以便于操作收货地址 } } */ } $response->send($this->v); }