Exemple #1
0
 public function beforeRoute($f3)
 {
     global $smarty;
     parent::beforeRoute($f3);
     // 用户没有登陆,让用户去登陆
     if (!AuthHelper::isAuthUser()) {
         // 如果已经记录了一个回跳 URL ,则不要再覆盖这个记录了
         RouteHelper::reRoute($this, '/User/Login', !RouteHelper::hasRememberUrl());
         return;
     }
     //把认证用户放入到 smarty 中
     $smarty->assign('authSupplierUser', AuthHelper::getAuthUser());
 }
Exemple #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);
 }
Exemple #3
0
 /**
  * 判断当前用户是否有某个权限
  *
  * @param string $needPrivilege
  *
  * @return bool
  */
 protected function hasPrivilege($needPrivilege)
 {
     $authAdminUser = AuthHelper::getAuthUser();
     if (empty($authAdminUser)) {
         goto out_fail;
     }
     // 检查权限
     if (!AdminUserService::verifyPrivilege($needPrivilege, $authAdminUser['action_list'] . ',' . $authAdminUser['role_action_list'])) {
         goto out_fail;
     }
     return true;
     out_fail:
     return false;
 }
Exemple #4
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['oldpassword'] = $validator->validate('oldpassword');
     $input['password'] = $validator->validate('password');
     $input['email'] = $validator->validate('email');
     $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone');
     // 用户打算修改密码
     if (!Utils::isBlank($input['password'])) {
         $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword');
     }
     // 提供的旧密码,但是新密码为空
     if (!Utils::isBlank($input['oldpassword'])) {
         $validator->required('新密码不能为空')->validate('password');
     }
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $userInfo = AuthHelper::getAuthUser();
     $userService = new UserService();
     $user = $userService->loadUserById($userInfo['user_id']);
     if (!$user) {
         // 非法用户,应该让它自动登陆出去
         $this->addFlashMessage('非法登陆用户');
         RouteHelper::reRoute($this, '/User/Logout', false);
     }
     // 用户打算修改密码,但是旧密码不对
     if (!empty($input['password']) && !$userService->verifyPassword($userInfo['user_id'], $input['oldpassword'])) {
         $this->addFlashMessage('旧密码不对');
         goto out_fail;
     }
     // 更新数据
     unset($input['oldpassword']);
     $userService->updateUser($user, $input);
     // 更新认证记录
     AuthHelper::removeAuthUser();
     AuthHelper::saveAuthUser($user->toArray());
     $this->addFlashMessage('资料更新成功');
     RouteHelper::reRoute($this, '/My/Profile');
     return;
     // 这里正常返回
     out_fail:
     // 失败返回
     $smarty->display('my_profile.tpl', 'post');
 }
Exemple #5
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['phone'] = $validator->validate('phone');
     $input['address'] = $validator->validate('address');
     $input['oldpassword'] = $validator->validate('oldpassword');
     $input['password'] = $validator->validate('password');
     // 用户打算修改密码
     if (!Utils::isBlank($input['password'])) {
         $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword');
     }
     // 提供的旧密码,但是新密码为空
     if (!Utils::isBlank($input['oldpassword'])) {
         $validator->required('新密码不能为空')->validate('password');
     }
     if (!$this->validate($validator)) {
         goto out;
     }
     $authSupplierUser = AuthHelper::getAuthUser();
     $supplierUserService = new SupplierUserService();
     // 验证用户登陆
     $supplierUser = $supplierUserService->loadSupplierById($authSupplierUser['suppliers_id']);
     if ($supplierUser->isEmpty()) {
         $this->addFlashMessage("非法登陆用户");
         RouteHelper::reRoute($this, '/User/Logout', false);
     }
     // 用户打算修改密码,但是旧密码不对
     if (!empty($input['password']) && !$supplierUserService->verifyPassword($authSupplierUser['suppliers_id'], $input['oldpassword'])) {
         $this->addFlashMessage('旧密码不对');
         goto out;
     }
     // 更新数据
     unset($input['oldpassword']);
     $supplierUserService->updateSupplier($supplierUser, $input);
     // 记录用户的登陆信息
     $supplierUserInfo = $supplierUser->toArray();
     unset($supplierUserInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($supplierUserInfo);
     $this->addFlashMessage("修改资料成功");
     $smarty->assign($supplierUserInfo);
     out:
     // 从这里出去
     $smarty->display('my_profile.tpl');
 }
Exemple #6
0
 public function get($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     $userInfo = AuthHelper::getAuthUser();
     // 构造查询条件
     $searchFormQuery = array();
     $searchFormQuery['oi.user_id'] = $userInfo['user_id'];
     // 合并查询参数
     $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray);
     // 查询订单
     $totalCount = SearchHelper::count(SearchHelper::Module_OrderGoodsOrderInfo, $searchParamArray);
     if ($totalCount <= 0) {
         // 没订单,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/My/Order');
     }
     // 订单排序
     $orderByParam = array();
     $orderByParam[] = array('og.rec_id', 'desc');
     // 订单列表
     $orderGoodsArray = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, 'og.order_id, og.goods_id, og.goods_attr, og.goods_number, og.goods_price, og.shipping_fee' . ', og.create_time, og.order_goods_status, oi.order_sn, oi.pay_time', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize);
     foreach ($orderGoodsArray as &$orderGoodsItem) {
         $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']];
     }
     unset($orderGoodsItem);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('orderGoodsArray', $orderGoodsArray);
     out_display:
     $smarty->display('my_order.tpl', 'get');
 }
