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
 private function outputDataRow($activeSheet, $rowIndex, $orderGoodsItem, $excludeKeyArray = null)
 {
     // 代表价格的列,需要特殊处理显示格式
     $priceColumnArray = array('suppliers_price', 'suppliers_total_price', 'suppliers_shipping_fee', 'refund', 'extra_refund', 'goods_price', 'shipping_fee', 'discount', 'extra_discount');
     // 输出数据
     $colIndex = 4;
     foreach ($this->filterArray as $key => $value) {
         if (!empty($excludeKeyArray) && in_array($key, $excludeKeyArray)) {
             $colIndex++;
             continue;
         }
         $cellValue = isset($orderGoodsItem[$key]) ? $orderGoodsItem[$key] : '';
         if (in_array($key, $priceColumnArray)) {
             // 金额需要做转化
             $cellValue = Money::toSmartyDisplay($cellValue);
             $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue);
         } else {
             $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue);
             $activeSheet->getCellByColumnAndRow($colIndex, $rowIndex)->setDataType(\PHPExcel_Cell_DataType::TYPE_STRING);
         }
         // 客服备注用黄色标明
         if ('memo' == $key) {
             $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
             $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFFFFF00');
         }
         // 不是付款订单,用红色标注 (退款订单)
         if (1 != $orderGoodsItem['order_goods_status']) {
             $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
             $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFFF0000');
         }
         $colIndex++;
     }
 }
Example #3
0
 public function doNotifyUrl($f3)
 {
     if (empty($this->orderId)) {
         throw new \InvalidArgumentException('orderId invalid');
     }
     // 记录所有的参数,方便调试查找
     printLog('CreditPay Notify orderId [' . $this->orderId . ']', 'PAYMENT', Base::INFO);
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($this->orderId);
     //判断金额是否一致
     if ($orderInfo->isEmpty() || 0 != $orderInfo['order_amount']) {
         printLog('CreditPay total_fee error, order_amount :' . Money::storageToCent($orderInfo['order_amount']) . ' total_fee : 0 ', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //检查订单状态
     if (OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         printLog('CreditPay order_status is not OS_UNCONFIRMED, order_status[' . $orderInfo['order_status'] . '] orderId[' . $this->orderId . ']', 'PAYMENT', Base::WARN);
         goto out_succ;
     }
     // 把订单设置为已付款状态
     $orderPaymentService = new OrderPaymentService();
     $orderPaymentService->markOrderInfoPay($this->orderId, $this->payId, $this->getGatewayType(), '0');
     printLog('CreditPay orderId[' . $this->orderId . '] notifyUrl success', 'PAYMENT', Base::INFO);
     //------------------------------
     //处理业务完毕
     //------------------------------
     out_succ:
     return true;
     out_fail:
     // 失败从这里返回
     return false;
 }
Example #4
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 #5
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 #6
0
/**
 * 正确显示商品价格,千分位价格显示 比如 52.10 显示为 52.1 , 52.00 显示为 52
 */
function smarty_helper_modifier_money_display($price)
{
    return \Core\Helper\Utility\Money::toSmartyDisplay($price);
}
Example #7
0
 public function get($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo');
     // 搜索参数数组
     $searchFormQuery = array();
     $searchKeywords = $validator->validate('keywords');
     $searchFormQuery['g.goods_name'] = $searchKeywords;
     // 这里支持多品牌查询
     $searchFormQuery['g.brand_id'] = array('=', $validator->validate('brand_id'));
     // 价格区间查询
     $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min');
     $shopPriceMin = null == $shopPriceMin ? null : Money::toStorage($shopPriceMin);
     $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max');
     $shopPriceMax = null == $shopPriceMax ? null : Money::toStorage($shopPriceMax);
     $searchFormQuery['g.shop_price'] = array($shopPriceMin, $shopPriceMax);
     // 排序
     $orderBy = $validator->oneOf(array('', 'total_buy_number', 'shop_price', 'add_time'))->validate('orderBy');
     $orderDir = $validator->oneOf(array('', 'asc', 'desc'))->validate('orderDir');
     $orderByParam = array();
     if (!empty($orderBy)) {
         $orderByParam = array(array($orderBy, $orderDir));
     }
     //增加一些我们的缺省排序
     $orderByParam[] = array('g.sort_order', 'desc');
     $orderByParam[] = array('g.goods_id', 'desc');
     // 参数验证
     if (!$this->validate($validator) || empty($searchFormQuery)) {
         goto out_fail;
     }
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = 45;
     // 每页固定显示 45 个商品
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Goods|Search|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $pageNo . '_' . $pageSize);
     // 开启并设置 smarty 缓存时间
     enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_search'));
     if ($smarty->isCached('goods_search.tpl', $smartyCacheId)) {
         goto out_display;
     }
     $goodsCategoryService = new GoodsCategoryService();
     // 1. 我们需要在左侧显示分类层级结构
     $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray(0, false, 1800);
     $smarty->assign('goodsCategoryTreeArray', $goodsCategoryTreeArray);
     /**
      * 构造 Filter 数组,结构如下
      *
      * array(
      *      '商品品牌' => array(
      *              filterKey => 'brand_id'
      *              filterValueArray => array( array(value=>'13', text=>'品牌1'), ...)
      *              ),
      *      '颜色' => array(
      *              filterKey => 'filter',
      *              filterValueArray => array( array(value=>'13', text=>'品牌1'), ...)
      *              )
      * )
      *
      */
     $goodsFilterArray = array();
     // filter 查询在这个条件下进行
     $goodsFilterQueryCond = array_merge(QueryBuilder::buildSearchParamArray(array('g.goods_name' => $searchKeywords)), $this->searchExtraCondArray);
     // 2. 商品品牌查询
     $goodsBrandIdArray = SearchHelper::search(SearchHelper::Module_Goods, 'distinct(g.brand_id)', array_merge($goodsFilterQueryCond, array(array('g.brand_id > 0'))), null, 0, 0);
     $brandIdArray = array_map(function ($elem) {
         return $elem['brand_id'];
     }, $goodsBrandIdArray);
     if (!empty($brandIdArray)) {
         $goodsBrandService = new GoodsBrandService();
         $goodsBrandArray = $goodsBrandService->fetchBrandArrayByIdArray(array_unique(array_values($brandIdArray)));
         $filterBrandArray = array();
         foreach ($goodsBrandArray as $brand) {
             $filterBrandArray[] = array('value' => $brand['brand_id'], 'text' => $brand['brand_name']);
         }
         if (!empty($filterBrandArray)) {
             $goodsFilterArray['品牌'] = array('filterKey' => 'brand_id', 'filterValueArray' => $filterBrandArray);
         }
     }
     if (!empty($goodsFilterArray)) {
         $smarty->assign('goodsFilterArray', $goodsFilterArray);
     }
     // 3. 商品属性过滤   TODO: 等以后扩展,看看 Search 怎么做属性过滤
     // 4. 商品查询
     // 构造 filter 参数,注意 filter 参数在 GoodsGoodsAttr 中具体解析
     // 合并查询参数
     $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray);
     $totalCount = SearchHelper::count(SearchHelper::Module_GoodsGoodsAttr, $searchParamArray);
     if ($totalCount <= 0) {
         goto out_display;
         // 没有商品,直接显示
     }
     // 页号可能是用户乱输入的,我们需要检查
     if ($pageNo * $pageSize >= $totalCount) {
         goto out_fail;
         // 返回首页
     }
     $goodsArray = SearchHelper::search(SearchHelper::Module_GoodsGoodsAttr, 'g.goods_id, g.cat_id, g.goods_sn, g.goods_name, g.brand_id, g.goods_number, g.market_price' . ', g.shop_price, g.suppliers_id, g.virtual_buy_number, g.user_buy_number, g.user_pay_number' . ', (g.virtual_buy_number + g.user_pay_number) as total_buy_number', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize);
     if (empty($goodsArray)) {
         goto out_display;
     }
     $smarty->assign('goodsArray', $goodsArray);
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     // SEO 考虑,网页标题加上分类的名称
     $smarty->assign('seo_title', '商品搜索,' . $searchKeywords . ',' . $smarty->getTemplateVars('seo_title'));
     out_display:
     // 滑动图片广告
     $goods_search_adv_slider = json_decode(bzf_get_option_value('goods_search_adv_slider'), true);
     if (!empty($goods_search_adv_slider)) {
         $smarty->assign('goods_search_adv_slider', $goods_search_adv_slider);
     }
     $smarty->display('goods_search.tpl', $smartyCacheId);
     return;
     out_fail:
     // 失败从这里返回
     RouteHelper::reRoute($this, '/');
     // 返回首页
 }
