920 行
38 KiB
PHP
可执行文件
920 行
38 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use Common\Business\TemplatePushNews;
|
||
use Think\Controller;
|
||
|
||
//[1.7.90]
|
||
class MarkController extends BaseController
|
||
{
|
||
public function index()
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$info = M('mark')->where(array('merchantid' => $userinfo['id']))->find();
|
||
$this->assign('info', $info);
|
||
$arr = array(
|
||
'mark_detail' => '/index.php/Retail/Mark/mark_detail',
|
||
'mark_set' => '/index.php/Retail/Mark/mark_set',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$typeArr = array(
|
||
array(
|
||
'k' => 1,
|
||
'v' => '会员卡激活',
|
||
),
|
||
array(
|
||
'k' => 2,
|
||
'v' => '会员卡充值',
|
||
),
|
||
array(
|
||
'k' => 3,
|
||
'v' => '会员消费',
|
||
),
|
||
array(
|
||
'k' => 4,
|
||
'v' => '优惠券发放',
|
||
),
|
||
array(
|
||
'k' => 5,
|
||
'v' => '退款通知',
|
||
),
|
||
array(
|
||
'k' => 6,
|
||
'v' => '活动通知',
|
||
),
|
||
array(
|
||
'k' => 7,
|
||
'v' => '分期到账',
|
||
),
|
||
array(
|
||
'k' => 8,
|
||
'v' => '代金券发放',
|
||
),
|
||
array(
|
||
'k' => 9,
|
||
'v' => '线上下单通知收银员',
|
||
),
|
||
);
|
||
$fieldsArr = array(
|
||
//注册会员
|
||
'1' => array(
|
||
array('field' => 'card', 'name' => '会员卡号'),
|
||
array('field' => 'name', 'name' => '会员姓名'),
|
||
array('field' => 'mobile_phone', 'name' => '会员手机'),
|
||
array('field' => 'balance', 'name' => '当前余额'),
|
||
array('field' => 'grade_name', 'name' => '会员等级'),
|
||
array('field' => 'index_time', 'name' => '加入时间'),
|
||
),
|
||
'2' => array(
|
||
//会员充值
|
||
array('field' => 'mobile_phone', 'name' => '会员手机'),
|
||
array('field' => 'name', 'name' => '会员名称'),
|
||
array('field' => 'balance', 'name' => '当前余额'),
|
||
array('field' => 'integral', 'name' => '当前积分'),
|
||
array('field' => 'recharge_balance', 'name' => '充值金额'),
|
||
array('field' => 'recharge_state', 'name' => '充值状态'),
|
||
array('field' => 'pay_type', 'name' => '充值方式'),
|
||
array('field' => 'add_time', 'name' => '充值时间'),
|
||
),
|
||
'3' => array(
|
||
//会员消费
|
||
array('field' => 'card', 'name' => '会员卡号'),
|
||
array('field' => 'mobile_phone', 'name' => '会员手机'),
|
||
array('field' => 'flower_balance', 'name' => '消费金额'),
|
||
array('field' => 'store_name', 'name' => '消费门店'),
|
||
array('field' => 'order_number', 'name' => '订单编号'),
|
||
array('field' => 'pay_type', 'name' => '支付方式'),
|
||
array('field' => 'balance', 'name' => '当前余额'),
|
||
array('field' => 'integral', 'name' => '当前积分'),
|
||
array('field' => 'add_time', 'name' => '消费时间'),
|
||
array('field' => 'name', 'name' => '会员名称'),
|
||
array('field' => 'grade_name', 'name' => '会员等级'),
|
||
),
|
||
'4' => array(
|
||
//优惠券
|
||
array('field' => 'start_time', 'name' => '生效时间'),
|
||
array('field' => 'end_time', 'name' => '到期时间'),
|
||
array('field' => 'coupon_name', 'name' => '优惠券名称'),
|
||
),
|
||
'5' => array(
|
||
//退款
|
||
array('field' => 'card', 'name' => '会员卡号'),
|
||
array('field' => 'mobile_phone', 'name' => '会员手机'),
|
||
array('field' => 'refund_balance', 'name' => '退款金额'),
|
||
array('field' => 'order_number', 'name' => '订单编号'),
|
||
array('field' => 'pay_type', 'name' => '退款方式'),
|
||
array('field' => 'name', 'name' => '会员名称'),
|
||
),
|
||
'6' => array(
|
||
//活动通知
|
||
array('field' => 'add_time', 'name' => '时间'),
|
||
),
|
||
'7' => array(
|
||
//分期到账
|
||
array('field' => 'aging_money', 'name' => '到账金额'),
|
||
array('field' => 'has_arrive', 'name' => '到账期数'),
|
||
array('field' => 'aging_date', 'name' => '到账时间'),
|
||
array('field' => 'un_arrive', 'name' => '剩余期数'),
|
||
),
|
||
'8' => array(
|
||
//代金券券
|
||
array('field' => 'start_time', 'name' => '有效时间'),
|
||
array('field' => 'end_time', 'name' => '到期时间'),
|
||
array('field' => 'coupon_name', 'name' => '代金券名称'),
|
||
),
|
||
'9' => array(
|
||
//线上订单推送
|
||
array('field' => 'order_number', 'name' => '订单号'),
|
||
array('field' => 'flower_balance', 'name' => '实付金额'),
|
||
array('field' => 'add_time', 'name' => '下单时间'),
|
||
array('field' => 'pickup_type_name', 'name' => '配送方式'),
|
||
array('field' => 'user_select_time', 'name' => '发货|自提的时间'),
|
||
array('field' => 'user_name', 'name' => '姓名'),
|
||
array('field' => 'mobile_phone', 'name' => '手机号'),
|
||
array('field' => 'user_address', 'name' => '配送地址'),
|
||
),
|
||
);
|
||
$this->assign('fieldsArr', json_encode($fieldsArr));
|
||
$this->assign('typeArr', json_encode($typeArr));
|
||
$this->display();
|
||
}
|
||
|
||
public function mark_set()
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
if (IS_POST) {
|
||
$type = I('post.type');
|
||
$msg = I('post.msg');
|
||
$id = I('post.id');
|
||
$data[$type] = $msg;
|
||
if ($id) {
|
||
// 修改
|
||
$msg = '公众号模板-旧版设置-修改消息(通知)设置';
|
||
$ret = M('mark')->where(array('merchantid' => $userinfo['id']))->save($data);
|
||
} else {
|
||
// 新增
|
||
$msg = '公众号模板-旧版设置-新增消息(通知)设置';
|
||
$data['merchantid'] = $userinfo['id'];
|
||
$ret = M('mark')->add($data);
|
||
}
|
||
if ($ret) {
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '设置成功';
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = $msg;//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$rt['status'] = 2;
|
||
$rt['msg'] = '设置失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
} else {
|
||
$type = I('get.type');
|
||
$msg = I('get.msg');
|
||
$id = I('get.id');
|
||
$arr['type'] = $type;
|
||
$arr['msg'] = $msg;
|
||
$arr['id'] = $id;
|
||
$this->assign('arr', $arr);
|
||
$this->display();
|
||
}
|
||
}
|
||
|
||
public function new_mark()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
public function mark_detail()
|
||
{
|
||
$arr = array(
|
||
'edit_template' => '/index.php/Retail/Mark/edit_template',
|
||
'open_template' => '/index.php/Retail/Mark/open_template',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
// 会员卡激活
|
||
public function get_template()
|
||
{
|
||
$model = I('post.model');
|
||
switch ($model) {
|
||
case 1:
|
||
$template_list = $this->get_do_card();
|
||
break;
|
||
case 2:
|
||
$template_list = $this->get_member_recharge();
|
||
break;
|
||
case 3:
|
||
$template_list = $this->get_member_consume();
|
||
break;
|
||
case 4:
|
||
$template_list = $this->get_discount_coupon();
|
||
break;
|
||
case 5:
|
||
$template_list = $this->get_refund();
|
||
break;
|
||
default:
|
||
$template_list = $this->get_do_card();
|
||
}
|
||
$res['template_list'] = $template_list;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
protected function get_do_card()
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$merchant_do_card_types = M('retail_template_do_card')->where(array('merchantid' => $merchantid))->getField('type', true); // 商户模板
|
||
$do_card_list = M('retail_template_do_card')->where(array('merchantid' => 0))->select(); // 默认模板
|
||
foreach ($do_card_list as &$val) {
|
||
if (in_array($val['type'], $merchant_do_card_types) == false) {
|
||
unset($val['id']);
|
||
$val['merchantid'] = $merchantid;
|
||
$add_do_card_merchant = M('retail_template_do_card')->add($val);
|
||
if (!$add_do_card_merchant) {
|
||
return array();
|
||
}
|
||
}
|
||
}
|
||
$merchant_do_card_list = M('retail_template_do_card')->where(array('merchantid' => $merchantid))->order('id asc')->select();
|
||
if (empty($merchant_do_card_list)) {
|
||
$merchant_do_card_list = array();
|
||
} else {
|
||
foreach ($merchant_do_card_list as &$val) {
|
||
$val['keyword1'] = explode(':', $val['member_number']);
|
||
$val['keyword2'] = explode(':', $val['member_rank']);
|
||
$val['keyword3'] = explode(':', $val['member_name']);
|
||
$val['keyword4'] = explode(':', $val['member_phone']);
|
||
$val['keyword5'] = explode(':', $val['member_addtime']);
|
||
$val['keyword6'] = explode(':', $val['member_balance']);
|
||
$val['keyword7'] = '';
|
||
$val['keyword8'] = '';
|
||
unset($val['member_number']);
|
||
unset($val['member_rank']);
|
||
unset($val['member_name']);
|
||
unset($val['member_phone']);
|
||
unset($val['member_addtime']);
|
||
unset($val['member_balance']);
|
||
}
|
||
}
|
||
return $merchant_do_card_list;
|
||
}
|
||
|
||
protected function get_member_recharge()
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$merchant_member_recharge_types = M('retail_template_member_recharge')->where(array('merchantid' => $merchantid))->getField('type', true); // 商户模板
|
||
$member_recharge_list = M('retail_template_member_recharge')->where(array('merchantid' => 0))->select(); // 默认模板
|
||
foreach ($member_recharge_list as &$val) {
|
||
if (in_array($val['type'], $merchant_member_recharge_types) == false) {
|
||
unset($val['id']);
|
||
$val['merchantid'] = $merchantid;
|
||
$add_member_recharge_merchant = M('retail_template_member_recharge')->add($val);
|
||
if (!$add_member_recharge_merchant) {
|
||
return array();
|
||
}
|
||
}
|
||
}
|
||
$merchant_member_recharge_list = M('retail_template_member_recharge')->where(array('merchantid' => $merchantid))->order('id asc')->select();
|
||
if (empty($merchant_member_recharge_list)) {
|
||
$merchant_member_recharge_list = array();
|
||
} else {
|
||
foreach ($merchant_member_recharge_list as &$val) {
|
||
$val['keyword1'] = explode(':', $val['recharge_number']);
|
||
$val['keyword2'] = explode(':', $val['recharge_money']);
|
||
$val['keyword3'] = explode(':', $val['recharge_mode']);
|
||
$val['keyword4'] = explode(':', $val['recharge_addtime']);
|
||
$val['keyword5'] = explode(':', $val['recharge_status']);
|
||
$val['keyword6'] = explode(':', $val['member_balance']);
|
||
$val['keyword7'] = explode(':', $val['member_integral']);
|
||
$val['keyword8'] = '';
|
||
unset($val['recharge_number']);
|
||
unset($val['recharge_money']);
|
||
unset($val['recharge_mode']);
|
||
unset($val['recharge_addtime']);
|
||
unset($val['recharge_status']);
|
||
unset($val['member_balance']);
|
||
unset($val['member_integral']);
|
||
}
|
||
}
|
||
return $merchant_member_recharge_list;
|
||
}
|
||
|
||
protected function get_member_consume()
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$merchant_member_consume_types = M('retail_template_member_consume')->where(array('merchantid' => $merchantid))->getField('type', true); // 商户模板
|
||
$member_consume_list = M('retail_template_member_consume')->where(array('merchantid' => 0))->select(); // 默认模板
|
||
foreach ($member_consume_list as &$val) {
|
||
if (in_array($val['type'], $merchant_member_consume_types) == false) {
|
||
unset($val['id']);
|
||
$val['merchantid'] = $merchantid;
|
||
$add_member_consume_merchant = M('retail_template_member_consume')->add($val);
|
||
if (!$add_member_consume_merchant) {
|
||
return array();
|
||
}
|
||
}
|
||
}
|
||
$merchant_member_consume_list = M('retail_template_member_consume')->where(array('merchantid' => $merchantid))->order('id asc')->select();
|
||
if (empty($merchant_member_consume_list)) {
|
||
$merchant_member_consume_list = array();
|
||
} else {
|
||
foreach ($merchant_member_consume_list as &$val) {
|
||
$val['keyword1'] = explode(':', $val['order_number']);
|
||
$val['keyword2'] = explode(':', $val['member_number']);
|
||
$val['keyword3'] = explode(':', $val['consume_money']);
|
||
$val['keyword4'] = explode(':', $val['consume_store']);
|
||
$val['keyword5'] = explode(':', $val['consume_addtime']);
|
||
$val['keyword6'] = explode(':', $val['consume_mode']);
|
||
$val['keyword7'] = explode(':', $val['gain_integral']);
|
||
$val['keyword8'] = explode(':', $val['member_balance']);
|
||
unset($val['order_number']);
|
||
unset($val['member_number']);
|
||
unset($val['consume_money']);
|
||
unset($val['consume_store']);
|
||
unset($val['consume_addtime']);
|
||
unset($val['consume_mode']);
|
||
unset($val['gain_integral']);
|
||
}
|
||
}
|
||
return $merchant_member_consume_list;
|
||
}
|
||
|
||
protected function get_discount_coupon()
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$merchant_discount_coupon_types = M('retail_template_discount_coupon')->where(array('merchantid' => $merchantid))->getField('type', true); // 商户模板
|
||
$discount_coupon_list = M('retail_template_discount_coupon')->where(array('merchantid' => 0))->select(); // 默认模板
|
||
foreach ($discount_coupon_list as &$val) {
|
||
if (in_array($val['type'], $merchant_discount_coupon_types) == false) {
|
||
unset($val['id']);
|
||
$val['merchantid'] = $merchantid;
|
||
$add_discount_coupon_merchant = M('retail_template_discount_coupon')->add($val);
|
||
if (!$add_discount_coupon_merchant) {
|
||
return array();
|
||
}
|
||
}
|
||
}
|
||
$merchant_discount_coupon_list = M('retail_template_discount_coupon')->where(array('merchantid' => $merchantid))->order('id asc')->select();
|
||
if (empty($merchant_discount_coupon_list)) {
|
||
$merchant_discount_coupon_list = array();
|
||
} else {
|
||
foreach ($merchant_discount_coupon_list as &$val) {
|
||
$val['keyword1'] = explode(':', $val['discounts_name']);
|
||
$val['keyword2'] = explode(':', $val['provide_date']);
|
||
$val['keyword3'] = explode(':', $val['expiration_date']);
|
||
$val['keyword4'] = '';
|
||
$val['keyword5'] = '';
|
||
$val['keyword6'] = '';
|
||
$val['keyword7'] = '';
|
||
$val['keyword8'] = '';
|
||
unset($val['discounts_name']);
|
||
unset($val['provide_date']);
|
||
unset($val['expiration_date']);
|
||
}
|
||
}
|
||
return $merchant_discount_coupon_list;
|
||
}
|
||
|
||
protected function get_refund()
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$refund_types = M('retail_template_refund')->where(array('merchantid' => $merchantid))->getField('type', true); // 商户模板
|
||
$refund_list = M('retail_template_refund')->where(array('merchantid' => 0))->select(); // 默认模板
|
||
foreach ($refund_list as &$val) {
|
||
if (in_array($val['type'], $refund_types) == false) {
|
||
unset($val['id']);
|
||
$val['merchantid'] = $merchantid;
|
||
$add_refund_merchant = M('retail_template_refund')->add($val);
|
||
if (!$add_refund_merchant) {
|
||
return array();
|
||
}
|
||
}
|
||
}
|
||
$merchant_refund_list = M('retail_template_refund')->where(array('merchantid' => $merchantid))->order('id asc')->select();
|
||
if (empty($merchant_refund_list)) {
|
||
$merchant_refund_list = array();
|
||
} else {
|
||
foreach ($merchant_refund_list as &$val) {
|
||
$val['keyword1'] = explode(':', $val['consume_store']);
|
||
$val['keyword2'] = explode(':', $val['order_number']);
|
||
$val['keyword3'] = explode(':', $val['refund_money']);
|
||
$val['keyword4'] = explode(':', $val['refund_type']);
|
||
$val['keyword5'] = explode(':', $val['refund_time']);
|
||
$val['keyword6'] = '';
|
||
$val['keyword7'] = '';
|
||
$val['keyword8'] = '';
|
||
unset($val['consume_store']);
|
||
unset($val['order_number']);
|
||
unset($val['refund_money']);
|
||
unset($val['refund_type']);
|
||
unset($val['refund_time']);
|
||
}
|
||
}
|
||
return $merchant_refund_list;
|
||
}
|
||
|
||
public function edit_template() // 编辑模板
|
||
{
|
||
$data = I('post.');
|
||
if (!$data['model'] || !$data['id'] || !$data['template_title'] || !$data['template_remark'] || !$data['template_id']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$data['titlecolor'] = !empty($data['titlecolor']) ? $data['titlecolor'] : '#000000';
|
||
$data['bodycolor'] = !empty($data['titlecolor']) ? $data['bodycolor'] : '#000000';
|
||
$data['remarkcolor'] = !empty($data['titlecolor']) ? $data['remarkcolor'] : '#000000';
|
||
switch ($data['model']) {
|
||
case 1:
|
||
$msg = '公众号模板-新版设置-会员卡激活';
|
||
$data['table'] = M('retail_template_do_card');
|
||
break;
|
||
case 2:
|
||
$msg = '公众号模板-新版设置-会员卡充值';
|
||
$data['table'] = M('retail_template_member_recharge');
|
||
break;
|
||
case 3:
|
||
$msg = '公众号模板-新版设置-会员消费';
|
||
$data['table'] = M('retail_template_member_consume');
|
||
break;
|
||
case 4:
|
||
$msg = '公众号模板-新版设置-优惠券发放';
|
||
$data['table'] = M('retail_template_discount_coupon');
|
||
break;
|
||
case 5:
|
||
$msg = '公众号模板-新版设置-退款通知';
|
||
$data['table'] = M('retail_template_refund');
|
||
break;
|
||
default:
|
||
$data['table'] = M('retail_template_do_card');
|
||
}
|
||
$result = $this->update_template($data);
|
||
if ($result['status'] == 1) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = $result['msg'];
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = $msg . '-编辑模板';//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = $result['msg'];
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
protected function update_template($data)
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$template_find = $data['table']->field('template_title,template_remark,template_id,titlecolor,bodycolor,remarkcolor')->where(array('id' => $data['id'], 'merchantid' => $merchantid))->find();
|
||
if (empty($template_find)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '模板查询失败';
|
||
return $res;
|
||
}
|
||
if (!$template_find['template_id']) {
|
||
$save_data['template_id'] = $data['template_id'];
|
||
} else if ($template_find['template_id'] && $template_find['template_id'] != $data['template_id']) {
|
||
$save_data['template_id'] = $data['template_id'];
|
||
}
|
||
if ($template_find['template_title'] != $data['template_title']) {
|
||
$save_data['template_title'] = $data['template_title'];
|
||
}
|
||
if ($template_find['template_remark'] != $data['template_remark']) {
|
||
$save_data['template_remark'] = $data['template_remark'];
|
||
}
|
||
if ($template_find['titlecolor'] != $data['titlecolor']) {
|
||
$save_data['titlecolor'] = $data['titlecolor'];
|
||
}
|
||
if ($template_find['bodycolor'] != $data['bodycolor']) {
|
||
$save_data['bodycolor'] = $data['bodycolor'];
|
||
}
|
||
if ($template_find['remarkcolor'] != $data['remarkcolor']) {
|
||
$save_data['remarkcolor'] = $data['remarkcolor'];
|
||
}
|
||
if (!$save_data) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先修改,再保存';
|
||
return $res;
|
||
}
|
||
$save = $data['table']->where(array('id' => $data['id'], 'merchantid' => $merchantid))->save($save_data);
|
||
if ($save) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '保存成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '保存失败';
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
public function open_template()
|
||
{ // 启用模板
|
||
$data = I('post.');
|
||
if (!$data['model'] || !$data['id'] || !$data['template_title'] || !$data['template_remark'] || !$data['template_id']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$data['titlecolor'] = !empty($data['titlecolor']) ? $data['titlecolor'] : '#000000';
|
||
$data['bodycolor'] = !empty($data['titlecolor']) ? $data['bodycolor'] : '#000000';
|
||
$data['remarkcolor'] = !empty($data['titlecolor']) ? $data['remarkcolor'] : '#000000';
|
||
switch ($data['model']) {
|
||
case 1:
|
||
$msg = '公众号模板-新版设置-会员卡激活';
|
||
$data['table'] = M('retail_template_do_card');
|
||
break;
|
||
case 2:
|
||
$msg = '公众号模板-新版设置-会员卡充值';
|
||
$data['table'] = M('retail_template_member_recharge');
|
||
break;
|
||
case 3:
|
||
$msg = '公众号模板-新版设置-会员消费';
|
||
$data['table'] = M('retail_template_member_consume');
|
||
break;
|
||
case 4:
|
||
$msg = '公众号模板-新版设置-优惠券发放';
|
||
$data['table'] = M('retail_template_discount_coupon');
|
||
break;
|
||
case 5:
|
||
$msg = '公众号模板-新版设置-退款通知';
|
||
$data['table'] = M('retail_template_refund');
|
||
break;
|
||
default:
|
||
$data['table'] = M('retail_do_card');
|
||
}
|
||
$result = $this->open_is_use($data);
|
||
if ($result['status'] == 1) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = $result['msg'];
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = $msg . '-开启模板使用';//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = $result['msg'];
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
protected function open_is_use($data) // 选择模板
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$template_find = $data['table']
|
||
->field('template_title,template_remark,template_id,titlecolor,bodycolor,remarkcolor')
|
||
->where(array('id' => $data['id'], 'is_use' => 0, 'merchantid' => $merchantid))
|
||
->find();
|
||
if (empty($template_find)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '模板查询失败';
|
||
return $res;
|
||
}
|
||
$template_get_ids = $data['table']->where(array('is_use' => 1, 'merchantid' => $merchantid))->getField('id', true);
|
||
if ($template_get_ids) {
|
||
foreach ($template_get_ids as &$val) {
|
||
$save_is_use = $data['table']->where(array('id' => $val))->setField('is_use', 0);
|
||
if (!$save_is_use) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '开启失败';
|
||
return $res;
|
||
}
|
||
}
|
||
}
|
||
if (!$template_find['template_id']) {
|
||
$save_data['template_id'] = $data['template_id'];
|
||
} else if ($template_find['template_id'] && $template_find['template_id'] != $data['template_id']) {
|
||
$save_data['template_id'] = $data['template_id'];
|
||
}
|
||
if ($template_find['template_title'] != $data['template_title']) {
|
||
$save_data['template_title'] = $data['template_title'];
|
||
}
|
||
if ($template_find['template_remark'] != $data['template_remark']) {
|
||
$save_data['template_remark'] = $data['template_remark'];
|
||
}
|
||
if ($template_find['titlecolor'] != $data['titlecolor']) {
|
||
$save_data['titlecolor'] = $data['titlecolor'];
|
||
}
|
||
if ($template_find['bodycolor'] != $data['bodycolor']) {
|
||
$save_data['bodycolor'] = $data['bodycolor'];
|
||
}
|
||
if ($template_find['remarkcolor'] != $data['remarkcolor']) {
|
||
$save_data['remarkcolor'] = $data['remarkcolor'];
|
||
}
|
||
$save_data['is_use'] = 1;
|
||
$save_is_use = $data['table']->where(array('id' => $data['id'], 'merchantid' => $merchantid))->save($save_data);
|
||
if ($save_is_use) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '开启成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '开启失败';
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
public function close_template()
|
||
{ // 关闭模板
|
||
$data = I('post.');
|
||
if (!$data['model'] || !$data['id']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
switch ($data['model']) {
|
||
case 1:
|
||
$msg = '公众号模板-新版设置-会员卡激活';
|
||
$data['table'] = M('retail_template_do_card');
|
||
break;
|
||
case 2:
|
||
$msg = '公众号模板-新版设置-会员卡充值';
|
||
$data['table'] = M('retail_template_member_recharge');
|
||
break;
|
||
case 3:
|
||
$msg = '公众号模板-新版设置-会员消费';
|
||
$data['table'] = M('retail_template_member_consume');
|
||
break;
|
||
case 4:
|
||
$msg = '公众号模板-新版设置-优惠券发放';
|
||
$data['table'] = M('retail_template_discount_coupon');
|
||
break;
|
||
case 5:
|
||
$msg = '公众号模板-新版设置-退款通知';
|
||
$data['table'] = M('retail_template_refund');
|
||
break;
|
||
default:
|
||
$data['table'] = M('retail_template_do_card');
|
||
}
|
||
$result = $this->close_is_use($data);
|
||
if ($result['status'] == 1) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = $result['msg'];
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = $msg . '-关闭模板使用';//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = $result['msg'];
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
protected function close_is_use($data) // 选择模板
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$template_find = $data['table']->where(array('id' => $data['id'], 'is_use' => 1, 'merchantid' => $merchantid))->find();
|
||
if (empty($template_find)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '模板查询失败';
|
||
return $res;
|
||
}
|
||
$set_is_use = $data['table']->where(array('id' => $data['id'], 'merchantid' => $merchantid))->setField('is_use', 0);
|
||
if ($set_is_use) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '关闭成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '关闭失败';
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 最新版模板设置
|
||
*/
|
||
public function getModelList()
|
||
{
|
||
$user = session("merchant_userinfo");
|
||
$merchant_id = $user['id'];
|
||
$MerchantTemplate = D('MerchantTemplate');
|
||
$map = array(
|
||
'merchant_id' => $merchant_id
|
||
);
|
||
$list = $MerchantTemplate->getSelect($map);
|
||
foreach ($list as &$val) {
|
||
$val['fields_json'] = json_decode($val['fields_json'], true);
|
||
if (!$val['fields_json']) {
|
||
$val['fields_json'] = array(
|
||
"first" => "",
|
||
"keyword_list" => array(),
|
||
"remark" => "",
|
||
"title" => "",
|
||
);
|
||
}
|
||
$val['type'] = intval($val['type']);
|
||
switch ($val['type']) {
|
||
case 1:
|
||
$val['type_name'] = '会员卡激活';
|
||
break;
|
||
case 2:
|
||
$val['type_name'] = '会员卡充值';
|
||
break;
|
||
case 3:
|
||
$val['type_name'] = '会员消费';
|
||
break;
|
||
case 4:
|
||
$val['type_name'] = '优惠券发放';
|
||
break;
|
||
case 5:
|
||
$val['type_name'] = '退款通知';
|
||
break;
|
||
}
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = '获取成功';
|
||
$res['template_list'] = $list;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 添加修改模板
|
||
*/
|
||
public function updateSet()
|
||
{
|
||
$MerchantTemplateModel = D('MerchantTemplate');
|
||
$merchant_id = session('merchant_userinfo')['id'];
|
||
$content = I("post.");
|
||
if (!$content['model_id'] || !$content['type'] || !$content['fields_json']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$fields_json = $content['fields_json'];
|
||
if (!$fields_json['keyword_list']) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请添加字段';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
foreach ($fields_json['keyword_list'] as $value) {
|
||
if (empty($value['key'])) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请输入字段键名';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
if (empty($value['value'])) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请选择字段键值';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
}
|
||
if (!empty($content['id'])) {
|
||
$map['id'] = array('neq', $content['id']);
|
||
}
|
||
$map['model_id'] = trim($content['model_id']);
|
||
$map['merchant_id'] = $merchant_id;
|
||
$info = $MerchantTemplateModel->getFind($map);
|
||
if ($info) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '已存在该模板ID';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$data = array(
|
||
'merchant_id' => $merchant_id,
|
||
'model_id' => $content['model_id'],
|
||
'type' => $content['type'],
|
||
'status' => $content['status'],
|
||
'fields_json' => json_encode($content['fields_json'])
|
||
);
|
||
if (!empty($content['id'])) {
|
||
$success = $MerchantTemplateModel->updateOrder(array('id' => $content['id']), $data);
|
||
} else {
|
||
$success = $MerchantTemplateModel->addOrder($data);
|
||
$content['id'] = $success;
|
||
}
|
||
if ($success) {
|
||
if ($content['status'] == 1) {
|
||
$this->saveTemplateStatus($content);
|
||
}
|
||
$res['status'] = 1;
|
||
$res['id'] = $content['id'];
|
||
$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'] = 1;
|
||
$res['msg'] = '暂无修改';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/*
|
||
* 改变其他模板状态
|
||
*/
|
||
public function saveTemplateStatus($content)
|
||
{
|
||
$MerchantTemplateModel = D('MerchantTemplate');
|
||
$map = array(
|
||
'merchant_id' => session('merchant_userinfo')['id'],
|
||
'type' => $content['type'],
|
||
'id' => array('neq', $content['id'])
|
||
);
|
||
$MerchantTemplateModel->updateOrder($map, array('status' => 0));
|
||
}
|
||
|
||
/*
|
||
* 修改状态
|
||
*/
|
||
public function saveState()
|
||
{
|
||
$MerchantTemplateModel = D('MerchantTemplate');
|
||
$content = I("post.");
|
||
if (!$content['id']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先保存';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$save = $MerchantTemplateModel->updateOrder(array('id' => $content['id']), array('status' => $content['status']));
|
||
if ($save) {
|
||
if ($content['status'] == 1) {
|
||
$this->saveTemplateStatus($content);
|
||
}
|
||
$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 deleteTemplate()
|
||
{
|
||
$merchant_id = session('merchant_userinfo')['id'];
|
||
$id = I('post.id');
|
||
if (!$id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$MerchantTemplateModel = D('MerchantTemplate');
|
||
$save = $MerchantTemplateModel->deleteOrder(array('id' => $id, 'merchant_id' => $merchant_id));
|
||
if ($save) {
|
||
$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 pushNews()
|
||
{
|
||
$data = I('post.');
|
||
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$TemplatePushNewsClass = new TemplatePushNews();
|
||
$result = $TemplatePushNewsClass->push($data);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
} |