Exemple #7
0
 public function get($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     $userInfo = AuthHelper::getAuthUser();
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($userInfo['user_id']);
     // 用户总共有资金余额
     $smarty->assign('userMoney', $userInfo['user_money']);
     $accountLog = new AccountLogService();
     // 用户总共有多少account_log
     $totalCount = $accountLog->countUserMoneyArray($userInfo['user_id'], 10);
     //缓存 10 秒钟
     if ($totalCount <= 0) {
         // 没资金变动记录,可以直接退出了
         goto out_display;
     }
     $smarty->assign('totalCount', $totalCount);
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/My/Money');
     }
     // 传递分页的变量
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     // account_log 列表
     $accountLogArray = $accountLog->fetchUserMoneyArray($userInfo['user_id'], $pageNo * $pageSize, $pageSize, 10);
     //缓存 10 秒钟
     foreach ($accountLogArray as &$accountLogItem) {
         $accountLogItem['change_type_desc'] = AccountLogService::$changeTypeDesc[$accountLogItem['change_type']];
     }
     unset($accountLogItem);
     $smarty->assign('accountLogArray', $accountLogArray);
     out_display:
     $smarty->display('my_money.tpl', 'get');
 }
Exemple #8
0
/**
 * 判断用户是否有某种权限
 *
 * @param                          $params
 * @param                          $content
 * @param Smarty_Internal_Template $template
 * @param                          $repeat
 */
function smarty_helper_block_verify_privilege($params, $content, Smarty_Internal_Template $template, &$repeat)
{
    if ($repeat) {
        return '';
    }
    if (array_key_exists('privilege', $params) && !empty($params['privilege'])) {
        $authAdminUser = AuthHelper::getAuthUser();
        if (empty($authAdminUser)) {
            return '';
        }
        // 检查权限
        if (!AdminUserService::verifyPrivilege($params['privilege'], $authAdminUser['action_list'] . ',' . $authAdminUser['role_action_list'])) {
            return '';
        }
        return $content;
        // 成功从这里返回
    }
}
Exemple #9
0
 public function beforeRoute($f3)
 {
     parent::beforeRoute($f3);
     //设置 SEO 信息
     global $smarty;
     $smarty->assign('seo_title', MobileThemePlugin::getOptionValue('seo_title'));
     $smarty->assign('seo_description', MobileThemePlugin::getOptionValue('seo_description'));
     $smarty->assign('seo_keywords', MobileThemePlugin::getOptionValue('seo_keywords'));
     // 设置页面显示用户名
     if (AuthHelper::isAuthUser()) {
         global $smarty;
         $authUser = AuthHelper::getAuthUser();
         $smarty->assign('USER_NAME_DISPLAY', $authUser['user_name']);
     }
     // 记录用户从什么来源到达网站的
     ReferHelper::setOrderRefer($f3);
     //设置 order_refer 信息
 }
Exemple #10
0
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail_list_goods;
     }
     unset($validator);
     // 用户提交的商品信息做验证
     $goodsPromoteInfo = $f3->get('POST.goods_promote');
     if (empty($goodsPromoteInfo)) {
         goto out_fail_validate;
     }
     //安全性处理
     unset($goodsPromoteInfo['promote_id']);
     $goodsPromoteInfo['goods_id'] = $goods_id;
     // 写入到数据库
     $goodsBasicService = new GoodsBasicService();
     $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id);
     $goodsPromote->copyFrom($goodsPromoteInfo);
     $goodsPromote->save();
     // 记录商品编辑日志
     $goodsLogContent = '360分类:' . $goodsPromote['360tuan_category'] . ',' . $goodsPromote['360tuan_category_end'] . "\n" . "360排序:" . $goodsPromote['360tuan_sort_order'];
     $authAdminUser = AuthHelper::getAuthUser();
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($goods_id, $authAdminUser['user_id'], $authAdminUser['user_name'], static::$goodsLogDesc, $goodsLogContent);
     // 成功,显示商品详情
     $this->addFlashMessage('商品推广渠道保存成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Promote', array('goods_id' => $goods_id), true));
     return;
     // 参数验证失败
     out_fail_validate:
     $smarty->display('goods_edit_promote.tpl');
     return;
     out_fail_list_goods:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
Exemple #11
0
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_get');
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $goods_id = $validator->required('商品ID不能为空')->validate('goods_id');
     $action = $validator->required('操作不能为空')->validate('action');
     //任务时间
     $taskTimeStr = $validator->required('必须选择时间')->validate('task_time');
     $taskTime = Time::gmStrToTime($taskTimeStr) ?: null;
     if (!$this->validate($validator)) {
         goto out;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 添加 Cron 任务
     CronHelper::addCronTask($authAdminUser['user_name'] . '[' . $authAdminUser['user_id'] . ']', GoodsCronTask::$task_name, @GoodsCronTask::$actionDesc[$action] . '[' . $goods_id . ']', '\\Core\\Cron\\GoodsCronTask', $taskTime, $f3->get('POST'), $goods_id);
     $this->addFlashMessage('成功添加定时任务');
     out:
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Cron', array('goods_id' => $goods_id), true));
 }
