Example #1
0
 private function preparePage($goods_id, $pageNo)
 {
     global $smarty;
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = 10;
     // 每页显示 10 个
     // 查询条件
     $condArray = array();
     $condArray[] = array('goods_id = ?', $goods_id);
     $condArray[] = array('is_show = 1');
     $baseService = new BaseService();
     $totalCount = $baseService->_countArray('goods_comment', $condArray);
     if ($totalCount <= 0) {
         // 没数据,可以直接退出了
         return;
     }
     // 页数超过最大值
     if ($pageNo * $pageSize >= $totalCount) {
         return;
     }
     // 查询数据
     $goodsCommentArray = $baseService->_fetchArray('goods_comment', '*', $condArray, array('order' => 'comment_id desc'), $pageNo * $pageSize, $pageSize);
     // 给 smarty 赋值
     $smarty->assign('currentUrl', RouteHelper::makeUrl('/Ajax/GoodsComment', array('goods_id' => $goods_id)));
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('goodsCommentArray', $goodsCommentArray);
 }
Example #2
0
 /**
  * 360 一站通登陆
  */
 public function get($f3)
 {
     // 标准动态链接,不能伪静态地址
     $callback = RouteHelper::makeUrl('/Thirdpart/Dev360Auth/Callback', null, false, true, false);
     $params = array('client_id' => Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_key'), 'redirect_uri' => $callback, 'response_type' => 'code');
     $url = 'https://openapi.360.cn/oauth2/authorize?' . http_build_query($params);
     header("Location: {$url}");
 }
Example #3
0
/**
 * 用于生成系统的操作链接,符合系统 URL 调用规范
 *
 * 在模板中的使用方法 {{makeUrl controller='/User/Login' username='******' password='******' }}
 *
 * 必须要有 controller 用于指定控制器,其它参数可以没有
 *
 * */
function smarty_helper_function_make_url(array $paramArray, $smarty)
{
    $controller = isset($paramArray['controller']) ? $paramArray['controller'] : '/Error/E404';
    $static = isset($paramArray['static']) ? $paramArray['static'] : null;
    // 去除 controller, static ,其它都是控制器的参数
    unset($paramArray['controller']);
    unset($paramArray['static']);
    return RouteHelper::makeUrl($controller, $paramArray, false, false, $static);
}
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');
     // 手机输入,输入法经常无故添加空格,我们需要去除所有的空额,防止出错
     $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 #5
0
 public function pluginGetConfigureUrl($system)
 {
     // manage 系统可以配置这个插件
     if (PluginHelper::SYSTEM_MANAGE === $system) {
         return RouteHelper::makeUrl('/Thirdpart/EtaoFeed/Configure');
     }
     // 其它系统不需要配置
     return null;
 }
Example #6
0
 public function pluginGetConfigureUrl($system)
 {
     // manage 系统可以配置这个插件
     if (PluginHelper::SYSTEM_MANAGE === $system) {
         return RouteHelper::makeUrl('/Theme/Shop/Index');
     }
     // 其它系统不需要配置
     return null;
 }
Example #7
0
 /**
  * QQ 登陆
  */
 public function get($f3)
 {
     $callback = RouteHelper::makeUrl('/Thirdpart/QQAuth/Callback', null, false, true);
     $qqLoginState = md5(uniqid(rand(), true));
     // 防止 csrf 攻击
     $f3->set('SESSION[qq_login_state]', $qqLoginState);
     $loginUrl = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=" . QQAuthPlugin::getOptionValue('qqauth_appid') . "&redirect_uri=" . urlencode($callback) . "&state=" . $qqLoginState . "&scope=get_user_info";
     header("Location:{$loginUrl}");
 }
Example #8
0
 public function pluginGetConfigureUrl($system)
 {
     // manage 系统可以配置这个插件
     if (PluginHelper::SYSTEM_MANAGE === $system) {
         return RouteHelper::makeUrl('/Payment/Alipay/Configure');
     }
     // 其它系统不需要配置
     return null;
 }
Example #9
0
    public function get($f3)
    {
        global $smarty;
        $smartyCacheId = 'EtaoFeed|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '_\\' . __METHOD__);
        // 判断是否有缓存
        enableSmartyCache(true, 1200);
        // 缓存 20 分钟
        if ($smarty->isCached('empty.tpl', $smartyCacheId)) {
            goto out_display;
        }
        $currentStamp = Time::localTimeStr();
        $sellerId = EtaoFeedPlugin::getOptionValue('etaofeed_seller_id');
        $categoryUrl = RouteHelper::makeUrl('/Thirdpart/EtaoFeed/Category', null, false, true);
        $itemDir = RouteHelper::makeUrl('/Thirdpart/EtaoFeed/Item', null, false, true);
        $itemIdXmlList = '';
        // 处理 delete 的商品
        $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance();
        $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array(array('is_on_sale = 0'), array('update_time', '>=', EtaoFeedPlugin::getOptionValue('etaofeed_query_timestamp')), array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray()))));
        if ($totalGoodsCount <= 0) {
            goto query_update_goods;
        }
        $totalPageCount = ceil($totalGoodsCount / Item::$pageSize);
        for ($index = 0; $index < $totalPageCount; $index++) {
            $itemIdXmlList .= '<outer_id action="delete">1' . $index . '</outer_id>';
        }
        query_update_goods:
        // 处理修改过的商品
        $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array(array('is_on_sale = 1'), array('update_time', '>=', EtaoFeedPlugin::getOptionValue('etaofeed_query_timestamp')), array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray()))));
        if ($totalGoodsCount <= 0) {
            goto out_output;
        }
        $totalPageCount = ceil($totalGoodsCount / Item::$pageSize);
        for ($index = 0; $index < $totalPageCount; $index++) {
            $itemIdXmlList .= '<outer_id action="upload">2' . $index . '</outer_id>';
        }
        out_output:
        $apiXml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<root>
  <version>1.0</version>
  <modified>{$currentStamp}</modified>
  <seller_id>{$sellerId}</seller_id>
  <cat_url>{$categoryUrl}</cat_url>
  <dir>{$itemDir}/</dir>
  <item_ids>{$itemIdXmlList}</item_ids>
</root>
XML;
        $smarty->assign('outputContent', $apiXml);
        // 更新查询时间
        //EtaoFeedPlugin::saveOptionValue('etaofeed_query_timestamp', Time::gmTime());
        out_display:
        header('Content-Type:text/xml;charset=utf-8');
        header("Cache-Control: no-cache, must-revalidate");
        // HTTP/1.1 //查询信息
        $smarty->display('empty.tpl', $smartyCacheId);
    }
