314 行
12 KiB
PHP
可执行文件
314 行
12 KiB
PHP
可执行文件
<?php
|
||
//[1.0.57]
|
||
function array_sort($array, $keys, $type = 'desc')
|
||
{
|
||
//$array为要排序的数组,$keys为要用来排序的键名,$type默认为升序排序
|
||
$keysvalue = $new_array = array();
|
||
foreach ($array as $k => $v) {
|
||
$keysvalue[$k] = $v[$keys];
|
||
}
|
||
if ($type == 'asc') {
|
||
asort($keysvalue);
|
||
} else {
|
||
arsort($keysvalue);
|
||
}
|
||
reset($keysvalue);
|
||
foreach ($keysvalue as $k => $v) {
|
||
$new_array[$k] = $array[$k];
|
||
}
|
||
return $new_array;
|
||
}
|
||
|
||
/**
|
||
* @param $id 商品id
|
||
* @param $storeid 门店id
|
||
* @param $merchantid 商户id
|
||
* @param $num 操作的数量
|
||
* @param $type 操作类型 2为减库存 1添加
|
||
* @param $remark 途径
|
||
*/
|
||
function quantityLogs($id, $storeid, $merchantid, $num, $type, $remark)
|
||
{
|
||
|
||
//根据商品id查询出商品现有库存(发生操作前)
|
||
$now_quantity = M('retail_goods')->where(array('id' => $id))->getField('goods_num');
|
||
// var_dump($now_quantity);
|
||
|
||
$log['original_stock'] = $now_quantity - $num;//商品原库存
|
||
$log['do_num'] = $num;//需要操作的数量
|
||
$log['type'] = $type;// 2为减库存 1添加
|
||
$log['goods_id'] = $id;//商品id
|
||
$log['storeid'] = $storeid;//门店id
|
||
$log['present_stock'] = $now_quantity;//现库存
|
||
$log['merchantid'] = $merchantid;//商户id
|
||
$log['addtime'] = time();
|
||
$log['remark'] = $remark;
|
||
|
||
$addLog = M('retail_quantity_logs')->add($log);
|
||
if ($addLog) {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
|
||
}
|
||
|
||
//**
|
||
//* 上传文件类型控制 此方法仅限ajax上传使用
|
||
//* @param string $path 字符串 保存文件路径示例: /Upload/image/
|
||
// * @param string $format 文件格式限制
|
||
//* @param integer $maxSize 允许的上传文件最大值 52428800
|
||
//* @return booler 返回ajax的json格式数据
|
||
//*/
|
||
function ajax_upload($path = 'file', $format = 'empty', $maxSize = '52428800')
|
||
{
|
||
ini_set('max_execution_time', '0');
|
||
// 去除两边的/
|
||
$path = trim($path, '/');
|
||
// 添加Upload根目录
|
||
$path = strtolower(substr($path, 0, 6)) === 'upload' ? ucfirst($path) : 'Upload/' . $path;
|
||
// 上传文件类型控制
|
||
$ext_arr = array(
|
||
'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
|
||
'photo' => array('jpg', 'jpeg', 'png'),
|
||
'flash' => array('swf', 'flv'),
|
||
'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
|
||
'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2', 'pdf')
|
||
);
|
||
if (!empty($_FILES)) {
|
||
// 上传文件配置
|
||
$config = array(
|
||
'maxSize' => $maxSize, // 上传文件最大为50M
|
||
'rootPath' => './', // 文件上传保存的根路径
|
||
'savePath' => './' . $path . '/', // 文件上传的保存路径(相对于根路径)
|
||
'saveName' => array('uniqid', ''), // 上传文件的保存规则,支持数组和字符串方式定义
|
||
'autoSub' => true, // 自动使用子目录保存上传文件 默认为true
|
||
'exts' => isset($ext_arr[$format]) ? $ext_arr[$format] : '',
|
||
);
|
||
// 实例化上传
|
||
$upload = new \Think\Upload($config);
|
||
// 调用上传方法
|
||
$info = $upload->upload();
|
||
$data = array();
|
||
if (!$info) {
|
||
// 返回错误信息
|
||
$error = $upload->getError();
|
||
$data['error_info'] = $error;
|
||
echo json_encode($data);
|
||
} else {
|
||
// 返回成功信息
|
||
foreach ($info as $file) {
|
||
$data['name'] = trim($file['savepath'] . $file['savename'], '.');
|
||
echo json_encode($data);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function file_upload($path = 'file', $format = 'empty', $maxSize = '52428800')
|
||
{
|
||
ini_set('max_execution_time', '0');
|
||
// 去除两边的/
|
||
$path = trim($path, '/');
|
||
// 添加Public根目录
|
||
// $path=strtolower(substr($path, 0,6))==='Public' ? ucfirst($path) : 'Public/'.$path;
|
||
// 上传文件类型控制
|
||
$ext_arr = array(
|
||
'file' => array('txt')
|
||
);
|
||
if (!empty($_FILES)) {
|
||
$str = $_FILES['file']['name'];
|
||
$str = explode('.', $str);
|
||
$str = $str[0];
|
||
// 上传文件配置
|
||
$config = array(
|
||
'maxSize' => $maxSize, // 上传文件最大为50M
|
||
'rootPath' => './', // 文件上传保存的根路径
|
||
'savePath' => './', // 文件上传的保存路径(相对于根路径)
|
||
'saveName' => $str, // 上传文件的保存规则,支持数组和字符串方式定义
|
||
'autoSub' => false, // 自动使用子目录保存上传文件 默认为true
|
||
//'exts' => isset($ext_arr[$format])?$ext_arr[$format]:'',
|
||
);
|
||
// 实例化上传
|
||
$upload = new \Think\Upload($config);
|
||
// 调用上传方法
|
||
$info = $upload->upload();
|
||
$data = array();
|
||
if (!$info) {
|
||
// 返回错误信息
|
||
$error = $upload->getError();
|
||
$data['error_info'] = $error;
|
||
echo json_encode($data);
|
||
} else {
|
||
// 返回成功信息
|
||
|
||
foreach ($info as $file) {
|
||
$data['name'] = trim($file['savepath'] . $file['savename'], '.');
|
||
}
|
||
$k = file_get_contents("." . $data['name']);
|
||
// print_r($k);
|
||
if (strlen($k) <= 20) {
|
||
$data['status'] = 1;
|
||
$data['msg'] = '文件正确,可上传!';
|
||
echo json_encode($data);
|
||
} else {
|
||
unlink("." . $data['name']);
|
||
$data['status'] = 0;
|
||
$suc['msg'] = '文件存在问题,请检查在上传!';
|
||
echo json_encode($suc);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
// function get_authorizer_access_token($storeid)
|
||
// {
|
||
//
|
||
// $where['merchantid'] = $storeid;
|
||
// $access_token_time = M('wxconfig')->where($where)->getField('access_token_time');
|
||
// if ($access_token_time + 7000 < time()) {
|
||
// //如果上次更新时间+7000小于当前时间说明该令牌已经过期
|
||
// $appid = M('appweixin')->where('id=1')->getField('appid');
|
||
// //根据自己的小程序id找到小程序的信息准备刷新令牌
|
||
// $res = M("wxconfig")->where(array('merchantid' => $storeid))->find();
|
||
// $access = get_acc_token();
|
||
// $urls = 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=' . $access;
|
||
// $authorizer_appid = $res['authorizer_appid'];
|
||
// $authorizer_refresh_token = $res['authorizer_refresh_token'];
|
||
// $datas = array(
|
||
// 'component_appid' => $appid,
|
||
// 'authorizer_appid' => $authorizer_appid,
|
||
// 'authorizer_refresh_token' => $authorizer_refresh_token
|
||
// );
|
||
// $datas = json_encode($datas);
|
||
// $responses = curl_get($urls, $datas);
|
||
// /*dump($responses);
|
||
// exit;*/
|
||
// $results = json_decode($responses, true);
|
||
// $dat['authorizer_access_token'] = $results['authorizer_access_token'];
|
||
// $dat['authorizer_refresh_token'] = $results['authorizer_refresh_token'];
|
||
// $dat['access_token_time'] = time();
|
||
//
|
||
// if ($dat['authorizer_access_token'] && $dat['authorizer_refresh_token'] != null) {
|
||
// M('wxconfig')->where(array('id' => $res['id']))->save($dat);
|
||
// } else {
|
||
// // echo "未获取到令牌信息";
|
||
// file_put_contents('./1.txt', $responses);
|
||
// }
|
||
// $authorizer_access_token = M('wxconfig')->where($where)->getField('authorizer_access_token');
|
||
// return $authorizer_access_token;
|
||
// } else {
|
||
// $authorizer_access_token = M('wxconfig')->where($where)->getField('authorizer_access_token');
|
||
// return $authorizer_access_token;
|
||
// }
|
||
// }
|
||
|
||
|
||
function ajax_upload_file($path = 'file', $format = 'empty', $maxSize = '52428800')
|
||
{
|
||
ini_set('max_execution_time', '0');
|
||
// 去除两边的/
|
||
$path = trim($path, '/');
|
||
// 添加Upload根目录
|
||
$path = strtolower(substr($path, 0, 6)) === 'upload' ? ucfirst($path) : 'Upload/' . $path;
|
||
// 上传文件类型控制
|
||
$ext_arr = array(
|
||
'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
|
||
'photo' => array('jpg', 'jpeg', 'png'),
|
||
'flash' => array('swf', 'flv'),
|
||
'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
|
||
'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2', 'pdf')
|
||
);
|
||
if (!empty($_FILES)) {
|
||
// 上传文件配置
|
||
$config = array(
|
||
'maxSize' => $maxSize, // 上传文件最大为50M
|
||
'rootPath' => './', // 文件上传保存的根路径
|
||
'savePath' => './' . $path . '/', // 文件上传的保存路径(相对于根路径)
|
||
'saveName' => array('uniqid', ''), // 上传文件的保存规则,支持数组和字符串方式定义
|
||
'autoSub' => true, // 自动使用子目录保存上传文件 默认为true
|
||
'exts' => isset($ext_arr[$format]) ? $ext_arr[$format] : '',
|
||
);
|
||
// 实例化上传
|
||
$upload = new \Think\Upload($config);
|
||
// 调用上传方法
|
||
$info = $upload->upload();
|
||
$data = array();
|
||
if (!$info) {
|
||
// 返回错误信息
|
||
$error = $upload->getError();
|
||
$data['error_info'] = $error;
|
||
return $data;
|
||
} else {
|
||
// 返回成功信息
|
||
foreach ($info as $file) {
|
||
$data['name'] = trim($file['savepath'] . $file['savename'], '.');
|
||
return $data;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
function ajax_upload_files($path = 'file', $format = 'empty', $maxSize = '52428800')
|
||
{
|
||
ini_set('max_execution_time', '0');
|
||
// 去除两边的/
|
||
$path = trim($path, '/');
|
||
// 添加Upload根目录
|
||
$path = strtolower(substr($path, 0, 6)) === 'upload' ? ucfirst($path) : 'Upload/' . $path;
|
||
// 上传文件类型控制
|
||
$ext_arr = array(
|
||
'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
|
||
'photo' => array('jpg', 'jpeg', 'png'),
|
||
'flash' => array('swf', 'flv'),
|
||
'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
|
||
'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2', 'pdf')
|
||
);
|
||
if (!empty($_FILES)) {
|
||
// 上传文件配置
|
||
$config = array(
|
||
'maxSize' => $maxSize, // 上传文件最大为50M
|
||
'rootPath' => './', // 文件上传保存的根路径
|
||
'savePath' => './' . $path . '/', // 文件上传的保存路径(相对于根路径)
|
||
'saveName' => array('uniqid', ''), // 上传文件的保存规则,支持数组和字符串方式定义
|
||
'autoSub' => true, // 自动使用子目录保存上传文件 默认为true
|
||
'exts' => isset($ext_arr[$format]) ? $ext_arr[$format] : '',
|
||
);
|
||
// 实例化上传
|
||
$upload = new \Think\Upload($config);
|
||
// 调用上传方法
|
||
$info = $upload->upload();
|
||
$data = array();
|
||
if (!$info) {
|
||
// 返回错误信息
|
||
$error = $upload->getError();
|
||
$data['msg'] = $error;
|
||
$data['status'] = 0;
|
||
return $data;
|
||
} else {
|
||
// 返回成功信息
|
||
// foreach ($info as $file) {
|
||
// $data['name'] = trim($file['savepath'] . $file['savename'], '.');
|
||
// return $data;
|
||
// }
|
||
return $info;
|
||
}
|
||
}
|
||
}
|
||
|
||
//删除图片
|
||
function delFile($filename){
|
||
$res = pathinfo($filename);
|
||
$arr = array('png','jpg','jpej');
|
||
if(in_array($res['extension'],$arr)){
|
||
$res1 = unlink($filename);
|
||
if($res1){
|
||
return true;
|
||
}else{
|
||
return false;
|
||
}
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|