예제 #1
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);
 }
예제 #2
0
 /**
  * 记录帐户变动
  * @param   int    $userId        用户id
  * @param   float  $userMoney     可用余额变动
  * @param   float  $frozenMoney   冻结余额变动
  * @param   int    $rankPoints    等级积分变动
  * @param   int    $payPoints     消费积分变动
  * @param   string $changeDesc    变动说明
  * @param   int    $changeType    变动类型:参见常量文件
  *
  * @return  void
  */
 function logChange($userId, $userMoney = 0, $frozenMoney = 0, $rankPoints = 0, $payPoints = 0, $changeDesc = '', $changeType = AccountLog::ACT_OTHER, $adminUserId = 0)
 {
     /* 插入帐户变动记录 */
     $accountLogInfo = array('user_id' => $userId, 'user_money' => $userMoney, 'frozen_money' => $frozenMoney, 'rank_points' => $rankPoints, 'pay_points' => $payPoints, 'change_time' => Time::gmTime(), 'change_desc' => $changeDesc, 'change_type' => $changeType, 'admin_user_id' => $adminUserId);
     // 插入一条记录
     $dataMapper = new DataMapper('account_log');
     $dataMapper->copyFrom($accountLogInfo);
     $dataMapper->save();
     // 更新用户信息
     $sql = "UPDATE " . DataMapper::tableName('users') . " SET user_money = user_money + ('{$userMoney}')," . " frozen_money = frozen_money + ('{$frozenMoney}')," . " rank_points = rank_points + ('{$rankPoints}')," . " pay_points = pay_points + ('{$payPoints}')" . " WHERE user_id = ? Order By user_id asc LIMIT 1 ";
     $dbEngine = DataMapper::getDbEngine();
     $dbEngine->exec($sql, $userId);
 }
예제 #3
0
파일: Task.php 프로젝트: jackycgq/bzfshop
 /**
  * 添加一个 Cron Task 到执行任务列表中
  *
  * @param string $user_name    哪个用户添加的
  * @param string $task_name    任务名
  * @param string $task_desc    任务描述
  * @param string $task_class   实现 ICronTask 接口的类名称(全名,包括 namespace)
  * @param int    $task_time    任务执行的时间,GMT 时间
  * @param array  $paramArray   任务执行需要的参数
  * @param string $search_param 用于任务的搜索
  */
 public function addCronTask($user_name, $task_name, $task_desc, $task_class, $task_time, array $paramArray, $search_param = null)
 {
     // 验证任务是否可以添加
     if (!CronHelper::loadTaskClass($task_class)) {
         throw new \InvalidArgumentException('class [' . $task_class . '] illegal');
     }
     $dataMapper = new DataMapper('cron_task');
     $dataMapper->user_name = $user_name;
     $dataMapper->task_name = $task_name;
     $dataMapper->task_desc = $task_desc;
     $dataMapper->task_class = $task_class;
     $dataMapper->task_time = $task_time;
     $dataMapper->task_param = json_encode($paramArray);
     $dataMapper->search_param = $search_param;
     $dataMapper->save();
     unset($dataMapper);
 }
