123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
-
-
- namespace app\admin\model;
-
- use think\Db;
- use think\Model;
-
-
- class ProductImg extends Model
- {
-
- protected function initialize()
- {
-
- parent::initialize();
- }
-
-
-
- public function getProImg($aid, $field = '*')
- {
- $result = Db::name('ProductImg')->field($field)
- ->where('aid', $aid)
- ->order('sort_order asc')
- ->select();
-
- return $result;
- }
-
-
-
- public function delProImg($aid = array())
- {
- if (!is_array($aid)) {
- $aid = array($aid);
- }
- $result = Db::name('ProductImg')->where(array('aid'=>array('IN', $aid)))->delete();
-
- return $result;
- }
-
-
-
- public function saveimg($aid, $post = array())
- {
- $proimg = isset($post['proimg']) ? $post['proimg'] : array();
- $imgintro = isset($post['imgintro']) ? $post['imgintro'] : array();
-
- if (!empty($proimg) && count($proimg) > 1) {
- array_pop($proimg);
-
- $this->delProImg($aid);
-
- $data = array();
- $sort_order = 0;
- foreach($proimg as $key => $val)
- {
- if($val == null || empty($val)) continue;
-
- $img_info = array();
- $filesize = 0;
- if (is_http_url($val)) {
- $imgurl = handle_subdir_pic($val);
- } else {
- $imgurl = ROOT_PATH.ltrim($val, '/');
- $filesize = @filesize('.'.$val);
- }
- $img_info = @getimagesize($imgurl);
- $width = isset($img_info[0]) ? $img_info[0] : 0;
- $height = isset($img_info[1]) ? $img_info[1] : 0;
- $type = isset($img_info[2]) ? $img_info[2] : 0;
- $attr = isset($img_info[3]) ? $img_info[3] : '';
- $mime = isset($img_info['mime']) ? $img_info['mime'] : '';
- $title = !empty($post['title']) ? $post['title'] : '';
- $intro = !empty($imgintro[$key]) ? $imgintro[$key] : '';
- ++$sort_order;
- $data[] = array(
- 'aid' => $aid,
- 'title' => $title,
- 'image_url' => $val,
- 'intro' => $intro,
- 'width' => $width,
- 'height' => $height,
- 'filesize' => $filesize,
- 'mime' => $mime,
- 'sort_order' => $sort_order,
- 'add_time' => getTime(),
- );
- }
- if (!empty($data)) {
- Db::name('ProductImg')->insertAll($data);
-
-
- $litpic = isset($post['litpic']) ? $post['litpic'] : '';
- if (empty($litpic)) {
- $litpic = $data[0]['image_url'];
- Db::name('archives')->where(array('aid'=>$aid))->update(array('litpic'=>$litpic, 'update_time'=>getTime()));
- }
- }
- delFile(UPLOAD_PATH."product/thumb/$aid");
- }
- }
- }
|