Author.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Content\Lib;
  3. use Dever;
  4. class Author
  5. {
  6. # 更新数据
  7. public function data($id, $name, $data)
  8. {
  9. $source_table = Dever::input('source_table');
  10. $author = Dever::param('author_id', $data);
  11. if ($author && $id > 0 && $source_table) {
  12. $info = Dever::db('content/author')->one($author);
  13. if (!$info) {
  14. $insert['name'] = $author;
  15. $author = Dever::db('content/author')->insert($insert);
  16. }
  17. Dever::db($source_table)->update(array('where_id' => $id, 'author_id' => $author));
  18. }
  19. }
  20. # 搜索
  21. public function search_api()
  22. {
  23. $keyword = Dever::input('keyword');
  24. $yes = Dever::input('yes');
  25. $where = array();
  26. if ($yes) {
  27. $yes = Dever::db('content/author')->getAll(array('ids' => $yes));
  28. }
  29. if (!$keyword) {
  30. $where['limit'] = '0,50';
  31. $data = Dever::db('content/author')->getAll($where);
  32. } else {
  33. $where['name'] = $keyword;
  34. $data = Dever::db('content/author')->getAll($where);
  35. }
  36. $insert = array();
  37. if (!$data && $keyword) {
  38. $insert[0]['name'] = $keyword . '[新增]';
  39. $insert[0]['value'] = $keyword;
  40. }
  41. $result = array();
  42. if ($yes) {
  43. foreach ($yes as $k => $v) {
  44. if (isset($data[$k])) {
  45. unset($data[$k]);
  46. }
  47. $yes[$k]['selected'] = 'selected';
  48. }
  49. $data = $insert + $yes + $data;
  50. $data = array_merge($data, array());
  51. } else {
  52. $data = $insert + $data;
  53. $data = array_merge($data, array());
  54. }
  55. if (!$data) {
  56. Dever::alert('暂无数据');
  57. }
  58. return $data;
  59. }
  60. }