where($where)->order('id desc'); return $model->page($model, $where, '', 24); } /** 获取图片列表 * @param $where * @return array */ public static function getImageList($where) { $model = new self; $model = $model->where('module_type', 1); if (isset($where['pid']) && $where['pid']) { $model = $model->where('pid', $where['pid']); } else { $model = $model->where('pid', '<>', 20); } $model = $model->page((int)$where['page'], (int)$where['limit']); $model = $model->order('id desc,time desc'); $list = $model->select(); $list = count($list) ? $list->toArray() : []; $site_url = sys_config('site_url'); foreach ($list as &$item) { if ($site_url) { $item['satt_dir'] = (strpos($item['satt_dir'], $site_url) !== false || strstr($item['satt_dir'], 'http') !== false) ? $item['satt_dir'] : $site_url . $item['satt_dir']; $item['att_dir'] = (strpos($item['att_dir'], $site_url) !== false || strstr($item['att_dir'], 'http') !== false) ? $item['satt_dir'] : $site_url . $item['att_dir']; } } $count = $where['pid'] ? self::where(['pid' => $where['pid'], 'module_type' => 1])->count() : self::where('module_type', 1)->count(); return compact('list', 'count'); } /** * TODO 获取单条信息 * @param $value * @param string $field * @return array * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function getInfo($value, $field = 'id') { $where[$field] = $value; // $count = self::where($where)->count(); // if (!$count) return false; // return self::where($where)->find()->toArray(); $row = self::where($where)->find(); $row = $row ? $row->toArray() : false; return $row; } /** * 清除昨日海报 * @return bool * @throws \Exception */ public static function emptyYesterdayAttachment() { $list = self::whereTime('time', 'yesterday')->where('module_type', 2) ->field('name,att_dir,id,image_type')->select(); try { $uploadType = (int)sys_config('upload_type', 1); $upload = new Upload($uploadType, [ 'accessKey' => sys_config('accessKey'), 'secretKey' => sys_config('secretKey'), 'uploadUrl' => sys_config('uploadUrl'), 'storageName' => sys_config('storage_name'), 'storageRegion' => sys_config('storage_region'), ]); foreach ($list as $key => $item) { if ($item['image_type'] == 1) { $att_dir = $item['att_dir']; if ($att_dir && strstr($att_dir, 'uploads') !== false) { if (strstr($att_dir, 'http') === false) $upload->delete($att_dir); else { $filedir = substr($att_dir, strpos($att_dir, 'uploads')); if ($filedir) $upload->delete($filedir); } } } else { if ($item['name']) $upload->delete($item['name']); } } self::whereTime('time', 'yesterday')->where('module_type', 2)->delete(); return true; } catch (\Exception $e) { self::whereTime('time', 'yesterday')->where('module_type', 2)->delete(); return true; } } /** 根据 商品 ID 找到商品图片,再根据任意一张图片找到商品图片的分类ID和父ID select esa.pid as id, esac.pid from eb_system_attachment esa left join eb_system_attachment_category esac on esa.pid = esac.id where esa.att_dir = 'http://twongpicd.shotshock.shop/606882670534/澳乐月亮围栏6+2_1.jpg' @return: ['pid'=>int, 'ppid'=>int] */ public static function getPidByProductId($productId) { $model = new self; $res = StoreProductModel::where('id', $productId)->field('image,slider_image')->select()->toArray(); if ($res) { $image = $res[0]['image']; if (!$image) { $arr = $res[0]['slider_image']; if ($arr) { $image = $arr[0]; } } } $ids = $model::alias('a')->field('a.pid, c.pid as ppid')->join('SystemAttachmentCategory c', 'c.id=a.pid') ->where('a.att_dir', $image)->find(); return $ids ? $ids->toArray() : ['pid' => 0, 'ppid' => 0]; } }