Пример #1
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');
 }
Пример #2
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');
 }
Пример #3
0
 public function get($f3)
 {
     // 清除客户端所有数据
     ClientData::clearClientData();
     // 清除服务器端数据
     AuthHelper::removeAuthUser();
     $f3->clear('SESSION');
     $this->addFlashMessage('成功退出登陆');
     $backUrl = RouteHelper::getRefer();
     if (Utils::isBlank($backUrl)) {
         // 没有来路域名则返回首页
         $backUrl = '/';
     }
     // 刷新当前页面
     RouteHelper::reRoute($this, $backUrl, false);
 }
Пример #4
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');
 }
Пример #5
0
 /**
  * 管理员详情显示
  */
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_admin_edit_get');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $user_id = $validator->digits()->min(1)->validate('user_id');
     $user_id = $user_id > 0 ? $user_id : 0;
     if (!$this->validate($validator)) {
         goto out;
     }
     // 查询管理员信息
     $adminUserService = new AdminUserService();
     $adminUser = $adminUserService->loadAdminById($user_id);
     if (0 != $user_id && $adminUser->isEmpty()) {
         // 不存在的管理员
         $this->addFlashMessage('管理员不存在');
         goto out;
     }
     if ($adminUser->isEmpty()) {
         // 新建管理员
         $this->requirePrivilege('manage_account_admin_create');
     } 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 (!$f3->get('POST')) {
         // 没有 post ,只是普通的显示
         goto out_display;
     }
     // 权限检查
     $this->requirePrivilege('manage_account_admin_edit_post');
     // 用户提交了更新请求,这里做管理员信息更新
     // 参数验证
     $inputArray = array();
     $validator = new Validator($f3->get('POST'));
     $inputArray['user_name'] = $validator->required()->minlength(3)->validate('user_name');
     $inputArray['disable'] = $validator->filter('ValidatorIntValue')->validate('disable');
     $inputArray['user_real_name'] = $validator->required()->minlength(2)->validate('user_real_name');
     $inputArray['is_kefu'] = $validator->filter('ValidatorIntValue')->validate('is_kefu');
     $inputArray['user_desc'] = $validator->validate('user_desc');
     $password = $validator->validate('password');
     if (!Utils::isBlank($password)) {
         // 权限检查
         $this->requirePrivilege('manage_account_admin_edit_change_account_password');
         $inputArray['password'] = $password;
         if ($f3->get('sysConfig[is_demo]')) {
             $this->addFlashMessage('演示系统不允许修改密码');
             goto out;
         }
     }
     if (!$this->validate($validator)) {
         goto out;
     }
     // 确认管理员账号没有重复
     if (!empty($inputArray['user_name'])) {
         $tmpAdminUser = $adminUserService->loadAdminByUserName($inputArray['user_name']);
         if (0 == $user_id && !$tmpAdminUser->isEmpty() || !$tmpAdminUser->isEmpty() && $tmpAdminUser['user_id'] != $user_id) {
             $this->addFlashMessage('管理员账号 ' . $inputArray['user_name'] . ' 已经存在');
             goto out;
         }
     }
     if ($adminUser['user_name'] != $inputArray['user_name']) {
         // 管理员账号发生修改,检查权限
         $this->requirePrivilege('manage_account_admin_edit_change_account_password');
     }
     // 更新管理员信息
     $adminUserService->updateAdmin($adminUser, $inputArray);
     $this->addFlashMessage('管理员信息更新成功');
     out_display:
     //给 smarty 模板赋值
     $smarty->assign($adminUser->toArray());
     out:
     $smarty->display('account_admin_edit.tpl');
 }
