Example #1
0
 /**
  * 取得一个订单的输出 Txt
  *
  *
  */
 private function getOrderTxt($orderReferInfo, $orderGoodsArray)
 {
     $retTxt = '';
     $orderGoodsNameStr = '';
     $coupon = $orderReferInfo['surplus'] + $orderReferInfo['bonus'];
     // 商品总价
     $orderAmount = $orderReferInfo['goods_amount'] - $orderReferInfo['discount'] - $orderReferInfo['extra_discount'] - $orderReferInfo['refund'];
     // 商品总的额外退款金额
     $orderExtraRefund = 0;
     // 订单状态
     $orderStatus = 'refund';
     switch ($orderReferInfo['pay_status']) {
         case OrderBasicService::PS_UNPAYED:
             $orderStatus = 'unpay';
             break;
         case OrderBasicService::PS_PAYED:
             $orderStatus = 'pay';
             break;
         default:
             $orderStatus = 'refund';
     }
     // 对订单中每个商品单独计算
     foreach ($orderGoodsArray as $orderGoodsItem) {
         $orderGoodsNameStr .= '{(' . $orderGoodsItem['goods_id'] . ')' . $orderGoodsItem['goods_name'] . '[' . $orderGoodsItem['goods_number'] . ' 件]},';
         if (OrderGoodsService::OGS_UNPAY != $orderGoodsItem['order_goods_status'] && OrderGoodsService::OGS_PAY != $orderGoodsItem['order_goods_status']) {
             // 有一个 order_goods 是退款状态,整个订单就是退款状态
             $orderStatus = 'refund';
         }
         // 累计额外退款的总金额
         $orderExtraRefund += $orderGoodsItem['extra_refund'];
     }
     $orderGoodsNameStr = str_replace('|', '_', $orderGoodsNameStr);
     $orderGoodsNameStr = mb_substr($orderGoodsNameStr, 0, 240);
     $referParamArray = json_decode($orderReferInfo['refer_param'], true);
     // CPS 应付总价
     $orderAmountOfCps = $orderAmount - $coupon - $orderExtraRefund;
     $orderAmountOfCps = $orderAmountOfCps > 0 ? $orderAmountOfCps : 0;
     // QQ订单要多输出一条记录
     if ('qqlogin' == $orderReferInfo['login_type']) {
         // 取得QQ登陆用户的信息
         static $userBasicService = null;
         if (null == $userBasicService) {
             $userBasicService = new UserBasicService();
         }
         $userInfo = $userBasicService->loadUserById($orderReferInfo['user_id']);
         //取得 QQ 用户的 openId ,QQ登陆的用户 sns_login 例子  qq:476BA0B2332440759D485548637DFCDD
         $qqUserOpenId = $userInfo->sns_login;
         $qqUserOpenId = substr($qqUserOpenId, strpos($qqUserOpenId, ':') + 1);
         //输出 QQ 登陆的记录
         $retTxt .= $referParamArray['wi'] . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['add_time'])) . "||" . $orderReferInfo['order_id'] . "||" . Money::toSmartyDisplay($orderAmountOfCps) . "||" . $orderGoodsNameStr . "||" . $orderStatus . "||" . $orderStatus . "||alipay" . "||" . Money::toSmartyDisplay($orderReferInfo['shipping_fee']) . "||" . Money::toSmartyDisplay($coupon) . "||0" . "||" . $qqUserOpenId . "||" . 'bangzhufu' . "||" . 'qqlogin003' . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['update_time'])) . "\n";
     }
     if ('YIQIFACPS' != $orderReferInfo['utm_source']) {
         // 不是亿起发的订单
         goto out;
     }
     //输出 亿起发 的订单记录
     $retTxt .= $referParamArray['wi'] . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['add_time'])) . "||" . $orderReferInfo['order_id'] . "||" . Money::toSmartyDisplay($orderAmountOfCps) . "||" . $orderGoodsNameStr . "||" . $orderStatus . "||" . $orderStatus . "||alipay" . "||" . Money::toSmartyDisplay($orderReferInfo['shipping_fee']) . "||" . Money::toSmartyDisplay($coupon) . "||0" . "||" . "||" . "||" . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['update_time'])) . "\n";
     out:
     return $retTxt;
 }
Example #2
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->minLength(2, '用户名最短为2个字符')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->minLength(6, '密码最短为6个非空字符')->validate('password');
     $input['email'] = $validator->validate('email');
     $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     // 手机输入,输入法经常无故添加空格,我们需要去除所有的空额,防止出错
     $p_captcha = Utils::filterAlnumStr($p_captcha);
     // 需要跳转回去的地址
     $returnUrl = $validator->validate('returnUrl');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage('验证码错误[' . $p_captcha . '][' . $captchaController->getCaptcha() . ']');
         goto out_fail;
     }
     $userService = new UserService();
     // 检查用户是否已经注册
     $isUserExist = $userService->isUserExist($input['user_name'], $input['email']);
     if ($isUserExist) {
         $this->addFlashMessage($isUserExist . '已经存在');
         goto out_fail;
     }
     // 注册用户
     $user = $userService->registerUser($input);
     if (!$user) {
         $this->addFlashMessage('用户注册失败,请稍后刷新页面重试');
         goto out_fail;
     }
     // 记录用户的登陆信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($userInfo, 'normal');
     $this->addFlashMessage("注册成功");
     if ($returnUrl) {
         header('Location:' . $returnUrl);
         return;
     } else {
         // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
         RouteHelper::jumpBack($this, '/', true);
     }
     return;
     // 这里正常返回
     out_fail:
     // 失败,从这里出口
     $smarty->assign('captchaUrl', RouteHelper::makeUrl('/Image/Captcha', array('hash' => time())));
     $smarty->display('user_register.tpl', 'User|Register|post');
 }