Example #8
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);
     // 用户提交的商品信息做验证
     $goodsTeam = $f3->get('POST.goods_team');
     if (empty($goodsTeam)) {
         goto out_fail_validate;
     }
     $validator = new Validator($goodsTeam);
     $goodsTeamInfo = array();
     $goodsTeamInfo['goods_id'] = $goods_id;
     //表单数据验证、过滤
     $goodsTeamInfo['team_enable'] = $validator->digits()->validate('team_enable');
     $goodsTeamInfo['team_title'] = $validator->required('团购标题不能为空')->validate('team_title');
     $goodsTeamInfo['team_seo_keyword'] = $validator->validate('team_seo_keyword');
     $goodsTeamInfo['team_seo_description'] = $validator->validate('team_seo_description');
     $goodsTeamInfo['team_price'] = Money::toStorage($validator->validate('team_price'));
     $goodsTeamInfo['team_sort_order'] = $validator->filter('ValidatorIntValue')->validate('team_sort_order');
     $goodsTeamInfo['team_per_number'] = $validator->filter('ValidatorIntValue')->validate('team_per_number');
     $goodsTeamInfo['team_min_number'] = $validator->filter('ValidatorIntValue')->validate('team_min_number');
     $goodsTeamInfo['team_max_number'] = $validator->filter('ValidatorIntValue')->validate('team_max_number');
     $goodsTeamInfo['team_pre_number'] = $validator->filter('ValidatorIntValue')->validate('team_pre_number');
     //单独解析时间
     $team_begin_time_str = $validator->validate('team_begin_time_str');
     $teamBeginTime = Time::gmStrToTime($team_begin_time_str);
     if ($teamBeginTime <= 0) {
         $this->addFlashMessage('团购开始时间无效');
         goto out_fail_validate;
     }
     $goodsTeamInfo['team_begin_time'] = $teamBeginTime;
     $team_end_time_str = $validator->validate('team_end_time_str');
     $teamEndTime = Time::gmStrToTime($team_end_time_str);
     if ($teamEndTime <= 0) {
         $this->addFlashMessage('团购结束时间无效');
         goto out_fail_validate;
     }
     $goodsTeamInfo['team_end_time'] = $teamEndTime;
     //参数验证
     if (!$this->validate($validator)) {
         goto out_fail_validate;
     }
     // 写入到数据库
     unset($goodsTeam);
     $goodsBasicService = new GoodsBasicService();
     $goodsTeam = $goodsBasicService->loadGoodsTeamByGoodsId($goods_id);
     $goodsTeam->copyFrom($goodsTeamInfo);
     $goodsTeam->save();
     // 成功,显示商品详情
     $this->addFlashMessage('商品团购信息保存成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Team', array('goods_id' => $goods_id), true));
     return;
     // 参数验证失败
     out_fail_validate:
     $smarty->display('goods_edit_team.tpl');
     return;
     out_fail_list_goods:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
