Example #1
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 . ']');
         }
     }
 }
Example #2
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);
 }
Example #3
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);
 }
Example #4
0
 /**
  * @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();
 }
Example #5
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 = '';
        $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance();
        $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array(array('is_on_sale = 1'), 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">0' . $index . '</outer_id>';
        }
        out_output:
        $apiXml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<root>
  <version>1.0</version>
  <modified>{$currentStamp}</modified>
  <seller_id>{$sellerId}</seller_id>
  <cat_url>{$categoryUrl}</cat_url>
  <dir>{$itemDir}/</dir>
  <item_ids>{$itemIdXmlList}</item_ids>
</root>
XML;
        $smarty->assign('outputContent', $apiXml);
        // 更新查询时间
        EtaoFeedPlugin::saveOptionValue('etaofeed_query_timestamp', Time::gmTime());
        out_display:
        header('Content-Type:text/xml;charset=utf-8');
        header("Cache-Control: no-cache, must-revalidate");
        // HTTP/1.1 //查询信息
        $smarty->display('empty.tpl', $smartyCacheId);
    }
Example #6
0
 /**
  * @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();
 }
Example #7
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);
    }
Example #8
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);
     }
 }
Example #9
0
 /**
  * 批量上传快递单号,必须上传配货单
  *
  * @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');
 }
Example #10
0
 /**
  * 保存 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;
 }
Example #11
0
 /**
  * 标记订单已经支付
  *
  * @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);
     }
 }
Example #12
0
 /**
  * 取得用户现在可以使用的 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];
 }
Example #13
0
 /**
  * 标记 order_goods 记录为已经支付状态
  *
  * @param $orderId
  */
 public function markOrderGoodsPay($orderInfo)
 {
     // 参数验证
     $validator = new Validator(array('orderId' => $orderInfo['order_id']));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $this->validate($validator);
     // 设置 order_goods 的状态
     $sql = 'update ' . DataMapper::tableName('order_goods') . ' set order_goods_status = ' . Goods::OGS_PAY . ', update_time = ' . Time::gmTime() . ' where order_id = ? ';
     $dbEngine = DataMapper::getDbEngine();
     $dbEngine->exec($sql, $orderId);
     $goodsCommentService = new GoodsCommentService();
     $userBasicService = new UserBasicSerivce();
     $userInfo = $userBasicService->loadUserById($orderInfo['user_id']);
     $orderBasicService = new OrderBasicService();
     $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderId);
     foreach ($orderGoodsArray as $orderGoodsItem) {
         // 更新商品的销售数量
         $this->updateGoodsUserPayCount($orderGoodsItem['goods_id'], $orderGoodsItem['goods_number']);
         // 更新商品的库存
         $this->updateGoodsGoodsNumber($orderGoodsItem['goods_id'], $orderGoodsItem['goods_attr'], $orderGoodsItem['goods_number']);
         // 添加一个 goods_comment 记录
         if (!$goodsCommentService->isOrderGoodsCommentExist($orderGoodsItem['rec_id'])) {
             $goodsComment = $goodsCommentService->loadGoodsCommentById(0);
             $goodsComment->create_time = Time::gmTime();
             $goodsComment->rec_id = $orderGoodsItem['rec_id'];
             $goodsComment->goods_id = $orderGoodsItem['goods_id'];
             $goodsComment->goods_price = $orderGoodsItem['goods_price'];
             $goodsComment->goods_number = $orderGoodsItem['goods_number'];
             $goodsComment->goods_attr = $orderGoodsItem['goods_attr'];
             $goodsComment->comment_rate = 5;
             // 用户不评论,我们默认为好评,显示
             $goodsComment->is_show = 1;
             // 用户不评论,我们默认为好评,显示
             $goodsComment->user_id = $userInfo['user_id'];
             $goodsComment->user_name = $userInfo['user_name'];
             $goodsComment->save();
         }
     }
 }
