Files
addons
app_download_files
extend
hyhproject
admin
behavior
common
conf
controller
model
Accreds.php
AdPositions.php
Addons.php
Adgoods.php
Ads.php
Alipays.php
Areas.php
ArticleCats.php
Articles.php
Attributes.php
Banks.php
Base.php
Brands.php
Carts.php
CashDraws.php
ChargeItems.php
CronJobs.php
DataCats.php
Datas.php
EctDay.php
EctDeal.php
EctTarget.php
Express.php
Friendlinks.php
Goods.php
GoodsAppraises.php
GoodsCats.php
GoodsClassify.php
GoodsConsult.php
HomeMenus.php
Hooks.php
Images.php
Index.php
Informs.php
LogMoneys.php
LogOperates.php
LogSms.php
LogStaffLogins.php
Member.php
Menus.php
Messages.php
MobileBtns.php
Navs.php
OrderComplains.php
OrderRefunds.php
Orders.php
Payments.php
Privileges.php
Recommends.php
Reports.php
Roles.php
Settlements.php
Shops.php
SpecCats.php
Staffs.php
Styles.php
SysConfigs.php
TemplateMsgs.php
TradeRule.php
UserRanks.php
UserScores.php
Users.php
Weixinpays.php
WeixinpaysApp.php
WxPassiveReplys.php
WxTemplateParams.php
Wxmenus.php
Wxusers.php
validate
view
app
common
home
home2
mobile2
wechat2
.htaccess
command.php
mobile
oss
static
thinkphp
upload
vendor
wxtmp
.gitignore
.htaccess
.user.ini
404.html
H5B854518.wgt
admin.php
app-release.apk
app_download.html
cash.lock
demo.php
get_startup.php
get_version.php
get_version_new.php
index.html
index.php
reg.lock
robots.txt
qlg.tsgz.moe/hyhproject/admin/model/Images.php
2019-09-06 23:53:10 +08:00

229 lines
4.1 KiB
PHP
Executable File

<?php
namespace wstmart\admin\model;
/**
* ============================================================================
* 图片空间业务处理
*/
use wstmart\common\model\Aliyunoss;
use think\Db;
class Images extends Base{
/**
* 获取图片空间概况
*/
public function summary(){
$rs = Db::name('images')->where(['dataFlag'=>1])->field('fromTable,isUse,sum(imgSize) imgSize')->group('fromTable,isUse')
->order('fromTable asc')->select();
//获取目录名称
$rs2 = Db::name('datas')->where(['catId'=>3])->field('dataName,dataVal')->select();
$imagesMap = [];
foreach ($rs2 as $key =>$v){
$imagesMap[$v['dataVal']] = $v['dataName'];
}
$images = [];
foreach ($rs as $key =>$v){
if(!isset($images[$v['fromTable']]))$images[$v['fromTable']] = ['directory'=>'','data'=>['0'=>0,'1'=>0]];
if(isset($imagesMap[$v['fromTable']]))$images[$v['fromTable']]['directory'] = $imagesMap[$v['fromTable']];
$images[$v['fromTable']]['data'][$v['isUse']] = round($v['imgSize']/1024/1024,2);
}
$maxSize = 0;
foreach ($images as $key =>$v){
$size = (float)$v['data']['0']+(float)$v['data']['1'];
if($maxSize<$size)$maxSize = $size;
}
$images['_WSTSummary_'] = $maxSize;
return $images;
}
/**
* 获取记录
*/
public function pageQuery(){
$key = input('keyword');
$isUse = (int)input('isUse');
$where = ['fromTable'=>$key,'a.dataFlag'=>1];
if($isUse !=-1)$where['isUse'] = $isUse;
$page = $this->alias('a')->join('__USERS__ u','a.ownId=u.userId and fromType=0','left')
->join('__SHOPS__ s','s.userId=u.userId','left')
->join('__STAFFS__ sf','sf.staffId=a.ownId','left')
->where($where)->field('a.imgId,u.loginName,u.userType,fromType,sf.loginName loginName2,s.shopName,imgPath,imgSize,isUse,a.createTime')
->order('a.imgId desc')->paginate(input('post.limit/d'))->toArray();
foreach ($page['Rows'] as $key => $v){
if($v['fromType']==1){
$page['Rows'][$key]['loginName'] = $v['loginName2'];
}
$page['Rows'][$key]['imgSize'] = round($v['imgSize']/1024/1024,2);
unset($page['Rows'][$key]['loginName2']);
}
return $page;
}
/**
* 删除图片
*/
public function del(){
$id = (int)input('id');
$image = $this->where('imgId',$id)->find();
$rs = $this->where('imgId',$id)->update(['dataFlag'=>-1]);
if(false !== $rs){
$m = WSTConf('CONF.wstMobileImgSuffix');
$timgPath = str_replace('.','_thumb.',$image['imgPath']);
$mimgPath = str_replace('.',$m.'.',$image['imgPath']);
$mtimgPath = str_replace('.',$m.'_thumb.',$image['imgPath']);
if(file_exists(WSTRootPath()."/".$image['imgPath']))unlink(WSTRootPath()."/".$image['imgPath']);
if(file_exists(WSTRootPath()."/".$timgPath))unlink(WSTRootPath()."/".$timgPath);
if(file_exists(WSTRootPath()."/".$mimgPath))unlink(WSTRootPath()."/".$mimgPath);
if(file_exists(WSTRootPath()."/".$mtimgPath))unlink(WSTRootPath()."/".$mtimgPath);
//添加删除oss上的图片 mark 20180608
$imgurl = getImgUrl().$image['imgPath'];
if(file_exists_oss($image['imgPath']))model('Aliyunoss')->del($image['imgPath']);
return WSTReturn("删除成功", 1);
}
return WSTReturn("删除失败");
}
//添加判断文件是否存在 mark 20180608 by zl
// public function file_exists_oss($object){
// $imgurl = getImgUrl().$object;
// $ch = curl_init();
// $timeout = 10;
// curl_setopt ($ch, CURLOPT_URL, $imgurl);
// curl_setopt($ch, CURLOPT_HEADER, 1);
// curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// $contents = curl_exec($ch);
// if (preg_match("/404/", $contents)){
// return false;
// }else{
// return true;
// }
// //说是在windows下可以,LINUX下无论图片在不在都返加TRUE
// // if(file_get_contents($imgurl,0,null,0,1)){
// // return true;
// // }else{
// // return false;
// // }
// // if(@fopen( $imgurl, 'r' )){
// // return true;
// // }else{
// // return false;
// // }
// }
}