예제 #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;
 }
예제 #2
0
 /**
  * 为系统设置运行环境
  *
  * @return bool
  */
 private function doYiqifaCpsAction()
 {
     // 获取当前插件的根地址
     $currentPluginBasePath = dirname(__FILE__);
     // yiqifacps code 目录加入到 auto load 的路径中,这样系统就能自动做 class 加载
     SystemHelper::addAutoloadPath($currentPluginBasePath . '/yiqifacps/Code');
     // 设置 CPS 日志,按照日期分目录存储
     $todayDateStr = \Core\Helper\Utility\Time::localTimeStr('Y-m-d');
     $todayDateArray = explode('-', $todayDateStr);
     $fileLogger = new \Core\Log\File('YIQIFACPS/' . $todayDateArray[0] . '/' . $todayDateArray[1] . '/' . implode('-', $todayDateArray) . '.yiqifacps.log');
     $fileLogger->sourceAllow[] = 'YIQIFACPS';
     // 只接收 YIQIFACPS 的日志
     global $logger;
     $logger->addLogger($fileLogger);
     // 把 $fileLogger 放到全局日志列表中
     // 设置路由,这样用户就能访问到我们的程序了
     SystemHelper::addRouteMap('/Thirdpart/YiqifaCps/Redirect', 'Controller\\Thirdpart\\YiqifaCps\\Redirect');
     SystemHelper::addRouteMap('/Thirdpart/YiqifaCps/QueryOrder', 'Controller\\Thirdpart\\YiqifaCps\\QueryOrder');
     SystemHelper::addRouteMap('/Thirdpart/YiqifaCps/CaibeiLogin', 'Controller\\Thirdpart\\YiqifaCps\\CaibeiLogin');
     // 设置一个 OrderRefer 用于记录订单来自于 亿起发CPS
     require_once $currentPluginBasePath . '/yiqifacps/Code/YiqifaCpsRefer.php';
     // 设置订单 refer 用于记录订单来源于 亿起发CPS
     ReferHelper::addReferItem('YiqifaCpsRefer', new YiqifaCpsRefer());
     // 增加 smarty 模板搜索路径
     global $smarty;
     $smarty->addTemplateDir($currentPluginBasePath . '/yiqifacps/Tpl/');
     return true;
 }
예제 #3
0
 public function run(array $params)
 {
     $pageSize = 500;
     $goodsBasicService = new Goods();
     $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array());
     for ($pageNo = 0; $pageNo * $pageSize < $totalGoodsCount; $pageNo++) {
         // 查询商品
         $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'g.goods_id', array(), array(array('g.goods_id', 'asc')), $pageNo * $pageSize, $pageSize);
         foreach ($goodsArray as $goodsItem) {
             $goods_id = $goodsItem['goods_id'];
             printLog('begin process goods [' . $goods_id . ']');
             $goodsObj = $goodsBasicService->loadGoodsById($goods_id);
             if ($goodsObj->isEmpty()) {
                 printLog('goods [' . $goods_id . '] is empty');
             } else {
                 $goodsObj->goods_desc = str_replace('tuan.bangzhufu.com', 'www.bangzhufu.com', $goodsObj->goods_desc);
                 $goodsObj->goods_desc = str_replace('cdn.bzfshop.net', 'img.bangzhufu.com', $goodsObj->goods_desc);
                 $goodsObj->goods_desc = preg_replace('!/Goods/View/goods_id~([0-9]+).html!', '/Goods/View/goods_id-\\1.html', $goodsObj->goods_desc);
                 $goodsObj->update_time = \Core\Helper\Utility\Time::gmTime();
                 $goodsObj->save();
             }
             unset($goodsObj);
             printLog('end process goods [' . $goods_id . ']');
         }
     }
 }
예제 #4
0
 /**
  * 加入一条日志信息
  *
  * @param string $level   日志等级
  * @param string $source  日志的来源,比如 'SQL'
  * @param string $msg     日志消息
  * */
 public function addLogInfo($level, $source, $msg)
 {
     $msg = '[' . Time::localTimeStr('Y-m-d H:i:s') . '][' . $level . '][' . $source . '][' . trim($msg) . ']' . PHP_EOL;
     echo $msg;
     flush();
     unset($msg);
 }