Exemple #12
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $addressInfo = array();
     $addressInfo['consignee'] = $validator->required('姓名不能为空')->validate('consignee');
     $addressInfo['address'] = $validator->required('地址不能为空')->validate('address');
     $addressInfo['mobile'] = $validator->required('手机号码不能为空')->digits('手机号码格式不正确')->validate('mobile');
     $addressInfo['tel'] = $validator->validate('tel');
     $addressInfo['zipcode'] = $validator->digits('邮编格式不正确')->validate('zipcode');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $userInfo = AuthHelper::getAuthUser();
     $userAddressService = new UserAddressService();
     $userAddressService->updateUserFirstAddress($userInfo['user_id'], $addressInfo);
     $this->addFlashMessage('地址更新成功');
     RouteHelper::reRoute($this, '/My/Address');
     return;
     out_fail:
     // 失败返回
     $smarty->display('my_address.tpl', 'post');
 }
Exemple #13
0
 /**
  * 管理员权限管理
  *
  * @param $f3
  */
 public function Privilege($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_admin_privilege_get');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $user_id = $validator->required()->digits()->min(1)->validate('user_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 查询管理员信息
     $adminUserService = new AdminUserService();
     $adminUser = $adminUserService->loadAdminById($user_id);
     if ($adminUser->isEmpty()) {
         // 不存在的管理员
         $this->addFlashMessage('管理员不存在');
         goto out_fail;
     } else {
         if (AdminUserService::verifyPrivilege(AdminUserService::privilegeAll, $adminUser['action_list'])) {
             // 拥有最高权限的管理员只有他自己能编辑自己
             $authAdminUser = AuthHelper::getAuthUser();
             if ($authAdminUser['user_id'] != $adminUser['user_id']) {
                 $this->addFlashMessage('超级管理员只有他自己能操作自己的信息');
                 RouteHelper::reRoute($this, '/Account/Admin/ListUser');
             }
         }
     }
     if (!Request::isRequestPost()) {
         // 没有 post ,只是普通的显示
         goto out_display;
     }
     // 权限检查
     $this->requirePrivilege('manage_account_admin_privilege_post');
     $action_list_str = '';
     $actionCodeArray = $f3->get('POST[action_code]');
     if (empty($actionCodeArray)) {
         // 清空了所有权限
         $action_list_str = '';
         goto update_privilege;
     }
     if (in_array(AdminUserService::privilegeAll, $actionCodeArray)) {
         // 权限检查,只有自身拥有 privilegeAll 权限的人才能给别人授权 privilegeAll
         $this->requirePrivilege(AdminUserService::privilegeAll);
         // 用户有所有的权限
         $action_list_str = AdminUserService::privilegeAll;
         goto update_privilege;
     }
     // 生成权限字符串
     $action_list_str = implode(',', $actionCodeArray);
     update_privilege:
     $adminUser->role_id = $f3->get('POST[role_id]');
     $adminUser->action_list = $action_list_str;
     $adminUser->save();
     $this->addFlashMessage('管理员权限保存成功');
     out_display:
     $smarty->assign($adminUser->toArray());
     // 取得权限显示列表
     $metaPrivilegeService = new MetaPrivilegeService();
     $smarty->assign('privilegeArray', $metaPrivilegeService->fetchPrivilegeArray());
     $smarty->display('account_admin_privilege.tpl');
     return;
     // 正常从这里返回
     out_fail:
     // 失败,返回管理员列表
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Account/Admin/ListUser', array('user_id' => $user_id), true));
 }
Exemple #14
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');
 }
Exemple #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);
 }
Exemple #16
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_real_name'] = $validator->required('管理员名称不能为空')->validate('user_real_name');
     $input['oldpassword'] = $validator->validate('oldpassword');
     $input['password'] = $validator->validate('password');
     $input['user_desc'] = $validator->validate('user_desc');
     // 用户打算修改密码
     if (!Utils::isBlank($input['password'])) {
         $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword');
         if ($f3->get('sysConfig[is_demo]')) {
             $this->addFlashMessage('演示系统不允许修改密码');
             goto out;
         }
     }
     // 提供的旧密码,但是新密码为空
     if (!Utils::isBlank($input['oldpassword'])) {
         $validator->required('新密码不能为空')->validate('password');
     }
     if (!$this->validate($validator)) {
         goto out;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     $adminUserService = new AdminUserService();
     // 验证用户登陆
     $adminUser = $adminUserService->loadAdminById($authAdminUser['user_id']);
     if ($adminUser->isEmpty()) {
         $this->addFlashMessage("非法登陆用户");
         RouteHelper::reRoute($this, '/User/Logout', false);
     }
     // 用户打算修改密码,但是旧密码不对
     if (!empty($input['password']) && !$adminUserService->verifyPassword($authAdminUser['user_id'], $input['oldpassword'])) {
         $this->addFlashMessage('旧密码不对');
         goto out;
     }
     // 更新数据
     unset($input['oldpassword']);
     $adminUserService->updateAdmin($adminUser, $input);
     // 记录用户的登陆信息
     $adminUserInfo = $adminUser->toArray();
     unset($adminUserInfo['password']);
     // 不要记录密码
     // 取得用户的角色权限
     $adminUserInfo['role_action_list'] = '';
     if ($adminUserInfo['role_id'] > 0) {
         $metaRoleService = new MetaRoleService();
         $role = $metaRoleService->loadRoleById($adminUserInfo['role_id']);
         if (!$role->isEmpty()) {
             // 赋值角色权限
             $adminUserInfo['role_action_list'] = $role['meta_data'];
         }
     }
     AuthHelper::saveAuthUser($adminUserInfo);
     $this->addFlashMessage("修改资料成功");
     $smarty->assign($adminUserInfo);
     out:
     // 从这里出去
     $smarty->display('my_profile.tpl');
 }