Example #9
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 #10
0
 /**
  * 下载 拣货单
  *
  * @param $f3
  * @param $validator
  */
 public function downloadJianHuo($f3, $validator)
 {
     $outputColumnArray = array('warehouse' => '仓库', 'shelf' => '货架', 'goods_sn' => '货号', 'goods_name' => '商品名', 'goods_attr' => '属性规格', 'goods_number' => '数量', 'suppliers_price' => '供货单价', 'total_suppliers_price' => '供货总价', 'total_suppliers_shipping_fee' => '供货快递');
     $outputColumnMoneyArray = array('suppliers_price', 'total_suppliers_price', 'total_suppliers_shipping_fee');
     //表单查询
     $searchFormQuery = array();
     $searchFormQuery['og.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id');
     //付款时间
     $payTimeStartStr = $validator->validate('pay_time_start');
     $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null;
     $payTimeEndStr = $validator->validate('pay_time_end');
     $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null;
     $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd);
     // 快递信息
     $expressType = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('expressType');
     switch ($expressType) {
         case 1:
             $searchFormQuery['og.shipping_id'] = 0;
             break;
         case 2:
             $searchFormQuery['og.shipping_id'] = array('>', 0);
             break;
         default:
             break;
     }
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     if (Utils::isBlank($searchFormQuery['og.goods_id']) && Utils::isBlank($payTimeStart)) {
         $this->addFlashMessage('查询参数非法');
         goto out_fail;
     }
     // 构造查询条件
     $authSupplierUser = AuthHelper::getAuthUser();
     $searchFormQuery['og.suppliers_id'] = $authSupplierUser['suppliers_id'];
     $searchParamArray = array();
     $searchParamArray[] = array('oi.order_id = og.order_id');
     //供货商,只查看有效订单,其它订单不显示
     $searchParamArray[] = array('og.order_goods_status > 0');
     // 表单查询
     $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery));
     $orderGoodsArray = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, 'og.warehouse, og.shelf, og.goods_id, og.goods_sn, og.goods_attr, sum(og.goods_number) as goods_number, sum(og.suppliers_price * og.goods_number) as total_suppliers_price, sum(og.suppliers_shipping_fee) as total_suppliers_shipping_fee', $searchParamArray, array(array('og.warehouse', 'asc'), array('og.shelf', 'asc')), 0, $f3->get('sysConfig[max_query_record_count]'), 'og.warehouse, og.shelf, og.goods_id, og.goods_sn, og.goods_attr');
     // 没有数据,退出
     if (empty($orderGoodsArray)) {
         goto out;
     }
     // 查询订单对应的商品
     $goodsIdArray = array();
     foreach ($orderGoodsArray as $orderGoodsItem) {
         $goodsIdArray[] = $orderGoodsItem['goods_id'];
     }
     $goodsIdArray = array_unique($goodsIdArray);
     $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'goods_id, goods_name_short, suppliers_price', array(array(QueryBuilder::buildInCondition('goods_id', $goodsIdArray, \PDO::PARAM_INT))), null, 0, $f3->get('sysConfig[max_query_record_count]'));
     $goodsIdToGoodsMap = array();
     foreach ($goodsArray as $goodsItem) {
         $goodsIdToGoodsMap[$goodsItem['goods_id']] = $goodsItem;
     }
     require_once PROTECTED_PATH . '/Vendor/PHPExcel/Settings.php';
     // 设置Excel缓存,防止数据太多拖死了程序
     \PHPExcel_Settings::setCacheStorageMethod(\PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp);
     // 导出为 Excel 格式
     $objPHPExcel = new \PHPExcel();
     // 设置工作 sheet
     $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet = $objPHPExcel->getActiveSheet();
     // 格式化数据
     $rowIndex = 1;
     $lastWarehouseShelf = null;
     $orderGoodsArraySize = count($orderGoodsArray);
     // 输出头部信息
     $colIndex = 1;
     foreach ($outputColumnArray as $value) {
         $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $value);
         $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFont()->setBold(true);
         $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
         $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFB0B0B0');
         $colIndex++;
     }
     $rowIndex++;
     // 换行
     for ($orderGoodsIndex = 0; $orderGoodsIndex < $orderGoodsArraySize; $orderGoodsIndex++) {
         // 取得这行数据
         $orderGoodsItem = $orderGoodsArray[$orderGoodsIndex];
         // 填入商品数据
         $orderGoodsItem['goods_name'] = $goodsIdToGoodsMap[$orderGoodsItem['goods_id']]['goods_name_short'];
         $orderGoodsItem['suppliers_price'] = $goodsIdToGoodsMap[$orderGoodsItem['goods_id']]['suppliers_price'];
         if ($lastWarehouseShelf != $orderGoodsItem['warehouse'] . '$' . $orderGoodsItem['shelf']) {
             $lastWarehouseShelf = $orderGoodsItem['warehouse'] . '$' . $orderGoodsItem['shelf'];
             // 不同的取货地点,需要特殊处理
             $rowIndex += 2;
             // 跳过 2 行
         }
         // 输出一行数据
         $colIndex = 1;
         foreach ($outputColumnArray as $key => $value) {
             $cellValue = isset($orderGoodsItem[$key]) ? $orderGoodsItem[$key] : '';
             if (!in_array($key, $outputColumnMoneyArray)) {
                 $activeSheet->getCellByColumnAndRow($colIndex, $rowIndex)->setDataType(\PHPExcel_Cell_DataType::TYPE_STRING);
             } else {
                 // 转换价格显示
                 $cellValue = Money::toSmartyDisplay($cellValue);
             }
             $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue);
             $colIndex++;
         }
         $rowIndex++;
         // 换行
     }
     $fileName = '拣货单_' . $searchFormQuery['og.goods_id'] . '_' . Time::gmTimeToLocalTimeStr($payTimeStart, 'Y-m-d_H-i-s') . '__' . Time::gmTimeToLocalTimeStr($payTimeEnd, 'Y-m-d_H-i-s');
     // 输出为 Excel5 格式
     $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
     header('Content-Type: application/vnd.ms-excel');
     if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
         header('Content-Disposition: attachment; filename="' . urlencode($fileName) . '.xls"');
     } else {
         header('Content-Disposition: attachment; filename="' . $fileName . '.xls"');
     }
     header('Cache-Control: max-age=0');
     $objWriter->save('php://output');
     //输出到浏览器
     die;
     out:
     echo "没有数据";
     die;
     out_fail:
     // 失败,打印错误消息
     $flashMessageArray = $this->flashMessageArray;
     foreach ($flashMessageArray as $flashMessage) {
         echo $flashMessage . '<br />';
     }
 }