예제 #5
0
파일: Settle.php 프로젝트: jackycgq/bzfshop
 /**
  * 列出结算列表
  *
  * @param $f3
  */
 public function ListSettle($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     // 表单查询
     $formQuery = array();
     //结算时间
     $settleTimeStartStr = $validator->validate('settle_time_start');
     $settleTimeStart = Time::gmStrToTime($settleTimeStartStr) ?: null;
     $settleTimeEndStr = $validator->validate('settle_time_end');
     $settleTimeEnd = Time::gmStrToTime($settleTimeEndStr) ?: null;
     $formQuery['create_time'] = array($settleTimeStart, $settleTimeEnd);
     //是否已经付款
     $is_pay = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('is_pay');
     switch ($is_pay) {
         case 1:
             $formQuery['pay_time'] = 0;
             break;
         case 2:
             $formQuery['pay_time'] = array($is_pay, null);
             break;
         default:
             break;
     }
     // 供货商只能查看自己的结算历史
     $authSupplierUser = AuthHelper::getAuthUser();
     $formQuery['suppliers_id'] = $authSupplierUser['suppliers_id'];
     // 构建查询条件
     $condArray = null;
     if (!empty($formQuery)) {
         $condArray = QueryBuilder::buildQueryCondArray($formQuery);
     }
     // 查询结算列表
     $orderSettleService = new OrderSettleService();
     $totalCount = $orderSettleService->countOrderSettleArray($condArray);
     if ($totalCount <= 0) {
         // 没商品,可以直接退出了
         goto out;
     }
     // 页数超过最大值,返回
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Order/Settle/ListSettle');
     }
     // 结算列表
     $orderSettleArray = $orderSettleService->fetchOrderSettleArray($condArray, $pageNo * $pageSize, $pageSize);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('orderSettleArray', $orderSettleArray);
     out:
     $smarty->display('order_settle_listsettle.tpl');
 }
예제 #6
0
 /**
  * 加入一条日志信息
  *
  * @param string $level  日志等级
  * @param string $source 日志的来源,比如 'SQL'
  * @param string $msg    日志消息
  * */
 public function addLogInfo($level, $source, $msg)
 {
     global $f3;
     if (!is_file($this->file)) {
         return;
     }
     $msg = '[' . Time::localTimeStr('Y-m-d H:i:s') . '][' . $level . '][' . $source . '][' . trim($msg) . ']' . PHP_EOL;
     $f3->write($this->file, $msg, true);
 }
예제 #7
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);
    }
예제 #8
0
파일: Cron.php 프로젝트: jackycgq/bzfshop
 public function get($f3)
 {
     global $smarty;
     // 权限检查
     $this->requirePrivilege('manage_misc_cron');
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 20;
     //查询条件
     $searchFormQuery = array();
     $searchFormQuery['task_name'] = $validator->validate('task_name');
     $searchFormQuery['task_desc'] = $validator->validate('task_desc');
     $returnCode = $validator->digits()->filter('ValidatorIntValue')->validate('return_code');
     if (0 === $returnCode) {
         $searchFormQuery['task_run_time'] = array('>', 0);
         $searchFormQuery['return_code'] = 0;
     } elseif ($returnCode > 0) {
         $searchFormQuery['task_run_time'] = array('>', 0);
         $searchFormQuery['return_code'] = array('<>', 0);
     } else {
         // do nothing
     }
     //任务时间
     $taskTimeStartStr = $validator->validate('task_time_start');
     $taskTimeStart = Time::gmStrToTime($taskTimeStartStr) ?: null;
     $taskTimeEndStr = $validator->validate('task_time_end');
     $taskTimeEnd = Time::gmStrToTime($taskTimeEndStr) ?: null;
     $searchFormQuery['task_time'] = array($taskTimeStart, $taskTimeEnd);
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 建立查询条件
     $searchParamArray = QueryBuilder::buildQueryCondArray($searchFormQuery);
     $cronTaskService = new CronTaskService();
     $totalCount = $cronTaskService->countCronTaskArray($searchParamArray);
     if ($totalCount <= 0) {
         // 没任务,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Misc/Cron');
     }
     $cronTaskArray = $cronTaskService->fetchCronTaskArray($searchParamArray, $pageNo * $pageSize, $pageSize);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('cronTaskArray', $cronTaskArray);
     out_display:
     $smarty->display('misc_cron.tpl');
 }
예제 #9
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;
 }
예제 #10
0
 /**
  * 记录管理员的操作日志
  *
  * @param string $operate 操作
  * @param string $operate_desc 操作描述
  * @param string $operate_data 操作数据,用于记录一些重要数据
  */
 public static function logAdminOperate($operate, $operate_desc, $operate_data)
 {
     $dataMapper = new DataMapper('admin_log');
     $authAdminUser = AuthHelper::getAuthUser();
     $dataMapper->user_id = $authAdminUser['user_id'];
     $dataMapper->user_name = $authAdminUser['user_name'];
     $dataMapper->operate = $operate;
     $dataMapper->operate_desc = $operate_desc;
     $dataMapper->operate_time = Time::gmTime();
     $dataMapper->operate_data = $operate_data;
     $dataMapper->save();
     unset($dataMapper);
 }