Example #14
0
 public function Edit($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $article_id = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('article_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得文章
     $articleService = new ArticleService();
     $article = $articleService->loadArticleById($article_id);
     if ($article_id > 0 && $article->isEmpty()) {
         $this->addFlashMessage('文章ID[' . $article_id . ']非法');
         goto out_fail;
     }
     // 只是显示文章内容而已
     if (Request::isRequestGet()) {
         $smarty->assign('article', $article->toArray());
         goto out_get;
     }
     // 权限检查
     $this->requirePrivilege('manage_article_article_edit');
     // 从这里开始是修改文章内容
     unset($validator);
     $articleInfoArray = $f3->get('POST[article]');
     $validator = new Validator($articleInfoArray);
     // 获得修改数据
     $inputArray = array();
     $inputArray['title'] = $validator->required()->validate('title');
     $inputArray['seo_keyword'] = $validator->validate('seo_keyword');
     $inputArray['cat_id'] = $validator->validate('cat_id');
     $inputArray['is_open'] = $validator->validate('is_open');
     $inputArray['description'] = $validator->validate('description');
     $inputArray['content'] = $articleInfoArray['content'];
     // 不要过滤 html
     if (!$this->validate($validator)) {
         goto out_get;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 新建文章
     if ($article_id <= 0) {
         $inputArray['admin_user_id'] = $authAdminUser['user_id'];
         $inputArray['admin_user_name'] = $authAdminUser['user_name'];
         $inputArray['add_time'] = Time::gmTime();
     }
     // 文章更新
     $inputArray['update_user_id'] = $authAdminUser['user_id'];
     $inputArray['update_user_name'] = $authAdminUser['user_name'];
     $inputArray['update_time'] = Time::gmTime();
     // 保存修改
     $article->copyFrom($inputArray);
     $article->save();
     // 清除文章缓存
     ClearHelper::clearArticleCacheById($article->article_id);
     $this->addFlashMessage('文章保存成功');
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Article/Article/Edit', array('article_id' => $article->article_id), true));
     return;
     // POST 从这里退出
     out_get:
     // GET 从这里退出
     $smarty->display('article_article_edit.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Article/Article/Search');
 }
Example #15
0
 /**
  * 设置订单为 退款中 状态
  *
  * 即:确认已经收到用户的退货了,告知财务这个订单可以给用户退款了
  *
  * @param $f3
  */
 public function SetRefund($f3)
 {
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 取得当前供货商
     $authSupplierUser = AuthHelper::getAuthUser();
     $orderBasicService = new OrderBasicService();
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id);
     if ($orderGoods->isEmpty() || OrderGoodsService::OGS_ASKREFUND != $orderGoods->order_goods_status || $orderGoods['suppliers_id'] != $authSupplierUser['suppliers_id']) {
         $this->addFlashMessage('订单ID非法');
         goto out;
     }
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']);
     if ($orderInfo->isEmpty() || $orderInfo->pay_status != OrderBasicService::PS_PAYED) {
         $this->addFlashMessage('订单ID非法');
         goto out;
     }
     // 设置订单状态为  退款中
     $orderGoods->order_goods_status = OrderGoodsService::OGS_REFUNDING;
     $orderGoods->save();
     // 更新 order_info 的 update_time 字段
     $orderInfo->update_time = Time::gmTime();
     $orderInfo->save();
     $action_note = '设置为退款中' . "\n";
     $action_note .= '操作人:[' . $authSupplierUser['suppliers_id'] . ']' . $authSupplierUser['suppliers_name'] . "\n";
     // 添加订单操作日志
     $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_name'], 0, $orderInfo['shipping_status']);
     $this->addFlashMessage('订单状态设置为[退款中]');
     out:
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }
Example #16
0
 public function doAuthSnsUser($sns_login, $user_name, $email, $autoRegister = true)
 {
     global $f3;
     $user = new DataMapper('users');
     $user->loadOne(array('sns_login = ?', $sns_login), array('order' => 'user_id asc'));
     if (!$user->isEmpty()) {
         // 记录登录时间和IP地址
         $user->last_login = Time::gmTime();
         $user->last_ip = $f3->get('IP');
         $user->save();
         return $user;
     }
     if (!$autoRegister) {
         return false;
     }
     // 自动注册用户
     $user->sns_login = $sns_login;
     $user->user_name = $user_name;
     $user->email = $email;
     $user->password = uniqid();
     // 记录登录时间和IP地址
     $user->last_login = $user->reg_time = Time::gmTime();
     $user->last_ip = $user->reg_ip = $f3->get('IP');
     $user->save();
     return $user;
 }
Example #17
0
 public function get($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_create');
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得商品信息
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     if ($goods->isEmpty()) {
         $this->addFlashMessage('非法商品ID');
         goto out_fail;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 1. 复制 goods 信息
     $goodsArray = $goods->toArray();
     unset($goodsArray['goods_id']);
     // 清除主键
     // 新商品缺省为下线状态
     $goodsArray['is_on_sale'] = 0;
     // 清除购买数量统计
     $goodsArray['user_buy_number'] = 0;
     $goodsArray['user_pay_number'] = 0;
     // 设置复制人
     $goodsArray['admin_user_id'] = $authAdminUser['user_id'];
     $goodsArray['admin_user_name'] = $authAdminUser['user_name'];
     // 处理商品的规格
     if (!empty($goodsArray['goods_spec'])) {
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goodsArray['goods_spec']);
         $goodsSpecService->clearGoodsSpecImgIdArray();
         // 清除图片 ID 的关联
         $goodsArray['goods_spec'] = $goodsSpecService->getJsonStr();
         unset($goodsSpecService);
     }
     $goodsArray['add_time'] = Time::gmTime();
     $newGoods = $goodsBasicService->loadGoodsById(0);
     $newGoods->copyFrom($goodsArray);
     $newGoods->save();
     // 更新 goods_sn
     $newGoods->goods_sn = $f3->get('sysConfig[goods_sn_prefix]') . $newGoods['goods_id'];
     $newGoods->save();
     unset($goodsArray);
     // 2. 复制 goods_attr 信息
     if ($goods->type_id > 0) {
         $goodsTypeService = new GoodsTypeService();
         $goodsAttrValueArray = $goodsTypeService->fetchGoodsAttrItemValueArray($goods->goods_id, $goods->type_id);
         foreach ($goodsAttrValueArray as $goodsAttrValue) {
             $goodsAttr = $goodsTypeService->loadGoodsAttrById(0);
             $goodsAttr->goods_id = $newGoods->goods_id;
             $goodsAttr->attr_item_id = $goodsAttrValue['meta_id'];
             $goodsAttr->attr_item_value = $goodsAttrValue['attr_item_value'];
             $goodsAttr->save();
             unset($goodsAttr);
         }
         unset($goodsAttrValueArray);
         unset($goodsTypeService);
     }
     // 3. 复制 goods_gallery 信息
     $goodsGalleryService = new GoodsGalleryService();
     $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsId($goods_id);
     foreach ($goodsGalleryArray as $goodsGalleryItem) {
         // 新建一个 goods_gallery 记录
         $goodsGallery = $goodsGalleryService->loadGoodsGalleryById(0);
         unset($goodsGalleryItem['img_id']);
         $goodsGallery->copyFrom($goodsGalleryItem);
         $goodsGallery->goods_id = $newGoods['goods_id'];
         $goodsGallery->save();
         unset($goodsGallery);
     }
     unset($goodsGalleryArray);
     unset($goodsGalleryService);
     // 4. 复制 goods_team 信息
     $goodsTeam = $goodsBasicService->loadGoodsTeamByGoodsId($goods_id);
     if (!$goodsTeam->isEmpty()) {
         $goodsTeamInfo = $goodsTeam->toArray();
         unset($goodsTeamInfo['team_id']);
         $goodsTeamInfo['goods_id'] = $newGoods['goods_id'];
         $newGoodsTeam = new DataMapper('goods_team');
         $newGoodsTeam->copyFrom($goodsTeamInfo);
         $newGoodsTeam->save();
         unset($newGoodsTeam);
         unset($goodsTeamInfo);
         unset($goodsTeam);
     }
     // 5. 复制 link_goods 信息
     $linkGoodsArray = $goodsBasicService->fetchSimpleLinkGoodsArray($goods_id);
     foreach ($linkGoodsArray as $linkGoodsItem) {
         unset($linkGoodsItem['link_id']);
         $linkGoodsItem['goods_id'] = $newGoods['goods_id'];
         $linkGoodsItem['admin_id'] = $authAdminUser['user_id'];
         $linkGoods = new DataMapper('link_goods');
         $linkGoods->copyFrom($linkGoodsItem);
         $linkGoods->save();
         unset($linkGoods);
     }
     unset($linkGoodsArray);
     // 6. 复制 goods_promote 信息
     $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id);
     if (!$goodsPromote->isEmpty()) {
         $goodsPromoteInfo = $goodsPromote->toArray();
         unset($goodsPromoteInfo['promote_id']);
         $goodsPromoteInfo['goods_id'] = $newGoods['goods_id'];
         $newGoodspromote = new DataMapper('goods_promote');
         $newGoodspromote->copyFrom($goodsPromoteInfo);
         $newGoodspromote->save();
         unset($newGoodspromote);
     }
     unset($goodsPromote);
     // 记录编辑日志
     $goodsLogContent = '从 [' . $goods_id . '] 复制过来';
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($newGoods['goods_id'], $authAdminUser['user_id'], $authAdminUser['user_name'], '复制商品', $goodsLogContent);
     $this->addFlashMessage('复制新建商品成功');
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Edit', array('goods_id' => $newGoods['goods_id']), true));
     return;
     //正常返回
     out_fail:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
Example #18
0
 /**
  * 订单商品评价
  *
  * @param $f3
  */
 public function GoodsComment($f3)
 {
     global $smarty;
     $errorMessage = '';
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     if (!$this->validate($validator)) {
         $errorMessage = '订单ID非法';
         goto out_fail;
     }
     $orderBasicService = new OrderBasicService();
     // 查询 order_goods
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id, 10);
     // 缓存 10 秒钟
     if ($orderGoods->isEmpty()) {
         $errorMessage = '订单ID非法';
         goto out_fail;
     }
     // 查询 order_info
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id'], 10);
     // 缓存 10 秒钟
     // 权限检查,用户只能查看自己的订单
     $userInfo = AuthHelper::getAuthUser();
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || !$this->verifyOrderSystem($orderInfo)) {
         $errorMessage = '订单ID非法';
         goto out_fail;
     }
     // 加载订单评论
     $goodsCommentService = new GoodsCommentService();
     $goodsComment = $goodsCommentService->loadGoodsCommentByOrderGoodsRecId($rec_id, 1);
     // 缓存1秒
     if ($goodsComment->isEmpty() || $goodsComment['user_id'] != $userInfo['user_id']) {
         $errorMessage = '无法评论此订单';
         goto out_fail;
     }
     // post 请求
     if (Request::isRequestPost()) {
         goto do_post;
     }
     // 赋值评论信息
     $smarty->assign('goodsComment', $goodsComment->toArray());
     out_fail:
     // GET 从这里退出
     $smarty->assign('errorMessage', $errorMessage);
     $smarty->display('my_order_goodscomment.tpl');
     return;
     do_post:
     // 这里处理 post 请求
     // 用户评论缺省不显示,需要等管理员审核通过才能显示
     $goodsComment->is_show = 0;
     $goodsComment->comment_time = Time::gmTime();
     // 过滤用户提交的数据
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     $goodsComment->comment_rate = $validator->filter('ValidatorIntValue')->validate('comment_rate');
     $goodsComment->comment = $validator->validate('comment');
     $goodsComment->save();
     $this->addFlashMessage('评论发表成功,请等待管理员审核通过才能显示');
     // 回到前面的页面
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }
Example #19
0
 public function Create($f3)
 {
     // 新建商品类型,权限检查
     $this->requirePrivilege('manage_goods_comment_create');
     global $smarty;
     $smarty->assign('create_time', Time::gmTime());
     $smarty->assign('goods_price', 0);
     $smarty->display('goods_comment_edit.tpl');
 }