Example #10
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 #11
0
 /**
  * 更新或者新建一个快递公司
  *
  * @param $f3
  */
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_misc_express_edit');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $meta_id = $validator->digits()->validate('meta_id');
     $meta_id = $meta_id ?: 0;
     //  加载 快递信息
     $expressService = new ExpressService();
     $expressInfo = $expressService->loadMetaById($meta_id);
     if (Request::isRequestGet()) {
         goto out_assign;
     }
     // 安全性检查
     if ($meta_id > 0) {
         if ($expressInfo->isEmpty() || ExpressService::META_TYPE != $expressInfo->meta_type) {
             $this->addFlashMessage('非法ID[' . $meta_id . ']');
             goto out;
         }
     }
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     $inputArray = array();
     $inputArray['meta_type'] = ExpressService::META_TYPE;
     $inputArray['meta_name'] = $validator->required()->validate('meta_name');
     $inputArray['meta_ename'] = $validator->required()->validate('meta_ename');
     $inputArray['meta_sort_order'] = $validator->digits()->validate('meta_sort_order');
     $inputArray['meta_status'] = $validator->digits()->validate('meta_status');
     $inputArray['meta_desc'] = $validator->validate('meta_desc');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 保存
     $expressInfo->copyFrom($inputArray);
     $expressInfo->save();
     $this->addFlashMessage('快递信息保存成功');
     // POST 成功从这里退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Misc/Express/Edit', array('meta_id' => $expressInfo->meta_id), true));
     return;
     out_assign:
     $smarty->assign($expressInfo->toArray());
     out:
     $smarty->display('misc_express_edit.tpl');
 }
Example #12
0
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_article_category_edit');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $meta_id = $validator->digits()->validate('meta_id');
     $meta_id = $meta_id ?: 0;
     //  加载 分类信息
     $articleCategoryService = new ArticleCategoryService();
     $articleCategory = $articleCategoryService->loadArticleCategoryById($meta_id);
     if (Request::isRequestGet()) {
         goto out_assign;
     }
     // 安全性检查
     if ($meta_id > 0) {
         if ($articleCategory->isEmpty() || ArticleCategoryService::META_TYPE != $articleCategory->meta_type) {
             $this->addFlashMessage('非法ID[' . $meta_id . ']');
             goto out;
         }
     }
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     $inputArray = array();
     $inputArray['meta_type'] = ArticleCategoryService::META_TYPE;
     $inputArray['meta_name'] = $validator->required()->validate('meta_name');
     $inputArray['meta_sort_order'] = $validator->digits()->validate('meta_sort_order');
     $inputArray['meta_desc'] = $validator->validate('meta_desc');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 保存
     $articleCategory->copyFrom($inputArray);
     $articleCategory->save();
     $this->addFlashMessage('分类信息保存成功');
     // POST 成功从这里退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Article/Category/Edit', array('meta_id' => $articleCategory->meta_id), true));
     return;
     out_assign:
     $smarty->assign($articleCategory->toArray());
     out:
     $smarty->display('article_category_edit.tpl');
 }
Example #13
0
 /**
  * 采用 Magic 方法来实现,就不用每个支付方式都实现一次了
  */
 public function __call($method, $args)
 {
     global $f3;
     $payGateway = PaymentGatewayHelper::getPaymentGateway($method);
     $ret = $payGateway->doReturnUrl($f3);
     if ($ret) {
         $this->addFlashMessage('订单支付成功');
     } else {
         $this->addFlashMessage('订单支付失败,请联系在线客服');
     }
     $order_id = $payGateway->getOrderId();
     if (!empty($order_id)) {
         // 跳转到订单查看
         RouteHelper::reRoute($this, RouteHelper::makeUrl('/My/Order/Detail', array('order_id' => $order_id), true));
         return;
     }
     // 跳转到我的订单
     RouteHelper::reRoute($this, '/My/Order');
 }
Example #14
0
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail_list_goods;
     }
     unset($validator);
     // 用户提交的商品信息做验证
     $goodsPromoteInfo = $f3->get('POST.goods_promote');
     if (empty($goodsPromoteInfo)) {
         goto out_fail_validate;
     }
     //安全性处理
     unset($goodsPromoteInfo['promote_id']);
     $goodsPromoteInfo['goods_id'] = $goods_id;
     // 写入到数据库
     $goodsBasicService = new GoodsBasicService();
     $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id);
     $goodsPromote->copyFrom($goodsPromoteInfo);
     $goodsPromote->save();
     // 记录商品编辑日志
     $goodsLogContent = '360分类:' . $goodsPromote['360tuan_category'] . ',' . $goodsPromote['360tuan_category_end'] . "\n" . "360排序:" . $goodsPromote['360tuan_sort_order'];
     $authAdminUser = AuthHelper::getAuthUser();
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($goods_id, $authAdminUser['user_id'], $authAdminUser['user_name'], static::$goodsLogDesc, $goodsLogContent);
     // 成功,显示商品详情
     $this->addFlashMessage('商品推广渠道保存成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Promote', array('goods_id' => $goods_id), true));
     return;
     // 参数验证失败
     out_fail_validate:
     $smarty->display('goods_edit_promote.tpl');
     return;
     out_fail_list_goods:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
Example #15
0
    private function getGoodsItemXml($index, $goodsItem, $goodsIdToGalleryArray)
    {
        global $f3;
        $siteName = $f3->get('sysConfig[site_name]');
        $goodsViewUrl = RouteHelper::makeUrl('/Goods/View', array('goods_id' => $goodsItem['goods_id']), false, true);
        $goodsViewUrl = RouteHelper::addParam($goodsViewUrl, array('utm_source' => 'baidutuan'));
        $goodsImageUrl = '';
        if (isset($goodsIdToGalleryArray[$goodsItem['goods_id']])) {
            $goodsImageUrl = RouteHelper::makeImageUrl($goodsIdToGalleryArray[$goodsItem['goods_id']][0]['img_url']);
        }
        // 购买数量
        $bought = $goodsItem['virtual_buy_number'] + $goodsItem['user_pay_number'];
        // 转换价格显示
        $goodsItem['market_price'] = Money::toSmartyDisplay($goodsItem['market_price']);
        $goodsItem['shop_price'] = Money::toSmartyDisplay($goodsItem['shop_price']);
        $rebate = 0;
        if ($goodsItem['market_price'] > 0) {
            $rebate = 10 * round($goodsItem['shop_price'] / $goodsItem['market_price'], 2);
        }
        $today = strtotime(date('Ymd'));
        $twoDaysLater = $today + 86400 * 2;
        $xmlitem = <<<XMLITEM
\t<url>
\t    <loc><![CDATA[{$goodsViewUrl}]]></loc>
\t    <data><display>
\t\t<website><![CDATA[{$siteName}]]></website>
\t\t<siteurl><![CDATA[{$this->siteUrl}]]></siteurl>
\t\t<city>全国</city>
\t\t<title><![CDATA[{$goodsItem['goods_name']}]]></title>
\t\t<image><![CDATA[{$goodsImageUrl}]]></image>
\t\t<startTime>{$today}</startTime>
\t\t<endTime>{$twoDaysLater}</endTime>
        <value>{$goodsItem['market_price']}</value>
        <price>{$goodsItem['shop_price']}</price>
        <rebate>{$rebate}</rebate>
        <bought>{$bought}</bought>
        </display></data>
        </url>
XMLITEM;
        return $xmlitem;
    }