예제 #11
0
 /**
  * 记录帐户变动
  * @param   int    $userId        用户id
  * @param   float  $userMoney     可用余额变动
  * @param   float  $frozenMoney   冻结余额变动
  * @param   int    $rankPoints    等级积分变动
  * @param   int    $payPoints     消费积分变动
  * @param   string $changeDesc    变动说明
  * @param   int    $changeType    变动类型:参见常量文件
  *
  * @return  void
  */
 function logChange($userId, $userMoney = 0, $frozenMoney = 0, $rankPoints = 0, $payPoints = 0, $changeDesc = '', $changeType = AccountLog::ACT_OTHER, $adminUserId = 0)
 {
     /* 插入帐户变动记录 */
     $accountLogInfo = array('user_id' => $userId, 'user_money' => $userMoney, 'frozen_money' => $frozenMoney, 'rank_points' => $rankPoints, 'pay_points' => $payPoints, 'change_time' => Time::gmTime(), 'change_desc' => $changeDesc, 'change_type' => $changeType, 'admin_user_id' => $adminUserId);
     // 插入一条记录
     $dataMapper = new DataMapper('account_log');
     $dataMapper->copyFrom($accountLogInfo);
     $dataMapper->save();
     // 更新用户信息
     $sql = "UPDATE " . DataMapper::tableName('users') . " SET user_money = user_money + ('{$userMoney}')," . " frozen_money = frozen_money + ('{$frozenMoney}')," . " rank_points = rank_points + ('{$rankPoints}')," . " pay_points = pay_points + ('{$payPoints}')" . " WHERE user_id = ? Order By user_id asc LIMIT 1 ";
     $dbEngine = DataMapper::getDbEngine();
     $dbEngine->exec($sql, $userId);
 }
예제 #12
0
파일: Action.php 프로젝트: jackycgq/bzfshop
 /**
  * @param int    $order_id             order_info 表的 id
  * @param int    $rec_id               order_goods 表的 id
  * @param int    $order_status         order_info 中的订单状态
  * @param int    $pay_status           order_info 中的支付状态
  * @param int    $order_goods_status   order_goods 中的状态
  * @param string $action_note          操作备注
  * @param string $action_user          操作人
  * @param int    $action_place         不清楚用途,暂时为 0
  * @param int    $shipping_status      order_info 中的快递状态
  */
 public function logOrderAction($order_id, $rec_id, $order_status, $pay_status, $order_goods_status, $action_note = '', $action_user, $action_place, $shipping_status)
 {
     $orderAction = $this->_loadById('order_action', 'action_id = ?', 0);
     $orderAction->order_id = $order_id;
     $orderAction->rec_id = $rec_id;
     $orderAction->order_status = $order_status;
     $orderAction->shipping_status = $shipping_status;
     $orderAction->pay_status = $pay_status;
     $orderAction->order_goods_status = $order_goods_status;
     $orderAction->action_note = $action_note;
     $orderAction->action_user = $action_user;
     $orderAction->action_place = $action_place;
     $orderAction->log_time = Time::gmTime();
     $orderAction->save();
 }
예제 #13
0
파일: Log.php 프로젝트: swcug/bzfshop
 /**
  * @param $goods_id
  * @param $admin_user_id
  * @param $admin_user_name
  * @param $desc
  * @param $content
  */
 public function addGoodsLog($goods_id, $admin_user_id, $admin_user_name, $desc, $content)
 {
     // 参数验证
     $validator = new Validator(array('goods_id' => $goods_id, 'admin_user_id' => $admin_user_id, 'admin_user_name' => $admin_user_name));
     $goods_id = $validator->required()->digits()->min(1)->validate('goods_id');
     $admin_user_id = $validator->required()->digits()->min(1)->validate('admin_user_id');
     $admin_user_name = $validator->required()->validate('admin_user_name');
     $this->validate($validator);
     $goodsLog = $this->_loadById('goods_log', 'log_id = ?', 0);
     $goodsLog->log_time = Time::gmTime();
     $goodsLog->goods_id = $goods_id;
     $goodsLog->admin_user_id = $admin_user_id;
     $goodsLog->admin_user_name = $admin_user_name;
     $goodsLog->desc = $desc;
     $goodsLog->content = $content;
     $goodsLog->save();
 }
예제 #14
0
파일: Cron.php 프로젝트: swcug/bzfshop
 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));
 }
예제 #15
0
    /**
     * 输出商品的列表
     *
     * @param $f3
     * @param $pageNo
     */
    public function outputGoodsViewListXml($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;
        }
        $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance();
        // 查询商品
        $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'g.goods_id, g.add_time, g.update_time', array(array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray(), 'g'))), array(array('g.goods_id', 'desc')), $pageNo * $this->pageSize, $this->pageSize);
        $xmlItems = '';
        if (empty($goodsArray)) {
            goto out;
        }
        $currentGmTime = Time::gmTime();
        $goodsArrayCount = count($goodsArray);
        for ($index = 0; $index < $goodsArrayCount; $index++) {
            $xmlItems .= $this->getGoodsItemXml($goodsArray[$index], $currentGmTime);
        }
        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);
    }
예제 #16
0
 /**
  * 驱动 Cron 任务执行
  *
  * @param $f3
  */
 public function Run($f3)
 {
     $taskCount = 0;
     while (($cronTask = CronHelper::loadNextUnRunCronTask(Time::gmTime())) && $taskCount++ < self::$maxRunTaskCount) {
         $cronResult = array('code' => -1, 'message' => '任务内部错误,请查看日志');
         // 加载 Task Class
         $taskInstance = CronHelper::loadTaskClass($cronTask['task_class']);
         // 无法实例化 task class,打印错误日志
         if (null == $taskInstance) {
             printLog('can not instantiate task ' . json_encode($cronTask->toArray()), __CLASS__, \Core\Log\Base::ERROR);
         } else {
             // 执行任务
             $cronResult = call_user_func_array(array($taskInstance, 'run'), array(json_decode($cronTask['task_param'], true)));
         }
         // 释放内存
         unset($taskInstance);
         // 更新任务执行状态
         $cronTask->task_run_time = Time::gmTime();
         $cronTask->return_code = @$cronResult['code'];
         $cronTask->return_message = @$cronResult['message'];
         $cronTask->save();
         unset($cronTask);
     }
 }