Example #20
0
 /**
  * 设置订单的快递信息
  *
  * @param $f3
  */
 public function ajaxUpdate($f3)
 {
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $rec_id = $validator->required('子订单ID不能为空')->digits('子订单ID必须是数字')->min(1)->validate('rec_id');
     $shipping_id = $validator->digits('快递ID必须是数字')->min(1)->validate('shipping_id');
     $shipping_no = $validator->validate('shipping_no');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取 order_goods
     $orderBasicService = new OrderBasicService();
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id);
     if ($orderGoods->isEmpty()) {
         $this->addFlashMessage('非法订单');
         goto out_fail;
     }
     // 权限检查
     $authSupplierUser = AuthHelper::getAuthUser();
     if ($orderGoods['suppliers_id'] !== $authSupplierUser['suppliers_id']) {
         $this->addFlashMessage('非法订单');
         goto out_fail;
     }
     // 取得快递名
     if ($shipping_id > 0) {
         //取得快递信息
         $expressService = new ExpressService();
         $expressInfo = $expressService->loadMetaById($shipping_id);
         if ($expressInfo->isEmpty() || ExpressService::META_TYPE != $expressInfo['meta_type']) {
             $this->addFlashMessage('快递ID非法');
             goto out_fail;
         }
         $shipping_name = $expressInfo['meta_name'];
     } else {
         $shipping_name = null;
     }
     // 更新快递信息
     $orderGoods->shipping_id = $shipping_id;
     $orderGoods->shipping_name = $shipping_name;
     $orderGoods->shipping_no = $shipping_no;
     $orderGoods->save();
     // 更新 order_info 的 update_time 字段
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']);
     $orderInfo->update_time = Time::gmTime();
     $orderInfo->save();
     // 添加订单操作日志
     if ($shipping_id > 0) {
         $action_note = '' . $shipping_id . ',' . $shipping_name . ',' . $shipping_no;
     } else {
         $action_note = '删除快递信息';
     }
     $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']);
     Ajax::header();
     echo Ajax::buildResult(null, null, null);
     return;
     // 成功从这里返回
     out_fail:
     // 失败从这里退出
     Ajax::header();
     $errorMessage = '';
     foreach ($this->flashMessageArray as $messageItem) {
         $errorMessage .= $messageItem . ',';
     }
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
Example #21
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 #22
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 #23
0
 /**
  * 把购物车中的信息保存到数据库订单中,如果订单已经存在,则更新订单数据,
  * 注意:这个方法必须在购物车计算完成之后调用,否则无法正确保存计算之后的数据
  *
  * @return mixed 失败返回 false,成功返回订单记录
  *
  * @param int    $userId   用户的数字 ID
  * @param string $username 用户名
  */
 public function saveOrder($userId, $username)
 {
     // 参数验证
     $validator = new Validator(array('userId' => $userId));
     $userId = $validator->required()->digits()->min(1)->validate('userId');
     $this->validate($validator);
     $orderBasicService = new OrderBasicService();
     $orderId = isset($this->cartContext->orderInfo) ? $this->cartContext->orderInfo['order_id'] : null;
     // 不允许创建空订单
     if (!$orderId && $this->cartContext->isEmpty()) {
         return false;
     }
     // 是否需要新建订单
     $isNewOrder = false;
     //检查这个 order_info 是否合法
     if ($orderId) {
         $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
         // 不存在的 order_info 或者 已经付款了的订单不能再用了
         if ($orderInfo->isEmpty() || OrderBasicService::PS_UNPAYED != $orderInfo->pay_status) {
             $orderId = null;
             $isNewOrder = true;
         }
     } else {
         $isNewOrder = true;
     }
     // 创建 order_info 记录
     $orderInfoArray = $this->cartContext->orderInfoValue;
     $orderInfoArray['user_id'] = $userId;
     $orderInfoArray['order_status'] = OrderBasicService::OS_UNCONFIRMED;
     $orderInfoArray['pay_status'] = OrderBasicService::PS_UNPAYED;
     if (!$orderId) {
         // 新订单,生成 add_time 和 order_sn
         $orderInfoArray['add_time'] = Time::gmTime();
         $orderInfoArray['order_sn'] = OrderBasicService::generateOrderSn();
         $orderInfoArray['system_id'] = Cart::$cartSystemId;
         // 记录订单来自于哪个系统
     } elseif ($this->cartContext->isOrderAmountChange()) {
         // 去支付网关支付,如果订单金额发生变化都需要重新生成一次 order_sn ,因为订单金额如果发生变化,支付网关会拒绝支付
         $orderInfoArray['order_sn'] = OrderBasicService::generateOrderSn();
     } else {
         // do nothing
     }
     // 我们需要数据库事务的保障
     $dbEngine = DataMapper::getDbEngine();
     $dbEngine->begin();
     // 记录余额支付
     $oldSurplus = $this->cartContext->orderInfo ? $this->cartContext->orderInfo['surplus'] : 0;
     $newSurplus = $this->cartContext->getValue('surplus') > 0 ? $this->cartContext->getValue('surplus') : 0;
     // 记录使用红包
     $oldBonusId = $this->cartContext->orderInfo ? $this->cartContext->orderInfo['bonus_id'] : 0;
     $newBonusId = $this->cartContext->getValue('bonus_id') > 0 ? $this->cartContext->getValue('bonus_id') : 0;
     // 创建订单或者更新 order_info
     $orderInfo = $orderBasicService->saveOrderInfo($orderId, $orderInfoArray);
     // 创建订单失败,返回 false
     if ($orderInfo->isEmpty()) {
         goto out_fail;
     }
     // 处理余额支付
     if ($oldSurplus != $newSurplus) {
         // 前后发生了支付余额的改变
         $accountLog = new AccountLog();
         if ($oldSurplus > 0) {
             // 把之前的余额退还
             $accountLog->logChange($userId, $oldSurplus, 0, 0, 0, '退还余额,订单:' . $orderInfo['order_id'], AccountLog::ACT_OTHER);
         }
         if ($newSurplus > 0) {
             // 使用余额
             $accountLog->logChange($userId, -1 * $newSurplus, 0, 0, 0, '使用余额,订单:' . $orderInfo['order_id'], AccountLog::ACT_OTHER);
         }
         // 由于修改了用户信息,需要 reload 用户数据
         AuthHelper::reloadAuthUser();
     }
     // 处理红包支付
     if ($oldBonusId != $newBonusId) {
         // 红包支付前后发生了变化
         $bonusService = new Bonus();
         if ($oldBonusId > 0) {
             //退还之前使用的红包
             $bonusService->unUseBonus($oldBonusId);
         }
         if ($newBonusId > 0) {
             // 使用新的红包
             $bonusService->useBonus($newBonusId, $orderInfo['order_id']);
         }
     }
     // 创建 orderRefer 对象,记录订单的来源
     $orderReferService = new OrderReferService();
     $orderRefer = $orderReferService->loadOrderReferByOrderId($orderInfo['order_id']);
     // order_refer 记录创建一次之后就不会再修改了
     if ($orderRefer->isEmpty()) {
         // 新的 order_refer 记录,设置 order_id 值
         $orderRefer->order_id = $orderInfo['order_id'];
         $orderRefer->create_time = Time::gmTime();
         $orderRefer->login_type = AuthHelper::getLoginType();
         global $f3;
         $orderReferArray = ReferHelper::parseOrderRefer($f3);
         if (!empty($orderReferArray)) {
             unset($orderReferArray['refer_id']);
             //清除掉危险字段
             unset($orderReferArray['order_id']);
             //清除掉危险字段
             $orderRefer->copyFrom($orderReferArray);
         }
         $orderRefer->save();
         // 保存 order_refer 记录
     }
     // 取得数据库中已经存在的 order_goods 列表
     $dbOrderGoodsArray = array();
     if ($orderId > 0) {
         $dbOrderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderId);
     }
     $stillExistOrderGoodsIdArray = array();
     // 在购物车中仍然存在的 orderGoods 对象
     // 创建 orderInfo 对应的 order_goods 对象
     foreach ($this->cartContext->orderGoodsArray as $orderGoodsItem) {
         $orderGoodsValueArray = array();
         $orderGoodsValueArray['order_id'] = $orderInfo['order_id'];
         //从 goods 中复制属性
         $orderGoodsValueArray['goods_id'] = $orderGoodsItem->goods['goods_id'];
         $orderGoodsValueArray['goods_admin_user_id'] = $orderGoodsItem->goods['admin_user_id'];
         $orderGoodsValueArray['goods_admin_user_name'] = $orderGoodsItem->goods['admin_user_name'];
         $orderGoodsValueArray['goods_name'] = $orderGoodsItem->goods['goods_name_short'];
         $orderGoodsValueArray['goods_sn'] = $orderGoodsItem->goods['goods_sn'];
         $orderGoodsValueArray['warehouse'] = $orderGoodsItem->goods['warehouse'];
         $orderGoodsValueArray['shelf'] = $orderGoodsItem->goods['shelf'];
         $orderGoodsValueArray['market_price'] = $orderGoodsItem->goods['market_price'];
         $orderGoodsValueArray['shop_price'] = $orderGoodsItem->goods['shop_price'];
         $orderGoodsValueArray['shipping_fee'] = $orderGoodsItem->goods['shipping_fee'];
         $orderGoodsValueArray['is_real'] = $orderGoodsItem->goods['is_real'];
         $orderGoodsValueArray['extension_code'] = $orderGoodsItem->goods['extension_code'];
         $orderGoodsValueArray['suppliers_id'] = $orderGoodsItem->goods['suppliers_id'];
         $orderGoodsValueArray['suppliers_price'] = $orderGoodsItem->goods['suppliers_price'];
         $orderGoodsValueArray['suppliers_shipping_fee'] = $orderGoodsItem->goods['suppliers_shipping_fee'];
         // 合并一些因为计算而覆盖的值
         $orderGoodsValueArray = array_merge($orderGoodsValueArray, $orderGoodsItem->orderGoodsValue);
         $orderGoodsId = null;
         if (!$isNewOrder && $orderGoodsItem->orderGoods) {
             // 如果不是新订单,并且已经存在的 order_goods,做更新
             $orderGoodsId = $orderGoodsItem->orderGoods['rec_id'];
             $stillExistOrderGoodsIdArray[] = $orderGoodsId;
         } else {
             // 新建的 order_goods,我们需要取得它的 CPS 信息,CPS 信息只在一开始加入,后面不会再被修改了
             $cpsArray = ReferHelper::getCpsParam($orderRefer, $orderInfo, $orderGoodsValueArray);
             if (!empty($cpsArray)) {
                 $orderGoodsValueArray['cps_rate'] = isset($cpsArray['cps_rate']) ? $cpsArray['cps_rate'] : 0;
                 $orderGoodsValueArray['cps_fix_fee'] = isset($cpsArray['cps_fix_fee']) ? $cpsArray['cps_fix_fee'] : 0;
             }
         }
         $orderGoods = $orderBasicService->saveOrderGoods($orderGoodsId, $orderInfo['order_id'], $orderGoodsValueArray);
         if ($orderGoods->isEmpty()) {
             //创建失败
             goto out_fail;
         }
     }
     // 删除已经被用户删除的 order_goods
     foreach ($dbOrderGoodsArray as $dbOrderGoodsItem) {
         // 这个 order_goods 已经不存在了,删除它
         if (!in_array($dbOrderGoodsItem['rec_id'], $stillExistOrderGoodsIdArray)) {
             $orderBasicService->removeOrderGoods($dbOrderGoodsItem['rec_id']);
         }
     }
     // 记录订单操作日志
     $orderActionService = new OrderActionService();
     $orderActionService->logOrderAction($orderInfo['order_id'], 0, OrderBasicService::OS_UNCONFIRMED, OrderBasicService::PS_UNPAYED, OrderGoodsService::OGS_UNPAY, '订单创建或更新', $username, 0, 0);
     $dbEngine->commit();
     return $orderInfo;
     // 返回创建的订单
     out_fail:
     $dbEngine->rollback();
     return false;
 }