Пример #6
0
 /**
  * 下载 拣货单
  *
  * @param $f3
  * @param $validator
  */
 public function downloadJianHuo($f3, $validator)
 {
     $outputColumnArray = array('warehouse' => '仓库', 'shelf' => '货架', 'goods_sn' => '货号', 'goods_name' => '商品名', 'goods_attr' => '属性规格', 'goods_number' => '数量', 'suppliers_price' => '供货单价', 'total_suppliers_price' => '供货总价', 'total_suppliers_shipping_fee' => '供货快递');
     $outputColumnMoneyArray = array('suppliers_price', 'total_suppliers_price', 'total_suppliers_shipping_fee');
     //表单查询
     $searchFormQuery = array();
     $searchFormQuery['og.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id');
     //付款时间
     $payTimeStartStr = $validator->validate('pay_time_start');
     $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null;
     $payTimeEndStr = $validator->validate('pay_time_end');
     $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null;
     $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd);
     // 快递信息
     $expressType = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('expressType');
     switch ($expressType) {
         case 1:
             $searchFormQuery['og.shipping_id'] = 0;
             break;
         case 2:
             $searchFormQuery['og.shipping_id'] = array('>', 0);
             break;
         default:
             break;
     }
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     if (Utils::isBlank($searchFormQuery['og.goods_id']) && Utils::isBlank($payTimeStart)) {
         $this->addFlashMessage('查询参数非法');
         goto out_fail;
     }
     // 构造查询条件
     $authSupplierUser = AuthHelper::getAuthUser();
     $searchFormQuery['og.suppliers_id'] = $authSupplierUser['suppliers_id'];
     $searchParamArray = array();
     $searchParamArray[] = array('oi.order_id = og.order_id');
     //供货商,只查看有效订单,其它订单不显示
     $searchParamArray[] = array('og.order_goods_status > 0');
     // 表单查询
     $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery));
     $orderGoodsArray = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, 'og.warehouse, og.shelf, og.goods_id, og.goods_sn, og.goods_attr, sum(og.goods_number) as goods_number, sum(og.suppliers_price * og.goods_number) as total_suppliers_price, sum(og.suppliers_shipping_fee) as total_suppliers_shipping_fee', $searchParamArray, array(array('og.warehouse', 'asc'), array('og.shelf', 'asc')), 0, $f3->get('sysConfig[max_query_record_count]'), 'og.warehouse, og.shelf, og.goods_id, og.goods_sn, og.goods_attr');
     // 没有数据,退出
     if (empty($orderGoodsArray)) {
         goto out;
     }
     // 查询订单对应的商品
     $goodsIdArray = array();
     foreach ($orderGoodsArray as $orderGoodsItem) {
         $goodsIdArray[] = $orderGoodsItem['goods_id'];
     }
     $goodsIdArray = array_unique($goodsIdArray);
     $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'goods_id, goods_name_short, suppliers_price', array(array(QueryBuilder::buildInCondition('goods_id', $goodsIdArray, \PDO::PARAM_INT))), null, 0, $f3->get('sysConfig[max_query_record_count]'));
     $goodsIdToGoodsMap = array();
     foreach ($goodsArray as $goodsItem) {
         $goodsIdToGoodsMap[$goodsItem['goods_id']] = $goodsItem;
     }
     require_once PROTECTED_PATH . '/Vendor/PHPExcel/Settings.php';
     // 设置Excel缓存,防止数据太多拖死了程序
     \PHPExcel_Settings::setCacheStorageMethod(\PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp);
     // 导出为 Excel 格式
     $objPHPExcel = new \PHPExcel();
     // 设置工作 sheet
     $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet = $objPHPExcel->getActiveSheet();
     // 格式化数据
     $rowIndex = 1;
     $lastWarehouseShelf = null;
     $orderGoodsArraySize = count($orderGoodsArray);
     // 输出头部信息
     $colIndex = 1;
     foreach ($outputColumnArray as $value) {
         $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $value);
         $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFont()->setBold(true);
         $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
         $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFB0B0B0');
         $colIndex++;
     }
     $rowIndex++;
     // 换行
     for ($orderGoodsIndex = 0; $orderGoodsIndex < $orderGoodsArraySize; $orderGoodsIndex++) {
         // 取得这行数据
         $orderGoodsItem = $orderGoodsArray[$orderGoodsIndex];
         // 填入商品数据
         $orderGoodsItem['goods_name'] = $goodsIdToGoodsMap[$orderGoodsItem['goods_id']]['goods_name_short'];
         $orderGoodsItem['suppliers_price'] = $goodsIdToGoodsMap[$orderGoodsItem['goods_id']]['suppliers_price'];
         if ($lastWarehouseShelf != $orderGoodsItem['warehouse'] . '$' . $orderGoodsItem['shelf']) {
             $lastWarehouseShelf = $orderGoodsItem['warehouse'] . '$' . $orderGoodsItem['shelf'];
             // 不同的取货地点,需要特殊处理
             $rowIndex += 2;
             // 跳过 2 行
         }
         // 输出一行数据
         $colIndex = 1;
         foreach ($outputColumnArray as $key => $value) {
             $cellValue = isset($orderGoodsItem[$key]) ? $orderGoodsItem[$key] : '';
             if (!in_array($key, $outputColumnMoneyArray)) {
                 $activeSheet->getCellByColumnAndRow($colIndex, $rowIndex)->setDataType(\PHPExcel_Cell_DataType::TYPE_STRING);
             } else {
                 // 转换价格显示
                 $cellValue = Money::toSmartyDisplay($cellValue);
             }
             $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue);
             $colIndex++;
         }
         $rowIndex++;
         // 换行
     }
     $fileName = '拣货单_' . $searchFormQuery['og.goods_id'] . '_' . Time::gmTimeToLocalTimeStr($payTimeStart, 'Y-m-d_H-i-s') . '__' . Time::gmTimeToLocalTimeStr($payTimeEnd, 'Y-m-d_H-i-s');
     // 输出为 Excel5 格式
     $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
     header('Content-Type: application/vnd.ms-excel');
     if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
         header('Content-Disposition: attachment; filename="' . urlencode($fileName) . '.xls"');
     } else {
         header('Content-Disposition: attachment; filename="' . $fileName . '.xls"');
     }
     header('Cache-Control: max-age=0');
     $objWriter->save('php://output');
     //输出到浏览器
     die;
     out:
     echo "没有数据";
     die;
     out_fail:
     // 失败,打印错误消息
     $flashMessageArray = $this->flashMessageArray;
     foreach ($flashMessageArray as $flashMessage) {
         echo $flashMessage . '<br />';
     }
 }
