RecycleBin.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 陈风任 <491085389@qq.com>
  11. * Date: 2018-12-25
  12. */
  13. namespace app\admin\controller;
  14. use think\Page;
  15. use think\Db;
  16. use app\common\logic\ArctypeLogic;
  17. // use app\admin\logic\RecycleBinLogic;
  18. /**
  19. * 模型字段控制器
  20. */
  21. class RecycleBin extends Base
  22. {
  23. public $recyclebinLogic;
  24. public $arctype_channel_id;
  25. public $arctypeLogic;
  26. public function _initialize() {
  27. parent::_initialize();
  28. $this->language_access(); // 多语言功能操作权限
  29. $this->arctypeLogic = new ArctypeLogic();
  30. // $this->recyclebinLogic = new RecycleBinLogic();
  31. $this->arctype = Db::name('arctype'); // 栏目数据表
  32. $this->archives = Db::name('archives'); // 内容数据表
  33. $this->config = Db::name('config'); // 配置数据表
  34. $this->config_attribute = Db::name('config_attribute'); // 自定义变量数据表
  35. $this->product_attribute = Db::name('product_attribute'); // 产品属性数据表
  36. $this->product_attr = Db::name('product_attr'); // 产品属性内容表
  37. $this->guestbook_attribute = Db::name('guestbook_attribute'); // 留言表单数据表
  38. $this->guestbook_attr = Db::name('guestbook_attr'); // 留言表单内容表
  39. $this->arctype_channel_id = config('global.arctype_channel_id');
  40. }
  41. /**
  42. * 回收站管理 - 栏目列表
  43. */
  44. public function arctype_index()
  45. {
  46. $list = array();
  47. $keywords = input('keywords/s');
  48. $condition = array();
  49. // 应用搜索条件
  50. if (!empty($keywords)) {
  51. $condition['a.typename'] = array('LIKE', "%{$keywords}%");
  52. }
  53. $condition['a.is_del'] = 1;
  54. $condition['a.lang'] = $this->admin_lang;
  55. $count = $this->arctype->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  56. $pageObj = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  57. $list = $this->arctype->alias('a')
  58. ->field('a.id, a.typename, a.current_channel, a.update_time')
  59. ->where($condition)
  60. ->order('a.update_time desc')
  61. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  62. ->select();
  63. $pageStr = $pageObj->show();// 分页显示输出
  64. $this->assign('pageStr',$pageStr);// 赋值分页输出
  65. $this->assign('list',$list);// 赋值数据集
  66. $this->assign('pageObj',$pageObj);// 赋值分页对象
  67. // 模型列表
  68. $channeltype_list = getChanneltypeList();
  69. $this->assign('channeltype_list', $channeltype_list);
  70. return $this->fetch();
  71. }
  72. /**
  73. * 回收站管理 - 栏目还原
  74. */
  75. public function arctype_recovery()
  76. {
  77. if (IS_POST) {
  78. $del_id = input('post.del_id/d', 0);
  79. if(!empty($del_id)){
  80. // 当前栏目信息
  81. $row = $this->arctype->field('id, parent_id, current_channel, typename')
  82. ->where([
  83. 'id' => $del_id,
  84. 'is_del'=> 1,
  85. ])
  86. ->find();
  87. if ($row) {
  88. $id_arr = [$row['id']];
  89. // 多语言处理逻辑
  90. if (is_language()) {
  91. $attr_name_arr = 'tid'.$row['id'];
  92. $id_arr = Db::name('language_attr')->where([
  93. 'attr_name' => $attr_name_arr,
  94. 'attr_group' => 'arctype',
  95. ])->column('attr_value');
  96. $list = $this->arctype->field('id,del_method')
  97. ->where([
  98. 'id' => ['IN', $id_arr],
  99. ])
  100. ->whereOr([
  101. 'parent_id' => ['IN', $id_arr],
  102. ])->select();
  103. }else{
  104. $list = $this->arctype->field('id,del_method,parent_id')
  105. ->where([
  106. 'parent_id' => ['IN', $id_arr],
  107. ])
  108. ->select();
  109. }
  110. }else{
  111. $this->error('参数错误');
  112. }
  113. // 需要更新的数据
  114. $data['is_del'] = 0; // is_del=0为正常数据
  115. $data['update_time']= getTime(); // 更新修改时间
  116. $data['del_method'] = 0; // 恢复删除方式为默认
  117. // 还原数据条件逻辑
  118. // 栏目逻辑
  119. $map = 'is_del=1';
  120. // 多语言处理逻辑
  121. if (is_language()) {
  122. $where = $map.' and (';
  123. $ids = get_arr_column($list, 'id');
  124. !empty($ids) && $where .= 'id IN ('.implode(',', $ids).') OR parent_id IN ('.implode(',', $ids).')';
  125. }else{
  126. $where = $map.' and (id='.$del_id.' or parent_id='.$del_id;
  127. if (0 == intval($row['parent_id'])) {
  128. foreach ($list as $value) {
  129. if (2 == intval($value['del_method'])) {
  130. $where .= ' or parent_id='.$value['id'];
  131. }
  132. }
  133. }
  134. }
  135. $where .= ')';
  136. // 文章逻辑
  137. $where1 = $map.' and typeid in (';
  138. // 栏目数据更新
  139. $arctype = $this->arctype->where($where)->select();
  140. foreach ($arctype as $key => $value) {
  141. $where = 'is_del=1 and ';
  142. if (0 == intval($value['parent_id'])) {
  143. $where .= 'id='.$value['id'];
  144. }else if(0 < intval($value['parent_id'])){
  145. $where .= '(id='.$value['id'].' or id='.$value['parent_id'].')';
  146. }
  147. if (!in_array($value['id'], $id_arr)) {
  148. $where .= ' and del_method=2'; // 不是当前栏目或对应的多语言栏目,则只还原被动删除栏目
  149. }
  150. $this->arctype->where($where)->update($data);
  151. // 还原父级栏目,不还原主动删除的子栏目下的文档
  152. if (in_array($value['id'], $id_arr) || 2 == intval($value['del_method'])) {
  153. $where1 .= $value['id'].',';
  154. }
  155. }
  156. $where1 = rtrim($where1,',');
  157. $where1 .= ') and del_method=2';
  158. // 还原三级栏目时需要一并还原顶级栏目
  159. // 多语言处理逻辑
  160. if (is_language()) {
  161. foreach ($list as $key => $value) {
  162. $parent_id = intval($value['parent_id']);
  163. if (0 < $parent_id) {
  164. $where = 'id='.$parent_id;
  165. $r1 = $this->arctype->where($where)->find();
  166. $parent_id = intval($r1['parent_id']);
  167. if (0 < $parent_id) {
  168. $where = 'is_del=1 and id='.$parent_id;
  169. $this->arctype->where($where)->update($data);
  170. }
  171. }
  172. }
  173. }else{
  174. $parent_id = intval($arctype['0']['parent_id']);
  175. if (0 < $parent_id) {
  176. $where = 'id='.$parent_id;
  177. $r1 = $this->arctype->where($where)->find();
  178. $parent_id = intval($r1['parent_id']);
  179. if (0 < $parent_id) {
  180. $where = 'is_del=1 and id='.$parent_id;
  181. $this->arctype->where($where)->update($data);
  182. }
  183. }
  184. }
  185. // 内容数据更新 - 还原父级栏目,不还原主动删除的子栏目下的文档
  186. $r = $this->archives->where($where1)->update($data);
  187. if (false !== $r) {
  188. delFile(CACHE_PATH);
  189. adminLog('还原栏目:'.$row['typename']);
  190. $this->success('操作成功');
  191. }
  192. }
  193. $this->error('操作失败');
  194. }
  195. $this->error('非法访问');
  196. }
  197. /**
  198. * 回收站管理 - 栏目删除
  199. */
  200. public function arctype_del()
  201. {
  202. // if (IS_POST) {
  203. // $post = input('post.');
  204. // $post['del_id'] = eyIntval($post['del_id']);
  205. // /*当前栏目信息*/
  206. // $row = M('arctype')->field('id, current_channel, typename')
  207. // ->where([
  208. // 'id' => $post['del_id'],
  209. // 'lang' => $this->admin_lang,
  210. // ])
  211. // ->find();
  212. // $r = model('arctype')->del($post['del_id']);
  213. // if (false !== $r) {
  214. // adminLog('删除栏目:'.$row['typename']);
  215. // $this->success('删除成功');
  216. // } else {
  217. // $this->error('删除失败');
  218. // }
  219. // }
  220. // $this->error('非法访问');
  221. if (IS_POST) {
  222. $del_id = input('post.del_id/d', 0);
  223. if(!empty($del_id)){
  224. // 当前栏目信息
  225. $row = $this->arctype->field('id, parent_id, current_channel, typename')
  226. ->where([
  227. 'id' => $del_id,
  228. 'is_del'=> 1,
  229. ])
  230. ->find();
  231. if ($row) {
  232. $id_arr = $row['id'];
  233. // 多语言处理逻辑
  234. if (is_language()) {
  235. $attr_name_arr = 'tid'.$row['id'];
  236. $id_arr = Db::name('language_attr')->where([
  237. 'attr_name' => $attr_name_arr,
  238. 'attr_group' => 'arctype',
  239. ])->column('attr_value');
  240. $list = $this->arctype->field('id,del_method')
  241. ->where([
  242. 'id' => ['IN', $id_arr],
  243. ])
  244. ->whereOr([
  245. 'parent_id' => ['IN', $id_arr],
  246. ])->select();
  247. }else{
  248. $list = $this->arctype->field('id,del_method')
  249. ->where([
  250. 'parent_id' => ['IN', $id_arr],
  251. ])
  252. ->select();
  253. }
  254. }else{
  255. $this->error('参数错误');
  256. }
  257. // 删除条件逻辑
  258. // 栏目逻辑
  259. $map = 'is_del=1';
  260. // 多语言处理逻辑
  261. if (is_language()) {
  262. $where = $map.' and (';
  263. $ids = get_arr_column($list, 'id');
  264. !empty($ids) && $where .= 'id IN ('.implode(',', $ids).') OR parent_id IN ('.implode(',', $ids).')';
  265. }else{
  266. $ids = [$del_id];
  267. $where = $map.' and (id='.$del_id.' or parent_id='.$del_id;
  268. if (0 == intval($row['parent_id'])) {
  269. foreach ($list as $value) {
  270. if (2 == intval($value['del_method'])) {
  271. $where .= ' or parent_id='.$value['id'];
  272. }
  273. }
  274. }
  275. }
  276. $where .= ')';
  277. // 文章逻辑
  278. $where1 = $map.' and typeid in (';
  279. // 查询栏目回收站数据并拼装删除文章逻辑
  280. $arctype = $this->arctype->field('id')->where($where)->select();
  281. foreach ($arctype as $key => $value) {
  282. $where1 .= $value['id'].',';
  283. }
  284. $where1 = rtrim($where1,',');
  285. $where1 .= ')';
  286. // 栏目数据删除
  287. $r = $this->arctype->where($where)->delete();
  288. if($r){
  289. // Tag标签删除
  290. Db::name('tagindex')->where([
  291. 'typeid' => ['IN', $ids],
  292. ])->delete();
  293. // 内容数据删除
  294. $r = $this->archives->where($where1)->delete();
  295. $msg = '';
  296. if (!$r) {
  297. $msg = ',文档清空失败!';
  298. }
  299. adminLog('删除栏目:'.$row['typename']);
  300. $this->success("操作成功".$msg);
  301. }
  302. }
  303. $this->error("操作失败!");
  304. }
  305. $this->error('非法访问');
  306. }
  307. /**
  308. * 回收站管理 - 内容列表
  309. */
  310. public function archives_index()
  311. {
  312. $assign_data = array();
  313. $condition = array();
  314. // 获取到所有URL参数
  315. $param = input('param.');
  316. // 应用搜索条件
  317. foreach (['keywords','typeid'] as $key) {
  318. if (isset($param[$key]) && $param[$key] !== '') {
  319. if ($key == 'keywords') {
  320. $condition['a.title'] = array('LIKE', "%{$param[$key]}%");
  321. } else {
  322. $condition['a.'.$key] = array('eq', $param[$key]);
  323. }
  324. }
  325. }
  326. $condition['a.channel'] = array('neq', 6); // 排除单页模型
  327. /*多语言*/
  328. $condition['a.lang'] = array('eq', $this->admin_lang);
  329. /*--end*/
  330. $condition['a.is_del'] = array('eq', 1); // 回收站功能
  331. /**
  332. * 数据查询,搜索出主键ID的值
  333. */
  334. $count = $this->archives->alias('a')->where($condition)->count('aid');// 查询满足要求的总记录数
  335. $pageObj = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  336. $list = $this->archives->field("a.aid,a.channel")
  337. ->alias('a')
  338. ->where($condition)
  339. ->order('a.aid desc')
  340. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  341. ->getAllWithIndex('aid');
  342. /**
  343. * 完善数据集信息
  344. * 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
  345. */
  346. if ($list) {
  347. $aids = array_keys($list);
  348. $fields = "a.aid, a.title, a.typeid, a.litpic, a.update_time, b.typename";
  349. $row = DB::name('archives')
  350. ->field($fields)
  351. ->alias('a')
  352. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  353. ->where('a.aid', 'in', $aids)
  354. ->getAllWithIndex('aid');
  355. foreach ($list as $key => $val) {
  356. $row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
  357. $list[$key] = $row[$val['aid']];
  358. }
  359. }
  360. $pageStr = $pageObj->show(); // 分页显示输出
  361. $assign_data['pageStr'] = $pageStr; // 赋值分页输出
  362. $assign_data['list'] = $list; // 赋值数据集
  363. $assign_data['pageObj'] = $pageObj; // 赋值分页对象
  364. $this->assign($assign_data);
  365. return $this->fetch();
  366. }
  367. /**
  368. * 回收站管理 - 内容还原
  369. */
  370. public function archives_recovery()
  371. {
  372. $id_arr = input('del_id/a');
  373. $id_arr = eyIntval($id_arr);
  374. if(IS_POST && !empty($id_arr)){
  375. // 当前文档信息
  376. $row = $this->archives->field('aid, title, typeid')
  377. ->where([
  378. 'aid' => ['IN', $id_arr],
  379. 'is_del' => 1,
  380. 'lang' => $this->admin_lang,
  381. ])
  382. ->select();
  383. if (!empty($row)) {
  384. $id_arr = get_arr_column($row, 'aid');
  385. // 关联的栏目ID集合
  386. $typeids = [];
  387. $typeidArr = get_arr_column($row, 'typeid');
  388. $typeidArr = array_unique($typeidArr);
  389. foreach ($typeidArr as $key => $val) {
  390. $pidArr = model('Arctype')->getAllPid($val);
  391. $typeids = array_merge($typeids, get_arr_column($pidArr, 'id'));
  392. }
  393. $typeids = array_unique($typeids);
  394. if (!empty($typeids)) {
  395. // 多语言处理逻辑
  396. if (is_language()) {
  397. $attr_name_arr = [];
  398. foreach ($typeids as $key => $val) {
  399. array_push($attr_name_arr, 'tid'.$val);
  400. }
  401. $attr_value = Db::name('language_attr')->where([
  402. 'attr_name' => ['IN', $attr_name_arr],
  403. 'attr_group' => 'arctype',
  404. ])->column('attr_value');
  405. $attr_value && $typeids = $attr_value;
  406. }
  407. // 还原数据
  408. $r = $this->arctype->where([
  409. 'id' => ['IN', $typeids],
  410. ])
  411. ->update([
  412. 'is_del' => 0,
  413. 'del_method' => 0,
  414. 'update_time' => getTime(),
  415. ]);
  416. if ($r) {
  417. $r2 = $this->archives->where([
  418. 'aid' => ['IN', $id_arr],
  419. ])
  420. ->update([
  421. 'is_del' => 0,
  422. 'del_method' => 0,
  423. 'update_time' => getTime(),
  424. ]);
  425. if ($r2) {
  426. delFile(CACHE_PATH);
  427. adminLog('还原文档:'.implode('|', get_arr_column($row, 'title')));
  428. $this->success('操作成功');
  429. } else {
  430. $this->success('关联栏目还原成功,文档还原失败!');
  431. }
  432. }
  433. $this->error('操作失败');
  434. }
  435. }
  436. $this->error('参数有误');
  437. }
  438. $this->error('非法访问');
  439. }
  440. /**
  441. * 回收站管理 - 内容删除
  442. */
  443. public function archives_del()
  444. {
  445. $id_arr = input('del_id/a');
  446. $id_arr = eyIntval($id_arr);
  447. if(IS_POST && !empty($id_arr)){
  448. // 当前文档信息
  449. $row = $this->archives->field('aid, title, channel')
  450. ->where([
  451. 'aid' => ['IN', $id_arr],
  452. 'is_del' => 1,
  453. 'lang' => $this->admin_lang,
  454. ])
  455. ->select();
  456. if (!empty($row)) {
  457. $id_arr = get_arr_column($row, 'aid');
  458. // 内容数据删除
  459. $r = $this->archives->where([
  460. 'aid' => ['IN', $id_arr],
  461. ])
  462. ->delete();
  463. if($r){
  464. /*按模型分组,然后进行分组删除*/
  465. $row2Group = group_same_key($row, 'channel');
  466. if (!empty($row2Group)) {
  467. $channelids = array_keys($row2Group);
  468. $channeltypeRow = Db::name('channeltype')->field('id,table')
  469. ->where([
  470. 'id' => ['IN', $channelids],
  471. ])->getAllWithIndex('id');
  472. foreach ($row2Group as $key => $val) {
  473. $table = $channeltypeRow[$key]['table'];
  474. $aidarr_tmp = get_arr_column($val, 'aid');
  475. model($table)->afterDel($id_arr);
  476. }
  477. }
  478. /*--end*/
  479. adminLog('删除文档:'.implode('|', get_arr_column($row, 'title')));
  480. $this->success("操作成功!");
  481. }
  482. $this->error("操作失败!");
  483. }
  484. }
  485. $this->error("参数有误!");
  486. }
  487. /**
  488. * 回收站管理 - 自定义变量列表
  489. */
  490. public function customvar_index()
  491. {
  492. $list = array();
  493. $keywords = input('keywords/s');
  494. $condition = array();
  495. // 应用搜索条件
  496. if (!empty($keywords)) {
  497. $condition['a.attr_name'] = array('LIKE', "%{$keywords}%");
  498. }
  499. $attr_var_names = M('config')->field('name')
  500. ->where([
  501. 'is_del' => 1,
  502. 'lang' => $this->admin_lang,
  503. ])->getAllWithIndex('name');
  504. $condition['a.attr_var_name'] = array('IN', array_keys($attr_var_names));
  505. $condition['a.lang'] = $this->admin_lang;
  506. $count = M('config_attribute')->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  507. $pageObj = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  508. $list = M('config_attribute')->alias('a')
  509. ->field('a.*, b.id')
  510. ->join('__CONFIG__ b', 'b.name = a.attr_var_name AND a.lang = b.lang', 'LEFT')
  511. ->where($condition)
  512. ->order('a.update_time desc')
  513. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  514. ->select();
  515. $pageStr = $pageObj->show();// 分页显示输出
  516. $this->assign('pageStr',$pageStr);// 赋值分页输出
  517. $this->assign('list',$list);// 赋值数据集
  518. $this->assign('pageObj',$pageObj);// 赋值分页对象
  519. return $this->fetch();
  520. }
  521. /**
  522. * 回收站管理 - 自定义变量还原
  523. */
  524. public function customvar_recovery()
  525. {
  526. if (IS_POST) {
  527. $id_arr = input('del_id/a');
  528. $id_arr = eyIntval($id_arr);
  529. if(!empty($id_arr)){
  530. $attr_var_name = $this->config->where([
  531. 'id' => ['IN', $id_arr],
  532. 'lang' => $this->admin_lang,
  533. 'is_del' => 1,
  534. ])->column('name');
  535. $r = $this->config->where('name', 'IN', $attr_var_name)->update([
  536. 'is_del' => 0,
  537. 'update_time' => getTime(),
  538. ]);
  539. if($r){
  540. delFile(CACHE_PATH, true);
  541. adminLog('还原自定义变量:'.implode(',', $attr_var_name));
  542. $this->success("操作成功!");
  543. }else{
  544. $this->error("操作失败!");
  545. }
  546. }
  547. }
  548. $this->error("参数有误!");
  549. }
  550. /**
  551. * 回收站管理 - 自定义变量删除
  552. */
  553. public function customvar_del()
  554. {
  555. if (IS_POST) {
  556. $id_arr = input('del_id/a');
  557. $id_arr = eyIntval($id_arr);
  558. if(!empty($id_arr)){
  559. $attr_var_name = $this->config->where([
  560. 'id' => ['IN', $id_arr],
  561. 'lang' => $this->admin_lang,
  562. 'is_del' => 1,
  563. ])->column('name');
  564. $r = $this->config->where('name', 'IN', $attr_var_name)->delete();
  565. if($r){
  566. // 同时删除
  567. $this->config_attribute->where('attr_var_name', 'IN', $attr_var_name)->delete();
  568. adminLog('彻底删除自定义变量:'.implode(',', $attr_var_name));
  569. $this->success("操作成功!");
  570. }else{
  571. $this->error("操作失败!");
  572. }
  573. }
  574. }
  575. $this->error("参数有误!");
  576. }
  577. /**
  578. * 回收站管理 - 产品属性列表
  579. */
  580. public function proattr_index()
  581. {
  582. $list = array();
  583. $condition = array();
  584. // 获取到所有URL参数
  585. $param = input('param.');
  586. // 应用搜索条件
  587. foreach (['keywords','typeid'] as $key) {
  588. if (isset($param[$key]) && $param[$key] !== '') {
  589. if ($key == 'keywords') {
  590. $condition['a.attr_name'] = array('LIKE', "%{$param[$key]}%");
  591. } else {
  592. $condition['a.'.$key] = array('eq', $param[$key]);
  593. }
  594. }
  595. }
  596. /*多语言*/
  597. $condition['a.lang'] = $this->admin_lang;
  598. /*--end*/
  599. $condition['a.is_del'] = array('eq', 1); // 回收站功能
  600. $count = $this->product_attribute->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  601. $pageObj = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  602. $list = $this->product_attribute->alias('a')
  603. ->field('a.*, b.typename')
  604. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  605. ->where($condition)
  606. ->order('a.update_time desc')
  607. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  608. ->select();
  609. $pageStr = $pageObj->show();// 分页显示输出
  610. $this->assign('pageStr',$pageStr);// 赋值分页输出
  611. $this->assign('list',$list);// 赋值数据集
  612. $this->assign('pageObj',$pageObj);// 赋值分页对象
  613. return $this->fetch();
  614. }
  615. /**
  616. * 回收站管理 - 产品属性还原
  617. */
  618. public function proattr_recovery()
  619. {
  620. $id_arr = input('del_id/a');
  621. $id_arr = eyIntval($id_arr);
  622. if(IS_POST && !empty($id_arr)){
  623. /*检测关联栏目是否已被伪删除*/
  624. $row1 = $this->product_attribute->field('attr_id, typeid')
  625. ->where([
  626. 'attr_id' => ['IN', $id_arr],
  627. ])->select();
  628. $row2 = $this->arctype->field('typename')
  629. ->where([
  630. 'id' => ['IN', get_arr_column($row1, 'typeid')],
  631. 'is_del' => 1,
  632. ])
  633. ->select();
  634. if (!empty($row2)) {
  635. $this->error('请先还原关联栏目:<font color="red">'.implode(' , ', get_arr_column($row2, 'typename')).'</font>');
  636. }
  637. /*--end*/
  638. // 多语言处理逻辑
  639. if (is_language()) {
  640. $attr_name_arr = [];
  641. foreach ($id_arr as $key => $val) {
  642. array_push($attr_name_arr, 'attr_'.$val);
  643. }
  644. $id_arr = Db::name('language_attr')->where([
  645. 'attr_name' => ['IN', $attr_name_arr],
  646. 'attr_group' => 'product_attribute',
  647. ])->column('attr_value');
  648. }
  649. $row = $this->product_attribute->field('attr_id, attr_name')
  650. ->where([
  651. 'attr_id' => ['IN', $id_arr],
  652. ])->select();
  653. $id_arr = get_arr_column($row, 'attr_id');
  654. // 更新数据
  655. $r = $this->product_attribute->where([
  656. 'attr_id' => ['IN', $id_arr],
  657. ])->update([
  658. 'is_del' => 0,
  659. 'update_time' => getTime(),
  660. ]);
  661. if($r){
  662. adminLog('还原产品参数:'.implode(',', get_arr_column($row, 'attr_name')));
  663. $this->success("操作成功!");
  664. }
  665. $this->error("操作失败!");
  666. }
  667. $this->error("参数有误!");
  668. }
  669. /**
  670. * 回收站管理 - 产品属性删除
  671. */
  672. public function proattr_del()
  673. {
  674. $id_arr = input('del_id/a');
  675. $id_arr = eyIntval($id_arr);
  676. if(IS_POST && !empty($id_arr)){
  677. // 多语言处理逻辑
  678. if (is_language()) {
  679. $attr_name_arr = [];
  680. foreach ($id_arr as $key => $val) {
  681. array_push($attr_name_arr, 'attr_'.$val);
  682. }
  683. $id_arr = Db::name('language_attr')->where([
  684. 'attr_name' => ['IN', $attr_name_arr],
  685. 'attr_group' => 'product_attribute',
  686. ])->column('attr_value');
  687. }
  688. $row = $this->product_attribute->field('attr_id, attr_name')
  689. ->where([
  690. 'attr_id' => ['IN', $id_arr],
  691. ])->select();
  692. $id_arr = get_arr_column($row, 'attr_id');
  693. // 产品属性删除
  694. $r = $this->product_attribute->where([
  695. 'attr_id' => ['IN', $id_arr],
  696. ])->delete();
  697. if($r){
  698. // 同时删除
  699. $this->product_attr->where([
  700. 'attr_id' => ['IN', $id_arr],
  701. ])->delete();
  702. adminLog('删除产品参数:'.implode(',', get_arr_column($row, 'attr_name')));
  703. $this->success("操作成功!");
  704. }
  705. $this->error("操作失败!");
  706. }
  707. $this->error("参数有误!");
  708. }
  709. /**
  710. * 回收站管理 - 留言属性列表
  711. */
  712. public function gbookattr_index()
  713. {
  714. $list = array();
  715. $condition = array();
  716. // 获取到所有URL参数
  717. $param = input('param.');
  718. // 应用搜索条件
  719. foreach (['keywords','typeid'] as $key) {
  720. if (isset($param[$key]) && $param[$key] !== '') {
  721. if ($key == 'keywords') {
  722. $condition['a.attr_name'] = array('LIKE', "%{$param[$key]}%");
  723. } else {
  724. $condition['a.'.$key] = array('eq', $param[$key]);
  725. }
  726. }
  727. }
  728. /*多语言*/
  729. $condition['a.lang'] = $this->admin_lang;
  730. /*--end*/
  731. $condition['a.is_del'] = array('eq', 1); // 回收站功能
  732. $count = $this->guestbook_attribute->alias('a')->where($condition)->count();// 查询满足要求的总记录数
  733. $pageObj = new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
  734. $list = $this->guestbook_attribute->alias('a')
  735. ->field('a.*, b.typename')
  736. ->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
  737. ->where($condition)
  738. ->order('a.update_time desc')
  739. ->limit($pageObj->firstRow.','.$pageObj->listRows)
  740. ->select();
  741. $pageStr = $pageObj->show();// 分页显示输出
  742. $this->assign('pageStr',$pageStr);// 赋值分页输出
  743. $this->assign('list',$list);// 赋值数据集
  744. $this->assign('pageObj',$pageObj);// 赋值分页对象
  745. return $this->fetch();
  746. }
  747. /**
  748. * 回收站管理 - 留言属性还原
  749. */
  750. public function gbookattr_recovery()
  751. {
  752. $id_arr = input('del_id/a');
  753. $id_arr = eyIntval($id_arr);
  754. if(IS_POST && !empty($id_arr)){
  755. /*检测关联栏目是否已被伪删除*/
  756. $row1 = $this->guestbook_attribute->field('attr_id, typeid')
  757. ->where([
  758. 'attr_id' => ['IN', $id_arr],
  759. ])->select();
  760. $row2 = $this->arctype->field('typename')
  761. ->where([
  762. 'id' => ['IN', get_arr_column($row1, 'typeid')],
  763. 'is_del' => 1,
  764. ])
  765. ->select();
  766. if (!empty($row2)) {
  767. $this->error('请先还原关联栏目:<font color="red">'.implode(' , ', get_arr_column($row2, 'typename')).'</font>');
  768. }
  769. /*--end*/
  770. // 多语言处理逻辑
  771. if (is_language()) {
  772. $attr_name_arr = [];
  773. foreach ($id_arr as $key => $val) {
  774. array_push($attr_name_arr, 'attr_'.$val);
  775. }
  776. $id_arr = Db::name('language_attr')->where([
  777. 'attr_name' => ['IN', $attr_name_arr],
  778. 'attr_group' => 'guestbook_attribute',
  779. ])->column('attr_value');
  780. }
  781. $row = $this->guestbook_attribute->field('attr_id, attr_name')
  782. ->where([
  783. 'attr_id' => ['IN', $id_arr],
  784. ])->select();
  785. $id_arr = get_arr_column($row, 'attr_id');
  786. // 更新数据
  787. $r = $this->guestbook_attribute->where([
  788. 'attr_id' => ['IN', $id_arr],
  789. ])->update([
  790. 'is_del' => 0,
  791. 'update_time' => getTime(),
  792. ]);
  793. if($r){
  794. adminLog('还原留言表单:'.implode(',', get_arr_column($row, 'attr_name')));
  795. $this->success("操作成功!");
  796. }
  797. $this->error("操作失败!");
  798. }
  799. $this->error("参数有误!");
  800. }
  801. /**
  802. * 回收站管理 - 留言属性删除
  803. */
  804. public function gbookattr_del()
  805. {
  806. $id_arr = input('del_id/a');
  807. $id_arr = eyIntval($id_arr);
  808. if(IS_POST && !empty($id_arr)){
  809. // 多语言处理逻辑
  810. if (is_language()) {
  811. $attr_name_arr = [];
  812. foreach ($id_arr as $key => $val) {
  813. array_push($attr_name_arr, 'attr_'.$val);
  814. }
  815. $id_arr = Db::name('language_attr')->where([
  816. 'attr_name' => ['IN', $attr_name_arr],
  817. 'attr_group' => 'guestbook_attribute',
  818. ])->column('attr_value');
  819. }
  820. $row = $this->guestbook_attribute->field('attr_id, attr_name')
  821. ->where([
  822. 'attr_id' => ['IN', $id_arr],
  823. ])->select();
  824. $id_arr = get_arr_column($row, 'attr_id');
  825. // 产品属性删除
  826. $r = $this->guestbook_attribute->where([
  827. 'attr_id' => ['IN', $id_arr],
  828. ])->delete();
  829. if($r){
  830. // 同时删除
  831. $this->guestbook_attr->where([
  832. 'attr_id' => ['IN', $id_arr],
  833. ])->delete();
  834. adminLog('删除留言表单:'.implode(',', get_arr_column($row, 'attr_name')));
  835. $this->success("操作成功!");
  836. }
  837. $this->error("操作失败!");
  838. }
  839. $this->error("参数有误!");
  840. }
  841. }