Example #11
0
 public function doNotifyUrl($f3)
 {
     // 记录所有的参数,方便调试查找
     printLog('Alipay Notify Paramters : ' . print_r($_REQUEST, true), 'PAYMENT', Base::INFO);
     //计算得出通知验证结果
     $alipayNotify = new AlipayNotify($this->alipayConfig);
     $verifyResult = $alipayNotify->verifyNotify();
     if (!$verifyResult) {
         printLog('Alipay verifyNotify Error ', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //验证成功
     //商户订单号
     $out_trade_no = $_POST['out_trade_no'];
     //支付宝交易号
     $trade_no = $_POST['trade_no'];
     //交易状态
     $trade_status = $_POST['trade_status'];
     //总金额
     $total_fee = $_POST['total_fee'];
     if ($_POST['trade_status'] != 'TRADE_FINISHED' && $_POST['trade_status'] != 'TRADE_SUCCESS') {
         printLog('Alipay trade_status Error', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //$_POST['trade_status'] == 'TRADE_FINISHED'
     //判断该笔订单是否在商户网站中已经做过处理
     //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
     //如果有做过处理,不执行商户的业务程序
     //注意:
     //该种交易状态只在两种情况下出现
     //1、开通了普通即时到账,买家付款成功后。
     //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。
     //$_POST['trade_status'] == 'TRADE_SUCCESS'
     //判断该笔订单是否在商户网站中已经做过处理
     //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
     //如果有做过处理,不执行商户的业务程序
     //注意:
     //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。
     //------------------------------
     //处理业务开始
     //------------------------------
     if (empty($out_trade_no)) {
         goto out_bad_trade_no;
     }
     $paramArray = explode('_', $out_trade_no);
     if (empty($paramArray) || count($paramArray) < 2 || !ctype_digit($paramArray[count($paramArray) - 1])) {
         goto out_bad_trade_no;
     }
     // 最后一个应该是订单 ID 号
     $orderId = intval($paramArray[count($paramArray) - 1]);
     if (empty($orderId)) {
         goto out_bad_trade_no;
     }
     // 设置订单 ID
     $this->orderId = $orderId;
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
     //判断金额是否一致,我们用 分 做单位来比较
     if ($orderInfo->isEmpty() || Money::storageToCent($orderInfo['order_amount']) != Money::displayToCent($total_fee)) {
         printLog('Alipay total_fee error, order_amount :{' . Money::storageToCent($orderInfo['order_amount']) . '} total_fee : {' . Money::displayToCent($total_fee) . '}', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //检查订单状态
     if (OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         printLog('Alipay order_status is not OS_UNCONFIRMED, order_status[' . $orderInfo['order_status'] . '] orderId[' . $orderId . ']', 'PAYMENT', Base::WARN);
         goto out_succ;
     }
     // 把订单设置为已付款状态
     $orderPaymentService = new OrderPaymentService();
     $orderPaymentService->markOrderInfoPay($orderId, $this->payId, $this->getGatewayType(), $trade_no);
     printLog('Alipay orderId[' . $orderId . '] notifyUrl success', 'PAYMENT', Base::INFO);
     //------------------------------
     //处理业务完毕
     //------------------------------
     out_succ:
     echo "success";
     //成功返回
     return true;
     out_bad_trade_no:
     printLog('Alipay bad out_trade_no', 'PAYMENT', Base::ERROR);
     out_fail:
     // 失败从这里返回
     echo "fail";
     return false;
 }
Example #12
0
    private function getGoodsItemXml($index, $goodsItem, $goodsIdToGalleryArray)
    {
        global $f3;
        static $buyNotice = "【下单说明】请在下单时留言注明尺码准确填写姓名、电话和收件地址!\n【发货说明】下单后48小时内发货,快递3-5天左右到达,节假日顺延。偏远地区需要补10元邮费。\n【关于尺寸】因测量手法问题,测量数据可能存在2-3CM误差,还请见谅!\n【关于色差】颜色因场景拍摄及电脑显示有差异均属于正常,不属于质量问题。图色显示与实物颜色我们保证以最接近实物的颜色上传。\n【关于签收】请务必本人签收。验货后,如商品有任何破损问题请当快递员面拒收!";
        $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' => 'gouwuke'));
        $goodsImageUrlList = '<picurls>';
        $goodsGalleryArray = @$goodsIdToGalleryArray[$goodsItem['goods_id']];
        if (!empty($goodsGalleryArray)) {
            foreach ($goodsGalleryArray as $goodsGalleryItem) {
                $goodsImageUrlList .= '<picurllist>';
                $goodsImageUrlList .= '<picurl><![CDATA[' . RouteHelper::makeImageUrl($goodsGalleryItem['img_url']) . ']]></picurl>';
                $goodsImageUrlList .= '<bigpicurl><![CDATA[' . RouteHelper::makeImageUrl($goodsGalleryItem['img_original']) . ']]></bigpicurl>';
                $goodsImageUrlList .= '</picurllist>';
            }
        }
        $goodsImageUrlList .= '</picurls>';
        // 取得商品的分类层级
        $goodsCategoryLevelArray = array();
        $categoryLevel = 5;
        // 最多取 5 层分类
        $currentCategoryId = $goodsItem['cat_id'];
        for (; $categoryLevel > 0; $categoryLevel--) {
            $category = $this->goodsCategoryService->loadCategoryById($currentCategoryId, 1800);
            if ($category->isEmpty()) {
                break;
            }
            array_unshift($goodsCategoryLevelArray, $category);
            if ($category['parent_meta_id'] <= 0) {
                break;
            }
            $currentCategoryId = $category['parent_meta_id'];
        }
        $goodsCategoryLevelStr = '';
        foreach ($goodsCategoryLevelArray as $goodsCategoryItem) {
            $goodsCategoryLevelStr .= $goodsCategoryItem['meta_name'] . ' > ';
        }
        $goodsCategoryLevelStr .= '当前商品';
        // 转换价格显示
        $goodsItem['market_price'] = Money::toSmartyDisplay($goodsItem['market_price']);
        $goodsItem['shop_price'] = Money::toSmartyDisplay($goodsItem['shop_price']);
        $xmlitem = <<<XMLITEM
\t<urlset>
\t    <ident><![CDATA[{$this->siteIdentify}_{$goodsItem['goods_id']}]]></ident>
\t    <productname><![CDATA[{$goodsItem['goods_name']}]]></productname>
\t    <refprice>{$goodsItem['market_price']}</refprice>
        <price_1>{$goodsItem['shop_price']}</price_1>
        <zhekou_price><![CDATA[]]></zhekou_price>
        <zhekou><![CDATA[]]></zhekou>
        <ifcuxiao><![CDATA[false]]></ifcuxiao>
        <quehuo><![CDATA[false]]></quehuo>
        {$goodsImageUrlList}
\t    <url><![CDATA[{$goodsViewUrl}]]></url>
\t    <shortintro><![CDATA[{$goodsItem['goods_name']}]]></shortintro>
\t    <shortintrohtml><![CDATA[{$buyNotice}]]></shortintrohtml>
\t    <orifenlei><![CDATA[{$goodsCategoryLevelStr}]]></orifenlei>
\t    <pinpai><![CDATA[]]></pinpai>
\t    <color><![CDATA[]]></color>
        <chandi><![CDATA[]]></chandi>
    </urlset>
XMLITEM;
        return $xmlitem;
    }
Example #13
0
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_comment_edit');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $comment_id = $validator->digits()->min(1)->validate('comment_id');
     if (!$comment_id) {
         $comment_id = 0;
     }
     $goodsCommentService = new GoodsCommentService();
     $goodsComment = $goodsCommentService->loadGoodsCommentById($comment_id);
     if (!$f3->get('POST')) {
         // 没有 post ,只是普通的显示
         goto out_display;
     }
     // 新建商品评论
     if (0 == $comment_id) {
         $this->requirePrivilege('manage_goods_comment_create');
         $goodsComment->create_time = Time::gmTime();
         $goodsComment->comment_time = Time::gmTime();
     }
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     $goodsComment->goods_id = $validator->digits()->filter('ValidatorIntValue')->validate('goods_id');
     $goodsComment->goods_price = Money::toStorage($validator->validate('goods_price'));
     $goodsComment->goods_number = $validator->required()->digits()->filter('ValidatorIntValue')->validate('goods_number');
     $goodsComment->goods_attr = $validator->validate('goods_attr');
     $goodsComment->is_show = $validator->digits()->filter('ValidatorIntValue')->validate('is_show');
     $goodsComment->user_name = $validator->required()->validate('user_name');
     $goodsComment->comment_time = Time::gmStrToTime($validator->required()->validate('comment_time'));
     $goodsComment->comment = $validator->validate('comment');
     $goodsComment->comment_rate = $validator->digits()->filter('ValidatorIntValue')->validate('comment_rate');
     $goodsComment->reply = $validator->validate('reply');
     if (!$this->validate($validator)) {
         goto out_display;
     }
     if (!empty($goodsComment->reply)) {
         $goodsComment->reply_time = Time::gmTime();
     }
     // 更新管理员信息
     $authAdminUser = AuthHelper::getAuthUser();
     $goodsComment->admin_user_id = $authAdminUser['user_id'];
     $goodsComment->admin_user_name = $authAdminUser['user_name'];
     $goodsComment->save();
     if (0 == $comment_id) {
         $this->addFlashMessage('新建商品评论成功');
     } else {
         $this->addFlashMessage('更新商品评论成功');
     }
     out_display:
     //给 smarty 模板赋值
     $smarty->assign($goodsComment->toArray());
     $smarty->display('goods_comment_edit.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Goods/Comment/ListComment');
 }
Example #14
0
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     $goodsLogContent = '';
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required()->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail_list_goods;
     }
     unset($validator);
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id, 1);
     if ($goods->isEmpty()) {
         $this->addFlashMessage('商品 id[' . $goods_id . '] 非法');
         goto out_fail_list_goods;
     }
     // POST 参数验证
     $validator = new Validator($f3->get('POST'));
     $goodsSpecNameArray = $validator->validate('goodsSpecNameArray');
     $goodsSpecValue1Array = $validator->validate('goodsSpecValue1Array');
     $goodsSpecValue2Array = $validator->validate('goodsSpecValue2Array');
     $goodsSpecValue3Array = $validator->validate('goodsSpecValue3Array');
     $goodsNumberArray = $validator->validate('goodsNumberArray');
     $goodsSpecAddPriceArray = $validator->validate('goodsSpecAddPriceArray');
     $goodsSnArray = $validator->validate('goodsSnArray');
     $imgIdArray = $validator->validate('imgIdArray');
     if (empty($goodsSpecValue1Array)) {
         goto save_spec;
     }
     // 检查,商品属性名不能为空
     foreach ($goodsSpecNameArray as $goodsSpecName) {
         if (!empty($goodsSpecName)) {
             break;
         }
         $this->addFlashMessage('商品属性名不能为空');
         goto out_fail_edit_spec;
     }
     // 商品选项中不能有特殊符号
     $valueArray = array_merge($goodsSpecValue1Array, $goodsSpecValue2Array, $goodsSpecValue3Array);
     foreach ($valueArray as $valueItem) {
         if (empty($valueItem)) {
             continue;
         }
         // 商品规格不允许有特殊符号
         if (preg_match('#[,\\\\t\\s\\n\\+\\?\\^~!%/$]+#', $valueItem)) {
             $this->addFlashMessage('商品选项不能有特殊符号: 逗号、空格、回车、\\、? 等 ...');
             goto out_validate_fail;
         }
     }
     // 做数据格式转换,商品库存
     foreach ($goodsNumberArray as &$number) {
         $number = abs(intval($number));
     }
     unset($number);
     // 做数据格式转换,商品规格对应的加价
     foreach ($goodsSpecAddPriceArray as &$add_price) {
         $add_price = Money::toStorage(abs(floatval($add_price)));
     }
     unset($add_price);
     if (!$this->validate($validator)) {
         goto out_reroute;
     }
     save_spec:
     $goodsSpecService = new GoodsSpecService();
     $goodsSpecService->initWithData($goodsSpecNameArray, $goodsSpecValue1Array, $goodsSpecValue2Array, $goodsSpecValue3Array, $goodsNumberArray, $goodsSpecAddPriceArray, $goodsSnArray, $imgIdArray);
     // 保存数据
     $goodsSpecService->saveGoodsSpec($goods_id);
     $this->addFlashMessage('更新商品规格成功');
     out:
     // 正常退出
     $goodsSpecNameArray = is_array($goodsSpecNameArray) ? $goodsSpecNameArray : array();
     $goodsLogContent .= '属性名:' . implode(',', $goodsSpecNameArray) . "\n";
     $valueCount = count($goodsSpecValue1Array);
     for ($valueIndex = 0; $valueIndex < $valueCount; $valueIndex++) {
         $goodsLogContent .= '选择:' . @$goodsSpecValue1Array[$valueIndex] . ',' . @$goodsSpecValue2Array[$valueIndex] . ',' . @$goodsSpecValue3Array[$valueIndex] . ',' . '库存:' . @$goodsNumberArray[$valueIndex] . ',' . '加价:' . Money::toSmartyDisplay(@$goodsSpecAddPriceArray[$valueIndex]) . ',' . 'SN:' . @$goodsSnArray[$valueIndex] . ',' . 'image:' . @$imgIdArray[$valueIndex] . ',' . "\n";
     }
     $authAdminUser = AuthHelper::getAuthUser();
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($goods_id, $authAdminUser['user_id'], $authAdminUser['user_name'], '商品规格', $goodsLogContent);
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     out_reroute:
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Spec', array('goods_id' => $goods_id), true));
     return;
     out_fail_list_goods:
     RouteHelper::reRoute($this, '/Goods/Search');
     return;
     out_validate_fail:
     global $smarty;
     $smarty->display('goods_edit_spec.tpl');
     return;
     out_fail_edit_spec:
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Spec', array('goods_id' => $goods->goods_id), true));
 }
Example #15
0
 public function get($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo');
     // 搜索参数数组
     $searchFormQuery = array();
     $searchFormQuery['g.category_id'] = $validator->required('商品分类不能为空')->digits('分类id非法')->min(1, true, '分类id非法')->filter('ValidatorIntValue')->validate('category_id');
     // 这里支持多品牌查询
     $searchFormQuery['g.brand_id'] = array('=', $validator->validate('brand_id'));
     // 价格区间查询
     $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min');
     $shopPriceMin = null == $shopPriceMin ? null : Money::toStorage($shopPriceMin);
     $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max');
     $shopPriceMax = null == $shopPriceMax ? null : Money::toStorage($shopPriceMax);
     $searchFormQuery['g.shop_price'] = array($shopPriceMin, $shopPriceMax);
     // 属性过滤
     $filter = $validator->validate('filter');
     // 排序
     $orderBy = $validator->oneOf(array('', 'total_buy_number', 'shop_price', 'add_time'))->validate('orderBy');
     $orderDir = $validator->oneOf(array('', 'asc', 'desc'))->validate('orderDir');
     $orderByParam = array();
     if (!empty($orderBy)) {
         $orderByParam = array(array($orderBy, $orderDir));
     }
     //增加一些我们的缺省排序
     $orderByParam[] = array('g.sort_order', 'desc');
     $orderByParam[] = array('g.goods_id', 'desc');
     // 参数验证
     if (!$this->validate($validator) || empty($searchFormQuery)) {
         goto out_fail;
     }
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = 45;
     // 每页固定显示 45 个商品
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Goods|Category|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $filter . '_' . $pageNo . '_' . $pageSize);
     // 开启并设置 smarty 缓存时间
     enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_search'));
     if ($smarty->isCached('goods_category.tpl', $smartyCacheId)) {
         goto out_display;
     }
     $goodsCategoryService = new GoodsCategoryService();
     $category = $goodsCategoryService->loadCategoryById($searchFormQuery['g.category_id'], 1800);
     if ($category->isEmpty()) {
         $this->addFlashMessage('分类[' . $searchFormQuery['category_id'] . ']不存在');
         goto out_fail;
     }
     $smarty->assign('category', $category);
     $metaData = json_decode($category['meta_data'], true);
     $metaFilterArray = @$metaData['filterArray'];
     // 1. 我们需要在左侧显示分类层级结构
     $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray($category['parent_meta_id'], false, 1800);
     $smarty->assign('goodsCategoryTreeArray', $goodsCategoryTreeArray);
     /**
      * 构造 Filter 数组,结构如下
      *
      * array(
      *      '商品品牌' => array(
      *              filterKey => 'brand_id'
      *              filterValueArray => array( array(value=>'13', text=>'品牌1'), ...)
      *              ),
      *      '颜色' => array(
      *              filterKey => 'filter',
      *              filterValueArray => array( array(value=>'13', text=>'品牌1'), ...)
      *              )
      * )
      *
      */
     $goodsFilterArray = array();
     // filter 查询在这个条件下进行
     $goodsFilterQueryCond = array_merge($this->searchExtraCondArray, array(array('g.category_id', '=', $searchFormQuery['g.category_id'])));
     // 2. 商品品牌查询
     $goodsBrandIdArray = SearchHelper::search(SearchHelper::Module_Goods, 'distinct(g.brand_id)', array_merge($goodsFilterQueryCond, array(array('g.brand_id > 0'))), null, 0, 0);
     $brandIdArray = array_map(function ($elem) {
         return $elem['brand_id'];
     }, $goodsBrandIdArray);
     if (!empty($brandIdArray)) {
         $goodsBrandService = new GoodsBrandService();
         $goodsBrandArray = $goodsBrandService->fetchBrandArrayByIdArray(array_unique(array_values($brandIdArray)));
         $filterBrandArray = array();
         foreach ($goodsBrandArray as $brand) {
             $filterBrandArray[] = array('value' => $brand['brand_id'], 'text' => $brand['brand_name']);
         }
         if (!empty($filterBrandArray)) {
             $goodsFilterArray['品牌'] = array('filterKey' => 'brand_id', 'filterValueArray' => $filterBrandArray);
         }
     }
     // 3. 查询属性过滤
     if (!empty($metaFilterArray)) {
         $goodsTypeService = new GoodsTypeService();
         foreach ($metaFilterArray as $filterItem) {
             $goodsTypeAttrItem = $goodsTypeService->loadGoodsTypeAttrItemById($filterItem['attrItemId']);
             if ($goodsTypeAttrItem->isEmpty()) {
                 continue;
             }
             // 取得商品属性值列表
             $goodsAttrItemValueArray = SearchHelper::search(SearchHelper::Module_GoodsAttrGoods, 'min(ga.goods_attr_id) as goods_attr_id, ga.attr_item_value', array_merge($goodsFilterQueryCond, array(array('ga.attr_item_id', '=', $filterItem['attrItemId']))), null, 0, 0, 'ga.attr_item_value');
             if (!empty($goodsAttrItemValueArray)) {
                 $filterValueArray = array();
                 foreach ($goodsAttrItemValueArray as $itemValue) {
                     $filterValueArray[] = array('value' => $itemValue['goods_attr_id'], 'text' => $itemValue['attr_item_value']);
                 }
                 $goodsFilterArray[$goodsTypeAttrItem['meta_name']] = array('filterKey' => 'filter', 'filterValueArray' => $filterValueArray);
             } else {
                 // 如果这个属性完全没有值(没有一个商品设过任何值),我们弄一个空的
                 $goodsFilterArray[$goodsTypeAttrItem['meta_name']] = array('filterKey' => 'filter', 'filterValueArray' => array());
             }
         }
     }
     // 赋值给模板
     if (!empty($goodsFilterArray)) {
         $smarty->assign('goodsFilterArray', $goodsFilterArray);
     }
     // 4. 商品查询
     if (!empty($metaFilterArray)) {
         // 构造 attrItemId
         $metaFilterTypeIdArray = array();
         foreach ($metaFilterArray as $metaFilterItem) {
             $metaFilterTypeIdArray[] = $metaFilterItem['attrItemId'];
         }
         // 构造 filter 参数,注意 filter 参数在 GoodsGoodsAttr 中具体解析
         // 合并查询参数
         $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray, array(array('ga.filter', implode('.', $metaFilterTypeIdArray), $filter)));
     } else {
         // 合并查询参数
         $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray);
     }
     $totalCount = SearchHelper::count(SearchHelper::Module_GoodsGoodsAttr, $searchParamArray);
     if ($totalCount <= 0) {
         goto out_display;
         // 没有商品,直接显示
     }
     // 页号可能是用户乱输入的,我们需要检查
     if ($pageNo * $pageSize >= $totalCount) {
         goto out_fail;
         // 返回首页
     }
     $goodsArray = SearchHelper::search(SearchHelper::Module_GoodsGoodsAttr, 'g.goods_id, g.cat_id, g.goods_sn, g.goods_name, g.brand_id, g.goods_number, g.market_price' . ', g.shop_price, g.suppliers_id, g.virtual_buy_number, g.user_buy_number, g.user_pay_number' . ', (g.virtual_buy_number + g.user_pay_number) as total_buy_number', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize);
     if (empty($goodsArray)) {
         goto out_display;
     }
     $smarty->assign('goodsArray', $goodsArray);
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     // SEO 考虑,网页标题加上分类的名称
     $smarty->assign('seo_title', $category['meta_name'] . ',' . $smarty->getTemplateVars('seo_title'));
     out_display:
     // 滑动图片广告
     $goods_search_adv_slider = json_decode(bzf_get_option_value('goods_search_adv_slider'), true);
     if (!empty($goods_search_adv_slider)) {
         $smarty->assign('goods_search_adv_slider', $goods_search_adv_slider);
     }
     $smarty->display('goods_category.tpl', $smartyCacheId);
     return;
     out_fail:
     // 失败从这里返回
     RouteHelper::reRoute($this, '/');
     // 返回首页
 }