Example #3
0
 public function getOrderReferNotifyUrl($f3, $orderRefer)
 {
     if (!('YIQIFACPS' == $orderRefer->utm_source || 'qqlogin' == $orderRefer->login_type && empty($orderRefer->utm_source))) {
         // 不是亿起发的订单,或者不是QQ登陆订单
         return null;
     }
     $notifyUrlArray = array();
     // 取得记录的 亿起发 参数
     $referParamArray = json_decode($orderRefer->refer_param, true);
     // 取得订单信息
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($orderRefer->order_id);
     // 取得订单商品详情
     $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderRefer->order_id);
     // 计算佣金
     $orderGoodsNameStr = '';
     $coupon = $orderInfo->surplus + $orderInfo->bonus;
     // 商品总价
     $orderAmount = $orderInfo->goods_amount - $orderInfo->discount - $orderInfo->extra_discount - $orderInfo->refund;
     // 商品总的额外退款金额
     $orderExtraRefund = 0;
     // 对订单中每个商品单独计算
     foreach ($orderGoodsArray as $orderGoodsItem) {
         $orderGoodsNameStr .= '{(' . $orderGoodsItem['goods_id'] . ')' . $orderGoodsItem['goods_name'] . '[' . $orderGoodsItem['goods_number'] . ' 件]},';
         // 累计额外退款的总金额
         $orderExtraRefund += $orderGoodsItem['extra_refund'];
     }
     // CPS 应付总价
     $orderAmountOfCps = $orderAmount - $coupon - $orderExtraRefund;
     $orderAmountOfCps = $orderAmountOfCps > 0 ? $orderAmountOfCps : 0;
     $orderGoodsNameStr = str_replace('|', '_', $orderGoodsNameStr);
     $orderGoodsNameStr = mb_substr($orderGoodsNameStr, 0, 240);
     // 推送QQ登陆订单
     if ('qqlogin' == $orderRefer->login_type) {
         // 取得QQ登陆用户的信息
         $userBasicService = new UserBasicService();
         $userInfo = $userBasicService->loadUserById($orderInfo->user_id);
         //取得 QQ 用户的 openId ,QQ登陆的用户 sns_login 例子  qq:476BA0B2332440759D485548637DFCDD
         $qqUserOpenId = $userInfo->sns_login;
         $qqUserOpenId = substr($qqUserOpenId, strpos($qqUserOpenId, ':') + 1);
         // QQ 登陆需要额外推单
         $param = "cid=6406" . "&wid=435983" . "&qqoid=" . $qqUserOpenId . "&qqmid=bangzhufu" . "&ct=qqlogin003" . "&on=" . $orderInfo->order_id . "&ta=1" . "&dt=" . YiqifaCpsRefer::$notifyParamDt . "&pp=" . Money::toSmartyDisplay($orderAmountOfCps) . "&sd=" . urlencode(date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderInfo->add_time))) . "&os=pay" . "&ps=pay" . "&pw=alipay" . "&far=" . Money::toSmartyDisplay($orderInfo->shipping_fee) . "&fav=" . Money::toSmartyDisplay($coupon) . "&fac=0" . "&encoding=utf-8";
         // QQ 登陆订单推送
         $notifyUrlArray[] = YiqifaCpsRefer::yiqifaNotifyGateway . $param;
     }
     if ('YIQIFACPS' != $orderRefer->utm_source) {
         // 不是亿起发的订单
         goto out;
     }
     // 亿起发 正常 CPS 推单
     $param = "cid=" . $referParamArray['cid'] . "&wi=" . $referParamArray['wi'] . "&on=" . $orderInfo->order_id . "&ta=1" . "&pna=" . urlencode($orderGoodsNameStr) . "&dt=" . YiqifaCpsRefer::$notifyParamDt . "&pp=" . Money::toSmartyDisplay($orderAmountOfCps) . "&sd=" . urlencode(date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderInfo->add_time))) . "&os=pay" . "&ps=pay" . "&pw=alipay" . "&far=" . Money::toSmartyDisplay($orderInfo->shipping_fee) . "&fav=" . Money::toSmartyDisplay($coupon) . "&fac=0" . "&encoding=utf-8";
     // 亿起发订单推送
     $notifyUrlArray[] = YiqifaCpsRefer::yiqifaNotifyGateway . $param;
     out:
     return $notifyUrlArray;
 }
Example #4
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->minLength(2, '用户名最短为2个字符')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->minLength(6, '密码最短为6个非空字符')->validate('password');
     $input['email'] = $validator->validate('email');
     $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage("验证码错误");
         goto out_fail;
     }
     $userService = new UserService();
     // 检查用户是否已经注册
     $isUserExist = $userService->isUserExist($input['user_name'], $input['email']);
     if ($isUserExist) {
         $this->addFlashMessage($isUserExist . '已经存在');
         goto out_fail;
     }
     // 注册用户
     $user = $userService->registerUser($input);
     if (!$user) {
         $this->addFlashMessage('用户注册失败,请稍后刷新页面重试');
         goto out_fail;
     }
     // 记录用户的登陆信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($userInfo, 'normal');
     // 设置用户名在网页显示
     ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name);
     $this->addFlashMessage("注册成功");
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
     return;
     // 这里正常返回
     out_fail:
     // 失败,从这里出口
     $smarty->display('user_login.tpl', 'User|Register|post');
 }
Example #5
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->validate('password');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     // 手机输入,输入法经常无故添加空格,我们需要去除所有的空额,防止出错
     $p_captcha = Utils::filterAlnumStr($p_captcha);
     // 需要跳转回去的地址
     $returnUrl = $validator->validate('returnUrl');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage('验证码错误[' . $p_captcha . '][' . $captchaController->getCaptcha() . ']');
         goto out_fail;
     }
     $userService = new UserService();
     // 验证用户登陆
     $user = $userService->doAuthUser($input['user_name'], $input['user_name'], $input['password']);
     if (!$user) {
         $this->addFlashMessage("登陆失败,用户名、密码错误");
         goto out_fail;
     }
     // 记录用户的登陆信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($userInfo, 'normal');
     $this->addFlashMessage("登陆成功");
     if ($returnUrl) {
         header('Location:' . $returnUrl);
         return;
     } else {
         // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
         RouteHelper::jumpBack($this, '/', true);
     }
     return;
     // 这里正常返回
     out_fail:
     // 失败从这里出口
     $smarty->assign('captchaUrl', RouteHelper::makeUrl('/Image/Captcha', array('hash' => time())));
     $smarty->display('user_login.tpl', 'User|Login|post');
 }
