<?php
/**
* Yzd_my模块小程序接口定义
*
* @author 沈阳云之道网络
* @url
*/
defined('IN_IA') or exit('Access Denied');
define("YZD_MY_IMG","/static/public/img");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header('Access-Control-Allow-Headers:x-requested-with,content-type');
require "inc/common/common.php";
require 'inc/common/order.php';
require "inc/common/tasks.php";
require 'lib/kuaidiniao/kuaidi.php';
include 'lib/php_poster/phpQrcode.class.php';
include 'lib/php_poster/poster.class.php';
// require "inc/common/pc.php";
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
use Qiniu\Storage\BucketManager;
class Yzd_myModuleWxapp extends WeModuleWxapp
{
public function doPageTask(){
global $_GPC, $_W;
// var_dump(111);
// exit();
Task::timer();
}
// 加密
public function encrypt($data)
{
global $_GPC, $_W;
$key = 'r5r8bloufgv12548'; //秘钥必须为:8/16/32位
$iv = '01goyvbnx845fiwm';
$base64_str = base64_encode(json_encode($data));
$encrypted = openssl_encrypt($base64_str, "aes-128-cbc", $key, 0, $iv);
return base64_encode($encrypted);
}
/**解密
* @param $data
* @return mixed
*/
public function decrypt($data)
{
global $_GPC, $_W;
$encrypted = base64_decode($data);
$key = 'r5r8bloufgv12548'; //秘钥必须为:8/16/32位
$iv = '01goyvbnx845fiwm';
$decrypted = openssl_decrypt($encrypted, 'aes-128-cbc', $key, OPENSSL_ZERO_PADDING, $iv);
return json_decode(base64_decode($decrypted), true);
}
public function doPageWebConfig(){
global $_W, $_GPC;
$result = pdo_get('yzd_my_sys',array('uniacid'=>$_W['uniacid']));
$result['copyright'] = $_W['setting']['copyright'];
$result['wxapp_versions'] = pdo_get('wxapp_versions',array('uniacid'=>$_W['uniacid']));
// $result['']
if($_GPC['op'] == 'get'){
$code = $result ? 1 : 0;
$msg = $result ? '成功' : '数据错误';
exit(json_encode(array('code'=>$code,'msg'=>$msg,'data' => $result)));
}
if($_GPC['op'] == 'save'){
$data['name'] = $_GPC['name'];
$data['logo'] = $_GPC['logo'];
$data['is_force_login'] = $_GPC['is_force_login'];
$data['is_force_getphone'] = $_GPC['is_force_getphone'];
$data['address'] = $_GPC['address'];
$data['longitude'] = $_GPC['longitude'];
$data['latitude'] = $_GPC['latitude'];
$data['phone'] = $_GPC['phone'];
$data['is_service_coupon'] = $_GPC['is_service_coupon'];
$data['is_good_coupon'] = $_GPC['is_good_coupon'];
$data['is_staff_location'] = $_GPC['is_staff_location'];
$data['staff_list_type'] = $_GPC['staff_list_type'];
$data['service_title'] = $_GPC['service_title'];
$data['staff_title'] = $_GPC['staff_title'];
$res = pdo_update('yzd_my_sys',$data,array('uniacid'=>$_W['uniacid']));
exit(json_encode(array('code'=>1,'msg'=>'保存成功','data' => $res)));
}
}
public function doPageStorage(){
global $_W, $_GPC;
if($_GPC['op'] == 'get'){
$res = pdo_get('yzd_my_storage',array('uniacid'=>$_W['uniacid']));
$code = $res ? 1 : 0;
$msg = $res ? '成功' : '数据错误';
exit(json_encode(array('code'=>$code,'msg'=>$msg,'data' => $res)));
}
if($_GPC['op'] == 'save'){
$data['aliyun'] = htmlspecialchars_decode($_GPC['aliyun']);
$data['qiniu'] = htmlspecialchars_decode($_GPC['qiniu']);
$data['tengxun'] = htmlspecialchars_decode($_GPC['tengxun']);
$data['type'] = $_GPC['type'];
$res = pdo_update('yzd_my_storage',$data,array('uniacid'=>$_W['uniacid']));
exit(json_encode(array('code'=>1,'msg'=>'保存成功','data' => $res)));
}
}
//获取存储分组
public function doPageGetStorageGroup() {
global $_W, $_GPC;
$list = pdo_getall('yzd_my_storage_group',array('uniacid'=>$_W['uniacid'],'type'=>$_GPC['type'],'m_id'=>$_GPC['m_id']));
array_unshift($list,array('title'=>'全部','id'=>0));
exit(json_encode(array('code'=>1,'msg'=>'成功','data' => $list)));
}
// 新建存储分组
public function doPageAddStorageGroup() {
global $_W, $_GPC;
$res = pdo_insert('yzd_my_storage_group',array('uniacid'=>$_W['uniacid'],'type'=>$_GPC['type'],'m_id'=>$_GPC['m_id'],'title'=>$_GPC['title']));
$code = $res ? 1 : 0;
$msg = $res ? '新建成功' : '数据错误';
exit(json_encode(array('code'=>$code,'msg'=>$msg,'data' => $res)));
}
// 删除存储分组
public function doPageDelStorageGroup(){
global $_W, $_GPC;
$res = pdo_delete('yzd_my_storage_group',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['id']));
$code = $res ? 1 : 0;
$msg = $res ? '删除成功' : '数据错误';
exit(json_encode(array('code'=>$code,'msg'=>$msg,'data' => $res)));
}
// 获取存储列表
public function doPageGetStorageList() {
global $_W, $_GPC;
$pageindex = max(1, intval($_GPC['page']));
$pagesize=10;
$where=' WHERE uniacid=:uniacid';
if($_GPC['type_id']> 0) {
$where .= " and storage_group_id =".$_GPC['type_id'];
}
if($_GPC['title']){
$where.=" and title LIKE concat('%', :title,'%') ";
$data[':title']=$_GPC['title'];
}
if($_GPC['type']){
$where .= " and type =".$_GPC['type'];
}
$data[':uniacid']=$_W['uniacid'];
$where .= " and m_id =".$_GPC['m_id'];
$sql="SELECT * FROM ".tablename('yzd_my_storage_list') .$where." ORDER BY id DESC";
$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('yzd_my_storage_list').$where,$data);
$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
$list=pdo_fetchall($select_sql,$data);
$code = $list ? 1 : 1;
$msg = $list ? '成功' : '成功';
exit(json_encode(array('code'=>$code,'msg'=>$msg,'data' => $list,'total'=>intval($total))));
}
public function doPageUploadFile(){
global $_W, $_GPC;
$destination_folder = "../attachment/yzd_my/uniacid" . $_W['uniacid'] . "/" . date('Y') . "/" . date('m') . "/" . date('d') . "/"; //上传文件路径
$file = $_FILES["upfile"];
if (!file_exists($destination_folder)) {
mkdir($destination_folder, 0777, true);
}
$filename = $file["tmp_name"];
$image_size = getimagesize($filename);
$pinfo = pathinfo($file["name"]);
$ftype = $pinfo['extension'];
$destination = $destination_folder . str_shuffle(time() . rand(111111, 999999)) . "." . $ftype;
if (file_exists($destination) && $overwrite != true) {
print_r('同名文件已经存在了');
}
if (!move_uploaded_file($filename, $destination)) {
print_r('移动文件出错');
}
$pinfo = pathinfo($destination);
$fname = "yzd_my/uniacid" . $_W['uniacid'] . "/" . date('Y') . "/" . date('m') . "/" . date('d') . "/" . $pinfo['basename'];
exit(json_encode(array('path' => $fname,'url' => $_W['attachurl_local'].$fname)));
}
//判断当前是否为https
function is_https() {
if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
return true;
} elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
return true;
} elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
return true;
}
return false;
}
//保存文件
public function doPageAddStorage() {
global $_W, $_GPC;
$data['storage_group_id'] = $_GPC['storage_group_id'];
$http_type = $this->is_https();
$http_type = $http_type?'https://':'http://';
$data['url'] = $_GPC['url'];
$data['path'] = $_GPC['path'];
$data['type'] = $_GPC['type'];
$data['add_time'] = time();
$data['uniacid'] = $_W['uniacid']
- 1
- 2
前往页