예제 #4
0
 /**
  * 商品数据转化
  */
 private function convertGoods()
 {
     global $f3;
     // 在这里配置源商品图片的路径前缀
     $f3->set('srcImagePrefix', "http://img.bangzhufu.com/static/");
     $tableMigrate = new TableMigrate();
     $tableMigrate->batchProcessCount = 100;
     // 每次批处理 100 个商品,防止商品过多搞死系统
     // 清空数据
     $dstTable = new DstDataMapper('goods');
     $tableMigrate->clearTable($dstTable);
     $goodsGalleryTable = new DstDataMapper('goods_gallery');
     $tableMigrate->clearTable($goodsGalleryTable);
     $tableMigrate->setAutoIncValue($goodsGalleryTable, 1);
     $goodsAttrTable = new DstDataMapper('goods_attr');
     $tableMigrate->clearTable($goodsAttrTable);
     $tableMigrate->setAutoIncValue($goodsAttrTable, 1);
     //转化数据
     $currentTime = time();
     $tableMigrate->convertTable('team', array(array('begin_time < ? and end_time > ?', $currentTime, $currentTime)), array('order' => 'id asc'), 'goods', array('id' => 'goods_id', 'user_id' => 'goods_sn', 'title' => 'goods_name', 'summary' => 'goods_brief', 'group_id' => 'cat_id', 'partner_id' => 'suppliers_id', 'team_price' => 'shop_price', 'market_price' => 'market_price', 'agent_price' => 'suppliers_price', 'product' => 'goods_name_short', 'condbuy' => 'condbuy', 'image' => null, 'image1' => null, 'image2' => null, 'agent_fare' => 'suppliers_shipping_fee', 'farefree' => 'shipping_free_number', 'detail' => 'goods_desc', 'notice' => 'goods_notice', 'sort_order' => 'sort_order', 'seo_title' => 'seo_title', 'seo_keyword' => 'seo_keyword', 'seo_description' => 'seo_description', 'express_relate' => 'shipping_fee', 'city_id' => 'goods_number'), array('user_id' => function ($user_id, $record) {
         global $f3;
         //在这里生成 goods_sn
         return $f3->get('sysConfig[goods_sn_prefix]') . $record->id;
     }, 'express_relate' => function ($express_relate, $record) {
         // 最土系统 -1 表示免邮费,我们这里修改邮费为 0
         if ($record['farefree'] < 0) {
             return 0;
         }
         $dataArray = unserialize($express_relate);
         $maxShippingFee = 0;
         // 取最大的快递费
         foreach ($dataArray as $data) {
             $maxShippingFee = $data['price'] > $maxShippingFee ? $data['price'] : $maxShippingFee;
         }
         return $maxShippingFee;
     }, 'farefree' => function ($farefree, $record) {
         // 最土 -1 表示免运费,我们这里一律改成不免邮费
         if ($farefree < 0) {
             return 0;
         }
         return $farefree;
     }, 'city_id' => function ($city_id, $record) {
         return 1000;
         // 所有库存缺省都设置为 1000
     }), function ($srcRecord) {
         global $f3;
         $srcImagePrefix = $f3->get('srcImagePrefix');
         $fetchImageArray = array();
         if (!empty($srcRecord->image)) {
             $fetchImageArray[] = $srcImagePrefix . $srcRecord->image;
         }
         if (!empty($srcRecord->image1)) {
             $fetchImageArray[] = $srcImagePrefix . $srcRecord->image1;
         }
         if (!empty($srcRecord->image2)) {
             $fetchImageArray[] = $srcImagePrefix . $srcRecord->image2;
         }
         if (!empty($fetchImageArray)) {
             // 设置 fetchImageArray 的值,用于后面图片抓取
             $f3->set('fetchImageArray_' . $srcRecord->id, $fetchImageArray);
         }
     }, function ($srcRecord, $dstRecord) {
         global $f3;
         $fetchImageArray = $f3->get('fetchImageArray_' . $srcRecord->id);
         if (empty($fetchImageArray)) {
             return;
         }
         // 我们在这里做图片的抓取操作
         foreach ($fetchImageArray as $fetchImageUrl) {
             fetchGoodsImage($srcRecord->id, $fetchImageUrl);
             //usleep(200000); // 睡 200 ms,防止抓取太快服务器不响应
         }
         // 释放资源
         $f3->clear('fetchImageArray_' . $srcRecord->id);
         // 处理 condbuy 字段
         if (empty($srcRecord->condbuy)) {
             return;
         }
         // 需要更新商品的选择
         $dstRecord->goods_type = $f3->get('sysConfig[condbuy_goods_type]');
         // 删除旧的数据
         $sql = 'delete from ' . DataMapper::tableName('goods_attr') . ' where goods_id = ?';
         $dbEngine = DstDataMapper::getDbEngine();
         $dbEngine->exec($sql, $srcRecord->id);
         // 解析 condbuy {红色}{绿色}{蓝色}
         $condBuyArray = explode('}{', '}' . $srcRecord->condbuy . '{');
         foreach ($condBuyArray as $condBuyItem) {
             if (empty($condBuyItem)) {
                 continue;
             }
             $dataMapper = new DataMapper('goods_attr');
             $dataMapper->goods_id = $srcRecord->id;
             $dataMapper->attr_id = $f3->get('sysConfig[condbuy_attr_id]');
             $dataMapper->attr_value = $condBuyItem;
             $dataMapper->attr_price = 0;
             $dataMapper->save();
             unset($dataMapper);
         }
     });
     // 重设表的 AUTO_INCREMENT 值
     $tableMigrate->resetAutoIncValue($dstTable, 'goods_id');
     // 清理数据
     unset($tableMigrate);
     unset($dstTable);
     unset($result);
 }
예제 #5
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);
 }