Example #16
0
 /**
  * 设置订单的信息,注意:这个方法里面糅合了很多功能,通过 action="xxxx" 来区分
  *
  * @param $f3
  */
 public function Update($f3)
 {
     // 验证 action
     $validator = new Validator($f3->get('GET'));
     $action = $validator->required()->oneOf(array('set_extra_discount', 'set_suppliers_price', 'set_shipping_no', 'set_memo', 'set_refund', 'set_extra_refund'), '非法操作')->validate('action');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 验证提交上来的参数
     $validator = new Validator($f3->get('POST'));
     $updateValueArray = array();
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     // 针对不同的 action  做不同的验证
     switch ($action) {
         case 'set_extra_discount':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_extra_discount');
             $updateValueArray['extra_discount'] = Money::toStorage($validator->validate('extra_discount'));
             $updateValueArray['extra_discount_note'] = $validator->required()->validate('extra_discount_note');
             break;
         case 'set_suppliers_price':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_suppliers_price');
             $updateValueArray['suppliers_price'] = Money::toStorage($validator->validate('suppliers_price'));
             $updateValueArray['suppliers_shipping_fee'] = Money::toStorage($validator->validate('suppliers_shipping_fee'));
             break;
         case 'set_shipping_no':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_shipping_no');
             $updateValueArray['shipping_id'] = $validator->digits()->min(1)->validate('shipping_id');
             $updateValueArray['shipping_no'] = $validator->validate('shipping_no');
             break;
         case 'set_memo':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_memo');
             $updateValueArray['memo'] = $validator->validate('memo');
             break;
         case 'set_refund':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_refund');
             $updateValueArray['refund'] = Money::toStorage($validator->validate('refund'));
             $updateValueArray['refund_note'] = $validator->required()->validate('refund_note');
             $updateValueArray['refund_time'] = Time::gmTime();
             $updateValueArray['suppliers_refund'] = Money::toStorage($validator->validate('suppliers_refund'));
             $updateValueArray['suppliers_refund_note'] = $validator->required()->validate('suppliers_refund_note');
             break;
         case 'set_extra_refund':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_extra_refund');
             $updateValueArray['extra_refund'] = Money::toStorage($validator->validate('extra_refund'));
             $updateValueArray['extra_refund_note'] = $validator->required()->validate('extra_refund_note');
             $updateValueArray['extra_refund_time'] = Time::gmTime();
             break;
         default:
             // 非法的 action
             goto out;
     }
     if (!$this->validate($validator)) {
         goto out;
     }
     // 取 order_goods
     $orderBasicService = new OrderBasicService();
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id);
     if ($orderGoods->isEmpty()) {
         $this->addFlashMessage('非法订单');
         goto out_fail;
     }
     // 取得 orderInfo
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']);
     // 针对不同的 action  做额外不同的工作
     $action_note = '';
     switch ($action) {
         case 'set_extra_discount':
             // 商品只有是未付款状态才可以设置额外优惠
             if (OrderGoodsService::OGS_UNPAY != $orderGoods['order_goods_status']) {
                 $this->addFlashMessage('只有未付款订单才可以给予额外优惠');
                 goto out;
             }
             // 额外优惠允许的最大金额
             $allowExtraDiscount = $orderGoods['goods_price'] + $orderGoods['shipping_fee'] - $orderGoods['discount'];
             $maxExtraDiscount = intval($allowExtraDiscount * $f3->get('sysConfig[max_order_goods_extra_discount_rate]'));
             $maxExtraDiscount = max($maxExtraDiscount, $f3->get('sysConfig[max_order_goods_extra_discount_value]'));
             $maxExtraDiscount = min($maxExtraDiscount, $allowExtraDiscount);
             // 额外优惠不能超过商品本身的金额
             if ($updateValueArray['extra_discount'] > $maxExtraDiscount) {
                 $this->addFlashMessage('额外优惠不能超过商品总金额 ' . $maxExtraDiscount);
                 goto out;
             }
             // 设置额外余额,需要重新计算 order_info 中的值
             $diffDiscount = 0;
             if ($orderGoods->extra_discount != $updateValueArray['extra_discount']) {
                 $diffDiscount = $updateValueArray['extra_discount'] - $orderGoods->extra_discount;
             }
             $orderInfo->extra_discount += $diffDiscount;
             $orderInfo->order_amount -= $diffDiscount;
             $action_note .= '额外优惠:' . Money::toSmartyDisplay($updateValueArray['extra_discount']) . ",";
             $action_note .= '优惠说明:' . $updateValueArray['extra_discount_note'] . "\n";
             break;
         case 'set_suppliers_price':
             $action_note .= '供货价:' . Money::toSmartyDisplay($updateValueArray['suppliers_price']) . ",";
             $action_note .= '供货快递费:' . Money::toSmartyDisplay($updateValueArray['suppliers_shipping_fee']) . "\n";
             break;
         case 'set_shipping_no':
             if ($updateValueArray['shipping_id'] > 0) {
                 //取得快递信息
                 $expressService = new ExpressService();
                 $expressInfo = $expressService->loadMetaById($updateValueArray['shipping_id']);
                 if ($expressInfo->isEmpty() || ExpressService::META_TYPE != $expressInfo['meta_type']) {
                     $this->addFlashMessage('快递ID非法');
                     goto out;
                 }
                 $updateValueArray['shipping_name'] = $expressInfo['meta_name'];
             } else {
                 $updateValueArray['shipping_name'] = null;
             }
             $action_note .= '快递公司:' . $updateValueArray['shipping_name'] . "\n";
             $action_note .= '快递单号:' . $updateValueArray['shipping_no'] . "\n";
             break;
         case 'set_memo':
             $action_note .= '客服备注:' . $updateValueArray['memo'] . "\n";
             break;
         case 'set_refund':
             // 检查订单状态
             if (!in_array($orderGoods['order_goods_status'], array(OrderGoodsService::OGS_PAY, OrderGoodsService::OGS_ASKREFUND))) {
                 $this->addFlashMessage('订单状态非法,不能退款');
                 goto out;
             }
             if ($orderGoods['settle_id'] > 0) {
                 $this->addFlashMessage('已经结算的订单不能退款');
                 goto out;
             }
             // 订单设置为 申请退款
             $updateValueArray['order_goods_status'] = OrderGoodsService::OGS_ASKREFUND;
             // 同步更新 order_info 中的 refund 字段
             $diffRefund = 0;
             if ($orderGoods->refund != $updateValueArray['refund']) {
                 $diffRefund = $updateValueArray['refund'] - $orderGoods->refund;
             }
             $orderInfo->refund += $diffRefund;
             // 检查金额,对一些常见错误提出警告
             if (0 == $updateValueArray['refund']) {
                 $this->addFlashMessage('警告:你确定给顾客退款金额设置为 ' . Money::toSmartyDisplay($updateValueArray['refund']) . ' ?');
             }
             if (0 == $updateValueArray['suppliers_refund']) {
                 $this->addFlashMessage('警告:你确定供货商给我们退款金额为 ' . Money::toSmartyDisplay($updateValueArray['refund']) . ' ?');
             }
             if ($updateValueArray['refund'] <= $updateValueArray['suppliers_refund']) {
                 $this->addFlashMessage('警告:给顾客退款金额 &lt;= 供货商给我们的退款金额');
             }
             // 日志信息记录
             $action_note .= '申请退款' . "\n";
             $action_note .= '顾客金额:' . Money::toSmartyDisplay($updateValueArray['refund']) . ",";
             $action_note .= '顾客说明:' . $updateValueArray['refund_note'] . "\n";
             $action_note .= '供货商金额:' . Money::toSmartyDisplay($updateValueArray['suppliers_refund']) . ",";
             $action_note .= '供货商说明:' . $updateValueArray['suppliers_refund_note'] . "\n";
             break;
         case 'set_extra_refund':
             // 检查订单状态
             if (OrderGoodsService::OGS_UNPAY == $orderGoods['order_goods_status']) {
                 $this->addFlashMessage('订单状态非法,不能退款');
                 goto out;
             }
             $action_note .= '额外退款:' . Money::toSmartyDisplay($updateValueArray['extra_refund']) . ",";
             $action_note .= '退款说明:' . $updateValueArray['extra_refund_note'] . "\n";
             break;
         default:
             // 非法的 action
             goto out;
     }
     // 更新订单信息
     $orderGoods->copyFrom($updateValueArray);
     $orderGoods->update_time = Time::gmTime();
     $orderGoods->save();
     // 更新 order_info 的 update_time 字段
     $orderInfo->update_time = Time::gmTime();
     $orderInfo->save();
     // 添加订单操作日志
     $authAdminUser = AuthHelper::getAuthUser();
     $orderActionService = new OrderActionService();
     $orderActionService->logOrderAction($orderGoods['order_id'], $orderGoods['rec_id'], $orderInfo['order_status'], $orderInfo['pay_status'], $orderGoods['order_goods_status'], $action_note, $authAdminUser['user_name'], 0, $orderInfo['shipping_status']);
     $this->addFlashMessage('订单信息保存成功');
     out:
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Order/Goods/Detail', array('rec_id' => $rec_id), true));
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Order/Goods/Search', false);
 }