Exemple #17
0
 public function post($f3)
 {
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1, true, '订单ID非法')->validate('order_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $validator = new Validator($f3->get('POST'));
     $payGatewayType = $validator->required('必须选择一种支付方式')->validate('pay_gateway_type');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得用户信息
     $userInfo = AuthHelper::getAuthUser();
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($userInfo['user_id']);
     // 支付某一个特定的订单需要把订单加载到临时购物车里面
     $orderBasicService = new OrderBasicService();
     // 检查权限
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id);
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         $this->addFlashMessage('订单ID非法');
         goto out_fail;
     }
     $cartBasicService = new CartBasicService();
     // 加载订单到购物车里
     if (!$cartBasicService->loadFromOrderInfo($order_id)) {
         $this->addFlashMessage('订单加载失败');
         goto out_fail;
     }
     $cartContext =& $cartBasicService->getCartContextRef();
     if ($cartContext->isEmpty()) {
         $this->addFlashMessage('订单为空,不能支付');
         goto out_fail;
     }
     // 做第一次购物车计算,需要计算原始订单的金额,后面红包使用的时候有最低订单金额限制
     $cartBasicService->calcOrderPrice();
     // 计算支付金额
     $cartBasicService->calcOrderPayment();
     // 如果购物车里面有错误消息,我们需要显示它
     if ($cartContext->hasError()) {
         $this->addFlashMessageArray($cartContext->getAndClearErrorMessageArray());
         goto out_fail;
     }
     // 更新订单信息
     $orderInfo = $cartBasicService->saveOrder($userInfo['user_id'], '买家:' . $userInfo['user_name']);
     if (!$orderInfo || $orderInfo->isEmpty()) {
         //订单创建失败,报错
         $this->addFlashMessage('更新订单信息失败,请联系客服');
         goto out_fail;
     }
     // 如果订单金额为 0 ,使用 credit 支付网关
     if ($orderInfo['order_amount'] <= 0) {
         $payGatewayType = 'credit';
     }
     $order_id = $orderInfo['order_id'];
     // 解析参数,我们允许写成 tenpay_cmbchina  代表财付通、招商银行
     $payGatewayParamArray = explode('_', $payGatewayType);
     // 获取支付网关
     $payGateway = PaymentGatewayHelper::getPaymentGateway($payGatewayParamArray[0]);
     // 根据参数做初始化
     if (!$payGateway->init($payGatewayParamArray)) {
         $this->addFlashMessage('支付网关' . $payGatewayType . '初始化失败');
         goto out_fail;
     }
     $payRequestUrl = $payGateway->getRequestUrl($order_id, RouteHelper::makeUrl('/Payment/PaymentReturn/' . $payGateway->getGatewayType(), null, false, true), RouteHelper::makeUrl('/Payment/PaymentNotify/' . $payGateway->getGatewayType(), null, false, true));
     //notifyUrl
     if (empty($payRequestUrl)) {
         $this->addFlashMessage('系统错误:无法生成支付链接');
         goto out_fail;
     }
     // 记录支付日志
     printLog('[orderId:' . $order_id . ']' . $payRequestUrl, 'PAYMENT', Base::INFO);
     // 跳转去支付
     header('Location:' . $payRequestUrl);
     return;
     out_fail:
     //失败从这里退出
     RouteHelper::reRoute($this, '/My/Order');
 }