Example #6
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['oldpassword'] = $validator->validate('oldpassword');
     $input['password'] = $validator->validate('password');
     $input['email'] = $validator->validate('email');
     $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone');
     // 用户打算修改密码
     if (!Utils::isBlank($input['password'])) {
         $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword');
     }
     // 提供的旧密码,但是新密码为空
     if (!Utils::isBlank($input['oldpassword'])) {
         $validator->required('新密码不能为空')->validate('password');
     }
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $userInfo = AuthHelper::getAuthUser();
     $userService = new UserService();
     $user = $userService->loadUserById($userInfo['user_id']);
     if (!$user) {
         // 非法用户,应该让它自动登陆出去
         $this->addFlashMessage('非法登陆用户');
         RouteHelper::reRoute($this, '/User/Logout', false);
     }
     // 用户打算修改密码,但是旧密码不对
     if (!empty($input['password']) && !$userService->verifyPassword($userInfo['user_id'], $input['oldpassword'])) {
         $this->addFlashMessage('旧密码不对');
         goto out_fail;
     }
     // 更新数据
     unset($input['oldpassword']);
     $userService->updateUser($user, $input);
     // 更新认证记录
     AuthHelper::removeAuthUser();
     AuthHelper::saveAuthUser($user->toArray());
     $this->addFlashMessage('资料更新成功');
     RouteHelper::reRoute($this, '/My/Profile');
     return;
     // 这里正常返回
     out_fail:
     // 失败返回
     $smarty->display('my_profile.tpl', 'post');
 }
Example #7
0
 public function get($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     $userInfo = AuthHelper::getAuthUser();
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($userInfo['user_id']);
     // 用户总共有资金余额
     $smarty->assign('userMoney', $userInfo['user_money']);
     $accountLog = new AccountLogService();
     // 用户总共有多少account_log
     $totalCount = $accountLog->countUserMoneyArray($userInfo['user_id'], 10);
     //缓存 10 秒钟
     if ($totalCount <= 0) {
         // 没资金变动记录,可以直接退出了
         goto out_display;
     }
     $smarty->assign('totalCount', $totalCount);
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/My/Money');
     }
     // 传递分页的变量
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     // account_log 列表
     $accountLogArray = $accountLog->fetchUserMoneyArray($userInfo['user_id'], $pageNo * $pageSize, $pageSize, 10);
     //缓存 10 秒钟
     foreach ($accountLogArray as &$accountLogItem) {
         $accountLogItem['change_type_desc'] = AccountLogService::$changeTypeDesc[$accountLogItem['change_type']];
     }
     unset($accountLogItem);
     $smarty->assign('accountLogArray', $accountLogArray);
     out_display:
     $smarty->display('my_money.tpl', 'get');
 }
Example #8
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->validate('password');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage("验证码错误");
         goto out_fail;
     }
     $userService = new UserService();
     // 验证用户登陆
     $user = $userService->doAuthUser($input['user_name'], $input['user_name'], $input['password']);
     if (!$user) {
         $this->addFlashMessage("登陆失败,用户名、密码错误");
         goto out_fail;
     }
     // 记录用户的登陆信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($userInfo, 'normal');
     // 设置用户名在网页显示
     ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name);
     $this->addFlashMessage("登陆成功");
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
     return;
     // 这里正常返回
     out_fail:
     // 失败从这里入口
     $smarty->display('user_login.tpl', 'User|Login|post');
 }
Example #9
0
 public function post($f3)
 {
     //首先验证参数签名
     $map = $_POST;
     unset($map['Vkey']);
     //读取除了vkey外的所有参数,并且放入数组map中
     ksort($map);
     //进行按参数的升序排序
     //进行签名,注意考虑到md5加密输出的大小写问题,所有约定md5的输出均为小写
     $vkey = implode('', array_values($map));
     $md5_1 = strtolower(md5($vkey . YiqifaCpsPlugin::getOptionValue('qqcaibei_key1')));
     $vkey = strtolower(md5($md5_1 . YiqifaCpsPlugin::getOptionValue('qqcaibei_key2')));
     if ($vkey != $_POST['Vkey']) {
         // 参数签名错误
         goto out;
     }
     // 保存额外的 亿起发 参数
     $orderRefer = array();
     $orderRefer['utm_medium'] = 'QQCAIBEI';
     //设置 cookie
     ReferHelper::setOrderReferSpecific($f3, $orderRefer, YiqifaCpsPlugin::getOptionValue('yiqifacps_duration'));
     $f3->set('SESSION[yiqifa_caibei_order_refer]', ReferHelper::parseOrderRefer($f3));
     // 取得QQ彩贝传递过来的参数
     //$acct     = @$_POST['Acct'];
     $url = @$_POST['Url'];
     $openId = @$_POST['OpenId'];
     //$clubInfo = @intval($_POST['ClubInfo']); // 会员等级信息,目前没用
     $viewInfo = @$_POST['ViewInfo'];
     if (get_magic_quotes_gpc()) {
         $viewInfo = stripslashes($viewInfo);
     }
     $viewInfoArray = array();
     parse_str($viewInfo, $viewInfoArray);
     //解析 viewInfoArray 数组
     //$f3->set('SESSION[qqcaibei_viewinfoarray]', json_encode($viewInfoArray)); //放入到 session 里面
     // 设置 ClientData
     ClientData::saveClientData('qqcaibei_viewinfoarray', json_encode($viewInfoArray));
     if (empty($openId)) {
         // 没有  openId 没法登陆,直接退出
         goto out;
     }
     // 这里做 QQ彩贝 联合登陆
     $sns_login = "******";
     // 用户登陆操作
     $userBasicService = new UserBasicService();
     $authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false);
     if ($authUser) {
         goto out_login_user;
     }
     // 之前没有登陆过,自动注册用户
     $authUser = $userBasicService->doAuthSnsUser($sns_login, $openId . '@qq.com', $openId . '@qq.com', true);
     printLog('注册QQ用户:' . print_r($viewInfoArray, true), 'QQLOGIN', \Core\Log\Base::INFO);
     out_login_user:
     AuthHelper::saveAuthUser($authUser->toArray(), 'qqcaibei');
     // 设置用户名在网页显示
     ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, 'QQ彩贝用户:' . $viewInfoArray['NickName']);
     out:
     // 页面跳转到商品
     $redirectUrl = empty($url) ? '/' : $url;
     RouteHelper::reRoute($this, $redirectUrl);
     return;
 }