Example #24
0
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_settle');
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $payTimeStart = $validator->required()->digits()->validate('payTimeStart');
     $payTimeEnd = $validator->required()->digits()->validate('payTimeEnd');
     $suppliers_id = $validator->required()->digits()->validate('suppliers_id');
     if (!$this->validate($validator)) {
         goto out;
     }
     $orderGoodsIdArray = $validator->validate('orderGoodsIdArray');
     $memo = $validator->validate('memo');
     if (empty($orderGoodsIdArray) || !is_array($orderGoodsIdArray)) {
         $this->addFlashMessage('没有订单需要结算');
         goto out;
     }
     // 取得供货商的信息
     $userSupplierService = new UserSupplierService();
     $supplier = $userSupplierService->loadSupplierById($suppliers_id);
     if ($supplier->isEmpty()) {
         $this->addFlashMessage('供货商不存在');
         goto out;
     }
     // 取得所有 order_goods 记录
     $orderGoodsService = new OrderGoodsService();
     $orderGoodsArray = $orderGoodsService->_fetchArray('order_goods', 'rec_id, order_goods_status, goods_number,suppliers_id, suppliers_price, suppliers_shipping_fee, suppliers_refund, shipping_id', array(array(QueryBuilder::buildInCondition('rec_id', $orderGoodsIdArray))), array('order' => 'rec_id asc'), 0, $f3->get('sysConfig[max_query_record_count]'), 0);
     //最多限制 max_query_record_count 条记录
     if (empty($orderGoodsArray)) {
         $this->addFlashMessage('没有订单需要结算');
         goto out;
     }
     // 检查订单,计算订单结算金额
     $totalGoodsPrice = 0;
     $totalShippingFee = 0;
     $totalRefund = 0;
     $totalOrderGoodsCount = 0;
     //剔除非法的 orderGoodsId
     $invalidOrderGoodsIdArray = array();
     foreach ($orderGoodsArray as $orderGoodsItem) {
         if (OrderGoodsService::OGS_UNPAY == $orderGoodsItem['order_goods_status'] || $orderGoodsItem['suppliers_id'] != $suppliers_id || $orderGoodsItem['shipping_id'] <= 0) {
             // 非法订单,剔除掉
             $invalidOrderGoodsIdArray[] = $orderGoodsItem['rec_id'];
             continue;
         }
         $totalGoodsPrice += $orderGoodsItem['goods_number'] * $orderGoodsItem['suppliers_price'];
         $totalShippingFee += $orderGoodsItem['suppliers_shipping_fee'];
         $totalRefund += $orderGoodsItem['suppliers_refund'];
         $totalOrderGoodsCount++;
     }
     //剔除非法的 orderGoodsId
     $orderGoodsIdArray = array_diff($orderGoodsIdArray, $invalidOrderGoodsIdArray);
     if (empty($orderGoodsIdArray)) {
         $this->addFlashMessage('没有订单需要结算');
         goto out;
     }
     // 取得当前结算的管理员
     $authAdminUser = AuthHelper::getAuthUser();
     $dbEngine = DataMapper::getDbEngine();
     try {
         // 我们这里需要事务保障
         $dbEngine->begin();
         //创建 order_settle 记录
         $orderSettleService = new OrderSettleService();
         $orderSettle = $orderSettleService->loadOrderSettleBySettleId(0);
         $orderSettle->user_id = $authAdminUser['user_id'];
         $orderSettle->user_name = $authAdminUser['user_name'];
         $orderSettle->settle_start_time = $payTimeStart;
         $orderSettle->settle_end_time = $payTimeEnd;
         $orderSettle->suppliers_id = $suppliers_id;
         $orderSettle->suppliers_name = $supplier['suppliers_name'];
         $orderSettle->suppliers_goods_price = $totalGoodsPrice;
         $orderSettle->suppliers_shipping_fee = $totalShippingFee;
         $orderSettle->suppliers_refund = $totalRefund;
         $orderSettle->create_time = Time::gmTime();
         $orderSettle->memo = $memo;
         $orderSettle->save();
         // 更新 order_goods ,设置上 settle_id
         $sql = "update " . DataMapper::tableName('order_goods') . ' set settle_id = ? where ' . QueryBuilder::buildInCondition('rec_id', $orderGoodsIdArray);
         $dbEngine->exec($sql, $orderSettle->settle_id);
         $dbEngine->commit();
         $this->addFlashMessage('成功创建结算记录');
     } catch (\Exception $e) {
         $dbEngine->rollback();
         $this->addFlashMessage('数据库读写错误');
     }
     out:
     // 回到结算页面
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }
Example #25
0
 /**
  * 拒绝退款请求
  *
  * @param $f3
  */
 public function Refuse($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_refund_confirm');
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     $refund_finish_note = $validator->required()->validate('refund_finish_note');
     if (!$this->validate($validator)) {
         goto out;
     }
     $orderBasicService = new OrderBasicService();
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id);
     if ($orderGoods->isEmpty() || OrderGoodsService::OGS_REFUNDING != $orderGoods->order_goods_status) {
         $this->addFlashMessage('订单ID非法');
         goto out;
     }
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']);
     if ($orderInfo->isEmpty() || $orderInfo->pay_status != OrderBasicService::PS_PAYED) {
         $this->addFlashMessage('订单ID非法');
         goto out;
     }
     // 标记订单为 付款
     $orderGoods->order_goods_status = OrderGoodsService::OGS_PAY;
     // 清除退款记录
     $orderGoods->refund = 0;
     // 我们给顾客退款
     $orderGoods->refund_time = 0;
     $orderGoods->refund_finish_time = Time::gmTime();
     $orderGoods->refund_finish_note = $refund_finish_note;
     $orderGoods->suppliers_refund = 0;
     // 供货商给我们退款
     $orderGoods->save();
     // 更新 order_info 的 update_time 字段
     $orderInfo->update_time = Time::gmTime();
     $orderInfo->save();
     $authAdminUser = AuthHelper::getAuthUser();
     $action_note = '拒绝退款' . "\n";
     $action_note .= '操作人:[' . $authAdminUser['user_id'] . ']' . $authAdminUser['user_name'] . "\n";
     $action_note .= '备注:' . $refund_finish_note . "\n";
     // 添加订单操作日志
     $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::getRefer(), false);
 }