Exemple #18
0
 public function post($f3)
 {
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1, true, '订单ID非法')->validate('order_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $validator = new Validator($f3->get('POST'));
     $payGatewayType = $validator->required('必须选择一种支付方式')->validate('pay_gateway_type');
     $surplus = Money::toStorage($validator->float('余额格式错误')->min(0, true, '余额格式错误')->validate('surplus'));
     $bonusSn = $validator->validate('bonus_sn');
     // 客服信息
     $orderInfoKefuInfo = array();
     $orderInfoKefuInfo['kefu_user_id'] = abs(intval($validator->digits()->validate('kefu_user_id')));
     $orderInfoKefuInfo['kefu_user_rate'] = abs(intval($validator->digits()->validate('kefu_user_rate')));
     $orderInfoKefuInfo['kefu_user_comment'] = $validator->validate('kefu_user_comment');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得用户信息
     $userInfo = AuthHelper::getAuthUser();
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($userInfo['user_id']);
     // 支付某一个特定的订单需要把订单加载到临时购物车里面
     $orderBasicService = new OrderBasicService();
     // 检查权限
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id);
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         $this->addFlashMessage('订单ID非法');
         goto out_fail;
     }
     // 更新客服信息
     if ($orderInfoKefuInfo['kefu_user_id'] > 0) {
         $adminUserService = new AdminUserService();
         $adminUser = $adminUserService->loadAdminById($orderInfoKefuInfo['kefu_user_id']);
         if (!$adminUser->isEmpty()) {
             $orderInfoKefuInfo['kefu_user_name'] = $adminUser['user_name'];
         } else {
             $orderInfoKefuInfo['kefu_user_id'] = 0;
             $orderInfoKefuInfo['kefu_user_name'] = null;
         }
         unset($adminUser);
         unset($adminUserService);
     } else {
         $orderInfoKefuInfo['kefu_user_id'] = 0;
         $orderInfoKefuInfo['kefu_user_name'] = null;
     }
     $orderInfo->copyFrom($orderInfoKefuInfo);
     $orderInfo->save();
     $cartBasicService = new CartBasicService();
     // 加载订单到购物车里
     if (!$cartBasicService->loadFromOrderInfo($order_id)) {
         $this->addFlashMessage('订单加载失败');
         goto out_fail;
     }
     $cartContext =& $cartBasicService->getCartContextRef();
     if ($cartContext->isEmpty()) {
         $this->addFlashMessage('订单为空,不能支付');
         goto out_fail;
     }
     // 做第一次购物车计算,需要计算原始订单的金额,后面红包使用的时候有最低订单金额限制
     $cartBasicService->calcOrderPrice();
     if (!empty($surplus) || !empty($bonusSn)) {
         if (null != $surplus && $surplus > 0 && $surplus <= $userInfo['user_money']) {
             // 设置余额支付金额,余额不能超过用户已经有的钱
             $cartContext->setValue('surplus', $surplus);
         }
         // 设置红包支付
         if (!empty($bonusSn)) {
             $bonusService = new Bonus();
             //检查红包是否可以使用
             $bonus = $bonusService->fetchUsableBonusBySn($userInfo['user_id'], $cartContext->getValue('order_amount'), $bonusSn);
             if (empty($bonus)) {
                 $this->addFlashMessage('红包' . $bonusSn . '不能使用');
                 goto out_fail;
             }
             // 设置红包的使用
             $cartContext->setValue('bonus_id', $bonus['bonus_id']);
             $cartContext->setValue('bonus', $bonus['type_money']);
         }
     }
     // 做第二次购物车计算,需要计算使用了余额或者红包
     $cartBasicService->calcOrderPayment();
     // 更新订单信息
     $orderInfo = $cartBasicService->saveOrder($userInfo['user_id'], '买家:' . $userInfo['user_name']);
     if (!$orderInfo || $orderInfo->isEmpty()) {
         //订单创建失败,报错
         $this->addFlashMessage('更新订单信息失败,请联系客服');
         goto out_my_order_detail;
     }
     // 如果购物车里面有错误消息,我们需要显示它
     if ($cartContext->hasError()) {
         $this->addFlashMessageArray($cartContext->getAndClearErrorMessageArray());
         goto out_my_order_cart;
     }
     // 如果订单金额为 0 ,使用 credit 支付网关
     if ($orderInfo['order_amount'] <= 0) {
         $payGatewayType = 'credit';
     }
     $order_id = $orderInfo['order_id'];
     // 解析参数,我们允许写成 tenpay_cmbchina  代表财付通、招商银行
     $payGatewayParamArray = explode('_', $payGatewayType);
     // 获取支付网关
     $payGateway = PaymentGatewayHelper::getPaymentGateway($payGatewayParamArray[0]);
     // 根据参数做初始化
     if (!$payGateway->init($payGatewayParamArray)) {
         $this->addFlashMessage('支付网关' . $payGatewayType . '初始化失败');
         goto out_my_order_detail;
     }
     $payRequestUrl = $payGateway->getRequestUrl($order_id, RouteHelper::makeUrl('/Payment/PaymentReturn/' . $payGateway->getGatewayType(), null, false, true), RouteHelper::makeUrl('/Payment/PaymentNotify/' . $payGateway->getGatewayType(), null, false, true));
     //notifyUrl
     if (empty($payRequestUrl)) {
         $this->addFlashMessage('系统错误:无法生成支付链接');
         goto out_my_order_detail;
     }
     // 记录支付日志
     printLog('[orderId:' . $order_id . ']' . $payRequestUrl, 'PAYMENT', Base::INFO);
     // 跳转支付
     RouteHelper::reRoute($this, $payRequestUrl);
     return;
     out_my_order_cart:
     //失败从这里退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/My/Order/Cart', array('order_id' => $order_id), true));
     return;
     out_my_order_detail:
     //失败从这里退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/My/Order/Detail', array('order_id' => $order_id), true));
     return;
     out_fail:
     //失败从这里退出
     RouteHelper::reRoute($this, '/My/Order');
 }