예제 #17
0
    public function get($f3)
    {
        global $smarty;
        $smartyCacheId = 'EtaoFeed|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '_\\' . __METHOD__);
        // 判断是否有缓存
        enableSmartyCache(true, 1800);
        // 缓存 30 分钟
        if ($smarty->isCached('empty.tpl', $smartyCacheId)) {
            goto out_display;
        }
        // 取得商品分类树形结构
        $goodsCategoryService = new GoodsCategoryService();
        $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray(0);
        $currentStamp = Time::localTimeStr();
        $sellerId = EtaoFeedPlugin::getOptionValue('etaofeed_seller_id');
        // 生成商品分类 XML
        $categoryXmlList = '';
        foreach ($goodsCategoryTreeArray as $goodsCategoryItem) {
            $categoryXmlList .= $this->getGoodsCategoryXml($goodsCategoryItem);
        }
        $apiXml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<root>
  <version>1.0</version>
  <modified>{$currentStamp}</modified>
  <seller_id>{$sellerId}</seller_id>
  <seller_cats>{$categoryXmlList}</seller_cats>
</root>
XML;
        $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);
    }
예제 #18
0
 public function getRequestUrl($orderId, $returnUrl, $notifyUrl)
 {
     // 参数验证
     $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $returnUrl = $validator->required()->validate('returnUrl');
     $notifyUrl = $validator->required()->validate('notifyUrl');
     $this->validate($validator);
     //设置订单 ID
     $this->orderId = $orderId;
     // 取得订单
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
     if (empty($orderInfo) || $orderInfo->isEmpty()) {
         throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']');
     }
     $desc = $orderInfo['order_id'] . '|' . Money::toSmartyDisplay($orderInfo['order_amount']) . '|' . $orderInfo['system_id'];
     // 创建支付请求对象
     $reqHandler = new RequestHandler();
     $reqHandler->init();
     $reqHandler->setKey($this->partnerKey);
     $reqHandler->setGateUrl("https://gw.tenpay.com/gateway/pay.htm");
     //设置支付参数
     $reqHandler->setParameter("partner", $this->partnerId);
     $reqHandler->setParameter("out_trade_no", $orderInfo['order_sn'] . '_' . $orderId);
     $reqHandler->setParameter("total_fee", Money::storageToCent($orderInfo['order_amount']));
     //总金额
     $reqHandler->setParameter("return_url", $returnUrl);
     $reqHandler->setParameter("notify_url", $notifyUrl);
     $reqHandler->setParameter("body", $desc);
     $reqHandler->setParameter("bank_type", $this->bankType);
     //银行类型,默认为财付通, DEFAULT
     //用户ip
     $reqHandler->setParameter("spbill_create_ip", $_SERVER['REMOTE_ADDR']);
     //客户端IP
     $reqHandler->setParameter("fee_type", "1");
     //币种
     $reqHandler->setParameter("subject", mb_substr($desc, 0, 32));
     //商品名称,(中介交易时必填)
     //系统可选参数
     $reqHandler->setParameter("sign_type", "MD5");
     //签名方式,默认为MD5,可选RSA
     $reqHandler->setParameter("service_version", "1.0");
     //接口版本号
     $reqHandler->setParameter("input_charset", "utf-8");
     //字符集
     $reqHandler->setParameter("sign_key_index", "1");
     //密钥序号
     //业务可选参数
     $reqHandler->setParameter("attach", "");
     //附件数据,原样返回就可以了
     $reqHandler->setParameter("product_fee", "");
     //商品费用
     $reqHandler->setParameter("transport_fee", "0");
     //物流费用
     $reqHandler->setParameter("time_start", date("YmdHis", Time::gmTimeToChinaTime($orderInfo['add_time'])));
     //订单生成时间
     $reqHandler->setParameter("time_expire", "");
     //订单失效时间
     $reqHandler->setParameter("buyer_id", "");
     //买方财付通帐号
     $reqHandler->setParameter("goods_tag", "");
     //商品标记
     $reqHandler->setParameter("trade_mode", $this->tradeMode);
     //交易模式(1.即时到帐模式,2.中介担保模式,3.后台选择(卖家进入支付中心列表选择))
     $reqHandler->setParameter("transport_desc", "");
     //物流说明
     $reqHandler->setParameter("trans_type", "1");
     //交易类型
     $reqHandler->setParameter("agentid", "");
     //平台ID
     $reqHandler->setParameter("agent_type", "");
     //代理模式(0.无代理,1.表示卡易售模式,2.表示网店模式)
     $reqHandler->setParameter("seller_id", "");
     //卖家的商户号
     //请求的URL
     $reqUrl = $reqHandler->getRequestURL();
     //获取debug信息,建议把请求和debug信息写入日志,方便定位问题
     $debugInfo = $reqHandler->getDebugInfo();
     return $reqUrl;
 }
