12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace Article\Lib;
- use Dever;
- class Author
- {
- # 更新数据
- public function data($id, $name, $data)
- {
- $source_table = Dever::input('source_table');
- $author = Dever::param('author_id', $data);
- if ($author && $id > 0 && $source_table) {
- $info = Dever::db('article/author')->one($author);
- if (!$info) {
- $insert['name'] = $author;
- $author = Dever::db('article/author')->insert($insert);
- }
- Dever::db($source_table)->update(array('where_id' => $id, 'author_id' => $author));
- }
- }
- # 搜索
- public function search_api()
- {
- $keyword = Dever::input('keyword');
- $yes = Dever::input('yes');
- $where = array();
- if ($yes) {
- $yes = Dever::db('article/author')->getAll(array('ids' => $yes));
- }
- if (!$keyword) {
- $where['limit'] = '0,50';
- $data = Dever::db('article/author')->getAll($where);
- } else {
- $where['name'] = $keyword;
- $data = Dever::db('article/author')->getAll($where);
- }
- $insert = array();
- if (!$data && $keyword) {
- $insert[0]['name'] = $keyword . '[新增]';
- $insert[0]['value'] = $keyword;
- }
- $result = array();
- if ($yes) {
- foreach ($yes as $k => $v) {
- if (isset($data[$k])) {
- unset($data[$k]);
- }
- $yes[$k]['selected'] = 'selected';
- }
- $data = $insert + $yes + $data;
- $data = array_merge($data, array());
- } else {
- $data = $insert + $data;
- $data = array_merge($data, array());
- }
- if (!$data) {
- Dever::alert('暂无数据');
- }
- return $data;
- }
- }
|