Пример #7
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');
 }
Пример #8
0
 /**
  * 更新用户信息到数据库
  *
  * @return object 更新之后的 user 对象
  *
  * @param object $admin  user对象
  * @param array  $input  需要更新的字段
  *
  * */
 public function updateAdmin($admin, array $input)
 {
     if (Utils::isEmpty($admin) || Utils::isEmpty($input)) {
         throw new \InvalidArgumentException('$admin, $input can not be empty');
     }
     // 去除掉一些关键的字段,不允许更新
     $password = null;
     if (isset($input['password']) && !Utils::isBlank($input['password'])) {
         $password = $input['password'];
     }
     unset($input['id']);
     unset($input['user_id']);
     unset($input['password']);
     $admin->copyFrom($input);
     if (!Utils::isBlank($password)) {
         $admin->ec_salt = substr(uniqid(), -10);
         //修改密码同时修改 salt,增强安全性
         $admin->password = $this->encryptPassword($password, $admin->ec_salt);
     }
     $admin->save();
     return $admin;
 }
Пример #9
0
 /**
  * 供货商详情显示
  */
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_supplier_edit_get');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $suppliers_id = $validator->digits()->min(1)->validate('suppliers_id');
     $suppliers_id = $suppliers_id > 0 ? $suppliers_id : 0;
     if (!$this->validate($validator)) {
         goto out;
     }
     // 查询供货商信息
     $supplierUserService = new SupplierUserService();
     $supplier = $supplierUserService->loadSupplierById($suppliers_id);
     if (0 != $suppliers_id && $supplier->isEmpty()) {
         // 不存在的供货商
         $this->addFlashMessage('供货商不存在');
         goto out;
     }
     if ($supplier->isEmpty()) {
         // 新建供货商账号,权限检查
         $this->requirePrivilege('manage_account_supplier_create');
     }
     if (!$f3->get('POST')) {
         // 没有 post ,只是普通的显示
         goto out_display;
     }
     // 用户提交了更新请求,这里做供货商信息更新
     // 权限检查
     $this->requirePrivilege('manage_account_supplier_edit_post');
     // 参数验证
     $inputArray = array();
     $validator = new Validator($f3->get('POST'));
     $inputArray['suppliers_account'] = $validator->required()->minlength(4)->validate('suppliers_account');
     $inputArray['suppliers_name'] = $validator->required()->minlength(4)->validate('suppliers_name');
     $inputArray['phone'] = $validator->validate('phone');
     $inputArray['address'] = $validator->validate('address');
     $inputArray['suppliers_desc'] = $validator->validate('suppliers_desc');
     $password = $validator->validate('password');
     if (!Utils::isBlank($password)) {
         // 权限检查
         $this->requirePrivilege('manage_account_supplier_edit_change_account_password');
         $inputArray['password'] = $password;
     }
     if (!$this->validate($validator)) {
         goto out;
     }
     // 确认供货商账号没有重复
     if (!empty($inputArray['suppliers_account'])) {
         $tmpSupplierUser = $supplierUserService->loadSupplierBySupplierAccount($inputArray['suppliers_account']);
         if (0 == $suppliers_id && !$tmpSupplierUser->isEmpty() || !$tmpSupplierUser->isEmpty() && $tmpSupplierUser['suppliers_id'] != $suppliers_id) {
             $this->addFlashMessage('供货商账号 ' . $inputArray['suppliers_account'] . ' 已经存在');
             goto out;
         }
     }
     // 如果供货商账号发生了变化
     if ($supplier['suppliers_account'] != $inputArray['suppliers_account']) {
         // 权限检查
         $this->requirePrivilege('manage_account_supplier_edit_change_account_password');
     }
     // 更新供货商信息
     $supplierUserService->updateSupplier($supplier, $inputArray);
     $this->addFlashMessage('供货商信息更新成功');
     out_display:
     //给 smarty 模板赋值
     $smarty->assign($supplier->toArray());
     out:
     $smarty->display('account_supplier_edit.tpl');
 }
