425 行
15 KiB
PHP
可执行文件
425 行
15 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Admin\Controller;
|
|
|
|
//[1.1.7]
|
|
use Think\Controller;
|
|
|
|
class IndexController extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
$user = session('admin_userinfo');
|
|
$this->assign('user', $user);
|
|
$logoinfo = M('retail_logo')->where(array('pid' => $user['id'], 'status' => 1))->find();
|
|
$this->assign('logoinfo', $logoinfo);
|
|
$types = M('retail_admin')->where(array('id' => $user['partnerid']))->getField('entry');
|
|
$this->assign('types', $types);
|
|
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
|
|
$domainname = $_SERVER['HTTP_HOST'];
|
|
$httpurl = $http_type . $domainname;
|
|
$this->assign('httpurl', $httpurl);
|
|
$this->display();
|
|
}
|
|
|
|
//退出登录
|
|
Public function loginOut()
|
|
{
|
|
session(null);
|
|
header('Location:' . U('Retail/login/index', array('code' => 2)));
|
|
// $this->success ( "退出成功!", $_SERVER ['SCRIPT_NAME'] . '/Admin/Login/index' ,1);
|
|
}
|
|
// 查询会员信息
|
|
|
|
|
|
//首页展示
|
|
public function home()
|
|
{
|
|
$user = session('admin_userinfo');
|
|
$map['partnerid'] = $user['pid'];
|
|
// 总商户数
|
|
$allshop = M('retail_merchant')->where($map)->count();
|
|
|
|
$MerchantModel = D('Agent');
|
|
$map['status'] = array('in', '1,2');
|
|
$count = $MerchantModel->getCount($map);
|
|
$Page = new \Common\Model\Pages($count, 10);
|
|
$show = $Page->show();
|
|
$this->assign('page', $show);
|
|
//$list = D('Agent')->getListLimit($map,$Page->firstRow.','.$Page->listRows);
|
|
$list = M('retail_agent')->where($map)->order('id desc')->limit($Page->firstRow, $Page->listRows)->select();
|
|
if ($list) {
|
|
foreach ($list as $key => &$val) {
|
|
$val['discountname'] = M('retail_group')->where(array('id' => $val['discountid']))->getField('name');
|
|
if ($val['end_time'] < time()) {
|
|
$val['overdue'] = 1;//过期
|
|
} else {
|
|
$val['overdue'] = 2;//为过期
|
|
}
|
|
$curformat = 'Y-m-d';
|
|
$val['end_time'] = newDate($curformat, $val['end_time']);
|
|
}
|
|
}
|
|
|
|
$Page = json_decode(json_encode($Page), true);
|
|
$this->assign('p', $Page['firstRow']);
|
|
$this->assign('c', $Page['listRows']);
|
|
|
|
$map['m.status'] = 1;
|
|
$map['m.end_time'] = array('gt', time());
|
|
$normalMerchant = $MerchantModel->getCount($map);
|
|
$map['m.end_time'] = array('lt', time());
|
|
$overdueMerchant = $MerchantModel->getCount($map);
|
|
|
|
// 版本更新信息
|
|
$where['type'] = '1';
|
|
$listone = M('work_message')->where($where)->limit(5)->order('id desc')->select();
|
|
// 公告信息
|
|
$where['type'] = '2';
|
|
$listtwo = M('work_message')->where($where)->limit(5)->order('id desc')->select();
|
|
|
|
// 未读版本更新信息
|
|
$mapone['state'] = 1;
|
|
$mapone['type'] = '1';
|
|
$countone = M('work_message')->where($mapone)->count();
|
|
$this->assign('countone', $countone);
|
|
|
|
// 未读公告信息
|
|
$maptwo['state'] = 1;
|
|
$maptwo['type'] = '2';
|
|
$counttwo = M('work_message')->where($maptwo)->count();
|
|
$this->assign('counttwo', $counttwo);
|
|
|
|
// 系统更新消息
|
|
$now = M('webset')->where(array('id' => 1))->find();
|
|
$this->assign("now", $now);
|
|
|
|
// 最新版本信息
|
|
$cache = $this->getNewVersion();
|
|
|
|
if (!$cache['status']) {
|
|
$updateData = $this->getVersionInfo($cache['newmsg']);
|
|
$this->assign("updateData", $updateData["cache"]);
|
|
}
|
|
$this->assign('cache', $cache);
|
|
|
|
// 读取文件内容
|
|
$file = file_get_contents('./Public/data.txt');
|
|
$array = json_decode($file, TRUE);
|
|
$this->assign('array', $array);
|
|
|
|
// 读取最新插件
|
|
$plug = M("plug")->order("addtime desc")->limit(5)->select();
|
|
$this->assign("plug", $plug);
|
|
|
|
// 工单未读消息
|
|
$work = M('work_question')->getField('number', true);
|
|
$newWork = implode(',', $work);
|
|
$url = "http://console.mobzhifu.com/index.php/VersionApi/WorkMessage/index";
|
|
|
|
$data['number'] = $newWork;
|
|
$data['appid'] = 4;
|
|
$re = http_request($url, $data);
|
|
$ree = json_decode($re, true);
|
|
if ($ree['type'] == 0) {
|
|
$nored = $ree['num'];
|
|
}
|
|
$this->assign("nored", $nored);
|
|
// 查询所有工单消息
|
|
$works = M('work_question')->getField('number', true);
|
|
$newWorks = implode(',', $works);
|
|
$urls = "http://console.mobzhifu.com/index.php/VersionApi/WorkMessage/home";
|
|
$datas['number'] = $newWorks;
|
|
$datas['appid'] = 4;
|
|
$rep = http_request($urls, $datas);
|
|
$repe = json_decode($rep, true);
|
|
if ($repe['type'] == 0) {
|
|
$WorkMessage = $repe['msg'];
|
|
}
|
|
$this->assign('WorkMessage', $WorkMessage);
|
|
|
|
$this->assign('overdueMerchant', $overdueMerchant);
|
|
$this->assign('normalMerchant', $normalMerchant);
|
|
$this->assign('allshop', $allshop);
|
|
$this->assign('allMerchant', $count);
|
|
$this->assign('listone', $listone);
|
|
$this->assign('listtwo', $listtwo);
|
|
$this->display();
|
|
|
|
}
|
|
|
|
static private $getverionurl = "http://console.mobzhifu.com/index.php/VersionApi/Version/CheckVersion";
|
|
static private $getverioninfo = "http://console.mobzhifu.com/index.php/VersionApi/Version/getVersionInfo";
|
|
static private $branchid = 2;
|
|
|
|
//获取版本信息
|
|
public function getVersionInfo($versionid)
|
|
{
|
|
$getverioninfo = self::$getverioninfo;
|
|
$branchid = self::$branchid;
|
|
$data = array('version' => $versionid, 'branchid' => $branchid);
|
|
$re = curl_get($getverioninfo, $data);
|
|
$jsonData = json_decode($re, true);
|
|
return $jsonData;
|
|
}
|
|
|
|
//获取新版本
|
|
public function getNewVersion()
|
|
{
|
|
$versionid = D("Webset")->getVersion();
|
|
//查询一个接口知晓是否为最新版本
|
|
$url = self::$getverionurl;
|
|
$branchid = self::$branchid;
|
|
$data = array('Version' => $versionid, 'branchid' => $branchid);
|
|
$re = curl_get($url, $data);
|
|
$cache = json_decode($re, true);
|
|
$cache["versionid"] = $versionid;
|
|
return $cache;
|
|
}
|
|
|
|
//检查版本更新
|
|
public function checkVersion()
|
|
{
|
|
$cache = $this->getNewVersion();
|
|
$this->ajaxReturn($cache);
|
|
}
|
|
|
|
// 首页表格显示
|
|
public function getadmin()
|
|
{
|
|
$user = session('admin_userinfo');
|
|
$where['partnerid'] = $user['pid'];
|
|
$superinfo = M('retail_agent')->where($where)->page((int)$_GET['page'], (int)$_GET['limit'])->order('id asc')->select();
|
|
$count = M('retail_agent')->where($where)->count();
|
|
if ($superinfo) {
|
|
foreach ($superinfo as $key => &$val) {
|
|
|
|
$val['discountname'] = M('retail_group')->where(array('id' => $val['discountid']))->getField('name');
|
|
if ($val['end_time'] < time()) {
|
|
$val['overdue'] = '过期';//过期
|
|
} else {
|
|
$val['overdue'] = '正常';//为过期
|
|
}
|
|
$val['end_time'] = newDate('Y-m-d', $val['end_time']);
|
|
|
|
}
|
|
}
|
|
$res['code'] = 0;
|
|
$res['msg'] = '';
|
|
$res['data'] = $superinfo;
|
|
$res['count'] = $count;
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
//合伙人修改密码
|
|
public function dochangepwd()
|
|
{
|
|
if (IS_POST) {
|
|
$oldpassword = I('post.oldpassword');
|
|
$newpassword = I('post.newpassword');
|
|
if (strlen($newpassword) > 16) {
|
|
$rt['status'] = 0;
|
|
$rt['msg'] = '密码不能大于16位';
|
|
$this->ajaxReturn($rt);
|
|
exit;
|
|
}
|
|
$user = session('admin_userinfo');
|
|
$user = M('retail_admin')->where(array('id' => $user['id']))->find();
|
|
$CryptrModel = new \Addons\Api\Crypto ();
|
|
$password = $CryptrModel->encrypt($oldpassword, date('YmdHis', $user['addtime']));
|
|
if ($password == $user['password']) {
|
|
$newpass = $CryptrModel->encrypt($newpassword, date('YmdHis', $user['addtime']));
|
|
$save['password'] = $newpass;
|
|
$ret = M('retail_admin')->where(array('id' => $user['id']))->save($save);
|
|
if ($ret) {
|
|
$rt['status'] = 1;
|
|
$rt['msg'] = '修改成功';
|
|
} else {
|
|
$rt['status'] = 0;
|
|
$rt['msg'] = '修改失败';
|
|
}
|
|
} else {
|
|
$rt['status'] = 0;
|
|
$rt['msg'] = '旧密码错误';
|
|
}
|
|
$rt['get'] = I('get.');
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
}
|
|
|
|
// 公告详情
|
|
public function look()
|
|
{
|
|
$id = I('get.id');
|
|
$map['id'] = $id;
|
|
$message = M('work_message');
|
|
$data = $message->where($map)->find();
|
|
$data['time'] = date('Y-m-d', $data['time']);
|
|
$this->assign('data', $data);
|
|
$this->display();
|
|
}
|
|
|
|
//上传图片
|
|
public function upload()
|
|
{
|
|
$upload = new \Think\Upload (); // 实例化上传类
|
|
$upload->maxSize = 5242880 / 2; // 设置附件上传大小5M/5
|
|
$upload->exts = array(
|
|
'jpg',
|
|
'png',
|
|
'jpeg',
|
|
); // 设置附件上传类型
|
|
$upload->rootPath = 'Uploads'; // 设置附件上传根目录
|
|
$upload->savePath = '/Admin/'; // 设置附件上传(子)目录
|
|
$upload->saveName = array(
|
|
'uniqid',
|
|
array('', true)
|
|
);
|
|
// 上传文件
|
|
$info = $upload->upload();
|
|
if (!empty($info['file']['savename'])) {
|
|
$path = "/" . $upload->rootPath . $info['file']['savepath'] . $info['file']['savename'];
|
|
$rt['status'] = 1;
|
|
$rt['path'] = $path;
|
|
} else {
|
|
$rt['status'] = 0;
|
|
$rt['msg'] = '图片上传失败';
|
|
}
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
|
|
//更新头像
|
|
public function userimg()
|
|
{
|
|
$user = session('admin_userinfo');
|
|
$userimg = I('post.userimg');
|
|
if (!$user || !$userimg) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '参数错误';
|
|
$this->ajaxReturn($res);
|
|
exit;
|
|
}
|
|
$save = M('retail_admin')->where(array('id' => $user['id']))->save(array('image' => $userimg));
|
|
if ($save) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = '头像更新成功,请重新登录';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '修改失败,请重新上传';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
public function get_openid_type()
|
|
{
|
|
$user = session('admin_userinfo');
|
|
if (!$user) {
|
|
$this->error('你无权操作');
|
|
exit;
|
|
}
|
|
/* 获取微信绑定 */
|
|
$res = M('retail_admin')->where(array('id' => $user['id']))->getField('openid_type');
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/* 存入token */
|
|
public function random()
|
|
{
|
|
$user = session('admin_userinfo');
|
|
if (!$user) {
|
|
$this->error('你无权操作');
|
|
exit;
|
|
}
|
|
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
$len = strlen($str) - 1;
|
|
$randStr = '';
|
|
for ($i = 0; $i < 10; $i++) {
|
|
$num = mt_rand(0, $len);
|
|
$randStr .= $str[$num];
|
|
}
|
|
$add['token'] = $randStr;
|
|
$add['user_id'] = $user['id'];
|
|
$add['user_type'] = 1; // 1 商户 2 店长
|
|
$add['start_time'] = time();
|
|
$add['end_time'] = time() + 60;
|
|
$add['status'] = 0;
|
|
$result = M('auth_token')->add($add);
|
|
if ($result) {
|
|
$url = 'http://'.$_SERVER['HTTP_HOST'] . '/index.php/Retail/Binding/index?token=' . $randStr;
|
|
$res['status'] = 1;
|
|
$res['url'] = $url;
|
|
$res['token'] = $randStr;
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = 'token值保存失败';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/* 判断用户是否扫描 */
|
|
public function check()
|
|
{
|
|
$token = I('post.token');
|
|
$find = M('auth_token')->where(array('token' => $token, 'status' => 1))->find();
|
|
if ($find) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = '用户已扫描';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '用户未扫描';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/* 判断用户是否操作 */
|
|
public function auth()
|
|
{
|
|
$token = I('post.token');
|
|
$result = M('auth_token')->where(array('token' => $token))->find();
|
|
if ($result['status'] == 2) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = '授权成功';
|
|
} else if ($result['status'] == 3) {
|
|
$res['status'] = 2;
|
|
$res['msg'] = '取消授权';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '用户未操作';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/* 解绑微信 */
|
|
public function relieve_wx(){
|
|
$user = session('admin_userinfo');
|
|
if(!$user){
|
|
$this->error('你无权操作');
|
|
exit;
|
|
}
|
|
$admin = M('retail_admin')->where(array('id'=>$user['id']))->find();
|
|
if(!$admin){
|
|
$res['status'] = 0;
|
|
$res['msg'] = '未查询到你的商户账号';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$up['openid'] = '';
|
|
$up['openid_type'] = 0;
|
|
$update = M('retail_admin')->where(array('id'=>$user['id']))->save($up);
|
|
if($update){
|
|
$res['status'] = 1;
|
|
$res['msg'] = '解除成功';
|
|
}else{
|
|
$res['status'] = 0;
|
|
$res['msg'] = '解除失败';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/* 合伙人是否开启公众号 */
|
|
public function get_scan_type(){
|
|
$logoinfo = I('session.logoinfo');
|
|
$find = M('partner_wxconfig')->where(array('partner_id'=>$logoinfo['id']))->find();
|
|
$res = $find ? 1 : 0;
|
|
$this->ajaxReturn($res);
|
|
}
|
|
} |