文件
mashangyoujiu/Application/Retail/Controller/XcxConfigController.class.php

349 行
9.8 KiB
PHP
可执行文件

<?php
namespace Retail\Controller;
use Common\Business\MerchantConfig;
use Common\Model\MerchantConfigModel;
use Common\Model\RetailMerchantConfigModel;
use Common\Model\RetailMerchantModel;
use Think\Controller;
//[1.8.68]
/**
* 所有小程序 合并处理
* Class XcxConfigController
* @package Retail\Controller
*/
class XcxConfigController extends BaseController
{
public function _initialize()
{
parent::_initialize();
if (!session('merchant_userinfo')) {
if (IS_POST) {
$this->ajaxReturn(array(
'status' => 0,
'msg' => '您无权操作',
));
} else {
echo '您无权操作';
exit;
}
}
}
public function wxconfig()
{
$merchant_id = $this->merchant_id;
$this->assign('merchant_id', $merchant_id);
$this->assign('type', 3); //1合伙人 2代理商 3商户
$arr = array(
'submitAudit' => '/index.php/Retail/XcxConfig/submitAudit',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
/**
* 设置小程序用户隐私保护指引
*/
public function setPrivacy(){
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$res = $MerXcxConf->setPrivacySetting();
$this->ajaxReturn($res);
}
/**
* 小程序获取基本信息
*/
public function getBaseData()
{
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$res = $MerXcxConf->getBaseData(); //获取小程序当前信息
$this->ajaxReturn($res);
}
/**
* 修改充值入口显示状态
*/
public function changeOnlineStatus()
{
$merchant_id = I('post.merchant_id');
$MerXcxConf = new \Addons\Api\MerXcxConf($merchant_id);
$res = $MerXcxConf->changeOnlineStatus(); //修改充值入口是否显示
$this->ajaxReturn($res);
}
/**
* 小程序获取预览码
*/
public function getPreviewQrImg()
{
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$res = $MerXcxConf->getPreviewQrImg(); //获取小程序当前信息
$this->ajaxReturn($res);
}
/*
* 小程序的授权功能
*/
public function authIndex()
{
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$url = $MerXcxConf->authIndex('Retail/XcxConfig/authSuccess');
header('location:' . $url);
}
/**
* 小程序授权回调
*/
public function authSuccess()
{
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$res = $MerXcxConf->authSuccess();
$this->assign('status', $res ? 1 : 0);
if (!$res) {
$this->assign('msg', $MerXcxConf->errMsg);
}
$this->display();
}
/**
* 小程序提交审核
*/
public function submitAudit()
{
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$res = $MerXcxConf->submitAudit();
$this->ajaxReturn($res);
}
/**
* 绑定开发体验用户
*/
public function bindUser()
{
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$res = $MerXcxConf->bindUser();
$this->ajaxReturn($res);
}
/**
* 小程序审核撤回
*/
public function undoCodeAudit()
{
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$res = $MerXcxConf->undoCodeAudit();
$this->ajaxReturn($res);
}
/**
* 发布小程序版本
*/
public function release()
{
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$res = $MerXcxConf->release();
$this->ajaxReturn($res);
}
/**
* 回退小程序版本
*/
public function reBack()
{
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$res = $MerXcxConf->reBack();
$this->ajaxReturn($res);
}
/**
* 回退小程序版本
*/
public function clearAuthInfo()
{
$MerXcxConf = new \Addons\Api\MerXcxConf($this->merchant_id);
$res = $MerXcxConf->clearAuthInfo();
$this->ajaxReturn($res);
}
// 修改小程序是否开启直接进入附近门店
public function saveNearby()
{
$nearby_status = I('post.nearby_status');
if (!empty($nearby_status)) {
$result = M('retail_merchant')->where(array('id' => $this->merchant_id))->setField('nearby_status', $nearby_status);
if (!empty($result)) {
$res['status'] = 1;
$res['msg'] = '提交成功!';
} else {
$res['status'] = 0;
$res['msg'] = '提交失败!';
}
} else {
$res['status'] = 0;
$res['msg'] = '参数不全!';
}
$this->ajaxReturn($res);
}
// 轮播图设置
public function slideshow()
{
$this->display();
}
public function getBanner()
{
$list = M('retail_slideshow')->where(array('merchantid' => $this->merchant_id))->order('id desc')->select();
$res['status'] = 1;
$res['msg'] = '查询成功';
$res['data'] = $list;
$this->ajaxReturn($res);
}
// 添加轮播图
public function addSlideShow()
{
if (IS_POST) {
$image_id = I('post.image_id');
$image = I('post.image');
if (empty($image_id) || empty($image)) {
$res['status'] = 0;
$res['msg'] = '请选择图片';
$this->ajaxReturn($res);
}
$data['merchantid'] = $this->merchant_id;
$data['addtime'] = time();
$data['status'] = 1;
$data['image_id'] = $image_id;
$data['image'] = $image;
$add = M('retail_slideshow')->add($data);
if ($add) {
$res['status'] = 1;
$res['msg'] = '添加成功';
$res['id'] = $add;
} else {
$res['status'] = 0;
$res['msg'] = '添加失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '登录超时';
}
$this->ajaxReturn($res);
}
// 删除轮播图
public function delSlideShow()
{
if (IS_POST) {
$id = I('post.id');
if (!empty($id)) {
$del_art = M('retail_slideshow')->where(array('id' => $id))->delete();
if (!empty($del_art)) {
$res['status'] = 1;
$res['msg'] = '删除成功';
} else {
$res['status'] = 0;
$res['msg'] = '删除失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '缺失参数';
}
} else {
$res['status'] = 0;
$res['msg'] = '登录超时';
}
$this->ajaxReturn($res);
}
/**
* 加载小程序设置模板
*/
public function setNearby()
{
// 权限
$arr = array(
'slideshow' => '/index.php/Retail/XcxConfig/slideshow',
'setting' => '/index.php/Retail/XcxConfig/setting',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
/**
* 获取小程序配置
*/
public function getXcxConfig()
{
if (IS_POST) {
$ConfigApi = new MerchantConfig();
$res = $ConfigApi->getXcxConfig(['merchant_id' => $this->merchant_id]);
$this->ajaxReturn($res);
}
}
/**
* 小程序自动跳转最近门店设置
*/
public function setting()
{
$nearby_status = I('post.nearby_status');
if (!$nearby_status) {
$res['status'] = 0;
$res['msg'] = '参数缺失';
$this->ajaxReturn($res);
}
// 查询商户配置
$map['id'] = $this->merchant_id;
$map['status'] = 1;
$save = M('retail_merchant')->where($map)->save(array('nearby_status' => $nearby_status));
if ($save) {
$res['status'] = 1;
$res['msg'] = '操作成功';
} else {
$res['status'] = 0;
$res['msg'] = '操作成功';
}
$this->ajaxReturn($res);
}
/**
* 保存设置
*/
public function saveStoreSetting()
{
$MerchantConfigModel = new MerchantConfigModel();
$store_access = I('post.store_access'); //会员进入门店方式 1进入最近门店 2进入会员绑定门店,3主店
$store_switch = I('post.store_switch'); //是否可以切换门店 1可 2否
$tourist_store_access = I('post.tourist_store_access'); //非会员进入门店方式 1最近门店,2所属门店,3主店
$update = [
'store_access' => $store_access,
'store_switch' => $store_switch,
'tourist_store_access' => $tourist_store_access,
];
$res = $MerchantConfigModel->updateOrder(['merchant_id' => $this->merchant_id], $update);
if ($res) {
$result = ['status' => 1, 'msg' => '修改成功!'];
} else {
$result = ['status' => 0, 'msg' => '暂无修改!'];
}
$this->ajaxReturn($result);
}
}