Exemple #19
0
 /**
  * 重新加载用户信息
  */
 public static function reloadAuthUser()
 {
     $authUser = Auth::getAuthUser();
     if (empty($authUser) || !isset($authUser['user_id']) || empty($authUser['user_id'])) {
         return;
     }
     $basicUserService = new UserBasicService();
     $user = $basicUserService->loadUserById($authUser['user_id']);
     if ($user->isEmpty()) {
         return;
     }
     Auth::saveAuthUser($user->toArray());
 }
Exemple #20
0
 /**
  * 增加商品关联
  *
  * @param $f3
  */
 public function ajaxAddLink($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post', true);
     // 首先做参数验证
     $validator = new Validator($f3->get('GET'));
     $errorMessage = '';
     $goods_id = $validator->required()->digits()->min(1)->validate('goods_id');
     $link_goods_id = $validator->required()->digits()->min(1)->validate('link_goods_id');
     if (!$this->validate($validator)) {
         $errorMessage = implode('|', $this->flashMessageArray);
         goto out_fail;
     }
     $dataMapper = new DataMapper('link_goods');
     $dataMapper->loadOne(array('goods_id = ? and link_goods_id = ?', $goods_id, $link_goods_id));
     // 已经关联了,不要重复关联
     if (!$dataMapper->isEmpty()) {
         goto out;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 添加记录
     $dataMapper->goods_id = $goods_id;
     $dataMapper->link_goods_id = $link_goods_id;
     $dataMapper->admin_id = $authAdminUser['user_id'];
     $dataMapper->save();
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     // 记录商品编辑日志
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($goods_id, $authAdminUser['user_id'], $authAdminUser['user_name'], '添加商品关联', $link_goods_id);
     out:
     Ajax::header();
     echo Ajax::buildResult(null, null, null);
     return;
     out_fail:
     // 失败,返回出错信息
     Ajax::header();
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
Exemple #21
0
 public function get($f3)
 {
     global $smarty;
     if (!$f3->get('GET')) {
         // 没有任何查询,直接显示空页面
         goto out;
     }
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     //订单表单查询
     $searchFormQuery = array();
     //下单时间
     $addTimeStartStr = $validator->validate('add_time_start');
     $addTimeStart = Time::gmStrToTime($addTimeStartStr) ?: null;
     $addTimeEndStr = $validator->validate('add_time_end');
     $addTimeEnd = Time::gmStrToTime($addTimeEndStr) ?: null;
     $searchFormQuery['oi.add_time'] = array($addTimeStart, $addTimeEnd);
     //付款时间
     $payTimeStartStr = $validator->validate('pay_time_start');
     $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null;
     $payTimeEndStr = $validator->validate('pay_time_end');
     $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null;
     $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd);
     if (!($addTimeStart || $addTimeEnd || $payTimeStart || $payTimeEnd)) {
         $this->addFlashMessage('必须最少选择一个时间');
         goto out;
     }
     $searchFormQuery['oi.kefu_user_id'] = $validator->required('必须选择一个客服')->digits()->filter('ValidatorIntValue')->validate('kefu_user_id');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 权限检查
     $authAdminUser = AuthHelper::getAuthUser();
     // 客服可以查看自己的页面
     if ($searchFormQuery['oi.kefu_user_id'] !== $authAdminUser['user_id']) {
         // 用户查看的不是自己的业绩,需要特别的权限
         if (!$this->hasPrivilege('manage_stat_kaohe_kefu')) {
             $this->addFlashMessage('你没有权限查看别人的业绩统计');
             goto out;
         }
     }
     // 统计订单金额总和
     $orderGoodsStat = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, 'og.order_goods_status' . ',count(1) as total_order_goods_count' . ',sum(og.goods_price) as total_goods_price' . ',sum(og.shipping_fee) as total_shipping_fee' . ',sum(og.discount) as total_discount' . ',sum(og.extra_discount) as total_extra_discount' . ',sum(og.refund) as total_refund' . ',sum(og.extra_refund) as total_extra_refund', QueryBuilder::buildSearchParamArray($searchFormQuery), array(array('og.order_goods_status', 'asc')), 0, $f3->get('sysConfig[max_query_record_count]'), 'og.order_goods_status');
     // 订单状态显示
     foreach ($orderGoodsStat as &$orderGoodsStatItem) {
         $orderGoodsStatItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsStatItem['order_goods_status']];
     }
     unset($orderGoodsStatItem);
     // 统计总结果
     $orderGoodsStatTotal = array();
     $orderGoodsStatTotal['total_order_goods_count'] = 0;
     $orderGoodsStatTotal['total_goods_price'] = 0;
     $orderGoodsStatTotal['total_shipping_fee'] = 0;
     $orderGoodsStatTotal['total_discount'] = 0;
     $orderGoodsStatTotal['total_extra_discount'] = 0;
     $orderGoodsStatTotal['total_refund'] = 0;
     $orderGoodsStatTotal['total_extra_refund'] = 0;
     foreach ($orderGoodsStat as $orderGoodsStatItem) {
         // 未付款的订单不计入统计
         if ($orderGoodsStatItem['order_goods_status'] < OrderGoodsService::OGS_PAY) {
             continue;
         }
         // 统计计算
         $orderGoodsStatTotal['total_order_goods_count'] += $orderGoodsStatItem['total_order_goods_count'];
         $orderGoodsStatTotal['total_goods_price'] += $orderGoodsStatItem['total_goods_price'];
         $orderGoodsStatTotal['total_shipping_fee'] += $orderGoodsStatItem['total_shipping_fee'];
         $orderGoodsStatTotal['total_discount'] += $orderGoodsStatItem['total_discount'];
         $orderGoodsStatTotal['total_extra_discount'] += $orderGoodsStatItem['total_extra_discount'];
         $orderGoodsStatTotal['total_refund'] += $orderGoodsStatItem['total_refund'];
         $orderGoodsStatTotal['total_extra_refund'] += $orderGoodsStatItem['total_extra_refund'];
     }
     // 给 smarty 赋值
     $smarty->assign('orderGoodsStat', $orderGoodsStat);
     $smarty->assign('orderGoodsStatTotal', $orderGoodsStatTotal);
     out:
     $smarty->display('stat_kaohe_kefu.tpl');
 }
