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

398 行
14 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Retail\Controller;
use Common\Business\MerchantConfig;
use Common\Model\RetailOtherPayModel;
use Think\Controller;
//[1.9.22]
/**
* 商户基本设置 2019-5-8
* Class BaseSetController
* @package Retail\Controller
*/
class BaseSetController extends BaseController
{
public function index()
{
$user = session('merchant_userinfo');
$MerchantConfig = D('MerchantConfig')->getFind(array('merchant_id' => $user['id']));
if (!$MerchantConfig) {
$MerchantConfig['other_pay'] = 1;
$MerchantConfig['pay_to_vip_state'] = '0';
$MerchantConfig['pay_coupon_goods_tag'] = 1;
}
$this->assign('MerchantConfig', $MerchantConfig);
$arr = array(
'changeOtherPay' => '/index.php/Retail/BaseSet/changeOtherPay',
'addOtherPay' => '/index.php/Retail/BaseSet/addOtherPay',
'upOtherPayName' => '/index.php/Retail/BaseSet/upOtherPayName',
'changeOtherPayStatus' => '/index.php/Retail/BaseSet/changeOtherPayStatus',
'delOtherPay' => '/index.php/Retail/BaseSet/delOtherPay',
'payToVip' => '/index.php/Retail/BaseSet/payToVip',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$refundList = D('RefundOrder')->getFindOrder($user['id']);
$this->assign('refundList', json_encode($refundList));
$this->display();
}
/**
* 修改其他支付开启关闭状态
* $other_pay 其他支付开启关闭状态 0|1
*/
public function changeOtherPay()
{
$user = session('merchant_userinfo');
$order_pay = I('post.other_pay');
if (isset($order_pay) && ($order_pay == 1 || $order_pay == 0)) {
$map['merchant_id'] = $user['id'];
$MerchantConfigModel = D('MerchantConfig');
$old = $MerchantConfigModel->getFind($map);
$item['other_pay'] = $order_pay;
if (empty($old)) {
$item['add_time'] = time();
$item['merchant_id'] = $user['id'];
$result = $MerchantConfigModel->addOrder($item);
} else {
$result = $MerchantConfigModel->updateOrder($map, $item);
}
$msg = $order_pay == 1 ? '开启' : '关闭';
if ($result) {
$res['status'] = 1;
$res['msg'] = $msg . '成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '支付设置-修改其它支付设置开启状态';//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = $msg . '失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '参数有误';
}
$this->ajaxReturn($res);
}
/**
* 获取其他支付数据
* $page 页码
* $limit 条数
*/
public function getOtherPay()
{
$page = I('post.page');
$limit = I('post.limit');
if (!empty($page) && !empty($limit)) {
$user = session('merchant_userinfo');
$map = array(
'merchant_id' => $user['id'],
'state' => 1
);
$OtherPayModel = D('OtherPay');
$count = $OtherPayModel->getCount($map);
$otherPay = $OtherPayModel->getSelect($map, 'id,name,status', 'order asc,status desc', $page . ',' . $limit);
$res['count'] = intval($count);
$res['data'] = $otherPay;
$res['status'] = 1;
$res['msg'] = '数据获取成功';
} else {
$res['status'] = 0;
$res['msg'] = '缺少参数';
}
$this->ajaxReturn($res);
}
/**
* 获取其他支付列表(供筛选)
*/
public function getOtherPayList()
{
$map = array(
'merchant_id' => $this->merchant_id,
'state' => 1,
'status' => 1,
);
$OtherPayModel = new RetailOtherPayModel();
$data = $OtherPayModel->getSelect($map, 'id,name', 'id asc');
$this->ajaxReturn([
'status' => 1,
'message' => empty($data) ? '暂无数据' : '数据获取成功',
'data' => $data,
]);
}
/**
* 添加其他支付
* $name 其他支付名称
*/
public function addOtherPay()
{
$user = session('merchant_userinfo');
$name = I('post.name');
$name = trim($name);
if ($name && $name) {
$item['name'] = $name;
$item['state'] = 1;
$item['merchant_id'] = $user['id'];
$OtherPayModel = D('OtherPay');
$old = $OtherPayModel->getFind($item);
if (empty($old)) {
$item['add_time'] = time();
$item['status'] = 1;
$add = $OtherPayModel->addOtherPay($item);
if ($add) {
$res['status'] = 1;
$res['msg'] = '添加成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '添加新的支付方式';//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '数据库错误,请重试';
}
} else {
$res['status'] = 0;
$res['msg'] = '该支付名称已存在';
}
} else {
$res['status'] = 0;
$res['msg'] = '请输入名称';
}
$this->ajaxReturn($res);
}
/**
* 删除其他支付
* $id 其他支付id
*/
public function delOtherPay()
{
$user = session('merchant_userinfo');
$id = I('post.id');
if (!empty($id)) {
$del = D('OtherPay')->delOtherPay(array('id' => array('in', $id), 'merchant_id' => $user['id']));
if ($del) {
$res['status'] = 1;
$res['msg'] = '删除成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '删除其它支付方式';//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '删除失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '请传入需要删除的支付信息';
}
$this->ajaxReturn($res);
}
/**
* 修改其他支付名称
* $id 其他支付id
* $name 修改的名称
*/
public function upOtherPayName()
{
$user = session('merchant_userinfo');
$id = I('post.id');
$name = I('post.name');
$name = trim($name);
if (!empty($id) && !empty($name)) {
$map['name'] = $name;
$map['state'] = 1;
$map['merchant_id'] = $user['id'];
$OtherPayModel = D('OtherPay');
$old = $OtherPayModel->getFind($map);
if (empty($old)) {
$update = $OtherPayModel->updateOtherPay(array('id' => $id), array('name' => $name));
$res['up'] = $update;
if ($update) {
$res['status'] = 1;
$res['msg'] = '修改成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '编辑其它支付方式';//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '您未修改数据';
}
} else {
$res['status'] = 0;
$res['msg'] = '该支付名称已存在';
}
} else {
$res['status'] = 0;
$res['msg'] = '请输入名称';
}
$this->ajaxReturn($res);
}
/**
* 修改其他支付状态
* $id 其他支付id
* $status 开关状态 0关闭 1开启
*/
public function changeOtherPayStatus()
{
$user = session('merchant_userinfo');
$id = I('post.id');
$status = I('post.status');
if (!empty($id) && isset($status) && ($status == 1 || $status == 0)) {
$up = D('OtherPay')->updateOtherPay(array('id' => $id, 'merchant_id' => $user['id']), array('status' => $status));
if ($up) {
$res['status'] = 1;
$res['msg'] = '修改成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '修改其它支付方式状态';//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '修改失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '缺少参数';
}
$this->ajaxReturn($res);
}
/**
* 修改退款顺序
*/
public function saveOrderSet()
{
$user = session('merchant_userinfo');
$refundList = I('post.refundList');
if (empty($refundList) || !is_array($refundList)) {
$res['status'] = 0;
$res['msg'] = '缺少参数';
$this->ajaxReturn($res);
}
$item = array();
foreach ($refundList as $key => $value) {
if (isset($value['cash_refund_order'])) {
$item['cash_refund_order'] = intval($key + 1);
}
if (isset($value['vip_refund_order'])) {
$item['vip_refund_order'] = intval($key + 1);
}
if (isset($value['other_refund_order'])) {
$item['other_refund_order'] = intval($key + 1);
}
if (isset($value['al_refund_order'])) {
$item['al_refund_order'] = intval($key + 1);
}
if (isset($value['wx_refund_order'])) {
$item['wx_refund_order'] = intval($key + 1);
}
if (isset($value['mec_refund_order'])) {
$item['mec_refund_order'] = intval($key + 1);
}
}
$RefundOrderModel = D('RefundOrder');
$old = $RefundOrderModel->getFind(array('merchant_id' => $user['id']));
if (empty($old)) {
$item['merchant_id'] = $user['id'];
$result = $RefundOrderModel->addOrder($item);
} else {
$result = $RefundOrderModel->updateOrder(array('merchant_id' => $user['id']), $item);
}
$res['data'] = $item;
if ($result) {
$res['status'] = 1;
$res['msg'] = '保存成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '编辑退款顺序设置';//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '保存失败';
}
$this->ajaxReturn($res);
}
/**
* 修改支付成为会员状态
*/
public function payToVip()
{
$state = I('post.state');
$MerConfModel = D('MerchantConfig');
$user = session('merchant_userinfo');
$map = array(
'merchant_id' => $user['id']
);
$config = $MerConfModel->getFind($map);
if (empty($config)) {
$item = array(
'merchant_id' => $user['id'],
'pay_to_vip_state' => $state,
'add_time' => time(),
);
$res = $MerConfModel->addOrder($item);
} else {
$item = array(
'pay_to_vip_state' => $state,
);
$res = $MerConfModel->updateOrder($map, $item);
}
if ($res) {
$result = array(
'status' => 1,
'msg' => '操作成功',
);
} else {
$result = array(
'status' => 0,
'msg' => '操作失败',
);
}
$this->ajaxReturn($result);
}
//代金券核销类型1指定商品id 2指定商品条码
public function payCouponType()
{
$data = I('post.');
$data['operator_type'] = 1;
$data['user_type'] = 3;
$data['merchant_id'] = $this->merchant_id;
$ConfigClass = new MerchantConfig();
$result = $ConfigClass->payCouponType($data);
$this->ajaxReturn($result);
}
}