예제 #19
0
/**
 * 系统使用的是 GM 时间,这个方法用于转换为 Local Time,并且显示
 */
function smarty_helper_modifier_localtime($gmTime, $format = null)
{
    return Time::gmTimeToLocalTimeStr($gmTime, $format);
}
예제 #20
0
파일: Goods.php 프로젝트: jackycgq/bzfshop
 /**
  * 设置订单的信息,注意:这个方法里面糅合了很多功能,通过 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);
 }
예제 #21
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');
 }
예제 #22
0
파일: Edit.php 프로젝트: jackycgq/bzfshop
 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');
 }
예제 #23
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);
    }
예제 #24
0
 /**
  * 注册用户账号转化
  */
 private function convertUsers()
 {
     $tableMigrate = new TableMigrate();
     // 清空数据
     $dstTable = new DstDataMapper('users');
     $tableMigrate->clearTable($dstTable);
     $tableMigrate->clearTable(new DstDataMapper('user_account'));
     $tableMigrate->clearTable(new DstDataMapper('user_address'));
     $tableMigrate->clearTable(new DstDataMapper('user_bonus'));
     $tableMigrate->clearTable(new DstDataMapper('user_feed'));
     $tableMigrate->clearTable(new DstDataMapper('user_rank'));
     //转化数据
     $tableMigrate->convertTable('user', array(), array('order' => 'id asc'), 'users', array('id' => 'user_id', 'email' => 'email', 'username' => 'user_name', 'password' => 'password', 'money' => 'user_money', 'sns' => 'sns_login', 'login_time' => 'last_login', 'create_time' => 'reg_time', 'score' => 'ec_salt'), array('login_time' => function ($login_time, $record) {
         //抓换成 GMT 时间
         return Time::localTimeToGmTime($login_time);
     }, 'create_time' => function ($create_time, $record) {
         //抓换成 GMT 时间
         return Time::localTimeToGmTime($create_time);
     }, 'score' => function ($score, $record) {
         return '@4!@#$%@';
         // 注意:这里是最土系统里面写死的值
     }));
     // 重设表的 AUTO_INCREMENT 值
     $tableMigrate->resetAutoIncValue($dstTable, 'user_id');
     // 清理数据
     unset($tableMigrate);
     unset($dstTable);
     unset($result);
 }
예제 #25
0
파일: Bonus.php 프로젝트: jackycgq/bzfshop
 /**
  * 取得用户现在可以使用的 bonus
  * 
  * @return array
  * 
  * @param int $userId 用户ID
  * @param float $price 订单金额
  * @param string $sn bonus 的 SN 编号
  */
 public function fetchUsableBonusBySn($userId, $price, $sn)
 {
     // 参数验证
     $validator = new Validator(array('userId' => $userId, 'price' => $price, 'sn' => $sn));
     $userId = $validator->required()->digits()->min(1)->validate('userId');
     $price = $validator->required()->float()->min(0)->validate('price');
     $sn = $validator->required()->digits()->validate('sn');
     $this->validate($validator);
     $currentGmTime = Time::gmTime();
     $condArray = array();
     $condArray[] = array('ub.bonus_type_id = bt.type_id and ub.used_time is null or ub.used_time = 0');
     $condArray[] = array('bt.use_start_date <= ? and bt.use_end_date > ?', $currentGmTime, $currentGmTime);
     $condArray[] = array('bt.min_goods_amount < ?', $price);
     $condArray[] = array('ub.user_id=?', $userId);
     $condArray[] = array('ub.bonus_sn = ?', $sn);
     $result = $this->_fetchArray(array('user_bonus' => 'ub', 'bonus_type' => 'bt'), '*', $condArray, array('order' => 'bonus_id asc'), 0, 1);
     if (empty($result)) {
         return null;
     }
     return $result[0];
 }
예제 #26
0
파일: Admin.php 프로젝트: jackycgq/bzfshop
 /**
  * 管理员操作日志
  *
  * @param $f3
  */
 public function ListLog($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_admin_listlog');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     //查询条件
     $formQuery = array();
     $formQuery['user_id'] = $validator->filter('ValidatorIntValue')->validate('user_id');
     $formQuery['operate'] = $validator->validate('operate');
     $formQuery['operate_desc'] = $validator->validate('operate_desc');
     //操作时间
     $operateTimeStartStr = $validator->validate('operate_time_start');
     $operateTimeStart = Time::gmStrToTime($operateTimeStartStr) ?: null;
     $operateTimeEndStr = $validator->validate('operate_time_end');
     $operateTimeEnd = Time::gmStrToTime($operateTimeEndStr) ?: null;
     $formQuery['operate_time'] = array($operateTimeStart, $operateTimeEnd);
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 20;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 建立查询条件
     $condArray = QueryBuilder::buildQueryCondArray($formQuery);
     // 查询管理员列表
     $adminLogService = new AdminLogService();
     $totalCount = $adminLogService->countAdminLogArray($condArray);
     if ($totalCount <= 0) {
         // 没数据,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Account/Admin/ListLog');
     }
     // 管理员列表
     $adminLogArray = $adminLogService->fetchAdminLogArray($condArray, $pageNo * $pageSize, $pageSize);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('adminLogArray', $adminLogArray);
     out_display:
     $smarty->display('account_admin_listlog.tpl');
 }