Example #10
0
 public function post($f3)
 {
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1, true, '订单ID非法')->validate('order_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $validator = new Validator($f3->get('POST'));
     $payGatewayType = $validator->required('必须选择一种支付方式')->validate('pay_gateway_type');
     $surplus = Money::toStorage($validator->float('余额格式错误')->min(0, true, '余额格式错误')->validate('surplus'));
     $bonusSn = $validator->validate('bonus_sn');
     // 客服信息
     $orderInfoKefuInfo = array();
     $orderInfoKefuInfo['kefu_user_id'] = abs(intval($validator->digits()->validate('kefu_user_id')));
     $orderInfoKefuInfo['kefu_user_rate'] = abs(intval($validator->digits()->validate('kefu_user_rate')));
     $orderInfoKefuInfo['kefu_user_comment'] = $validator->validate('kefu_user_comment');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得用户信息
     $userInfo = AuthHelper::getAuthUser();
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($userInfo['user_id']);
     // 支付某一个特定的订单需要把订单加载到临时购物车里面
     $orderBasicService = new OrderBasicService();
     // 检查权限
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id);
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         $this->addFlashMessage('订单ID非法');
         goto out_fail;
     }
     // 更新客服信息
     if ($orderInfoKefuInfo['kefu_user_id'] > 0) {
         $adminUserService = new AdminUserService();
         $adminUser = $adminUserService->loadAdminById($orderInfoKefuInfo['kefu_user_id']);
         if (!$adminUser->isEmpty()) {
             $orderInfoKefuInfo['kefu_user_name'] = $adminUser['user_name'];
         } else {
             $orderInfoKefuInfo['kefu_user_id'] = 0;
             $orderInfoKefuInfo['kefu_user_name'] = null;
         }
         unset($adminUser);
         unset($adminUserService);
     } else {
         $orderInfoKefuInfo['kefu_user_id'] = 0;
         $orderInfoKefuInfo['kefu_user_name'] = null;
     }
     $orderInfo->copyFrom($orderInfoKefuInfo);
     $orderInfo->save();
     $cartBasicService = new CartBasicService();
     // 加载订单到购物车里
     if (!$cartBasicService->loadFromOrderInfo($order_id)) {
         $this->addFlashMessage('订单加载失败');
         goto out_fail;
     }
     $cartContext =& $cartBasicService->getCartContextRef();
     if ($cartContext->isEmpty()) {
         $this->addFlashMessage('订单为空,不能支付');
         goto out_fail;
     }
     // 做第一次购物车计算,需要计算原始订单的金额,后面红包使用的时候有最低订单金额限制
     $cartBasicService->calcOrderPrice();
     if (!empty($surplus) || !empty($bonusSn)) {
         if (null != $surplus && $surplus > 0 && $surplus <= $userInfo['user_money']) {
             // 设置余额支付金额,余额不能超过用户已经有的钱
             $cartContext->setValue('surplus', $surplus);
         }
         // 设置红包支付
         if (!empty($bonusSn)) {
             $bonusService = new Bonus();
             //检查红包是否可以使用
             $bonus = $bonusService->fetchUsableBonusBySn($userInfo['user_id'], $cartContext->getValue('order_amount'), $bonusSn);
             if (empty($bonus)) {
                 $this->addFlashMessage('红包' . $bonusSn . '不能使用');
                 goto out_fail;
             }
             // 设置红包的使用
             $cartContext->setValue('bonus_id', $bonus['bonus_id']);
             $cartContext->setValue('bonus', $bonus['type_money']);
         }
     }
     // 做第二次购物车计算,需要计算使用了余额或者红包
     $cartBasicService->calcOrderPayment();
     // 更新订单信息
     $orderInfo = $cartBasicService->saveOrder($userInfo['user_id'], '买家:' . $userInfo['user_name']);
     if (!$orderInfo || $orderInfo->isEmpty()) {
         //订单创建失败,报错
         $this->addFlashMessage('更新订单信息失败,请联系客服');
         goto out_my_order_detail;
     }
     // 如果购物车里面有错误消息,我们需要显示它
     if ($cartContext->hasError()) {
         $this->addFlashMessageArray($cartContext->getAndClearErrorMessageArray());
         goto out_my_order_cart;
     }
     // 如果订单金额为 0 ,使用 credit 支付网关
     if ($orderInfo['order_amount'] <= 0) {
         $payGatewayType = 'credit';
     }
     $order_id = $orderInfo['order_id'];
     // 解析参数,我们允许写成 tenpay_cmbchina  代表财付通、招商银行
     $payGatewayParamArray = explode('_', $payGatewayType);
     // 获取支付网关
     $payGateway = PaymentGatewayHelper::getPaymentGateway($payGatewayParamArray[0]);
     // 根据参数做初始化
     if (!$payGateway->init($payGatewayParamArray)) {
         $this->addFlashMessage('支付网关' . $payGatewayType . '初始化失败');
         goto out_my_order_detail;
     }
     $payRequestUrl = $payGateway->getRequestUrl($order_id, RouteHelper::makeUrl('/Payment/PaymentReturn/' . $payGateway->getGatewayType(), null, false, true), RouteHelper::makeUrl('/Payment/PaymentNotify/' . $payGateway->getGatewayType(), null, false, true));
     //notifyUrl
     if (empty($payRequestUrl)) {
         $this->addFlashMessage('系统错误:无法生成支付链接');
         goto out_my_order_detail;
     }
     // 记录支付日志
     printLog('[orderId:' . $order_id . ']' . $payRequestUrl, 'PAYMENT', Base::INFO);
     // 跳转支付
     RouteHelper::reRoute($this, $payRequestUrl);
     return;
     out_my_order_cart:
     //失败从这里退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/My/Order/Cart', array('order_id' => $order_id), true));
     return;
     out_my_order_detail:
     //失败从这里退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/My/Order/Detail', array('order_id' => $order_id), true));
     return;
     out_fail:
     //失败从这里退出
     RouteHelper::reRoute($this, '/My/Order');
 }
Example #11
0
 /**
  * 订单详情
  */
 public function Detail($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_order_detail');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1)->validate('order_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 查询订单
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id);
     if ($orderInfo->isEmpty()) {
         $this->addFlashMessage('订单ID非法');
         goto out_fail;
     }
     $orderInfo['order_status_desc'] = OrderBasicService::$orderStatusDesc[$orderInfo['order_status']];
     $orderInfo['pay_status_desc'] = OrderBasicService::$payStatusDesc[$orderInfo['pay_status']];
     $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($order_id);
     // 转换状态显示
     foreach ($orderGoodsArray as &$orderGoodsItem) {
         $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']];
     }
     unset($orderGoodsItem);
     // 取订单来源信息
     $orderReferService = new OrderReferService();
     $orderRefer = $orderReferService->loadOrderReferByOrderId($orderInfo['order_id'], 300);
     //缓存5分钟
     // 取用户账户
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($orderInfo['user_id']);
     // 取得订单的操作日志
     $orderActionService = new OrderActionService();
     $orderLogArray = $orderActionService->fetchOrderLogArray($order_id, 0);
     // 状态字段转换成可以显示的字符串
     foreach ($orderLogArray as &$orderLog) {
         $orderLog['order_status'] = OrderBasicService::$orderStatusDesc[$orderLog['order_status']];
         $orderLog['pay_status'] = OrderBasicService::$payStatusDesc[$orderLog['pay_status']];
         $orderLog['order_goods_status'] = OrderGoodsService::$orderGoodsStatusDesc[$orderLog['order_goods_status']];
         $orderLog['action_note'] = nl2br($orderLog['action_note']);
     }
     unset($orderLog);
     // 给模板赋值
     $smarty->assign('orderInfo', $orderInfo);
     $smarty->assign('orderRefer', $orderRefer);
     $smarty->assign('userInfo', $userInfo);
     $smarty->assign('orderGoodsArray', $orderGoodsArray);
     $smarty->assign('orderLogArray', $orderLogArray);
     $smarty->display('order_order_detail.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Order/Order/Search');
 }
Example #12
0
 public function post($f3)
 {
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1, true, '订单ID非法')->validate('order_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $validator = new Validator($f3->get('POST'));
     $payGatewayType = $validator->required('必须选择一种支付方式')->validate('pay_gateway_type');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得用户信息
     $userInfo = AuthHelper::getAuthUser();
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($userInfo['user_id']);
     // 支付某一个特定的订单需要把订单加载到临时购物车里面
     $orderBasicService = new OrderBasicService();
     // 检查权限
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id);
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         $this->addFlashMessage('订单ID非法');
         goto out_fail;
     }
     $cartBasicService = new CartBasicService();
     // 加载订单到购物车里
     if (!$cartBasicService->loadFromOrderInfo($order_id)) {
         $this->addFlashMessage('订单加载失败');
         goto out_fail;
     }
     $cartContext =& $cartBasicService->getCartContextRef();
     if ($cartContext->isEmpty()) {
         $this->addFlashMessage('订单为空,不能支付');
         goto out_fail;
     }
     // 做第一次购物车计算,需要计算原始订单的金额,后面红包使用的时候有最低订单金额限制
     $cartBasicService->calcOrderPrice();
     // 计算支付金额
     $cartBasicService->calcOrderPayment();
     // 如果购物车里面有错误消息,我们需要显示它
     if ($cartContext->hasError()) {
         $this->addFlashMessageArray($cartContext->getAndClearErrorMessageArray());
         goto out_fail;
     }
     // 更新订单信息
     $orderInfo = $cartBasicService->saveOrder($userInfo['user_id'], '买家:' . $userInfo['user_name']);
     if (!$orderInfo || $orderInfo->isEmpty()) {
         //订单创建失败,报错
         $this->addFlashMessage('更新订单信息失败,请联系客服');
         goto out_fail;
     }
     // 如果订单金额为 0 ,使用 credit 支付网关
     if ($orderInfo['order_amount'] <= 0) {
         $payGatewayType = 'credit';
     }
     $order_id = $orderInfo['order_id'];
     // 解析参数,我们允许写成 tenpay_cmbchina  代表财付通、招商银行
     $payGatewayParamArray = explode('_', $payGatewayType);
     // 获取支付网关
     $payGateway = PaymentGatewayHelper::getPaymentGateway($payGatewayParamArray[0]);
     // 根据参数做初始化
     if (!$payGateway->init($payGatewayParamArray)) {
         $this->addFlashMessage('支付网关' . $payGatewayType . '初始化失败');
         goto out_fail;
     }
     $payRequestUrl = $payGateway->getRequestUrl($order_id, RouteHelper::makeUrl('/Payment/PaymentReturn/' . $payGateway->getGatewayType(), null, false, true), RouteHelper::makeUrl('/Payment/PaymentNotify/' . $payGateway->getGatewayType(), null, false, true));
     //notifyUrl
     if (empty($payRequestUrl)) {
         $this->addFlashMessage('系统错误:无法生成支付链接');
         goto out_fail;
     }
     // 记录支付日志
     printLog('[orderId:' . $order_id . ']' . $payRequestUrl, 'PAYMENT', Base::INFO);
     // 跳转去支付
     header('Location:' . $payRequestUrl);
     return;
     out_fail:
     //失败从这里退出
     RouteHelper::reRoute($this, '/My/Order');
 }
Example #13
0
 /**
  * 360 登陆
  */
 public function get($f3)
 {
     global $logger;
     if (empty($_GET['code'])) {
         $this->addFlashMessage('360联合登陆失败,Code 不存在');
         goto out;
     }
     require_once 'sdk/QClient.php';
     // 获取access token
     $callback = RouteHelper::makeUrl('/Thirdpart/Dev360Auth/Callback', null, false, true);
     $oauth = new \QOAuth2(Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_key'), Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_secrect'), '');
     $token = $oauth->getAccessTokenByCode($_GET['code'], $callback);
     if (empty($token['access_token'])) {
         $this->addFlashMessage('360联合登陆失败,获取 access_token 失败');
         goto out;
     }
     // 调用API,获取用户信息
     $client = new \QClient(Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_key'), Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_secrect'), $token['access_token']);
     $user = $client->userMe();
     if (empty($user)) {
         $this->addFlashMessage('360联合登陆失败,用户信息为空');
         goto out;
     }
     $param = array('user_id' => $user['id'], 'username' => !empty($user['name']) ? (string) $user['name'] : '网友', 'token' => $token['access_token']);
     // put all values into $_POST[]
     $qid = $param['user_id'];
     $qname = urldecode($param['username']);
     $qmail = '';
     if (empty($qid)) {
         // 没有 qid 没法登陆
         $this->addFlashMessage('360联合登陆失败,没有 qid');
         goto out;
     }
     $sns_login = "******";
     // 用户登陆操作
     $userBasicService = new UserBasicService();
     $authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false);
     if ($authUser) {
         goto out_login_user;
     }
     // 用户不存在,自动注册一个用户
     if (empty($qmail)) {
         $qmail = '' . $qid . '@360.cn';
     }
     if (empty($qname)) {
         $qname = $qmail;
     }
     $retry = 10;
     // 重试 10 次
     $regUserName = $qname;
     while ($userBasicService->isUserExist($regUserName, null) && $retry-- > 0) {
         $regUserName = $qname . '_' . rand(10000, 99999);
     }
     if ($retry <= 0) {
         $this->addFlashMessage('360联合登陆失败,用户名已经存在,无法自动注册');
         goto out;
     }
     $authUser = $userBasicService->doAuthSnsUser($sns_login, $qname, $qmail, true);
     $logger->addLogInfo(\Core\Log\Base::INFO, 'DEV360AUTH', '注册360用户' . print_r(array('sns_login' => $sns_login, 'qname' => $qname, 'qmail' => $qmail), true));
     out_login_user:
     AuthHelper::saveAuthUser($authUser->toArray(), 'dev360auth');
     // 设置用户名在网页显示
     ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, '360用户:' . $authUser['user_name']);
     out:
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
 }
Example #14
0
 /**
  * 标记 order_goods 记录为已经支付状态
  *
  * @param $orderId
  */
 public function markOrderGoodsPay($orderInfo)
 {
     // 参数验证
     $validator = new Validator(array('orderId' => $orderInfo['order_id']));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $this->validate($validator);
     // 设置 order_goods 的状态
     $sql = 'update ' . DataMapper::tableName('order_goods') . ' set order_goods_status = ' . Goods::OGS_PAY . ', update_time = ' . Time::gmTime() . ' where order_id = ? ';
     $dbEngine = DataMapper::getDbEngine();
     $dbEngine->exec($sql, $orderId);
     $goodsCommentService = new GoodsCommentService();
     $userBasicService = new UserBasicSerivce();
     $userInfo = $userBasicService->loadUserById($orderInfo['user_id']);
     $orderBasicService = new OrderBasicService();
     $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderId);
     foreach ($orderGoodsArray as $orderGoodsItem) {
         // 更新商品的销售数量
         $this->updateGoodsUserPayCount($orderGoodsItem['goods_id'], $orderGoodsItem['goods_number']);
         // 更新商品的库存
         $this->updateGoodsGoodsNumber($orderGoodsItem['goods_id'], $orderGoodsItem['goods_attr'], $orderGoodsItem['goods_number']);
         // 添加一个 goods_comment 记录
         if (!$goodsCommentService->isOrderGoodsCommentExist($orderGoodsItem['rec_id'])) {
             $goodsComment = $goodsCommentService->loadGoodsCommentById(0);
             $goodsComment->create_time = Time::gmTime();
             $goodsComment->rec_id = $orderGoodsItem['rec_id'];
             $goodsComment->goods_id = $orderGoodsItem['goods_id'];
             $goodsComment->goods_price = $orderGoodsItem['goods_price'];
             $goodsComment->goods_number = $orderGoodsItem['goods_number'];
             $goodsComment->goods_attr = $orderGoodsItem['goods_attr'];
             $goodsComment->comment_rate = 5;
             // 用户不评论,我们默认为好评,显示
             $goodsComment->is_show = 1;
             // 用户不评论,我们默认为好评,显示
             $goodsComment->user_id = $userInfo['user_id'];
             $goodsComment->user_name = $userInfo['user_name'];
             $goodsComment->save();
         }
     }
 }