Example #16
0
 /**
  * 商品修改价格
  *
  * @param array $paramArray
  *
  * @return array
  */
 public function setPrice(array $paramArray)
 {
     $resultArray = array('code' => '-1', 'message' => '参数错误');
     $goods_id = abs(intval(@$paramArray['goods_id']));
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     if ($goods->isEmpty()) {
         goto out;
     }
     // 更新商品字段
     $goodsUpdateFieldArray = @$paramArray['goods'];
     foreach ($goodsUpdateFieldArray as $field => $value) {
         if (in_array($field, array('goods_id'))) {
             // 安全考虑,一些字段不允许修改
             continue;
         }
         // 价格特殊处理
         if ('shop_price' == $field) {
             $goods->shop_price = Money::toStorage($value);
             continue;
         }
         $goods->{$field} = $value;
     }
     $goods->save();
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods->goods_id);
     $resultArray = array('code' => '0', 'message' => '商品[' . $goods_id . ']属性修改成功');
     out:
     return $resultArray;
 }
Example #17
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 #18
0
 private function outputDataRow($activeSheet, $rowIndex, $dataRowItem, $excludeKeyArray = null)
 {
     // 代表价格的列,需要特殊处理显示格式
     $priceColumnArray = array('goods_price', 'shipping_fee', 'discount', 'extra_discount', 'refund', 'extra_refund', 'surplus', 'bonus', 'cps_amount', 'cps_fee', 'cps_extra');
     // 输出数据
     $colIndex = 1;
     foreach ($this->filterArray as $key => $value) {
         if (!array_key_exists($key, $dataRowItem) || !empty($excludeKeyArray) && in_array($key, $excludeKeyArray)) {
             $colIndex++;
             continue;
         }
         $cellValue = isset($dataRowItem[$key]) ? $dataRowItem[$key] : '';
         if (in_array($key, $priceColumnArray)) {
             // 金额需要做转化
             $cellValue = Money::toSmartyDisplay($cellValue);
             $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue);
         } else {
             $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue);
             $activeSheet->getCellByColumnAndRow($colIndex, $rowIndex)->setDataType(\PHPExcel_Cell_DataType::TYPE_STRING);
         }
         // 未付款订单,用淡蓝色标注
         if (array_key_exists('order_goods_status', $dataRowItem) && 0 == $dataRowItem['order_goods_status']) {
             $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
             $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FF49AFCD');
         }
         // 退款订单,用红色标注 (退款订单)
         if (array_key_exists('order_goods_status', $dataRowItem) && $dataRowItem['order_goods_status'] > 1) {
             $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
             $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFFF0000');
         }
         $colIndex++;
     }
 }