Example #17
0
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_get');
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $goods_id = $validator->required('商品ID不能为空')->validate('goods_id');
     $action = $validator->required('操作不能为空')->validate('action');
     //任务时间
     $taskTimeStr = $validator->required('必须选择时间')->validate('task_time');
     $taskTime = Time::gmStrToTime($taskTimeStr) ?: null;
     if (!$this->validate($validator)) {
         goto out;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 添加 Cron 任务
     CronHelper::addCronTask($authAdminUser['user_name'] . '[' . $authAdminUser['user_id'] . ']', GoodsCronTask::$task_name, @GoodsCronTask::$actionDesc[$action] . '[' . $goods_id . ']', '\\Core\\Cron\\GoodsCronTask', $taskTime, $f3->get('POST'), $goods_id);
     $this->addFlashMessage('成功添加定时任务');
     out:
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Cron', array('goods_id' => $goods_id), true));
 }
Example #18
0
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     global $smarty;
     $isCreateGoods = false;
     // 是否是创建新商品
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->digits()->filter('ValidatorIntValue')->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail_list_goods;
     }
     unset($validator);
     // 用户提交的商品信息做验证
     $goods = $f3->get('POST[goods]');
     if (empty($goods)) {
         goto out_fail_validate;
     }
     $validator = new Validator($goods);
     $goodsInfo = array();
     //表单数据验证、过滤
     $goodsInfo['goods_name'] = $validator->required('商品名不能为空')->validate('goods_name');
     $goodsInfo['goods_name_short'] = $validator->required('商品短标题不能为空')->validate('goods_name_short');
     $goodsInfo['keywords'] = $validator->validate('keywords');
     $goodsInfo['seo_title'] = $validator->validate('seo_title');
     $goodsInfo['seo_keyword'] = $validator->validate('seo_keyword');
     $goodsInfo['seo_description'] = $validator->validate('seo_description');
     $goodsInfo['goods_sn'] = $validator->validate('goods_sn');
     $goodsInfo['warehouse'] = $validator->validate('warehouse');
     $goodsInfo['shelf'] = $validator->validate('shelf');
     $goodsInfo['cat_id'] = $validator->required('商品分类不能为空')->filter('ValidatorIntValue')->validate('cat_id');
     // 记录管理员
     $authAdminUser = AuthHelper::getAuthUser();
     $goodsInfo['admin_user_id'] = $validator->filter('ValidatorIntValue')->validate('admin_user_id');
     // 如果没有选择管理员,就用当前管理员
     if (empty($goodsInfo['admin_user_id'])) {
         $goodsInfo['admin_user_id'] = $authAdminUser['user_id'];
         $goodsInfo['admin_user_name'] = $authAdminUser['user_name'];
     } else {
         $adminUserService = new AdminUserService();
         $adminUser = $adminUserService->loadAdminById($goodsInfo['admin_user_id']);
         if ($adminUser->isEmpty()) {
             $this->addFlashMessage('管理员[' . $goodsInfo['admin_user_id'] . ']不存在');
             goto out_fail_validate;
         }
         $goodsInfo['admin_user_name'] = $adminUser['user_name'];
         unset($adminUser);
         unset($adminUserService);
     }
     $goodsInfo['brand_id'] = $validator->filter('ValidatorIntValue')->validate('brand_id');
     $goodsInfo['suppliers_id'] = $validator->required('供货商不能为空')->filter('ValidatorIntValue')->validate('suppliers_id');
     $goodsInfo['is_alone_sale'] = $validator->filter('ValidatorIntValue')->validate('is_alone_sale');
     $goodsInfo['is_best'] = $validator->filter('ValidatorIntValue')->validate('is_best');
     $goodsInfo['is_new'] = $validator->filter('ValidatorIntValue')->validate('is_new');
     $goodsInfo['is_hot'] = $validator->filter('ValidatorIntValue')->validate('is_hot');
     $goodsInfo['is_on_sale'] = $validator->filter('ValidatorIntValue')->validate('is_on_sale');
     $goodsInfo['market_price'] = Money::toStorage($validator->validate('market_price'));
     $goodsInfo['shop_price'] = Money::toStorage($validator->validate('shop_price'));
     $goodsInfo['shipping_fee'] = Money::toStorage($validator->validate('shipping_fee'));
     $goodsInfo['shipping_free_number'] = $validator->validate('shipping_free_number');
     $goodsInfo['goods_number'] = abs($validator->filter('ValidatorIntValue')->validate('goods_number'));
     $goodsInfo['virtual_buy_number'] = $validator->filter('ValidatorIntValue')->validate('virtual_buy_number');
     $goodsInfo['suppliers_price'] = Money::toStorage($validator->validate('suppliers_price'));
     $goodsInfo['suppliers_shipping_fee'] = Money::toStorage($validator->validate('suppliers_shipping_fee'));
     $goodsInfo['sort_order'] = $validator->validate('sort_order');
     $goodsInfo['warn_number'] = $validator->filter('ValidatorIntValue')->validate('warn_number');
     $goodsInfo['goods_brief'] = @$goods['goods_brief'];
     //不需要过滤 html
     $goodsInfo['goods_notice'] = @$goods['goods_notice'];
     //不需要过滤 html
     $goodsInfo['goods_after_service'] = @$goods['goods_after_service'];
     //不需要过滤 html
     $goodsInfo['seller_note'] = $validator->validate('seller_note');
     $goodsInfo['system_tag_list'] = Utils::makeTagString(@$goods['system_tag_list']);
     // 生成系统的 tag string
     $goodsInfo['update_time'] = Time::gmTime();
     // 商品的更新时间
     $goodsInfo['goods_desc'] = @$goods['goods_desc'];
     //不需要过滤 html
     if (!$this->validate($validator)) {
         goto out_fail_validate;
     }
     // 某些时候,我们不允许编辑直接粘贴别人网站的图片上来,所以我们需要过滤图片的域名
     $goodsDescAllowImageDomainArray = $f3->get('sysConfig[goods_desc_allow_image_domain_array]');
     if ($goodsDescAllowImageDomainArray && is_array($goodsDescAllowImageDomainArray) && !empty($goodsDescAllowImageDomainArray)) {
         $patternMatch = array();
         preg_match_all('/<img(.*?)src="(.*?)"(.*?)\\/?>/', $goodsInfo['goods_desc'], $patternMatch, PREG_SET_ORDER);
         // 检查每一个图片
         foreach ($patternMatch as $matchItem) {
             $imageUrl = $matchItem[2];
             $urlInfo = parse_url($imageUrl);
             if (!in_array(@$urlInfo['host'], $goodsDescAllowImageDomainArray)) {
                 $this->addFlashMessage('商品详情非法图片 ' . $imageUrl);
                 goto out_fail_validate;
             }
         }
     }
     // 写入到数据库
     unset($goods);
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     // 判断是否是新建商品
     $isCreateGoods = $goods->isEmpty();
     if ($isCreateGoods) {
         // 权限检查
         $this->requirePrivilege('manage_goods_create');
         $goodsInfo['add_time'] = Time::gmTime();
     }
     $post_goods_sn = $validator->validate('goods_sn');
     if ($isCreateGoods && !Utils::isBlank($post_goods_sn)) {
         $goodsInfo['goods_sn'] = $post_goods_sn;
     }
     $goods->copyFrom($goodsInfo);
     $goods->save();
     // 新商品需要自动生成 goods_sn
     if ($isCreateGoods && Utils::isBlank($post_goods_sn)) {
         $goods->goods_sn = $f3->get('sysConfig[goods_sn_prefix]') . $goods['goods_id'];
         $goods->save();
     }
     // 取得供货商信息
     $supplierName = '';
     if (!empty($goods['suppliers_id'])) {
         $supplierUserService = new SupplierUserService();
         $supplierInfo = $supplierUserService->loadSupplierById($goods['suppliers_id']);
         if (!$supplierInfo->isEmpty()) {
             $supplierName = $supplierInfo['suppliers_name'];
         }
     }
     // 记录商品编辑日志
     $goodsLogContent = '商品编辑:[' . $goods['admin_user_id'] . ']' . $goods['admin_user_name'] . "\n" . '上架状态:' . ($goods['is_on_sale'] > 0 ? '已上架' : '未上架') . "\n" . '销售价:' . Money::toSmartyDisplay($goods['shop_price']) . '  供货价:' . Money::toSmartyDisplay($goods['suppliers_price']) . "\n" . '快递费:' . Money::toSmartyDisplay($goods['shipping_fee']) . '  供货快递费:' . Money::toSmartyDisplay($goods['suppliers_shipping_fee']) . "\n" . ($goods['shipping_free_number'] > 0 ? '' . $goods['shipping_free_number'] . "件免邮\n" : '') . '商品排序:' . $goods['sort_order'] . "\n" . '系统Tag:' . $goods['system_tag_list'] . "\n" . '供货商:[' . $goods['suppliers_id'] . ']' . $supplierName;
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($goods['goods_id'], $authAdminUser['user_id'], $authAdminUser['user_name'], $isCreateGoods ? '新建商品' : static::$goodsLogDesc, $goodsLogContent);
     // 成功,显示商品详情
     $this->addFlashMessage('商品信息保存成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods->goods_id);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Edit', array('goods_id' => $goods->goods_id), true));
     return;
     // 参数验证失败
     out_fail_validate:
     if (!$goods_id) {
         // 新建商品验证失败
         RouteHelper::reRoute($this, '/Goods/Create');
         return;
     }
     $smarty->assign('goods', $goodsInfo);
     $smarty->display('goods_edit_edit.tpl');
     return;
     out_fail_list_goods:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