Example #15
0
 public function Search($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_refund_search');
     /**
      * 我们使用搜索模块做搜索操作
      */
     $searchFieldSelector = 'og.*, oi.user_id, oi.system_id';
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     // shippingStatus, 0 全部,1 已发货,2 未发货
     $shippingStatus = $validator->digits()->min(1)->validate('shippingStatus');
     //订单表单查询
     $searchFormQuery = array();
     $searchFormQuery['og.order_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('order_id');
     $searchFormQuery['og.rec_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('rec_id');
     $searchFormQuery['og.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id');
     $searchFormQuery['og.goods_name'] = $validator->validate('goods_name');
     $searchFormQuery['oi.order_sn'] = $validator->validate('order_sn');
     $searchFormQuery['oi.pay_no'] = $validator->validate('pay_no');
     $order_goods_status = $validator->min(0)->filter('ValidatorIntValue')->validate('order_goods_status');
     if (null == $order_goods_status) {
         // 选择 请求退款、退款中、退款完成 状态的订单
         $searchFormQuery['og.order_goods_status'] = array('>', OrderGoodsService::OGS_PAY);
     } else {
         $searchFormQuery['og.order_goods_status'] = $order_goods_status;
     }
     $searchFormQuery['oi.consignee'] = $validator->validate('consignee');
     $searchFormQuery['oi.mobile'] = $validator->validate('mobile');
     $searchFormQuery['oi.address'] = $validator->validate('address');
     $searchFormQuery['oi.postscript'] = $validator->validate('postscript');
     $searchFormQuery['og.memo'] = $validator->validate('memo');
     //退款时间
     $refundTimeStartStr = $validator->validate('refund_time_start');
     $refundTimeStart = Time::gmStrToTime($refundTimeStartStr) ?: null;
     $refundTimeEndStr = $validator->validate('refund_time_end');
     $refundTimeEnd = Time::gmStrToTime($refundTimeEndStr) ?: null;
     $searchFormQuery['og.refund_time'] = array($refundTimeStart, $refundTimeEnd);
     //完成时间
     $refundFinishTimeStartStr = $validator->validate('refund_finish_time_start');
     $refundFinishTimeStart = Time::gmStrToTime($refundFinishTimeStartStr) ?: null;
     $refundFinishTimeEndStr = $validator->validate('refund_finish_time_end');
     $refundFinishTimeEnd = Time::gmStrToTime($refundFinishTimeEndStr) ?: null;
     $searchFormQuery['og.refund_finish_time'] = array($refundFinishTimeStart, $refundFinishTimeEnd);
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 构造查询条件
     $searchParamArray = array();
     // 用户取消的订单商品我们就不再显示了
     $searchParamArray[] = array(QueryBuilder::buildNotInCondition('oi.order_status', array(OrderBasicService::OS_CANCELED, OrderBasicService::OS_INVALID), \PDO::PARAM_INT));
     if (1 == $shippingStatus) {
         // 1 未发货
         $searchParamArray[] = array('og.shipping_id = 0');
     } elseif (2 == $shippingStatus) {
         // 2 已发货
         $searchParamArray[] = array('og.shipping_id <> 0');
     } else {
         // do nothing
     }
     // 用户查询,目前支持 用户名、邮箱 查询
     $user_name = $validator->validate('user_name');
     $email = $validator->validate('email');
     if (!empty($user_name) || !empty($email)) {
         $userQuery = array();
         $userQuery['user_name'] = $user_name;
         $userQuery['email'] = $email;
         $userBasicService = new UserBasicService();
         $queryUserArray = $userBasicService->_fetchArray('users', 'user_id', QueryBuilder::buildQueryCondArray($userQuery), array('order' => 'user_id desc'), 0, 1000);
         unset($userBasicService);
         if (empty($queryUserArray)) {
             $this->addFlashMessage('搜索的用户不存在');
         } else {
             $userIdArray = array();
             foreach ($queryUserArray as $queryUser) {
                 $userIdArray[] = $queryUser['user_id'];
             }
             if (!empty($userIdArray)) {
                 $searchParamArray[] = array(QueryBuilder::buildInCondition('oi.user_id', $userIdArray, \PDO::PARAM_INT));
             }
             unset($userIdArray);
             unset($queryUserArray);
         }
     }
     // 表单查询
     $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery));
     // 使用哪个搜索模块
     $searchModule = SearchHelper::Module_OrderGoodsOrderInfo;
     // 查询订单列表
     $totalCount = SearchHelper::count($searchModule, $searchParamArray);
     if ($totalCount <= 0) {
         // 没订单,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Order/Refund/Search');
     }
     // 查询订单列表
     $orderGoodsArray = SearchHelper::search($searchModule, $searchFieldSelector, $searchParamArray, array(array('og.order_id', 'desc')), $pageNo * $pageSize, $pageSize);
     // 订单的支付状态显示
     foreach ($orderGoodsArray as &$orderGoodsItem) {
         $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']];
     }
     // 前面用了引用,这里一定要清除,防止影响后面的数据
     unset($orderGoodsItem);
     // 取得用户 id 列表
     $userIdArray = array();
     foreach ($orderGoodsArray as $orderGoodsItem) {
         $userIdArray[] = $orderGoodsItem['user_id'];
     }
     $userIdArray = array_unique($userIdArray);
     //取得用户信息
     $userBasicService = new UserBasicService();
     $userArray = $userBasicService->fetchUserArrayByUserIdArray($userIdArray);
     // 建立 user_id --> user 的反查表,方便快速查询
     $userIdToUserArray = array();
     foreach ($userArray as $user) {
         $userIdToUserArray[$user['user_id']] = $user;
     }
     // 放入用户信息
     foreach ($orderGoodsArray as &$orderGoodsItem) {
         if (isset($userIdToUserArray[$orderGoodsItem['user_id']])) {
             // 很老的订单,用户可能被删除了
             $orderGoodsItem['user_name'] = @$userIdToUserArray[$orderGoodsItem['user_id']]['user_name'];
             $orderGoodsItem['email'] = @$userIdToUserArray[$orderGoodsItem['user_id']]['email'];
         }
     }
     // 前面用了引用,这里一定要清除,防止影响后面的数据
     unset($orderGoodsItem);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('orderGoodsArray', $orderGoodsArray);
     out_display:
     $smarty->display('order_refund_search.tpl');
 }
Example #16
0
 /**
  * 重新加载用户信息
  */
 public static function reloadAuthUser()
 {
     $authUser = Auth::getAuthUser();
     if (empty($authUser) || !isset($authUser['user_id']) || empty($authUser['user_id'])) {
         return;
     }
     $basicUserService = new UserBasicService();
     $user = $basicUserService->loadUserById($authUser['user_id']);
     if ($user->isEmpty()) {
         return;
     }
     Auth::saveAuthUser($user->toArray());
 }
Example #17
0
 /**
  * QQ 登陆
  */
 public function get($f3)
 {
     global $logger;
     global $smarty;
     // 验证 state 参数,防止 csrf 攻击
     if ($_REQUEST['state'] != $f3->get('SESSION[qq_login_state]')) {
         $errorMessage = 'qq login state doest not match, GET[' . $f3->get('GET[state]') . '] SESSION[' . $f3->get('SESSION[qq_login_state]') . ']';
         $logger->addLogInfo(\Core\Log\Base::NOTICE, 'QQLOGIN', $errorMessage);
         goto out;
     }
     // 获取 access_token
     $callback = RouteHelper::makeUrl('/Thirdpart/QQAuth/Callback', null, false, true);
     $tokenUrl = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&" . "client_id=" . QQAuthPlugin::getOptionValue('qqauth_appid') . "&redirect_uri=" . urlencode($callback) . "&client_secret=" . QQAuthPlugin::getOptionValue('qqauth_appkey') . "&code=" . $_REQUEST["code"];
     $response = $this->get_url_contents($tokenUrl);
     if (strpos($response, "callback") !== false) {
         $lpos = strpos($response, "(");
         $rpos = strrpos($response, ")");
         $response = substr($response, $lpos + 1, $rpos - $lpos - 1);
         $msg = json_decode($response);
         if (isset($msg->error)) {
             $errorMessage = 'error [' . $msg->error . '] msg [' . $msg->error_description . ']';
             $logger->addLogInfo(\Core\Log\Base::NOTICE, 'QQLOGIN', $errorMessage);
             goto out;
         }
     }
     $params = array();
     parse_str($response, $params);
     $logger->addLogInfo(\Core\Log\Base::DEBUG, 'QQLOGIN', print_r($params, true));
     $accessToken = $params["access_token"];
     // 取得 OpenID
     $graphUrl = "https://graph.qq.com/oauth2.0/me?access_token=" . $accessToken;
     $response = $this->get_url_contents($graphUrl);
     if (strpos($response, "callback") !== false) {
         $lpos = strpos($response, "(");
         $rpos = strrpos($response, ")");
         $response = substr($response, $lpos + 1, $rpos - $lpos - 1);
     }
     $user = json_decode($response);
     if (isset($user->error)) {
         $errorMessage = 'error [' . $msg->error . '] msg [' . $msg->error_description . ']';
         goto out;
     }
     $openId = $user->openid;
     // 取得 userInfo
     $get_user_info = "https://graph.qq.com/user/get_user_info?" . "access_token=" . $accessToken . "&oauth_consumer_key=" . QQAuthPlugin::getOptionValue('qqauth_appid') . "&openid=" . $openId . "&format=json";
     $response = $this->get_url_contents($get_user_info);
     $qqUserInfo = json_decode($response, true);
     $sns_login = "******";
     // 用户登陆操作
     $userBasicService = new UserBasicService();
     $authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false);
     if ($authUser) {
         goto out_login_user;
     }
     // 之前没有登陆过,自动注册用户
     $authUser = $userBasicService->doAuthSnsUser($sns_login, $openId . '@qq.com', $openId . '@qq.com', true);
     $logger->addLogInfo(\Core\Log\Base::INFO, 'QQLOGIN', '注册QQ用户:' . print_r($qqUserInfo, true));
     out_login_user:
     AuthHelper::saveAuthUser($authUser->toArray(), 'qqlogin');
     // 设置用户名在网页显示
     ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, 'QQ用户:' . $qqUserInfo['nickname']);
     out:
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
 }
