123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace app\admin\controller\wwh;
- use app\common\controller\Backend;
- use fast\Tree;
- use think\Db;
- class Archives extends Base
- {
- /**
- * Archives模型对象
- * @var \app\admin\model\wwh\Archives
- */
- protected $model = null;
- protected $searchFields = 'title';
- protected $multiFields = ['weigh'];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\wwh\Archives;
- $columnList = [];
- $disabledIds = [];
- $all = collection(model('\app\admin\model\wwh\Column')->order('weigh desc,id desc')->select())->toArray();
- foreach ($all as $k => $v) {
- $state = ['opened' => true];
- if (($v['classify'] == 'none') or ($v['classify'] == 'link') or ($v['classify'] == 'service') or ($v['classify'] == 'partner') or ($v['classify'] == 'about')) {
- $disabledIds[] = $v['id'];
- }
- if (($v['classify'] == 'none') or ($v['classify'] == 'link') or ($v['classify'] == 'service') or ($v['classify'] == 'partner') or ($v['classify'] == 'about')) {
- $state['disabled'] = true;
- }
- $columnList[] = [
- 'id' => $v['id'],
- 'parent' => $v['parent_id'] ? $v['parent_id'] : '#',
- 'text' => $v['name'] . " <en> " . $v['e_name'] . "</en>",
- 'type' => $v['type'],
- 'state' => $state
- ];
- }
- $tree = Tree::instance()->init($all, 'parent_id');
- $columnOptions = $tree->getTree(0,
- "<option model='@model_id' value=@id @selected @disabled>@spacer@name @e_name</option>", '', $disabledIds);
- $this->view->assign('columnOptions', $columnOptions);
- $this->assignconfig('columnList', $columnList);
- $this->view->assign("typeList", $this->model->getTypeList());
- $this->view->assign("recDataList", $this->model->getRecDataList());
- $this->view->assign("langList", $this->model->getLangList());
- $this->view->assign("dTypeList", $this->model->getdTypeList());
- }
- /**
- * 查看
- */
- public function index()
- {
- //当前是否为关联查询
- $this->relationSearch = true;
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- //获取是否启用英文配置
- $addon_config = get_addon_config("wwh");
- $switch_lang = $addon_config['switch_lang'];
- if ($switch_lang == 1) {
- $lang = '1,2';
- } else {
- $lang = '1';
- }
- $list = $this->model
- ->with(['column'])
- ->where($where)
- ->whereIn('lang', $lang)
- ->order($sort, $order)
- ->paginate($limit);
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 编辑
- */
- public function edit($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isPost()) {
- return parent::edit($ids);
- }
- $column = \app\admin\model\wwh\Column::get($row['column_id']);
- if (!$column) {
- $this->error(__('No specified column found'));
- }
- $disabledIds = [];
- $all = collection(model('\app\admin\model\wwh\Column')->order('weigh desc,id desc')->select())->toArray();
- foreach ($all as $k => $v) {
- if ($v['type'] == 'link' || $v['classify'] != $column['classify']) {
- $disabledIds[] = $v['id'];
- }
- }
- $disabledIds = array_diff($disabledIds, [$row['column_id']]);
- $tree = Tree::instance()->init($all, 'parent_id');
- $columnOptions = $tree->getTree(0,
- "<option model='@model_id' value=@id @selected @disabled>@spacer@name @e_name</option>", $row['column_id'],
- $disabledIds);
- $this->view->assign('columnOptions', $columnOptions);
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
- /**
- * 删除
- */
- public function del($ids = "")
- {
- if (!$this->request->isPost()) {
- $this->error(__("Invalid parameters"));
- }
- $ids = $ids ? $ids : $this->request->post("ids");
- if ($ids) {
- $pk = $this->model->getPk();
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- $this->model->where($this->dataLimitField, 'in', $adminIds);
- }
- $list = $this->model->where($pk, 'in', $ids)->select();
- $count = 0;
- Db::startTrans();
- try {
- foreach ($list as $k => $v) {
- $liststatus = $this->model->where(['status' => '1', 'id' => $ids])->limit(1)->select();
- if ($liststatus) {
- $this->error('该文章已审核,不能删除!');
- } else {
- $count += $v->delete();
- }
- }
- Db::commit();
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($count) {
- $this->success();
- } else {
- $this->error(__('No rows were deleted'));
- }
- }
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
- /**
- * 审核
- */
- public function audit($ids)
- {
- foreach ($ids as $k => $v) {
- $res = $this->model->where(['id' => ['in', $ids]])->update(['status' => 1]);
- if ($res == true) {
- $this->success('审核成功');
- } else {
- $this->error('未更新任何行');
- }
- }
- }
- /**
- * 反审核
- */
- public function faudit($ids)
- {
- $res = $this->model->where(['status' => '1', 'id' => $ids])->update(['status' => 0]);
- if ($res) {
- $this->success('反审核成功');
- } else {
- $this->error('未更新任何行');
- }
- }
- }
|