Exemple #22
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);
 }
Exemple #23
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);
 }
Exemple #24
0
 /**
  * 把订单加载到购物车
  */
 public function Cart($f3)
 {
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1, true, '订单ID非法')->validate('order_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $userInfo = AuthHelper::getAuthUser();
     // 查询订单
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id, 10);
     // 缓存 10 秒钟
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status'] || !$this->verifyOrderSystem($orderInfo)) {
         $this->addFlashMessage('订单ID非法');
         goto out_fail;
     }
     //加载订单
     $cartBasicService = new CartBasicService();
     // 加载订单到购物车里
     if (!$cartBasicService->loadFromOrderInfo($order_id)) {
         $this->addFlashMessage('订单加载失败');
         goto out_fail;
     }
     $cartContext =& $cartBasicService->getCartContextRef();
     if ($cartContext->isEmpty()) {
         $this->addFlashMessage('订单为空,不能支付');
         goto out_fail;
     }
     // 保存购物车
     $cartBasicService->syncStorage();
     RouteHelper::reRoute($this, '/Cart/Show');
     return;
     // 成功从这里返回
     out_fail:
     // 从这里退出
     RouteHelper::reRoute($this, '/My/Order');
 }
Exemple #25
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');
 }
Exemple #26
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);
 }
Exemple #27
0
 /**
  * 把订单手动设置成已经付款
  *
  * @param $f3
  */
 public function MarkPay($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_order_markpay');
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1)->validate('order_id');
     if (!$this->validate($validator)) {
         goto out;
     }
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id);
     if ($orderInfo->isEmpty()) {
         $this->addFlashMessage('订单不存在');
         goto out;
     }
     if ($orderBasicService::PS_PAYED == $orderInfo['pay_status']) {
         $this->addFlashMessage('订单已经是支付状态,不允许重复设置');
         goto out;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     $orderPaymentService = new OrderPaymentService();
     $orderPaymentService->markOrderInfoPay($order_id, 1, 'admin_set', '0', '手动设置为已经支付', $authAdminUser['user_name']);
     $this->addFlashMessage('订单成功设置为支付状态');
     out:
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Order/Order/Detail', array('order_id' => $order_id), true));
 }
Exemple #28
0
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_comment_edit');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $comment_id = $validator->digits()->min(1)->validate('comment_id');
     if (!$comment_id) {
         $comment_id = 0;
     }
     $goodsCommentService = new GoodsCommentService();
     $goodsComment = $goodsCommentService->loadGoodsCommentById($comment_id);
     if (!$f3->get('POST')) {
         // 没有 post ,只是普通的显示
         goto out_display;
     }
     // 新建商品评论
     if (0 == $comment_id) {
         $this->requirePrivilege('manage_goods_comment_create');
         $goodsComment->create_time = Time::gmTime();
         $goodsComment->comment_time = Time::gmTime();
     }
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     $goodsComment->goods_id = $validator->digits()->filter('ValidatorIntValue')->validate('goods_id');
     $goodsComment->goods_price = Money::toStorage($validator->validate('goods_price'));
     $goodsComment->goods_number = $validator->required()->digits()->filter('ValidatorIntValue')->validate('goods_number');
     $goodsComment->goods_attr = $validator->validate('goods_attr');
     $goodsComment->is_show = $validator->digits()->filter('ValidatorIntValue')->validate('is_show');
     $goodsComment->user_name = $validator->required()->validate('user_name');
     $goodsComment->comment_time = Time::gmStrToTime($validator->required()->validate('comment_time'));
     $goodsComment->comment = $validator->validate('comment');
     $goodsComment->comment_rate = $validator->digits()->filter('ValidatorIntValue')->validate('comment_rate');
     $goodsComment->reply = $validator->validate('reply');
     if (!$this->validate($validator)) {
         goto out_display;
     }
     if (!empty($goodsComment->reply)) {
         $goodsComment->reply_time = Time::gmTime();
     }
     // 更新管理员信息
     $authAdminUser = AuthHelper::getAuthUser();
     $goodsComment->admin_user_id = $authAdminUser['user_id'];
     $goodsComment->admin_user_name = $authAdminUser['user_name'];
     $goodsComment->save();
     if (0 == $comment_id) {
         $this->addFlashMessage('新建商品评论成功');
     } else {
         $this->addFlashMessage('更新商品评论成功');
     }
     out_display:
     //给 smarty 模板赋值
     $smarty->assign($goodsComment->toArray());
     $smarty->display('goods_comment_edit.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Goods/Comment/ListComment');
 }