Example #19
0
 /**
  * 要求某个权限才能执行
  *
  * @param string $needPrivilege
  * @param bool   $isAjax 是否是 ajax 请求
  *
  */
 protected function requirePrivilege($needPrivilege, $isAjax = false)
 {
     if (!$this->hasPrivilege($needPrivilege)) {
         goto out_fail;
     }
     return;
     // 成功从这里返回
     out_fail:
     // 失败,reroute 到错误页面
     if ($isAjax) {
         $needPrivilegeName = $needPrivilege;
         $metaPrivilegeService = new MetaPrivilegeService();
         $privilege = $metaPrivilegeService->loadPrivilegeItem($needPrivilege, 600);
         //缓存 10 分钟
         if (!$privilege->isEmpty()) {
             $needPrivilegeName = $privilege['meta_name'] ?: $needPrivilegeName;
         }
         Ajax::header();
         echo Ajax::buildResult(-1, '没有权限:' . $needPrivilegeName, null);
         die;
     }
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Error/Privilege', array('privilege' => $needPrivilege), true));
 }
Example #20
0
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     unset($validator);
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     if ($goods->isEmpty()) {
         $this->addFlashMessage('商品ID[' . $goods_id . ']非法');
         goto out_fail;
     }
     // 商品类型属性做验证
     $validator = new Validator($f3->get('POST'));
     //表单数据验证、过滤
     $type_id = $validator->digits()->min(1)->validate('type_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $goodsTypeService = new GoodsTypeService();
     // 商品类型发生了变化,清除所有旧的属性
     if ($goods['type_id'] != $type_id) {
         $goodsTypeService->removeAllGoodsAttrItemValue($goods_id);
         $goods->type_id = $type_id;
         $goods->save();
     }
     // 获得属性值列表
     $goodsAttrValueArray = $f3->get('POST[goodsAttrValueArray]');
     if (!empty($goodsAttrValueArray)) {
         foreach ($goodsAttrValueArray as $goodsAttrValueInfo) {
             $goodsAttrValueInfo = @json_decode($goodsAttrValueInfo, true);
             if (empty($goodsAttrValueInfo)) {
                 continue;
             }
             // 更新属性值
             $goodsAttrValue = $goodsTypeService->loadGoodsAttrById(intval($goodsAttrValueInfo['goods_attr_id']));
             $goodsAttrValue->goods_id = $goods_id;
             $goodsAttrValue->attr_item_id = $goodsAttrValueInfo['meta_id'];
             $goodsAttrValue->attr_item_value = $goodsAttrValueInfo['attr_item_value'];
             $goodsAttrValue->save();
         }
     }
     // 成功,显示商品详情
     $this->addFlashMessage('商品类型属性保存成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Type', array('goods_id' => $goods_id), true));
     return;
     out_fail:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