예제 #6
0
파일: Copy.php 프로젝트: jackycgq/bzfshop
 public function get($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_create');
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得商品信息
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     if ($goods->isEmpty()) {
         $this->addFlashMessage('非法商品ID');
         goto out_fail;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 1. 复制 goods 信息
     $goodsArray = $goods->toArray();
     unset($goodsArray['goods_id']);
     // 清除主键
     // 新商品缺省为下线状态
     $goodsArray['is_on_sale'] = 0;
     // 清除购买数量统计
     $goodsArray['user_buy_number'] = 0;
     $goodsArray['user_pay_number'] = 0;
     // 设置复制人
     $goodsArray['admin_user_id'] = $authAdminUser['user_id'];
     $goodsArray['admin_user_name'] = $authAdminUser['user_name'];
     // 处理商品的规格
     if (!empty($goodsArray['goods_spec'])) {
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goodsArray['goods_spec']);
         $goodsSpecService->clearGoodsSpecImgIdArray();
         // 清除图片 ID 的关联
         $goodsArray['goods_spec'] = $goodsSpecService->getJsonStr();
         unset($goodsSpecService);
     }
     $goodsArray['add_time'] = Time::gmTime();
     $newGoods = $goodsBasicService->loadGoodsById(0);
     $newGoods->copyFrom($goodsArray);
     $newGoods->save();
     // 更新 goods_sn
     $newGoods->goods_sn = $f3->get('sysConfig[goods_sn_prefix]') . $newGoods['goods_id'];
     $newGoods->save();
     unset($goodsArray);
     // 2. 复制 goods_attr 信息
     if ($goods->type_id > 0) {
         $goodsTypeService = new GoodsTypeService();
         $goodsAttrValueArray = $goodsTypeService->fetchGoodsAttrItemValueArray($goods->goods_id, $goods->type_id);
         foreach ($goodsAttrValueArray as $goodsAttrValue) {
             $goodsAttr = $goodsTypeService->loadGoodsAttrById(0);
             $goodsAttr->goods_id = $newGoods->goods_id;
             $goodsAttr->attr_item_id = $goodsAttrValue['meta_id'];
             $goodsAttr->attr_item_value = $goodsAttrValue['attr_item_value'];
             $goodsAttr->save();
             unset($goodsAttr);
         }
         unset($goodsAttrValueArray);
         unset($goodsTypeService);
     }
     // 3. 复制 goods_gallery 信息
     $goodsGalleryService = new GoodsGalleryService();
     $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsId($goods_id);
     foreach ($goodsGalleryArray as $goodsGalleryItem) {
         // 新建一个 goods_gallery 记录
         $goodsGallery = $goodsGalleryService->loadGoodsGalleryById(0);
         unset($goodsGalleryItem['img_id']);
         $goodsGallery->copyFrom($goodsGalleryItem);
         $goodsGallery->goods_id = $newGoods['goods_id'];
         $goodsGallery->save();
         unset($goodsGallery);
     }
     unset($goodsGalleryArray);
     unset($goodsGalleryService);
     // 4. 复制 goods_team 信息
     $goodsTeam = $goodsBasicService->loadGoodsTeamByGoodsId($goods_id);
     if (!$goodsTeam->isEmpty()) {
         $goodsTeamInfo = $goodsTeam->toArray();
         unset($goodsTeamInfo['team_id']);
         $goodsTeamInfo['goods_id'] = $newGoods['goods_id'];
         $newGoodsTeam = new DataMapper('goods_team');
         $newGoodsTeam->copyFrom($goodsTeamInfo);
         $newGoodsTeam->save();
         unset($newGoodsTeam);
         unset($goodsTeamInfo);
         unset($goodsTeam);
     }
     // 5. 复制 link_goods 信息
     $linkGoodsArray = $goodsBasicService->fetchSimpleLinkGoodsArray($goods_id);
     foreach ($linkGoodsArray as $linkGoodsItem) {
         unset($linkGoodsItem['link_id']);
         $linkGoodsItem['goods_id'] = $newGoods['goods_id'];
         $linkGoodsItem['admin_id'] = $authAdminUser['user_id'];
         $linkGoods = new DataMapper('link_goods');
         $linkGoods->copyFrom($linkGoodsItem);
         $linkGoods->save();
         unset($linkGoods);
     }
     unset($linkGoodsArray);
     // 6. 复制 goods_promote 信息
     $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id);
     if (!$goodsPromote->isEmpty()) {
         $goodsPromoteInfo = $goodsPromote->toArray();
         unset($goodsPromoteInfo['promote_id']);
         $goodsPromoteInfo['goods_id'] = $newGoods['goods_id'];
         $newGoodspromote = new DataMapper('goods_promote');
         $newGoodspromote->copyFrom($goodsPromoteInfo);
         $newGoodspromote->save();
         unset($newGoodspromote);
     }
     unset($goodsPromote);
     // 记录编辑日志
     $goodsLogContent = '从 [' . $goods_id . '] 复制过来';
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($newGoods['goods_id'], $authAdminUser['user_id'], $authAdminUser['user_name'], '复制商品', $goodsLogContent);
     $this->addFlashMessage('复制新建商品成功');
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Edit', array('goods_id' => $newGoods['goods_id']), true));
     return;
     //正常返回
     out_fail:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
예제 #7
0
파일: User.php 프로젝트: jackycgq/bzfshop
 public function doAuthSnsUser($sns_login, $user_name, $email, $autoRegister = true)
 {
     global $f3;
     $user = new DataMapper('users');
     $user->loadOne(array('sns_login = ?', $sns_login), array('order' => 'user_id asc'));
     if (!$user->isEmpty()) {
         // 记录登录时间和IP地址
         $user->last_login = Time::gmTime();
         $user->last_ip = $f3->get('IP');
         $user->save();
         return $user;
     }
     if (!$autoRegister) {
         return false;
     }
     // 自动注册用户
     $user->sns_login = $sns_login;
     $user->user_name = $user_name;
     $user->email = $email;
     $user->password = uniqid();
     // 记录登录时间和IP地址
     $user->last_login = $user->reg_time = Time::gmTime();
     $user->last_ip = $user->reg_ip = $f3->get('IP');
     $user->save();
     return $user;
 }