Exemple #29
0
 public function Edit($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $article_id = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('article_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得文章
     $articleService = new ArticleService();
     $article = $articleService->loadArticleById($article_id);
     if ($article_id > 0 && $article->isEmpty()) {
         $this->addFlashMessage('文章ID[' . $article_id . ']非法');
         goto out_fail;
     }
     // 只是显示文章内容而已
     if (Request::isRequestGet()) {
         $smarty->assign('article', $article->toArray());
         goto out_get;
     }
     // 权限检查
     $this->requirePrivilege('manage_article_article_edit');
     // 从这里开始是修改文章内容
     unset($validator);
     $articleInfoArray = $f3->get('POST[article]');
     $validator = new Validator($articleInfoArray);
     // 获得修改数据
     $inputArray = array();
     $inputArray['title'] = $validator->required()->validate('title');
     $inputArray['seo_keyword'] = $validator->validate('seo_keyword');
     $inputArray['cat_id'] = $validator->validate('cat_id');
     $inputArray['is_open'] = $validator->validate('is_open');
     $inputArray['description'] = $validator->validate('description');
     $inputArray['content'] = $articleInfoArray['content'];
     // 不要过滤 html
     if (!$this->validate($validator)) {
         goto out_get;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 新建文章
     if ($article_id <= 0) {
         $inputArray['admin_user_id'] = $authAdminUser['user_id'];
         $inputArray['admin_user_name'] = $authAdminUser['user_name'];
         $inputArray['add_time'] = Time::gmTime();
     }
     // 文章更新
     $inputArray['update_user_id'] = $authAdminUser['user_id'];
     $inputArray['update_user_name'] = $authAdminUser['user_name'];
     $inputArray['update_time'] = Time::gmTime();
     // 保存修改
     $article->copyFrom($inputArray);
     $article->save();
     // 清除文章缓存
     ClearHelper::clearArticleCacheById($article->article_id);
     $this->addFlashMessage('文章保存成功');
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Article/Article/Edit', array('article_id' => $article->article_id), true));
     return;
     // POST 从这里退出
     out_get:
     // GET 从这里退出
     $smarty->display('article_article_edit.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Article/Article/Search');
 }
Exemple #30
0
 public function post($f3)
 {
     // 用户没有登陆,让用户去登陆
     if (!AuthHelper::isAuthUser()) {
         // 如果已经记录了一个回跳 URL ,则不要再覆盖这个记录了
         RouteHelper::reRoute($this, '/User/Login', !RouteHelper::hasRememberUrl());
     }
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $addressInfo = array();
     $addressInfo['consignee'] = $validator->required('姓名不能为空')->validate('consignee');
     $addressInfo['address'] = $validator->required('地址不能为空')->validate('address');
     $addressInfo['mobile'] = $validator->required('手机号码不能为空')->digits('手机号码格式不正确')->validate('mobile');
     $addressInfo['tel'] = $validator->validate('tel');
     $addressInfo['zipcode'] = $validator->digits('邮编格式不正确')->validate('zipcode');
     $postScript = $validator->validate('postscript');
     // 订单附言
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $cartBasicService = new CartBasicService();
     $cartBasicService->loadFromStorage();
     // 加载购物车的数据
     $cartContext =& $cartBasicService->getCartContextRef();
     if ($cartContext->isEmpty()) {
         $this->addFlashMessage('购物车为空');
         goto out_fail;
     }
     // 做一次购物车计算
     $cartBasicService->calcOrderPrice();
     // 如果购物车里面有错误消息,我们需要显示它
     if ($cartContext->hasError()) {
         $this->addFlashMessageArray($cartContext->getAndClearErrorMessageArray());
     }
     // 更新用户的地址信息
     $userInfo = AuthHelper::getAuthUser();
     $userAddressService = new UserAddressService();
     $userAddressService->updateUserFirstAddress($userInfo['user_id'], $addressInfo);
     // 地址信息放入购物车结构
     $cartContext->setAddressInfo($addressInfo);
     // 订单附言放入购物车
     $cartContext->setValue('postscript', $postScript);
     // 创建或者更新订单
     $orderInfo = $cartBasicService->saveOrder($userInfo['user_id'], '买家:' . $userInfo['user_name']);
     if (!$orderInfo || $orderInfo->isEmpty()) {
         //订单创建失败,报错
         $this->addFlashMessage('订单创建失败,请联系客服');
         goto out_fail;
     }
     //订单创建成功,清空购物车
     $cartBasicService->clearStorage();
     // 跳转到支付页面
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Cart/Pay', array('order_id' => $orderInfo['order_id']), true));
     return;
     out_fail:
     RouteHelper::reRoute($this, '/Cart/Show');
 }