Example #21
0
    private function getGoodsItemXml($goodsItem, $goodsIdToGalleryArray)
    {
        // 截取描述,不能太长
        $goodsItem['goods_desc'] = mb_substr($goodsItem['goods_name'] . ' ' . strip_tags($goodsItem['goods_desc']), 0, 1000);
        // 截取商品标题,标题不能太长了
        $goodsItem['goods_name'] = mb_substr($goodsItem['goods_name'], 0, 60);
        $goodsViewUrl = RouteHelper::makeUrl('/Goods/View', array('goods_id' => $goodsItem['goods_id']), false, true);
        // 增加额外的链接参数
        $goodsViewUrl .= EtaoFeedPlugin::getOptionValue('etaofeed_goods_url_extra_param');
        // 处理图片列表
        $goodsGalleryArray = array();
        if (array_key_exists($goodsItem['goods_id'], $goodsIdToGalleryArray)) {
            $goodsGalleryArray = $goodsIdToGalleryArray[$goodsItem['goods_id']];
        }
        $goodsItemImageXml = '';
        if (!empty($goodsGalleryArray)) {
            $goodsItemImageXml = '<image is_default="true">' . RouteHelper::makeImageUrl($goodsGalleryArray[0]['img_original']) . '</image>';
            array_shift($goodsGalleryArray);
            // 去掉第一个图片
            $goodsItemImageXml .= '<more_images>';
            // 图片集中的图片
            foreach ($goodsGalleryArray as $goodsGalleryItem) {
                $goodsItemImageXml .= '<img>' . RouteHelper::makeImageUrl($goodsGalleryItem['img_original']) . '</img>';
            }
            $goodsItemImageXml .= '</more_images>';
        }
        // 转换数据显示
        $goodsItem['shop_price'] = Money::toSmartyDisplay($goodsItem['shop_price']);
        $goodsItem['shipping_fee'] = Money::toSmartyDisplay($goodsItem['shipping_fee']);
        $goodsItemXml = <<<XML
<item>
\t<seller_id><![CDATA[{$this->sellerId}]]></seller_id>
\t<outer_id>{$goodsItem['goods_id']}</outer_id>
\t<title><![CDATA[{$goodsItem['goods_name']}]]></title>
\t<product_id>{$goodsItem['goods_sn']}</product_id>
\t<type>fixed</type>
\t<available>1</available>
\t<price>{$goodsItem['shop_price']}</price>
\t<desc><![CDATA[{$goodsItem['goods_desc']}]]></desc>
\t{$goodsItemImageXml}
\t<scids>{$goodsItem['cat_id']}</scids>
\t<post_fee>{$goodsItem['shipping_fee']}</post_fee>
\t<href><![CDATA[{$goodsViewUrl}]]></href>
</item>
XML;
        return $goodsItemXml;
    }
Example #22
0
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_brand_listbrand');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $brand_id = $validator->digits()->min(1)->validate('brand_id');
     if (!$brand_id) {
         $brand_id = 0;
     }
     $goodsBrandService = new GoodsBrandService();
     $goodsBrand = $goodsBrandService->loadBrandById($brand_id);
     if (!$f3->get('POST')) {
         // 没有 post ,只是普通的显示
         goto out_display;
     }
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     $goodsBrand->brand_name = $validator->required()->validate('brand_name');
     $goodsBrand->brand_desc = $validator->required()->validate('brand_desc');
     $goodsBrand->brand_logo = $validator->validate('brand_logo');
     $goodsBrand->is_custom = $validator->digits()->filter('ValidatorIntValue')->validate('is_custom');
     $goodsBrand->custom_page = $f3->get('POST[custom_page]');
     if (!$this->validate($validator)) {
         goto out_display;
     }
     $goodsBrand->save();
     if (0 == $brand_id) {
         $this->addFlashMessage('新建商品品牌成功');
     } else {
         $this->addFlashMessage('更新商品品牌成功');
     }
     // 记录管理员日志
     AdminLog::logAdminOperate('goods.brand.edit', '编辑品牌', $goodsBrand->brand_name);
     out_display:
     // 新建的品牌,reRoute 到编辑页面
     if (!$brand_id) {
         RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Brand/Edit', array('brand_id' => $goodsBrand->brand_id), true));
     }
     //给 smarty 模板赋值
     $smarty->assign($goodsBrand->toArray());
     $smarty->display('goods_brand_edit.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Goods/Brand/ListBrand');
 }