예제 #27
0
파일: Refer.php 프로젝트: jackycgq/bzfshop
 /**
  * 订单下载
  *
  * @param $f3
  */
 public function Download($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_stat_order_refer_download');
     $errorMessage = '';
     if (!$f3->get('GET')) {
         // 没有任何查询,直接显示空页面
         $errorMessage = '查询参数不能为空';
         goto out_fail;
     }
     // 做数据查询
     $orderGoodsArray = $this->doQuery($f3);
     // 没有数据,不需要计算
     if (empty($orderGoodsArray)) {
         $errorMessage = '没有订单可以下载';
         goto out_fail;
     }
     // 转换显示格式
     foreach ($orderGoodsArray as &$orderGoodsItem) {
         $orderGoodsItem['add_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['add_time'], 'Y-m-d H:i:s');
         $orderGoodsItem['pay_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['pay_time'], 'Y-m-d H:i:s');
         $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']];
     }
     unset($orderGoodsItem);
     // 生成 Excel 并且提供下载
     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;
     $lastOrderId = 0;
     $orderGoodsArraySize = count($orderGoodsArray);
     // 输出表头
     $this->outputHeaderRow($activeSheet, $rowIndex);
     $rowIndex++;
     // 用于订单计算的 order_goods
     $calOrderGoodsArray = array();
     for ($orderGoodsIndex = 0; $orderGoodsIndex < $orderGoodsArraySize; $orderGoodsIndex++) {
         // 取得这行数据
         $orderGoodsItem = $orderGoodsArray[$orderGoodsIndex];
         if ($lastOrderId != $orderGoodsItem['order_id']) {
             // 计算整个订单的 CPS 费用
             if (!empty($calOrderGoodsArray)) {
                 $tmpIndex = 0;
                 $orderStatResult = $this->calculateOrder($lastOrderId, $tmpIndex, $calOrderGoodsArray);
                 $orderStatResult['utm_source'] = '订单CPS总计-->';
                 unset($orderStatResult['utm_medium']);
                 // 输出订单的计算结果
                 $this->outputDataRow($activeSheet, $rowIndex, $orderStatResult);
                 $rowIndex += 2;
                 // 留出一个空行
                 // 释放内存
                 unset($calOrderGoodsArray);
                 unset($orderStatResult);
                 $calOrderGoodsArray = array();
             }
             // 更新订单 id
             $lastOrderId = $orderGoodsItem['order_id'];
         }
         // 加入需要计算的 order_goods 记录
         $calOrderGoodsArray[] = $orderGoodsItem;
         // 输出 order_goods 行
         $this->outputDataRow($activeSheet, $rowIndex, $orderGoodsItem);
         // 数据换行
         $rowIndex++;
     }
     // 最后一次计算整个订单的 CPS 费用
     if (!empty($calOrderGoodsArray)) {
         $tmpIndex = 0;
         $orderStatResult = $this->calculateOrder($lastOrderId, $tmpIndex, $calOrderGoodsArray);
         $orderStatResult['utm_source'] = '订单CPS总计-->';
         unset($orderStatResult['utm_medium']);
         // 输出订单的计算结果
         $this->outputDataRow($activeSheet, $rowIndex, $orderStatResult);
         $rowIndex += 2;
         // 留出一个空行
         // 释放内存
         unset($calOrderGoodsArray);
         unset($orderStatResult);
     }
     // 输出为 Excel5 格式
     $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
     $fileName = '来源渠道订单下载';
     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_fail:
     echo $errorMessage;
 }
예제 #28
0
파일: Excel.php 프로젝트: jackycgq/bzfshop
 /**
  * 批量上传快递单号,必须上传配货单
  *
  * @param $f3
  */
 public function Upload($f3)
 {
     $recIdColumnIndex = 5;
     // 子订单 ID 列号
     $shippingIdColumnIndex = 23;
     // 快递公司 ID 列号
     $shippingNoColumnIndex = 24;
     // 快递单号列
     if (empty($_FILES) || !array_key_exists('uploadfile', $_FILES)) {
         $this->addFlashMessage('没有上传文件');
         goto out;
     }
     if ($_FILES['uploadfile']['error'] > 0) {
         $this->addFlashMessage('上传文件错误:' . $_FILES['uploadfile']['error']);
         goto out;
     }
     // 解析上传的文件名
     $pathInfoArray = pathinfo($_FILES['uploadfile']['name']);
     $fileExt = strtolower($pathInfoArray['extension']);
     if ('xls' != $fileExt) {
         $this->addFlashMessage('文件格式错误,必须是 Excel xls 文件');
         goto out;
     }
     $targetFile = $f3->get('TEMP') . time() . $fileExt;
     move_uploaded_file($_FILES['uploadfile']['tmp_name'], $targetFile);
     require_once PROTECTED_PATH . '/Vendor/PHPExcel/Settings.php';
     // 设置Excel缓存,防止数据太多拖死了程序
     \PHPExcel_Settings::setCacheStorageMethod(\PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp);
     try {
         $objPHPExcel = \PHPExcel_IOFactory::load($targetFile);
     } catch (\Exception $e) {
         $this->addFlashMessage('上传的文件格式错误,请注意不要修改批量下载订单文件的格式');
         goto out;
     }
     // 取得快递公司列表
     $expressService = new ExpressService();
     $expressArray = $expressService->fetchExpressArray();
     // 构建 shipping_id --> express 的反查表
     $shippingIdExpressArray = array();
     foreach ($expressArray as $expressItem) {
         $shippingIdExpressArray[$expressItem['meta_id']] = $expressItem;
     }
     unset($expressArray);
     unset($expressService);
     // 释放内存
     $activeSheet = $objPHPExcel->setActiveSheetIndex(0);
     $maxRow = $activeSheet->getHighestRow();
     $expressSetCount = 0;
     // 成功设置计数
     // 当前登录用户
     $authSupplierUser = AuthHelper::getAuthUser();
     $orderBasicService = new OrderBasicService();
     // 一行一行的读取数据
     for ($currentRow = 1; $currentRow <= $maxRow; $currentRow++) {
         // 取得子订单 ID
         $recIdStr = trim($activeSheet->getCellByColumnAndRow($recIdColumnIndex, $currentRow)->getValue());
         if (!ctype_digit($recIdStr)) {
             // 如果不全是数字,说明这列不对
             continue;
         }
         $orderGoods = $orderBasicService->loadOrderGoodsById(intval($recIdStr));
         if ($orderGoods->isEmpty() || OrderGoodsService::OGS_PAY != $orderGoods->order_goods_status || $orderGoods['suppliers_id'] != $authSupplierUser['suppliers_id']) {
             $this->addFlashMessage('子订单[' . $recIdStr . ']非法');
             continue;
         }
         //取得快递公司 ID 设置
         $shippingIdStr = trim($activeSheet->getCellByColumnAndRow($shippingIdColumnIndex, $currentRow)->getValue());
         if (!ctype_digit($shippingIdStr) || intval($shippingIdStr) <= 0) {
             $this->addFlashMessage('子订单[' . $recIdStr . '] 对应的 快递ID 错误');
             continue;
         }
         $shipping_id = intval($shippingIdStr);
         if (!isset($shippingIdExpressArray[$shipping_id])) {
             $this->addFlashMessage('子订单[' . $recIdStr . '] 对应的 快递ID[' . $shipping_id . '] 非法');
             continue;
         }
         if ($orderGoods->shipping_id > 0) {
             $this->addFlashMessage('子订单[' . $recIdStr . '] 覆盖了之前已有的快递信息 [' . $orderGoods->shipping_name . ':' . $orderGoods->shipping_no . ']');
         }
         //取得快递单号
         $shippingNoStr = trim($activeSheet->getCellByColumnAndRow($shippingNoColumnIndex, $currentRow)->getValue());
         //设置快递信息
         $orderGoods->shipping_id = $shipping_id;
         $orderGoods->shipping_name = $shippingIdExpressArray[$shipping_id]['meta_name'];
         $orderGoods->shipping_no = $shippingNoStr;
         $orderGoods->save();
         $expressSetCount++;
         // 更新 order_info 的 update_time 字段
         $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id'], 1);
         //缓存1秒
         $orderInfo->update_time = Time::gmTime();
         $orderInfo->save();
         // 添加订单操作日志
         $action_note = '' . $shipping_id . ',' . $shippingIdExpressArray[$shipping_id]['meta_name'] . ',' . $shippingNoStr;
         $orderActionService = new OrderActionService();
         $orderActionService->logOrderAction($orderGoods['order_id'], $orderGoods['rec_id'], $orderInfo['order_status'], $orderInfo['pay_status'], $orderGoods['order_goods_status'], $action_note, '供货商:[' . $authSupplierUser['suppliers_id'] . ']' . $authSupplierUser['suppliers_name'], 0, $orderInfo['shipping_status']);
     }
     $this->addFlashMessage('一共更新了 ' . $expressSetCount . ' 个快递信息');
     out:
     // 删除上传文件
     if (!empty($targetFile)) {
         @unlink($targetFile);
     }
     // 回到批量下载界面
     RouteHelper::reRoute($this, '/Order/Excel');
 }
예제 #29
0
파일: Order.php 프로젝트: jackycgq/bzfshop
 /**
  * 保存 order_goods 信息,如果没有 $id 则创建记录
  *
  * @return object order_goods 对象
  *
  * @param int   $id              order_goods 的数字 id : rec_id
  * @param int   $orderId         订单 ID , order_info 中的字段
  * @param array $orderGoodsInfo  orderGoods 的数据数组
  */
 public function saveOrderGoods($id, $orderId, array $orderGoodsInfo)
 {
     // 参数验证
     $validator = new Validator(array('id' => $id, 'orderId' => $orderId, 'orderGoodsInfo' => $orderGoodsInfo), '');
     $id = $validator->digits()->min(0)->validate('id');
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $orderGoodsInfo = $validator->required()->requireArray(false)->validate('orderGoodsInfo');
     $this->validate($validator);
     $orderGoods = $this->loadOrderGoodsById($id);
     if ($orderGoods->isEmpty()) {
         // 新记录
         $orderGoods->create_time = Time::gmTime();
         $orderGoods->update_time = $orderGoods->create_time;
     } else {
         // 更新记录
         $orderGoods->update_time = Time::gmTime();
     }
     // 更新 goods 中对应的 user_buy_number
     $oldBuyNumber = intval($orderGoods->goods_number);
     $newBuyNumber = array_key_exists('goods_number', $orderGoodsInfo) ? intval($orderGoodsInfo['goods_number']) : $oldBuyNumber;
     $this->updateGoodsUserBuyCount($orderGoodsInfo['goods_id'], $oldBuyNumber, $newBuyNumber);
     //清除对主键的修改
     unset($orderGoodsInfo['rec_id']);
     unset($orderGoodsInfo['order_id']);
     // 商品货号如果已经有了,就不允许修改
     if (!empty($orderGoods->goods_sn)) {
         unset($orderGoodsInfo['goods_sn']);
     }
     //保存记录到数据库
     $orderGoods->copyFrom($orderGoodsInfo);
     $orderGoods->order_id = $orderId;
     $orderGoods->save();
     return $orderGoods;
 }
예제 #30
0
파일: Payment.php 프로젝트: swcug/bzfshop
 /**
  * 标记订单已经支付
  *
  * @param int    $orderId 订单数字ID
  * @param int    $payId   支付类型,比如 4 代表财付通,5代表支付宝
  * @param string $payType 支付类型,比如 alipay, tenpay
  * @param string $payNo   支付方返回的交易编号,比如支付宝返回的交易号
  */
 public function markOrderInfoPay($orderId, $payId, $payType, $payNo, $note = '', $username = '******')
 {
     global $logger;
     // 参数验证
     $validator = new Validator(array('orderId' => $orderId, 'payId' => $payId));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $payId = $validator->required()->digits()->min(1)->validate('payId');
     $this->validate($validator);
     // 订单操作,需要保证事务
     $dbEngine = DataMapper::getDbEngine();
     try {
         $dbEngine->begin();
         // 更新 order_info
         $orderBasicService = new Order();
         $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
         if ($orderInfo->isEmpty()) {
             $logger->addLogInfo(\Core\Log\Base::ERROR, 'PAYMENT', __CLASS__ . '-' . __FUNCTION__ . ' invalid order_id [' . $orderId . ']');
             throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']');
         }
         $currentGmTime = Time::gmTime();
         $orderInfo->order_status = Order::OS_CONFIRMED;
         $orderInfo->pay_status = Order::PS_PAYED;
         $orderInfo->update_time = $currentGmTime;
         $orderInfo->confirm_time = $currentGmTime;
         $orderInfo->pay_time = $currentGmTime;
         $orderInfo->pay_id = $payId;
         $orderInfo->pay_type = $payType;
         $orderInfo->pay_no = $payNo;
         $orderInfo->money_paid = $orderInfo->order_amount;
         $orderInfo->save();
         // 更新 order_goods
         $orderGoodsService = new Goods();
         $orderGoodsService->markOrderGoodsPay($orderInfo);
         if (empty($note)) {
             $note = '[' . $payType . ']付款确认';
         }
         //记录订单操作日志
         $orderActionService = new Action();
         $orderActionService->logOrderAction($orderId, 0, Order::OS_CONFIRMED, Order::PS_PAYED, Goods::OGS_PAY, $note, $username, 0, $orderInfo['shipping_status']);
         // 提交事务
         $dbEngine->commit();
         // 记录成功日志
         $logger->addLogInfo(\Core\Log\Base::INFO, 'PAYMENT', __CLASS__ . '-' . __FUNCTION__ . ' success order_id [' . $orderId . ']');
     } catch (Exception $e) {
         // 记录异常日志
         $logger->addLogInfo(\Core\Log\Base::ERROR, 'PAYMENT', print_r($e->getTrace(), true));
         $dbEngine->rollback();
     }
     // 由于商品库存发生变化,我们需要清除商品缓存,显示新的库存
     // 注意: 这个操作绝对不能在前面的 Transaction 中操作,防止对数据库性能造成巨大影响
     $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderId);
     $goodsIdArray = array();
     foreach ($orderGoodsArray as $orderGoodsItem) {
         $goodsIdArray[] = $orderGoodsItem['goods_id'];
     }
     $goodsIdArray = array_unique($goodsIdArray);
     foreach ($goodsIdArray as $goodsId) {
         // 清除商品的缓存,确保库存数据显示是正确的
         ClearHelper::clearGoodsCacheById($goodsId);
     }
 }