/** * 清空一个表 * * @param DataMapper $dataMapper */ public function clearTable(DataMapper $dataMapper) { $dataMapper->erase('1'); }
/** * 删除一组 meta 记录 * * @param string $meta_type * @param string $meta_key * * @throws \InvalidArgumentException */ public function removeMetaArrayByTypeAndKey($meta_type, $meta_key) { if (empty($meta_type) || empty($meta_key)) { throw new \InvalidArgumentException('meta_type, meta_key can not be empty'); } $dataMapper = new DataMapper('meta'); $dataMapper->erase(array('meta_type = ? and meta_key = ?', $meta_type, $meta_key)); unset($dataMapper); }
/** * 删除商品关联 * * @param $f3 */ public function ajaxRemoveLink($f3) { // 权限检查 $this->requirePrivilege('manage_goods_edit_edit_post', true); // 首先做参数验证 $validator = new Validator($f3->get('GET')); $errorMessage = ''; $link_id = $validator->required()->digits()->min(1)->validate('link_id'); if (!$this->validate($validator)) { $errorMessage = implode('|', $this->flashMessageArray); goto out_fail; } $dataMapper = new DataMapper('link_goods'); $dataMapper->loadOne(array('link_id = ?', $link_id)); if ($dataMapper->isEmpty()) { $errorMessage = '关联记录不存在'; goto out_fail; } $goods_id = $dataMapper->goods_id; $goodsLogContent = $dataMapper->link_goods_id; // 删除记录 $dataMapper->erase(); //清除缓存,确保商品显示正确 ClearHelper::clearGoodsCacheById($goods_id); // 记录商品编辑日志 $authAdminUser = AuthHelper::getAuthUser(); $goodsLogService = new GoodsLogService(); $goodsLogService->addGoodsLog($goods_id, $authAdminUser['user_id'], $authAdminUser['user_name'], '取消商品关联', $goodsLogContent); out: Ajax::header(); echo Ajax::buildResult(null, null, null); return; out_fail: // 失败,返回出错信息 Ajax::header(); echo Ajax::buildResult(-1, $errorMessage, null); }
/** * * 清除所有的定义,请谨慎使用这个方法 * */ public function clearPrivilege() { $dataMapper = new DataMapper('meta'); $dataMapper->erase(array('meta_type = ?'), Privilege::META_TYPE_PRIVILEGE_ITEM); $dataMapper->erase(array('meta_type = ?'), Privilege::META_TYPE_PRIVILEGE_GROUP); }
/** * 删除商品的所有属性值 * * @param int $goods_id 商品ID */ public function removeAllGoodsAttrItemValue($goods_id) { // 首先验证参数 $validator = new Validator(array('goods_id' => $goods_id)); $goods_id = $validator->required()->digits()->min(1)->validate('goods_id'); $this->validate($validator); $DataMapper = new DataMapper('goods_attr'); $DataMapper->erase(array('goods_id = ?', $goods_id)); }