Example #23
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 #24
0
 public function post($f3)
 {
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Category', $_POST, false, true));
 }
Example #25
0
 /**
  * 从网络抓取图片进入相册
  *
  * @param $f3
  */
 public function Fetch($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     $imageUrl = $validator->required('图片地址不能为空')->validate('imageUrl');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 抓取图片,伪装成浏览器防止被某些服务器阻止
     $webInstance = \Web::instance();
     $webInstance->engine('curl');
     $request = $webInstance->request($imageUrl, array('user_agent' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729)'));
     if (!$request || isset($request['http_code']) && 200 != $request['http_code']) {
         $this->addFlashMessage('抓取失败,请检查你的抓取地址');
         goto out;
     }
     // 把图片保存到 Storage 中
     $cloudStorage = CloudHelper::getCloudModule(CloudHelper::CLOUD_MODULE_STORAGE);
     // 图片文件先保存到临时文件中
     $tempSrcFilePath = $cloudStorage->getTempFilePath();
     file_put_contents($tempSrcFilePath, $request['body']);
     // 上传目录
     $dataPathRoot = $f3->get('sysConfig[data_path_root]');
     $saveFilePathRelative = 'upload/image/' . date("Y/m/d") . '/' . date("YmdHis") . '_' . rand(1, 10000) . strtolower(strrchr($imageUrl, '.'));
     // 文件上传到 Storage
     if (!$cloudStorage->moveFileToStorage($dataPathRoot, $saveFilePathRelative, $tempSrcFilePath)) {
         $this->addFlashMessage('保存文件到存储失败,失败');
         goto out;
     }
     @unlink($tempSrcFilePath);
     // 保存 goods_gallery 记录
     $imageOriginalFileRelativeName = $saveFilePathRelative;
     $pathInfoArray = pathinfo($imageOriginalFileRelativeName);
     //生成头图
     $imageFileRelativeName = $pathInfoArray['dirname'] . '/' . $pathInfoArray['filename'] . '_' . $f3->get('sysConfig[image_width]') . 'x' . $f3->get('sysConfig[image_height]') . '.jpg';
     StorageImageHelper::resizeImage($dataPathRoot, $imageOriginalFileRelativeName, $imageFileRelativeName, $f3->get('sysConfig[image_width]'), $f3->get('sysConfig[image_height]'));
     //生成缩略图
     $imageThumbFileRelativeName = $pathInfoArray['dirname'] . '/' . $pathInfoArray['filename'] . '_' . $f3->get('sysConfig[image_thumb_width]') . 'x' . $f3->get('sysConfig[image_thumb_height]') . '.jpg';
     StorageImageHelper::resizeImage($dataPathRoot, $imageOriginalFileRelativeName, $imageThumbFileRelativeName, $f3->get('sysConfig[image_thumb_width]'), $f3->get('sysConfig[image_thumb_height]'));
     //保存 goods_gallery 记录
     $goodsGalleryService = new GoodsGalleryService();
     // ID 为0,返回一个新建的 dataMapper
     $goodsGallery = $goodsGalleryService->_loadById('goods_gallery', 'img_id=?', 0);
     $goodsGallery->goods_id = $goods_id;
     $goodsGallery->img_desc = '网络下载图片';
     $goodsGallery->img_original = $imageOriginalFileRelativeName;
     $goodsGallery->img_url = $imageFileRelativeName;
     $goodsGallery->thumb_url = $imageThumbFileRelativeName;
     $goodsGallery->save();
     $this->addFlashMessage('抓取图片成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goodsGallery->goods_id);
     out:
     // 释放资源
     unset($request);
     unset($webInstance);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Gallery', array('goods_id' => $goods_id), true));
     return;
     // 成功从这里返回
     out_fail:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
Example #26
0
    /**
     * 输出文章的列表
     *
     * @param $f3
     * @param $pageNo
     */
    public function outputArticleViewListXml($f3, $pageNo)
    {
        global $smarty;
        // 缓存 1 小时
        enableSmartyCache(true, 3600, \Smarty::CACHING_LIFETIME_CURRENT);
        $smartyCacheId = 'Api|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__ . '\\' . $pageNo);
        // 判断是否有缓存
        if ($smarty->isCached('empty.tpl', $smartyCacheId)) {
            goto out_display;
        }
        // 查询商品
        $articleArray = SearchHelper::search(SearchHelper::Module_Article, 'a.article_id, a.update_time', QueryBuilder::buildSearchParamArray(array('a.is_open' => 1)), array(array('a.article_id', 'desc')), $pageNo * $this->pageSize, $this->pageSize);
        $xmlItems = '';
        if (empty($articleArray)) {
            goto out;
        }
        foreach ($articleArray as $articleItem) {
            $articleViewUrl = RouteHelper::makeUrl('/Article/View', array('article_id' => $articleItem['article_id']), false, true);
            $articleLastModTime = date('Y-m-d\\TH:i:sP', Time::gmTimeToLocalTime($articleItem['update_time']));
            $xmlItems .= <<<XMLITEM
\t    <url>
\t    <loc><![CDATA[{$articleViewUrl}]]></loc>
\t    <lastmod>{$articleLastModTime}</lastmod>
\t    <changefreq>always</changefreq>
        </url>
XMLITEM;
        }
        out:
        $apiXml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" >
\t{$xmlItems}
</urlset>
XML;
        unset($xmlItems);
        $smarty->assign('outputContent', $apiXml);
        out_display:
        header('Content-Type:text/xml;charset=utf-8');
        header("Cache-Control: no-cache, must-revalidate");
        // HTTP/1.1 //查询信息
        $smarty->display('empty.tpl', $smartyCacheId);
    }
Example #27
0
 public function AttrItemEdit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_type_listtype');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $meta_id = $validator->digits()->min(1)->validate('meta_id');
     if (!$meta_id) {
         $meta_id = 0;
     }
     $goodsTypeService = new GoodsTypeService();
     $goodsAttrItem = $goodsTypeService->loadGoodsTypeAttrItemById($meta_id);
     if (!$f3->get('POST')) {
         // 没有 post ,只是普通的显示
         goto out_display;
     }
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     if (0 === $meta_id) {
         // 新建的组
         $goodsAttrItem->parent_meta_id = $validator->required()->validate('typeId');
     }
     // 属性组
     $goodsAttrItem->meta_key = $validator->digits()->validate('meta_key');
     $goodsAttrItem->meta_name = $validator->required()->validate('meta_name');
     $goodsAttrItem->meta_desc = $validator->required()->validate('meta_desc');
     $goodsAttrItem->meta_sort_order = $validator->digits()->validate('meta_sort_order');
     // 属性类型,单选、单行输入、多行输入
     $goodsAttrItem->meta_ename = $validator->required()->validate('meta_ename');
     // 选项列表,逗号分隔
     $goodsAttrItem->meta_data = $validator->validate('meta_data');
     if (!$this->validate($validator)) {
         goto out_display;
     }
     $goodsAttrItem->save();
     if (0 === $meta_id) {
         $this->addFlashMessage('新建商品属性成功');
     } else {
         $this->addFlashMessage('更新商品属性成功');
     }
     // 记录管理员日志
     AdminLog::logAdminOperate('goods.type.attritem.edit', '商品属性', $goodsAttrItem->meta_name);
     out_display:
     // 新建的,reRoute 到编辑页面
     if (!$meta_id) {
         RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Type/AttrItemEdit', array('meta_id' => $goodsAttrItem->meta_id), true));
     }
     //给 smarty 模板赋值
     $smarty->assign('typeId', $goodsAttrItem->parent_meta_id);
     $smarty->assign($goodsAttrItem->toArray());
     $smarty->display('goods_type_attritemedit.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Goods/Type/ListType');
 }
Example #28
0
 /**
  * 管理员权限管理
  *
  * @param $f3
  */
 public function Privilege($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_admin_privilege_get');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $user_id = $validator->required()->digits()->min(1)->validate('user_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 查询管理员信息
     $adminUserService = new AdminUserService();
     $adminUser = $adminUserService->loadAdminById($user_id);
     if ($adminUser->isEmpty()) {
         // 不存在的管理员
         $this->addFlashMessage('管理员不存在');
         goto out_fail;
     } else {
         if (AdminUserService::verifyPrivilege(AdminUserService::privilegeAll, $adminUser['action_list'])) {
             // 拥有最高权限的管理员只有他自己能编辑自己
             $authAdminUser = AuthHelper::getAuthUser();
             if ($authAdminUser['user_id'] != $adminUser['user_id']) {
                 $this->addFlashMessage('超级管理员只有他自己能操作自己的信息');
                 RouteHelper::reRoute($this, '/Account/Admin/ListUser');
             }
         }
     }
     if (!Request::isRequestPost()) {
         // 没有 post ,只是普通的显示
         goto out_display;
     }
     // 权限检查
     $this->requirePrivilege('manage_account_admin_privilege_post');
     $action_list_str = '';
     $actionCodeArray = $f3->get('POST[action_code]');
     if (empty($actionCodeArray)) {
         // 清空了所有权限
         $action_list_str = '';
         goto update_privilege;
     }
     if (in_array(AdminUserService::privilegeAll, $actionCodeArray)) {
         // 权限检查,只有自身拥有 privilegeAll 权限的人才能给别人授权 privilegeAll
         $this->requirePrivilege(AdminUserService::privilegeAll);
         // 用户有所有的权限
         $action_list_str = AdminUserService::privilegeAll;
         goto update_privilege;
     }
     // 生成权限字符串
     $action_list_str = implode(',', $actionCodeArray);
     update_privilege:
     $adminUser->role_id = $f3->get('POST[role_id]');
     $adminUser->action_list = $action_list_str;
     $adminUser->save();
     $this->addFlashMessage('管理员权限保存成功');
     out_display:
     $smarty->assign($adminUser->toArray());
     // 取得权限显示列表
     $metaPrivilegeService = new MetaPrivilegeService();
     $smarty->assign('privilegeArray', $metaPrivilegeService->fetchPrivilegeArray());
     $smarty->display('account_admin_privilege.tpl');
     return;
     // 正常从这里返回
     out_fail:
     // 失败,返回管理员列表
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Account/Admin/ListUser', array('user_id' => $user_id), true));
 }
Example #29
0
 public function Edit($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $article_id = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('article_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得文章
     $articleService = new ArticleService();
     $article = $articleService->loadArticleById($article_id);
     if ($article_id > 0 && $article->isEmpty()) {
         $this->addFlashMessage('文章ID[' . $article_id . ']非法');
         goto out_fail;
     }
     // 只是显示文章内容而已
     if (Request::isRequestGet()) {
         $smarty->assign('article', $article->toArray());
         goto out_get;
     }
     // 权限检查
     $this->requirePrivilege('manage_article_article_edit');
     // 从这里开始是修改文章内容
     unset($validator);
     $articleInfoArray = $f3->get('POST[article]');
     $validator = new Validator($articleInfoArray);
     // 获得修改数据
     $inputArray = array();
     $inputArray['title'] = $validator->required()->validate('title');
     $inputArray['seo_keyword'] = $validator->validate('seo_keyword');
     $inputArray['cat_id'] = $validator->validate('cat_id');
     $inputArray['is_open'] = $validator->validate('is_open');
     $inputArray['description'] = $validator->validate('description');
     $inputArray['content'] = $articleInfoArray['content'];
     // 不要过滤 html
     if (!$this->validate($validator)) {
         goto out_get;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 新建文章
     if ($article_id <= 0) {
         $inputArray['admin_user_id'] = $authAdminUser['user_id'];
         $inputArray['admin_user_name'] = $authAdminUser['user_name'];
         $inputArray['add_time'] = Time::gmTime();
     }
     // 文章更新
     $inputArray['update_user_id'] = $authAdminUser['user_id'];
     $inputArray['update_user_name'] = $authAdminUser['user_name'];
     $inputArray['update_time'] = Time::gmTime();
     // 保存修改
     $article->copyFrom($inputArray);
     $article->save();
     // 清除文章缓存
     ClearHelper::clearArticleCacheById($article->article_id);
     $this->addFlashMessage('文章保存成功');
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Article/Article/Edit', array('article_id' => $article->article_id), true));
     return;
     // POST 从这里退出
     out_get:
     // GET 从这里退出
     $smarty->display('article_article_edit.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Article/Article/Search');
 }
Example #30
0
 public function post($f3)
 {
     // Search 采用 post,这样可以保证生成唯一的 URL 然后跳转到 GET, Search 不做静态化地址
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Search', $_POST, false, true, false));
 }