/** * 用户地址接口 */ public function actionInfo($id) { $util = Yii::$app->util; $request = Yii::$app->getRequest(); $params = Yii::$app->request->get(); //判断用户是否登录 if (!UserBaseInfo::isLogin()) { $util->formatResData(1202, 'please_login', ['msg' => '请你登录']); } $id = intval($id); //判断参数的是否为空 if (!$id) { $util->formatResData(1101, 'address_param_missing', ['msg' => '地址信息参数缺失']); } //判断是否是Ajax请求 if (!$request->getIsAjax($id)) { $util->formatResData(1301, 'illegal_request', ['msg' => '非法请求']); } $address = new Address(); $data = $address->getByUserId($id); //通过地址ID获取对应的地址信息 $data = $address->getById($id); if (!$data) { $util->formatResData(1102, 'id_not_exists', ['msg' => 'ID信息不存在']); } //从session或cookie中获取用户id $userId = UserBaseInfo::getUserId(); if ($data['user_id'] != $userId) { $util->formatResData(1103, 'can_not_operate_other\'s_order_message', ['msg' => '不能操作其他人的订单信息']); } if (!$data['post_code']) { unset($data['post_code']); } //根据子区域id获取区域信息 $region = District::getById($data['county'], true); if (!$region) { $util->formatResData(1104, 'region_message_not_exists', ['msg' => '该子区域ID对应的区域信息不存在']); } $result = ['city' => $region['upid'], 'province' => $region['parent']['upid']]; $result = array_merge($data, $result); if ($result) { $util->formatResData(0, 'success', $result); } else { $util->formatResData(1201, 'get_address_fail', ['msg' => '获取地区信息失败']); } }
public function actionSafety() { $userBaseInfo = new UserBaseInfo(); $address = new Address(); $userTB = new UserThirdPartyLogin(); $this->layout = 'uc'; if (!$userBaseInfo->islogin()) { return $this->redirect(array('user/login')); } else { // 获取用户密码信息 // $cookie = Yii::$app->getRequest()->cookies; // $cookieId = $cookie[UserBaseInfo::COOKIE_KEY_ID]->value; $session = Yii::$app->session[UserBaseInfo::SESSION_KEY_USER]; $userId = isset($session['id']) && $session['id'] ? $session['id'] : 0; $inforMation = $userBaseInfo->getUserById($userId); $addr = $address->getAddress($userId); $thirds = $userTB->getBindByUser($userId, UserThirdPartyLogin::BIND_WEB_CHANNEL) ? $userTB->getBindByUser($userId, UserThirdPartyLogin::BIND_WEB_CHANNEL) : []; foreach ($thirds as $key => $value) { $thirds[$key]['type'] = strtoupper($thirds[$key]['type']); } $level = 0; $item = 5; if ($thirds) { $level += count($thirds) * 10; $item -= count($thirds); } if ($inforMation['mobile']) { $level += 40; $item -= 1; } if ($inforMation['email']) { $level += 30; $item -= 1; } $inforMation['level'] = $level; $inforMation['item'] = $item; $inforMation['addrNum'] = count($addr); $inforMation['thirds'] = arrayColumn($thirds, 'type'); return $this->render('safety', $inforMation); } }
/** * 用户支付页面 */ public function actionOrderPay() { /** * 获取第三方绑定token * $url = 'http://test-api.chuangyejia.com/v1/token?app_id=100003&app_key=f8d80e9a'; * $res = do_request($url); * p($token = $res['data']['ret']['access_token']);die; * * do_request 获取借口信息 * $request = Yii::$app->getRequest(); * $get = $request->get(); * $data = [ * 'open_id' => $open_id, * 'add_order_sn' => $get['app_order_sn'], * 'access_token' => $token, * ]; * $url = 'adfadfaf'; * $orderInfo = do_request($url, $data); * $orderInfo = json_decode($orderInfo, true); * if ($orderInfo['code'] == 1101) { * return '订单不存在'; * } * if ($orderInfo['code'] == 1201) { * return '用户不存在'; * } * if ($orderInfo['code'] == 1301) { * return ... * } * if (!isset($_SERVER['HTTP_REFERER']) || !$_SERVER['HTTP_REFERER']) { * $this->redirect($_SERVER['HTTP_REFERER'] . '?fileInfo=非法请求'); * return '非法请求'; * } */ $mBind = new PayBinding(); $payMethods = new PayMethod(); $mOrder = new Order(); $mAddress = new Address(); $mApp = new ApplicationBaseInfo(); $request = Yii::$app->getRequest(); $get = $request->get(); $session = Yii::$app->getSession(); $cookie = $request->cookies->getValue('open_id'); $openId = $session[UserBaseInfo::SESSION_KEY_USER]['open_id'] ?: $cookie; $order = ''; //没有第三方传值 暂时默认 app_id = 100002, app_order_sn = 554892031231322 $appId = isset($get['app_id']) && $get['app_id'] ? $get['app_id'] : '100002'; if (!$appId) { return '应用id失效'; } $appOrderSn = isset($get['app_order_sn']) && $get['app_order_sn'] ? $get['app_order_sn'] : '555892131' . mt_rand(100000, 999999); if (!$appOrderSn) { // $this->redirect($_SERVER['HTTP_REFERER'] . '?fileInfo=因无订单号为空'); return '订单号为空'; } if (isset($get['order_sn']) && $get['order_sn']) { $order = Order::getByOrderSn($get['order_sn']); if (!$order) { return $this->redirect(Url::toRoute('order/index')); } $appId = $order['app_id']; $appOrderSn = $order['app_order_sn']; if (!$appId || !$appOrderSn) { $order = ''; } } if (!isset($get['order_sn']) || !$get['order_sn'] || !$order) { $order = $mOrder->getByAppOrderSn($appOrderSn, $appId); } // 伪代码 访问应用接口返回data数据 // if ($data['open_id'] != $openId) { // return '非法请求'; // } $payIds = $mBind->getByAppId($appId); if (!$payIds) { // $this->redirect($_SERVER['HTTP_REFERER'] . '?fileInfo=应用未绑定任何支付方式'); return '应用未绑定任何支付方式'; } $appUrls = arrayColumn($payIds, 'app_url'); $appUrls = array_unique($appUrls); $returnUrl = array_pop($appUrls); $app = $mApp->getByAppId($appId); $app = ['app_order_sn' => $appOrderSn, 'origin' => $app['app_name']]; $time = time(); $orderSn = Yii::$app->util->orderSn(); if (!$order) { try { // TODO:: 通过接口获取应用生成的订单信息 $orderInfo = ['open_id' => $openId, 'product_id' => '1', 'product_name' => 'Young K' . mt_rand(100000, 999999), 'order_sn' => $orderSn, 'turnover' => '0.01', 'app_order_title' => '黑马大赛报名' . mt_rand(100000, 999999), 'create_time' => $time, 'expires_time' => $time + 24 * 3600, 'address_id' => 1, 'app_id' => $appId]; $data = $this->wxQrCode($orderInfo); $app['address_id'] = $orderInfo['address_id']; $app['app_id'] = $orderInfo['app_id']; $orderId = $mOrder->add(array_merge($app, $data)); if (empty($orderId)) { // $this->redirect($_SERVER['HTTP_REFERER'] . '?fileInfo=生成订单失败'); return '生成订单失败'; } $address = $mAddress->getById($orderInfo['address_id']); } catch (\Exception $e) { return $e->getMessage(); } } else { if ($order['expires_time'] < $time) { // $this->redirect($_SERVER['HTTP_REFERER'] . '?fileInfo=订单过期'); return '订单过期'; } if ($order['open_id'] != $openId) { return '不具备操作该订单权限'; } if ($order['pay_status'] == Order::ORDER_PAID_STATUS) { // $this->redirect($_SERVER['HTTP_REFERER'] . '?fileInfo=该订单已完成交易'); return '该订单已完成交易'; } if ($order['pay_status'] == Order::ORDER_REFUND_STATUS) { // $this->redirect($_SERVER['HTTP_REFERER'] . '?fileInfo=该订单已退款'); return '该订单已退款'; } if ($order['pay_status'] == Order::ORDER_INVALID_STATUS) { // $this->redirect($_SERVER['HTTP_REFERER'] . '?fileInfo=该订单已失效'); return '该订单已失效'; } if ($order['pay_status'] == Order::ORDER_CANCLE_STATUS) { // $this->redirect($_SERVER['HTTP_REFERER'] . '?fileInfo=已取消订单'); return '已取消订单'; } $data = $this->wxQrCode($order); $address = $mAddress->getById($order['address_id']); } $address['county'] = isset($address['county']) && $address['county'] ? District::getRegionById($address['county']) : ''; $alipayForm = $this->genAlipayForm($data); $alipayQrcode = $this->genAlipayQrcode($data); $sig = $this->wxCodeSig($data); $data['signature'] = $sig; $methods = $payMethods->getById(arrayColumn($payIds, 'pay_id'), true); if (!$methods) { // $this->redirect($_SERVER['HTTP_REFERER'] . '?fileInfo=未找到支付方式'); return '未找到支付方式'; } $this->layout = 'main'; return $this->render('order_pay', ['methods' => $methods, 'data' => $data, 'appOrderSn' => $appOrderSn, 'address' => $address, 'returnUrl' => $returnUrl, 'alipayForm' => $alipayForm, 'alipayQrcode' => $alipayQrcode]); }