Example #19
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 #20
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 #21
0
 public function doNotifyUrl($f3)
 {
     // 记录所有的参数,方便调试查找
     printLog($this->getGatewayType() . ' Notify Paramters : ' . print_r($_REQUEST, true), 'PAYMENT', Base::INFO);
     //计算得出通知验证结果
     $notifyArray = array("service" => $_POST['service'], "v" => $_POST['v'], "sec_id" => $_POST['sec_id'], "notify_data" => $_POST['notify_data']);
     $calcSign = build_mysign($notifyArray, $this->partnerKey, $this->configSecId);
     // 如果签名验证失败则直接退出
     if ($calcSign != $_POST["sign"]) {
         printLog($this->getGatewayType() . ' sign error calcSign[' . $calcSign . '] sign[' . $_POST["sign"] . ']', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //交易状态
     $trade_status = getDataForXML($_POST['notify_data'], '/notify/trade_status');
     if ($trade_status != 'TRADE_FINISHED' && $trade_status != 'TRADE_SUCCESS') {
         printLog($this->getGatewayType() . ' trade_status Error [' . $trade_status . ']', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //商户订单号
     $out_trade_no = getDataForXML($_POST['notify_data'], '/notify/out_trade_no');
     //支付宝交易号
     $trade_no = getDataForXML($_POST['notify_data'], '/notify/trade_no');
     //总金额
     $total_fee = getDataForXML($_POST['notify_data'], '/notify/total_fee');
     //$_POST['trade_status'] == 'TRADE_FINISHED'
     //判断该笔订单是否在商户网站中已经做过处理
     //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
     //如果有做过处理,不执行商户的业务程序
     //注意:
     //该种交易状态只在两种情况下出现
     //1、开通了普通即时到账,买家付款成功后。
     //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。
     //$_POST['trade_status'] == 'TRADE_SUCCESS'
     //判断该笔订单是否在商户网站中已经做过处理
     //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
     //如果有做过处理,不执行商户的业务程序
     //注意:
     //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。
     //------------------------------
     //处理业务开始
     //------------------------------
     if (empty($out_trade_no)) {
         goto out_bad_trade_no;
     }
     $paramArray = explode('_', $out_trade_no);
     if (empty($paramArray) || count($paramArray) < 2 || !ctype_digit($paramArray[count($paramArray) - 1])) {
         goto out_bad_trade_no;
     }
     // 最后一个应该是订单 ID 号
     $orderId = intval($paramArray[count($paramArray) - 1]);
     if (empty($orderId)) {
         goto out_bad_trade_no;
     }
     // 设置订单 ID
     $this->orderId = $orderId;
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
     //判断金额是否一致,我们用 分 做单位比较
     if ($orderInfo->isEmpty() || Money::storageToCent($orderInfo['order_amount']) != Money::displayToCent($total_fee)) {
         printLog('Alipay total_fee error, order_amount :{' . Money::storageToCent($orderInfo['order_amount']) . '} total_fee : {' . Money::displayToCent($total_fee) . '}', 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //检查订单状态
     if (OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         printLog($this->getGatewayType() . ' order_status is not OS_UNCONFIRMED, order_status[' . $orderInfo['order_status'] . '] orderId[' . $orderId . ']', 'PAYMENT', Base::WARN);
         goto out_succ;
     }
     // 把订单设置为已付款状态
     $orderPaymentService = new OrderPaymentService();
     $orderPaymentService->markOrderInfoPay($orderId, $this->payId, $this->getGatewayType(), $trade_no);
     printLog($this->getGatewayType() . ' orderId[' . $orderId . '] notifyUrl success', 'PAYMENT', Base::INFO);
     //------------------------------
     //处理业务完毕
     //------------------------------
     out_succ:
     echo "success";
     //成功返回
     return true;
     out_bad_trade_no:
     printLog($this->getGatewayType() . ' bad out_trade_no', 'PAYMENT', Base::ERROR);
     out_fail:
     // 失败从这里返回
     echo "fail";
     return false;
 }
Example #22
0
 public function doNotifyUrl($f3)
 {
     // 记录所有的参数,方便调试查找
     printLog('Tenpay Notify Paramters : ' . print_r($_REQUEST, true), 'PAYMENT', Base::INFO);
     /* 创建支付应答对象 */
     $resHandler = new ResponseHandler();
     $resHandler->setKey($this->partnerKey);
     //判断签名
     if (!$resHandler->isTenpaySign()) {
         //签名错误
         printLog('Tenpay Notify sign error:' . $resHandler->getDebugInfo(), 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //通知id
     $notify_id = $resHandler->getParameter("notify_id");
     //通过通知ID查询,确保通知来至财付通
     //创建查询请求
     $queryReq = new RequestHandler();
     $queryReq->init();
     $queryReq->setKey($this->partnerKey);
     $queryReq->setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
     $queryReq->setParameter("partner", $this->partnerId);
     $queryReq->setParameter("notify_id", $notify_id);
     //通信对象
     $httpClient = new TenpayHttpClient();
     $httpClient->setTimeOut(10);
     //设置请求内容
     $httpClient->setReqContent($queryReq->getRequestURL());
     //后台调用
     if (!$httpClient->call()) {
         //通信失败 后台调用通信失败,写日志,方便定位问题
         printLog('Tenpay verify notify_id connect error :responseCode[' . $httpClient->getResponseCode() . ']' . $httpClient->getErrInfo(), 'PAYMENT', Base::ERROR);
         goto out_fail;
     }
     //设置结果参数
     $queryRes = new ClientResponseHandler();
     $queryRes->setContent($httpClient->getResContent());
     $queryRes->setKey($this->partnerKey);
     if ($resHandler->getParameter("trade_mode") == "1") {
         //判断签名及结果(即时到帐)
         //只有签名正确,retcode为0,trade_state为0才是支付成功
         if (!($queryRes->isTenpaySign() && $queryRes->getParameter("retcode") == "0" && $resHandler->getParameter("trade_state") == "0")) {
             $logMsg = "Tenpay sign error or trade_state error : trade_state=" . $resHandler->getParameter("trade_state") . ",retcode=" . $queryRes->getParameter("retcode") . ",retmsg=" . $queryRes->getParameter("retmsg");
             printLog($logMsg, 'PAYMENT', Base::ERROR);
             //更多的错误信息方便调试
             printLog('Tenpay QueryRequestUrl:' . $queryReq->getRequestURL(), 'PAYMENT', Base::ERROR);
             printLog('Tenpay QueryRequestDebugInfo:' . $queryReq->getDebugInfo(), 'PAYMENT', Base::ERROR);
             printLog('Tenpay QueryResponseContent:' . $queryRes->getContent(), 'PAYMENT', Base::ERROR);
             printLog('Tenpay QueryResponseDebugInfo:' . $queryRes->getDebugInfo(), 'PAYMENT', Base::ERROR);
             goto out_fail;
         }
         //取结果参数做业务处理
         $out_trade_no = $resHandler->getParameter("out_trade_no");
         //财付通订单号
         $transaction_id = $resHandler->getParameter("transaction_id");
         //金额,以分为单位
         $total_fee = $resHandler->getParameter("total_fee");
         //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
         $discount = $resHandler->getParameter("discount");
         //------------------------------
         //处理业务开始
         //------------------------------
         if (empty($out_trade_no)) {
             printLog('Tenpay bad out_trade_no', 'PAYMENT', Base::ERROR);
             goto out_fail;
         }
         $paramArray = explode('_', $out_trade_no);
         if (empty($paramArray) || count($paramArray) < 2 || !ctype_digit($paramArray[count($paramArray) - 1])) {
             printLog('Tenpay bad out_trade_no', 'PAYMENT', Base::ERROR);
             goto out_fail;
         }
         // 最后一个应该是订单 ID 号
         $orderId = intval($paramArray[count($paramArray) - 1]);
         if (empty($orderId)) {
             printLog('Tenpay bad out_trade_no', 'PAYMENT', Base::ERROR);
             goto out_fail;
         }
         // 设置订单 ID
         $this->orderId = $orderId;
         $orderBasicService = new OrderBasicService();
         $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
         // 判断金额是否一致,使用 分 做单位来比较
         if ($orderInfo->isEmpty() || Money::storageToCent($orderInfo['order_amount']) != intval($total_fee)) {
             printLog('Tenpay total_fee error, order_amount :{' . Money::storageToCent($orderInfo['order_amount']) . '} total_fee :{' . $total_fee . '}', 'PAYMENT', Base::ERROR);
             goto out_fail;
         }
         //检查订单状态
         if (OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
             printLog('Tenpay order_status is not OS_UNCONFIRMED, order_status[' . $orderInfo['order_status'] . '] orderId[' . $orderId . ']', 'PAYMENT', Base::WARN);
             goto out_succ;
         }
         // 把订单设置为已付款状态
         $orderPaymentService = new OrderPaymentService();
         $orderPaymentService->markOrderInfoPay($orderId, $this->payId, $this->getGatewayType(), $transaction_id);
         printLog('Tenpay orderId[' . $orderId . '] notify success', 'PAYMENT', Base::INFO);
         //------------------------------
         //处理业务完毕
         //------------------------------
     } else {
         printLog('Tenpay trade_mode is not 1', 'PAYMENT', Base::ERROR);
     }
     out_succ:
     // 成功从这里返回
     echo "success";
     return true;
     out_fail:
     // 错误从这里返回
     echo "fail";
     return false;
 }
Example #23
0
 /**
  * 给用户余额充值
  * @param $f3
  */
 public function Charge($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_user_charge');
     $validator = new Validator($f3->get('POST'));
     $user_id = $validator->required()->digits()->validate('user_id');
     $chargeMoney = Money::toStorage($validator->validate('chargeMoney'));
     $chargeMoneyDesc = $validator->validate('chargeMoneyDesc');
     if (!$this->validate($validator)) {
         goto out;
     }
     if (0 == $chargeMoney) {
         $this->addFlashMessage('充值为0,不操作');
         goto out;
     }
     // 加载用户信息
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($user_id);
     if ($userInfo->isEmpty()) {
         $this->addFlashMessage('用户ID非法[' . $user_id . ']');
         goto out;
     }
     // 当前操作的管理员
     $authAdminUser = AuthHelper::getAuthUser();
     // 给用户充值
     $accountLog = new AccountLog();
     $accountLog->logChange($user_id, $chargeMoney, 0, 0, 0, '管理员[' . $authAdminUser['user_name'] . ']充值[' . Money::toSmartyDisplay($chargeMoney) . ']元' . "\n" . $chargeMoneyDesc, $chargeMoney > 0 ? AccountLog::ACT_SAVING : AccountLog::ACT_DRAWING, $authAdminUser['user_id']);
     $this->addFlashMessage('充值 [' . Money::toSmartyDisplay($chargeMoney) . '] 元成功');
     out:
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }