Initial commit

This commit is contained in:
易焱
2021-04-18 18:51:51 +08:00
commit ec705f2fa8
3240 changed files with 623103 additions and 0 deletions
+88
View File
@@ -0,0 +1,88 @@
<?php
namespace Model;
use Think\Model;
class FileModel extends Model {
public function upload($files, $setting, $driver= 'Local', $config= null,$thumb=false) {
/* 上传文件 */
$setting['callback']= array($this, 'isFile');
$setting['removeTrash']= array($this, 'removeTrash');
$Upload= new \Think\Upload($setting, $driver, $config);
$info= $Upload->upload($files);
/* 设置文件保存位置 */
$this->_auto[]= array('location', 'ftp' === strtolower($driver) ? 1 : 0, self::MODEL_INSERT);
if ($info) { //文件上传成功,记录文件信息
foreach ($info as $key => &$value) {
//关联信息的随机id
$value['pubid']= I("get.pubid") ? I("get.pubid") : I("post.pubid");
$value['create_time']= time();
$value['filepath']= $setting['rootPath'] . $value['savepath'] . $value['savename'];
$value['filepath']= trim($value['filepath'], ".");
//是否自动生成小图
if($thumb){
//压缩图片
$image=new \Think\Image();
$image->open($setting['rootPath'] . $value['savepath'] . $value['savename']);
$image->thumb(200,200);
$small_path=$setting['rootPath'] . $value['savepath'] ."small_". $value['savename'];
$image->save($small_path);
$value['smallpath']=trim($small_path,".");
}
//
//赋值给info数组,返回给控制器
$info['smallpath']= $value['smallpath'];
$info['filepath']= $value['filepath'];
//
/* 已经存在文件记录 */
if (isset($value['id']) && is_numeric($value['id'])) {
//更新create_time
$this->save(array("id" => $value['id'], "create_time" => time(), "pubid" => $value['pubid']));
continue;
} else {
/* 不存在记录文件信息 */
if ($this->create($value) && ($id= $this->add())) {
$value['id'] = $id;
} else {
//TODO: 文件上传成功,但是记录文件信息失败,需记录日志
unset($info[$key]);
}
}
}
$info['id']= $value['id'];
return $info; //文件上传成功
} else {
$this->error= $Upload->getError();
return false;
}
}
/**
* 检测当前上传的文件是否已经存在
* @param array $file 文件上传数组
* @return boolean 文件信息, false - 不存在该文件
*/
public function isFile($file) {
if (empty($file['md5'])) {
throw new \Exception('缺少参数:md5');
}
/* 查找文件 */
$map= array('md5' => $file['md5'], 'sha1' => $file['sha1'],'name' => $file['name'],);
return $this->field(true)->where($map)->find();
}
/**
* 清除数据库存在但本地不存在的数据
* @param $data
*/
public function removeTrash($data) {
$this->where(array('id' => $data['id'],))->delete();
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace Model;
use Think\Model;
class KuaidiModel extends Model{
public function __construct($com,$num){
$this->com=$com;
$this->num=$num;
}
//快递接口api查询
public function getKuaidi(){
$post_data = array();
$post_data["customer"] = C("shop.customer");
$key= C("shop.sign");
$post_data["param"]=array(
"com"=>$this->com,
"num"=>$this->num
);
$post_data["param"] = json_encode($post_data["param"]);
$url='http://poll.kuaidi100.com/poll/query.do';
$post_data["sign"] = md5($post_data["param"].$key.$post_data["customer"]);
$post_data["sign"] = strtoupper($post_data["sign"]);
$o="";
foreach ($post_data as $k=>$v)
{
$o.= "$k=".$v."&"; //默认UTF-8编码格式
}
$post_data=substr($o,0,-1);
$url2=$url."?".$post_data;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$data = str_replace("\"",'"',$result );
$data = json_decode($data,true);
//检测状态
if($data["status"]!=200){
$this->error=$data["message"];
return false;
}else{
return $data["data"];
}
}
}