Пример #10
0
 /**
  * 是否是已经有记住的回跳 URL
  *
  * @return boolean
  * */
 public static function hasRememberUrl()
 {
     global $f3;
     $uniqueKey = $f3->get('SESSION.' . Route::getUniqueKey());
     return !Utils::isBlank($uniqueKey);
 }
Пример #11
0
 /**
  *
  * 批量下载订单
  *
  */
 public function Download($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_excel_download');
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     //表单查询
     $formQuery = array();
     $formQuery['suppliers_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('suppliers_id');
     $formQuery['goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id');
     if (empty($formQuery['suppliers_id']) && empty($formQuery['goods_id'])) {
         $this->addFlashMessage('供货商ID 和 商品ID 不能同时为空');
         goto out_fail;
     }
     //付款时间
     $payTimeStartStr = $validator->validate('pay_time_start');
     $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null;
     $payTimeEndStr = $validator->validate('pay_time_end');
     $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null;
     $formQuery['pay_time'] = array($payTimeStart, $payTimeEnd);
     //额外退款,时间
     $extraRefundTimeStartStr = $validator->validate('extra_refund_time_start');
     $extraRefundTimeStart = Time::gmStrToTime($extraRefundTimeStartStr) ?: null;
     $extraRefundTimeEndStr = $validator->validate('extra_refund_time_end');
     $extraRefundTimeEnd = Time::gmStrToTime($extraRefundTimeEndStr) ?: null;
     $formQuery['extra_refund_time'] = array($extraRefundTimeStart, $extraRefundTimeEnd);
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     if (Utils::isBlank($formQuery['suppliers_id']) || (Utils::isBlank($payTimeStart) || Utils::isBlank($payTimeEnd)) && (Utils::isBlank($extraRefundTimeStart) || Utils::isBlank($extraRefundTimeEnd))) {
         $this->addFlashMessage('按照供货商下载订单必须提供时间段参数');
         goto out_fail;
     }
     $condArray = array();
     $condArray[] = array('oi.order_id = og.order_id');
     $condArray[] = array('order_goods_status > 0');
     // 表单查询
     $condArray = array_merge($condArray, QueryBuilder::buildQueryCondArray($formQuery));
     $orderGoodsService = new OrderGoodsService();
     $orderGoodsArray = $orderGoodsService->_fetchArray(array('order_info' => 'oi', 'order_goods' => 'og'), 'og.*, oi.add_time, oi.pay_time, oi.consignee, oi.mobile, oi.tel, oi.zipcode, oi.postscript, oi.address', $condArray, array('order' => 'oi.order_id asc, og.rec_id asc, og.goods_id asc'), 0, $f3->get('sysConfig[max_query_record_count]'), 0);
     //最多限制 max_query_record_count 条记录
     // 转换显示格式
     foreach ($orderGoodsArray as &$orderGoodsItem) {
         $orderGoodsItem['add_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['add_time'], 'Y-m-d H:i:s');
         $orderGoodsItem['pay_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['pay_time'], 'Y-m-d H:i:s');
         $orderGoodsItem['extra_refund_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['extra_refund_time'], 'Y-m-d H:i:s');
         $orderGoodsItem['suppliers_total_price'] = $orderGoodsItem['suppliers_price'] * $orderGoodsItem['goods_number'];
         $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']];
     }
     unset($orderGoodsItem);
     require_once PROTECTED_PATH . '/Vendor/PHPExcel/Settings.php';
     // 设置Excel缓存,防止数据太多拖死了程序
     \PHPExcel_Settings::setCacheStorageMethod(\PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp);
     // 导出为 Excel 格式
     $objPHPExcel = new \PHPExcel();
     // 设置工作 sheet
     $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet = $objPHPExcel->getActiveSheet();
     // 取得快递公司列表
     $expressService = new ExpressService();
     $expressArray = $expressService->fetchExpressArray();
     //输出快递公司参考表
     $this->outputExpressArray($activeSheet, $expressArray);
     //释放内存
     unset($expressArray);
     unset($expressService);
     // 格式化数据
     $rowIndex = 1;
     $lastOrderId = 0;
     $orderGoodsArraySize = count($orderGoodsArray);
     // 输出头部信息
     $this->outputHeaderRow($activeSheet, $rowIndex);
     $rowIndex++;
     // 换行
     for ($orderGoodsIndex = 0; $orderGoodsIndex < $orderGoodsArraySize; $orderGoodsIndex++) {
         // 取得这行数据
         $orderGoodsItem = $orderGoodsArray[$orderGoodsIndex];
         if ($lastOrderId != $orderGoodsItem['order_id']) {
             $lastOrderId = $orderGoodsItem['order_id'];
             // 不同的订单,需要特殊处理
             $rowIndex += 2;
             // 跳过 2 行
         }
         // 输出数据
         //$this->outputDataRow($activeSheet, $rowIndex, $orderGoodsItem, array('goods_name', 'goods_id'));
         $this->outputDataRow($activeSheet, $rowIndex, $orderGoodsItem);
         $rowIndex++;
         // 换行
     }
     $fileName = '订单下载_' . $formQuery['goods_id'] . '_' . Time::gmTimeToLocalTimeStr($payTimeStart, 'Y-m-d_H-i-s') . '__' . Time::gmTimeToLocalTimeStr($payTimeEnd, 'Y-m-d_H-i-s');
     // 输出为 Excel5 格式
     $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
     header('Content-Type: application/vnd.ms-excel');
     if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
         header('Content-Disposition: attachment; filename="' . urlencode($fileName) . '.xls"');
     } else {
         header('Content-Disposition: attachment; filename="' . $fileName . '.xls"');
     }
     header('Cache-Control: max-age=0');
     $objWriter->save('php://output');
     //输出到浏览器
     die;
     out_fail:
     // 失败,打印错误消息
     $flashMessageArray = $this->flashMessageArray;
     foreach ($flashMessageArray as $flashMessage) {
         echo $flashMessage . '<br />';
     }
 }