Example #18
0
 /**
  * 显示订单详情
  */
 public function Detail($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_goods_detail');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 取 order_goods
     $orderBasicService = new OrderBasicService();
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id);
     if ($orderGoods->isEmpty() || $orderGoods['order_id'] <= 0) {
         $this->addFlashMessage('订单ID非法');
         goto out_display;
     }
     // 转换状态显示
     $orderGoods['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoods['order_goods_status']];
     // 额外优惠允许的最大金额
     $allowExtraDiscount = $orderGoods['goods_price'] + $orderGoods['shipping_fee'] - $orderGoods['discount'];
     $maxExtraDiscount = round($allowExtraDiscount * $f3->get('sysConfig[max_order_goods_extra_discount_rate]'), 2);
     $maxExtraDiscount = max($maxExtraDiscount, $f3->get('sysConfig[max_order_goods_extra_discount_value]'));
     $maxExtraDiscount = min($maxExtraDiscount, $allowExtraDiscount);
     // 退款允许退的最大金额
     $maxRefund = $orderGoods['goods_price'] + $orderGoods['shipping_fee'] - $orderGoods['discount'] - $orderGoods['extra_discount'];
     // 取商品信息
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($orderGoods['goods_id'], 300);
     // 缓存 300 秒
     // 取 order_info
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']);
     if ($orderInfo->isEmpty()) {
         $this->addFlashMessage('订单ID非法');
         goto out_display;
     }
     $orderInfo['order_status_desc'] = OrderBasicService::$orderStatusDesc[$orderInfo['order_status']];
     $orderInfo['pay_status_desc'] = OrderBasicService::$payStatusDesc[$orderInfo['pay_status']];
     // 取订单来源信息
     $orderReferService = new OrderReferService();
     $orderRefer = $orderReferService->loadOrderReferByOrderId($orderInfo['order_id'], 300);
     //缓存5分钟
     // 取用户账户
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($orderInfo['user_id']);
     // 取得订单的操作日志
     $orderActionService = new OrderActionService();
     $orderLogArray = $orderActionService->fetchOrderLogArray($orderGoods['order_id'], $orderGoods['rec_id']);
     // 状态字段转换成可以显示的字符串
     foreach ($orderLogArray as &$orderLog) {
         $orderLog['order_status'] = OrderBasicService::$orderStatusDesc[$orderLog['order_status']];
         $orderLog['pay_status'] = OrderBasicService::$payStatusDesc[$orderLog['pay_status']];
         $orderLog['order_goods_status'] = OrderGoodsService::$orderGoodsStatusDesc[$orderLog['order_goods_status']];
         $orderLog['action_note'] = nl2br($orderLog['action_note']);
     }
     unset($orderLog);
     // 查询供货商信息
     $supplierUserService = new SupplierUserService();
     $supplierInfo = $supplierUserService->loadSupplierById($orderGoods['suppliers_id']);
     // 给模板赋值
     $smarty->assign('orderGoods', $orderGoods);
     $smarty->assign('goods', $goods);
     $smarty->assign('maxExtraDiscount', $maxExtraDiscount);
     $smarty->assign('maxRefund', $maxRefund);
     $smarty->assign('orderInfo', $orderInfo);
     $smarty->assign('orderRefer', $orderRefer);
     $smarty->assign('userInfo', $userInfo);
     $smarty->assign('supplierInfo', $supplierInfo);
     $smarty->assign('orderLogArray', $orderLogArray);
     out_display:
     $smarty->display('order_goods_detail.tpl');
 }
Example #19
0
 /**
  * 用户资金变动列表
  *
  * @param $f3
  */
 public function Money($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_user_money');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     //查询条件
     $formQuery = array();
     $formQuery['user_id'] = $validator->filter('ValidatorIntValue')->validate('user_id');
     $formQuery['admin_user_id'] = $validator->filter('ValidatorIntValue')->validate('admin_user_id');
     $formQuery['change_type'] = $validator->filter('ValidatorIntValue')->validate('change_type');
     $formQuery['change_desc'] = $validator->validate('change_desc');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 20;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 建立查询条件
     $condArray = QueryBuilder::buildQueryCondArray($formQuery);
     // 查询资金列表
     $accountLogService = new AccountLogService();
     $totalCount = $accountLogService->_countArray('account_log', $condArray);
     if ($totalCount <= 0) {
         // 没用户,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Account/User/Money');
     }
     // 资金列表
     $accountLogArray = $accountLogService->_fetchArray('account_log', '*', $condArray, array('order' => 'log_id desc'), $pageNo * $pageSize, $pageSize);
     // 取用户信息
     $userIdArray = array();
     foreach ($accountLogArray as $accountLogItem) {
         $userIdArray[] = $accountLogItem['user_id'];
     }
     $userIdArray = array_unique($userIdArray);
     $userBasicService = new UserBasicService();
     $userInfoArray = $userBasicService->fetchUserArrayByUserIdArray($userIdArray);
     //建立倒查表
     $userIdToUserInfoMap = array();
     foreach ($userInfoArray as $userInfo) {
         $userIdToUserInfoMap[$userInfo['user_id']] = $userInfo;
     }
     // 转换显示
     foreach ($accountLogArray as &$accountLogItem) {
         $accountLogItem['user_name'] = @$userIdToUserInfoMap[$accountLogItem['user_id']]['user_name'];
         $accountLogItem['change_type_desc'] = AccountLogService::$changeTypeDesc[$accountLogItem['change_type']];
     }
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('accountLogArray', $accountLogArray);
     out_display:
     $smarty->display('account_user_money.tpl');
 }