123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
-
-
- namespace app\admin\model;
-
- use think\Db;
- use think\Model;
-
-
- class Images extends Model
- {
-
- public $nid = 'images';
-
- public $channeltype = '';
-
-
- protected function initialize()
- {
-
- parent::initialize();
- $channeltype_list = config('global.channeltype_list');
- $this->channeltype = $channeltype_list[$this->nid];
- }
-
-
-
- public function afterSave($aid, $post, $opt)
- {
- $post['aid'] = $aid;
- $addonFieldExt = !empty($post['addonFieldExt']) ? $post['addonFieldExt'] : array();
- model('Field')->dealChannelPostData($post['channel'], $post, $addonFieldExt);
-
-
- if (is_dir('./weapp/Waimao/')) {
- $waimaoLogic = new \weapp\Waimao\logic\WaimaoLogic;
- $waimaoLogic->update_htmlfilename($aid, $post, $opt);
- }
-
-
- model('ImagesUpload')->saveimg($aid, $post);
-
-
-
- model('Taglist')->savetags($aid, $post['typeid'], $post['tags'], $post['arcrank'], $opt);
-
- if ('edit' == $opt) {
-
- Db::name('sql_cache_table')->execute('TRUNCATE TABLE '.config('database.prefix').'sql_cache_table');
- model('SqlCacheTable')->InsertSqlCacheTable(true);
- } else {
-
- if (isset($post['arcrank']) && -1 == $post['arcrank'] && -1 == $post['old_arcrank'] && !empty($post['users_id'])) {
-
- model('SqlCacheTable')->UpdateDraftSqlCacheTable($post, $opt);
- } else if (isset($post['arcrank'])) {
-
- $post['old_typeid'] = intval($post['attr']['typeid']);
- model('SqlCacheTable')->UpdateSqlCacheTable($post, $opt, 'images');
- }
- }
- }
-
-
-
- public function getInfo($aid, $field = '', $isshowbody = true)
- {
- $result = array();
- $field = !empty($field) ? $field : '*';
- $result = Db::name('archives')->field($field)
- ->where([
- 'aid' => $aid,
- 'lang' => get_admin_lang(),
- ])
- ->find();
- if ($isshowbody) {
- $tableName = Db::name('channeltype')->where('id','eq',$result['channel'])->getField('table');
- $result['addonFieldExt'] = Db::name($tableName.'_content')->where('aid',$aid)->find();
- }
-
-
- if (!empty($result)) {
- $typeid = isset($result['typeid']) ? $result['typeid'] : 0;
- $tags = model('Taglist')->getListByAid($aid, $typeid);
- $result['tags'] = $tags['tag_arr'];
- $result['tag_id'] = $tags['tid_arr'];
- }
-
- return $result;
- }
-
-
-
-
- public function getListByLimit($map = array(), $limit = 15, $field = '*', $order = 'a.aid desc')
- {
- $data = array();
- $field_arr = explode(',', $field);
- foreach ($field_arr as $key => $val) {
- array_push($data, 'a.'.trim($val));
- }
- $field = implode(',', $data);
- $field = 'b.*, '.$field;
-
- if (!empty($map) && is_array($map)) {
- foreach ($map as $key => $val) {
- if (preg_match("/^(a\.)/i", $val) == 0) {
- $map['a.'.$key] = $val;
- unset($map[$key]);
- }
- }
- }
- $map['a.channel'] = $this->channeltype;
-
- $result = Db::name('archives')
- ->field($field)
- ->alias('a')
- ->join('__ARCTYPE__ b', 'b.id = a.typeid', 'LEFT')
- ->where($map)
- ->order($order)
- ->limit($limit)
- ->select();
-
- return $result;
- }
-
-
-
- public function getListByClick($limit = 10, $map = array(), $field = '*')
- {
- $map['channel'] = $this->channeltype;
- $map['status'] = 1;
- $result = Db::name('archives')
- ->field($field)
- ->where($map)
-
- ->order('click desc')
- ->limit($limit)
- ->select();
-
- return $result;
- }
-
-
-
- public function getAllCateByTypeid($typeid)
- {
- $result = Db::name('arctype')->field('id,parent_id,typename')
- ->where(array('id|parent_id'=>$typeid, 'status'=>1))
- ->order('parent_id asc, sort_order asc')
- ->getAllWithIndex('id');
-
- return $result;
- }
-
-
-
- public function afterDel($aidArr = array())
- {
- if (is_string($aidArr)) {
- $aidArr = explode(',', $aidArr);
- }
-
- Db::name('images_content')->where(
- array(
- 'aid'=>array('IN', $aidArr)
- )
- )
- ->delete();
-
- $result = Db::name('images_upload')->field('image_url')
- ->where(
- array(
- 'aid'=>array('IN', $aidArr)
- )
- )
- ->select();
- if (!empty($result)) {
-
-
-
-
-
-
-
- Db::name('images_upload')->where(
- array(
- 'aid'=>array('IN', $aidArr)
- )
- )
- ->delete();
- }
-
- model('Taglist')->delByAids($aidArr);
- }
- }
|