1463 行
52 KiB
PHP
可执行文件
1463 行
52 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use Common\Business\VipEdit;
|
||
use Retail\Business\PlusVip;
|
||
use Think\Controller;
|
||
|
||
//[1.8.50]
|
||
|
||
class PlusController extends BaseController
|
||
{
|
||
/*
|
||
* ************************************************商户Plus会员列表*************************************************
|
||
*/
|
||
|
||
public function plusvip()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 商户-获取PLUS会员列表头部统计
|
||
*/
|
||
public function getPlusVipTotal()
|
||
{
|
||
$param = I('post.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['is_total'] = true;
|
||
$param['user_type'] = 1;
|
||
$PlusVip = new PlusVip();
|
||
$result = $PlusVip->getPlusVipTotal($param);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 商户-获取PLUS会员列表
|
||
*/
|
||
public function getPlusVipList()
|
||
{
|
||
$param = I('post.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['is_need_count'] = true;
|
||
$param['user_type'] = 1;
|
||
$PlusVip = new PlusVip();
|
||
$result = $PlusVip->getPlusVipList($param);
|
||
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 商户-PLUS会员-冻结
|
||
*/
|
||
public function frozenVip()
|
||
{
|
||
$VipEditClass = new VipEdit();
|
||
|
||
$this->ajaxReturn($VipEditClass->operateVipStatus([
|
||
'merchant_id' => $this->merchant_id,
|
||
'vip_id' => I('post.vip_id'),
|
||
'status' => 3,//1恢复 3冻结 4挂失
|
||
'plus_type' => 2,
|
||
'scene' => 3,//3商户 4门店
|
||
]));
|
||
}
|
||
|
||
/**
|
||
* 商户-PLUS会员挂失
|
||
*/
|
||
public function lossVip()
|
||
{
|
||
$VipEditClass = new VipEdit();
|
||
|
||
$this->ajaxReturn($VipEditClass->operateVipStatus([
|
||
'merchant_id' => $this->merchant_id,
|
||
'vip_id' => I('post.vip_id'),
|
||
'status' => 4,//1恢复 3冻结 4挂失
|
||
'plus_type' => 2,
|
||
'scene' => 3,//3商户 4门店
|
||
]));
|
||
}
|
||
|
||
/**
|
||
* 商户-PLUS会员恢复
|
||
*/
|
||
public function thawVip()
|
||
{
|
||
$VipEditClass = new VipEdit();
|
||
|
||
$this->ajaxReturn($VipEditClass->operateVipStatus([
|
||
'merchant_id' => $this->merchant_id,
|
||
'vip_id' => I('post.vip_id'),
|
||
'status' => 1,//1恢复 3冻结 4挂失
|
||
'plus_type' => 2,
|
||
'scene' => 3,//3商户 4门店
|
||
]));
|
||
}
|
||
|
||
/**
|
||
* 商户-修改PLUS会员支付密码
|
||
*/
|
||
public function modifyPassword()
|
||
{
|
||
$VipEditClass = new VipEdit();
|
||
|
||
$this->ajaxReturn($VipEditClass->editVipPassword([
|
||
'vip_id' => I('post.vip_id'),
|
||
'password' => I('post.password'),
|
||
'operator_type' => 1,
|
||
'user_type' => 3,
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'operator_id' => $this->login_user['id'],
|
||
]));
|
||
}
|
||
|
||
/**
|
||
* 商户-修改PLUS会员信息
|
||
*/
|
||
public function modifyVipInfo()
|
||
{
|
||
$data = I('post.');
|
||
$data['operator_type'] = 1;
|
||
$data['user_type'] = 3;
|
||
$data['operator_id'] = session("jurisdiction_user")['id'];
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$data['platform_type'] = $this->role_info['platform_type']?$this->role_info['platform_type']:1;
|
||
$VipEditClass = new VipEdit();
|
||
$this->ajaxReturn($VipEditClass->editInfo($data));
|
||
}
|
||
|
||
// 付费记录
|
||
public function plus_record($vip_id)
|
||
{
|
||
$this->assign('vip_id', $vip_id);
|
||
$this->display();
|
||
}
|
||
|
||
/*获取付费记录
|
||
*@param $vip_id 会员id
|
||
*@return array
|
||
* */
|
||
public function getRecord()
|
||
{
|
||
$vip_id = I('post.vip_id');
|
||
if (!$vip_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数缺失';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$record = M('retail_plus_record')->where(array('vip_id' => $vip_id, 'pay_state' => 1))->select();
|
||
if (!$record) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无数据';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
foreach ($record as &$val) {
|
||
$val['addtime'] = date('Y-m-d H:m:s', $val['addtime']);
|
||
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;
|
||
case 6:
|
||
$val['type_name'] = '购买套餐';
|
||
break;
|
||
default:
|
||
$val['type_name'] = '其他';
|
||
}
|
||
switch ($val['pay_type']) {
|
||
case 1:
|
||
$val['pay_type_name'] = '微信支付';
|
||
break;
|
||
case 2:
|
||
$val['pay_type_name'] = '余额支付';
|
||
break;
|
||
case 3:
|
||
$val['pay_type_name'] = '支付宝支付';
|
||
break;
|
||
case 4:
|
||
$val['pay_type_name'] = '现金支付';
|
||
break;
|
||
case 5:
|
||
$val['pay_type_name'] = '其他支付';
|
||
break;
|
||
default:
|
||
$val['pay_type_name'] = '其他支付';
|
||
}
|
||
}
|
||
$res['status'] = 1;
|
||
$res['record'] = $record;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/*
|
||
* ********************************************************** 导出 **********************************************
|
||
*/
|
||
/**
|
||
* 商户-导出PLUS会员
|
||
*/
|
||
public function exportVip()
|
||
{
|
||
$param = I('get.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['is_export'] = true;
|
||
$param['user_type'] = 1;
|
||
$PlusVip = new PlusVip();
|
||
$result = $PlusVip->getPlusVipList($param);
|
||
$filename = 'Plus成员';
|
||
$headerArr = array(
|
||
array('index', '序号'),
|
||
array('name', '会员姓名'),
|
||
array('nickname', '会员昵称'),
|
||
array('mobile_phone', '手机号'),
|
||
array('integral', '积分'),
|
||
array('balance', '余额(元)'),
|
||
array('birthday', '生日'),
|
||
array('add_time', '注册时间'),
|
||
array('start_time', '开始时间'),
|
||
array('end_time', '到期时间'),
|
||
array('store_name', '门店'),
|
||
array('state_name', '状态'),
|
||
);
|
||
$str = $filename . '导出时间' . date('Y-m-d', time());
|
||
getExcel($filename, $headerArr, $result['data']['list'], $str);
|
||
}
|
||
|
||
/*
|
||
* **********************************************************plus会员设置******************************************
|
||
*/
|
||
public function index()
|
||
{
|
||
$merchantid = session("ls_userinfo")['merchantid'];
|
||
$where['merchantid'] = $merchantid;
|
||
$plus_info = M('retail_plus_set')->where($where)->find();
|
||
if ($plus_info) {
|
||
$gallery_path = M('image_gallery')->where(array('id' => $plus_info['gallery_id']))->getField("path");
|
||
$renew_gallery_path = M('image_gallery')->where(array('id' => $plus_info['renew_gallery_id']))->getField("path");
|
||
$this->assign('gallery_path', $gallery_path);
|
||
$this->assign('renew_gallery_path', $renew_gallery_path);
|
||
$this->assign('plus_info', $plus_info);
|
||
}
|
||
$arr = array(
|
||
'switch_operation' => '/index.php/Retail/Plus/switch_operation',
|
||
'getGalleryImages' => '/index.php/Retail/Plus/getGalleryImages',
|
||
'onSubmit' => '/index.php/Retail/Plus/onSubmit',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
public function switch_operation()
|
||
{
|
||
$merchantid = session("ls_userinfo")['merchantid'];
|
||
$switch_state = I('post.switch_state');
|
||
if (!$switch_state) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时,请重新登录';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$plus_info = M('retail_plus_set')->where(array('merchantid' => $merchantid))->find();
|
||
$content['switch_type'] = $switch_state;
|
||
$content['addtime'] = time();
|
||
if ($plus_info) {
|
||
if ($switch_state == 1) {
|
||
$where['merchantid'] = $merchantid;
|
||
$where['end_time'] = array('egt', time());
|
||
$where['status'] = 1;
|
||
$plus_existence = M('retail_plus_vip')->where($where)->find();
|
||
if ($plus_existence) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '已存在有效plus会员无法关闭';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
if ($plus_info['purchase_switch_type'] == 2) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '直接购买plus会员未关闭';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
if ($plus_info['renew_purchase_switch_type'] == 2) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '续费购买plus会员未关闭';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
if ($plus_info['recharge_switch_type'] == 2) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '初次充值为plus会员未关闭';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
if ($plus_info['renew_recharge_switch_type'] == 2) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '续费充值为plus会员未关闭';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
if ($plus_info['goods_switch_type'] == 2) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '单个plus商品未关闭';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
if ($plus_info['goods_group_switch_type'] == 2) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '套餐plus商品未关闭';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
}
|
||
$ret = M('retail_plus_set')->where(array('merchantid' => $merchantid))->save($content);
|
||
} else {
|
||
$content['merchantid'] = $merchantid;
|
||
$ret = M('retail_plus_set')->add($content);
|
||
}
|
||
if ($ret) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = 'Plus会员功能的总开关操作'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
// 文件上传
|
||
public function setDefaultImg()
|
||
{
|
||
$user = session('ls_userinfo');
|
||
$merchantid = $user['merchantid'];
|
||
if (!empty($user) && IS_POST) {
|
||
$type = I('post.type');
|
||
if (!$type) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
if ($type == 1) {
|
||
$image_id = I('post.image_id');
|
||
} else if ($type == 2) {
|
||
$image_id = I('post.image_two_id');
|
||
}
|
||
if ($type == 1) {
|
||
$file_image = $_FILES['image']['error'];
|
||
} else if ($type == 2) {
|
||
$file_image = $_FILES['image_two']['error'];
|
||
}
|
||
if ((empty($_FILES) || $file_image != 0) && !$image_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请选择图片';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if ($file_image == 0) {
|
||
$item = array(
|
||
'add_time' => time(),
|
||
'from_type_id' => 36,
|
||
'localUrl' => 'Plus/image',
|
||
'user_type' => 3,
|
||
'merchant_id' => $merchantid
|
||
);
|
||
$uploads = uploadFiles($item);
|
||
if ($type == 1) {
|
||
if (!empty($uploads['image']['savePath'])) {
|
||
$image_id = $uploads['image']['id'];
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '图片上传失败,请重试';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
} else if ($type == 2) {
|
||
if (!empty($uploads['image_two']['savePath'])) {
|
||
$image_id = $uploads['image_two']['id'];
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '图片上传失败,请重试';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
}
|
||
$where['merchantid'] = $merchantid;
|
||
$plus_info = M('retail_plus_set')->where($where)->find();
|
||
if ($type == 1) { //初始化
|
||
$content['gallery_id'] = $image_id;
|
||
} else if ($type == 2) { //续费
|
||
$content['renew_gallery_id'] = $image_id;
|
||
}
|
||
$content['addtime'] = time();
|
||
if ($plus_info) {
|
||
$ret = M('retail_plus_set')->where($where)->save($content);
|
||
} else {
|
||
$content['merchantid'] = $merchantid;
|
||
$ret = M('retail_plus_set')->add($content);
|
||
}
|
||
if ($ret) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '设置成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '设置失败';
|
||
}
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//初始化保存
|
||
public function onSubmit()
|
||
{
|
||
$merchantid = session("ls_userinfo")['merchantid'];
|
||
$text = I('post.text');
|
||
$type = I('post.type');
|
||
$where['merchantid'] = $merchantid;
|
||
$plus_info = M('retail_plus_set')->where($where)->find();
|
||
if ($type == 1) { //初始化
|
||
$msg = '初始化引导设置进行编辑';
|
||
$content['text'] = $text;
|
||
} else if ($type == 2) { //续费
|
||
$msg = '续费引导设置进行编辑';
|
||
$content['renew_text'] = $text;
|
||
}
|
||
$content['addtime'] = time();
|
||
if ($plus_info) {
|
||
$ret = M('retail_plus_set')->where($where)->save($content);
|
||
} else {
|
||
$content['merchantid'] = $merchantid;
|
||
$ret = M('retail_plus_set')->add($content);
|
||
}
|
||
if ($ret) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = 'Plus会员设置:' . $msg; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无修改';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
/*
|
||
* ****************************************plus会员管理*************************************************
|
||
*/
|
||
|
||
//plus会员管理页面
|
||
public function administration()
|
||
{
|
||
$merchant_id = session("ls_userinfo")['merchantid'];
|
||
$where['merchantid'] = $merchant_id;
|
||
$plus_info = M('retail_plus_set')->where($where)->find();
|
||
$where['state'] = 0;
|
||
$store_info = M('retail_store')->field("id,storetag")->where($where)->select();
|
||
$this->assign('store_info', json_encode($store_info));
|
||
$this->assign('plus_info', $plus_info);
|
||
$arr = array(
|
||
'preservation' => '/index.php/Retail/Plus/preservation',
|
||
'shop_goods_deposit' => '/index.php/Retail/Plus/shop_goods_deposit',
|
||
'delPromotion' => '/index.php/Retail/Plus/delPromotion',
|
||
'shop_goods_group_deposit' => '/index.php/Retail/Plus/shop_goods_group_deposit',
|
||
'groupGoods' => '/index.php/Retail/Plus/groupGoods',
|
||
'delMealGroup' => '/index.php/Retail/Plus/delMealGroup',
|
||
'delete_group_goods' => '/index.php/Retail/Plus/delete_group_goods',
|
||
'group_goods_add' => '/index.php/Retail/Plus/group_goods_add',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
//套餐开关设置
|
||
public function preservation()
|
||
{
|
||
$merchant_id = session("ls_userinfo")['merchantid'];
|
||
$data = I('post.');
|
||
$plus_info = M('retail_plus_set')->where(array('merchantid' => $merchant_id))->find();
|
||
if (!$merchant_id || !$data) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时,请重新登录';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if ($data['recharge_switch_type'] == 2 || $data['purchase_switch_type'] == 2 || $data['renew_purchase_switch_type'] == 2 || $data['goods_switch_type'] == 2 || $data['renew_recharge_switch_type'] == 2 || $data['goods_group_switch_type'] == 2) {
|
||
$plus_switch_type = $plus_info['switch_type'];
|
||
if ($plus_switch_type != 2) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先开启plus会员';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
$content['recharge_switch_type'] = $data['recharge_switch_type'];
|
||
$content['purchase_switch_type'] = $data['purchase_switch_type'];
|
||
$content['renew_purchase_switch_type'] = $data['renew_purchase_switch_type'];
|
||
$content['goods_switch_type'] = $data['goods_switch_type'];
|
||
$content['renew_recharge_switch_type'] = $data['renew_recharge_switch_type'];
|
||
$content['goods_group_switch_type'] = $data['goods_group_switch_type'];
|
||
|
||
$content['addtime'] = time();
|
||
if ($plus_info) { //编辑
|
||
$ret = M('retail_plus_set')->where(array('merchantid' => $merchant_id))->save($content);
|
||
} else { //添加
|
||
$content['merchantid'] = $merchant_id;
|
||
$ret = M('retail_plus_set')->add($content);
|
||
}
|
||
if ($ret) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = 'Plus会员管理-基本设置修改'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//获取购买指定商品送plus会员套餐列表
|
||
public function plus_goods_show()
|
||
{
|
||
$merchant_id = session('ls_userinfo')['merchantid'];
|
||
$home_store_id = I('post.home_store_id');
|
||
$home_goods_query = I('post.home_goods_query');
|
||
$p = I('post.page');
|
||
$l = I('post.limit');
|
||
if (!empty($home_store_id)) {
|
||
$where['p.storeid'] = $home_store_id;
|
||
}
|
||
if (!empty($home_goods_query)) {
|
||
$map['goods_name|goods_number'] = $home_goods_query;
|
||
$map['merchant_id'] = $merchant_id;
|
||
$goods_id_arr = M('retail_goods')->where($map)->getField("id", true);
|
||
if ($goods_id_arr) {
|
||
$where['p.goods_id'] = array('in', $goods_id_arr);
|
||
} else {
|
||
$where['p.goods_id'] = 0;
|
||
}
|
||
}
|
||
$where['p.merchantid'] = $merchant_id;
|
||
$where['p.status'] = 1;
|
||
$goods_info = M('retail_single_plus_goods as p')
|
||
->join('ls_retail_goods as g on p.goods_id=g.id')
|
||
->where($where)
|
||
->page($p, $l)
|
||
->order('id desc')
|
||
->field("p.*,g.goods_name,g.goods_number,g.goods_code")
|
||
->select();
|
||
if ($goods_info) {
|
||
$count = M('retail_single_plus_goods as p')
|
||
->join('ls_retail_goods as g on p.goods_id=g.id')
|
||
->where($where)
|
||
->count();
|
||
foreach ($goods_info as $key => &$val) {
|
||
$val['storetag'] = M('retail_store')->where(array('id' => $val['storeid']))->getField("storetag");
|
||
}
|
||
}
|
||
$res['page'] = (int)$p;
|
||
$res['count'] = $count ? (int)$count : 0;
|
||
$res['info'] = $goods_info ? $goods_info : array();
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//删除指定商品
|
||
public function delPromotion()
|
||
{
|
||
$merchant_id = session('ls_userinfo')['merchantid'];
|
||
$id = I('post.id');
|
||
if (!$merchant_id || !$id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时,请重新登录';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$where['id'] = $id;
|
||
$save = M('retail_single_plus_goods')->where($where)->save(array('status' => 2));
|
||
if ($save) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = 'Plus会员管理-商品删除成功'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//获取门店中可添加的商品
|
||
public function store_goods()
|
||
{
|
||
$merchant_id = session('ls_userinfo')['merchantid'];
|
||
$store_id = I('post.store_id');
|
||
if (!$store_id || !$merchant_id) {
|
||
$res['status'] = 2;
|
||
$res['msg'] = '请选择门店';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$goods_query = I('post.goods_query');
|
||
$p = I('post.page');
|
||
$l = I('post.limit');
|
||
if (!empty($goods_query)) {
|
||
$where['goods_name|goods_number'] = array('like', $goods_query . '%');
|
||
}
|
||
$map['merchantid'] = $merchant_id;
|
||
$map['storeid'] = $store_id;
|
||
$map['status'] = 1;
|
||
$goods_ids = M('retail_single_plus_goods')->where($map)->getField("goods_id", true); //单个plus商品
|
||
if (!empty($goods_ids)) {
|
||
$where['id'] = array('not in', $goods_ids);
|
||
}
|
||
$wap['merchantid'] = $merchant_id;
|
||
$wap['storeid'] = $store_id;
|
||
$wap['status'] = 1;
|
||
$goods_group_ids = M('retail_meal_plus_goods')->where($wap)->getField("goods_id", true); //套餐组plus商品
|
||
if (!empty($goods_group_ids)) {
|
||
$where['id'] = array('not in', $goods_group_ids);
|
||
}
|
||
if (!empty($goods_ids) && !empty($goods_group_ids)) {
|
||
$id_arr = array_merge($goods_ids, $goods_group_ids);
|
||
$where['id'] = array('not in', $id_arr);
|
||
}
|
||
$where['merchant_id'] = $merchant_id;
|
||
$where['store_id'] = $store_id;
|
||
$where['status'] = 0;
|
||
$where['online_state'] = 1;
|
||
$field = array(
|
||
'id',
|
||
'goods_name',
|
||
'goods_code',
|
||
'goods_number',
|
||
);
|
||
$goods_info = M('retail_goods')->where($where)->page($p, $l)->field($field)->order('id desc')->select();
|
||
if ($goods_info) {
|
||
$count = M('retail_goods')->where($where)->count();
|
||
$res['status'] = 1;
|
||
$res['info'] = $goods_info;
|
||
$res['page'] = (int)$p;
|
||
$res['store_len'] = (int)$count;
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['info'] = array();
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//添加购买指定商品送次卡
|
||
public function shop_goods_deposit()
|
||
{
|
||
$merchant_id = session('ls_userinfo')['merchantid'];
|
||
$shop_goods_id = I('post.shop_goods_id');
|
||
$store_id = I('post.store_id');
|
||
$goods_time = I('post.goods_time');
|
||
if (!$merchant_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时,请重新登录';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (!verifyNumber($goods_time, 0, 1, 9999)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '天数设置有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$plus_switch_type = M('retail_plus_set')->where(array('merchantid' => $merchant_id))->getField("switch_type");
|
||
if ($plus_switch_type != 2) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请先开启plus会员';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (!$store_id || !$shop_goods_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请选择商品';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (count($shop_goods_id) > 5) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '最多可添加5种该类型商品';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$where['merchantid'] = $merchant_id;
|
||
$where['storeid'] = $store_id;
|
||
$where['status'] = 1;
|
||
$plus_count = M('retail_single_plus_goods')->where($where)->count();
|
||
if ($plus_count >= 5) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '最多可添加5种该类型商品';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$arr_count = count($shop_goods_id);
|
||
$arr_count = $arr_count + $plus_count;
|
||
if ($arr_count > 5) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '最多可添加5种该类型商品';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$where['goods_id'] = array('in', $shop_goods_id);
|
||
$plus_goods_count = M('retail_single_plus_goods')->where($where)->count();
|
||
if ($plus_goods_count > 0) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '已存在选中plus商品';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$time = time();
|
||
$content = array();
|
||
$content['merchantid'] = $merchant_id;
|
||
$content['storeid'] = $store_id;
|
||
$content['status'] = 1;
|
||
$content['addtime'] = $time;
|
||
$content['time'] = $goods_time;
|
||
foreach ($shop_goods_id as $key => &$val) {
|
||
$content['goods_id'] = $val;
|
||
$add = M('retail_single_plus_goods')->add($content);
|
||
}
|
||
if ($add) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = 'Plus会员管理-添加购买指定商品送次卡'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/*
|
||
* ****************************************门店plus会员***********************************************
|
||
*/
|
||
/**
|
||
* 门店-PLUS会员列表展示页面
|
||
*/
|
||
public function store_plusvip()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 门店-获取PLUS会员列表头部统计
|
||
*/
|
||
public function getStorePlusVipTotal()
|
||
{
|
||
$param = I('post.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['store_id'] = $this->store_id;
|
||
$param['is_total'] = true;
|
||
$param['user_type'] = 2;
|
||
$PlusVip = new PlusVip();
|
||
$this->ajaxReturn($PlusVip->getPlusVipTotal($param));
|
||
}
|
||
|
||
/**
|
||
* 门店-获取PLUS会员列表
|
||
*/
|
||
public function getStorePlusVipList()
|
||
{
|
||
$param = I('post.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
if (self::$global_store_jurisdiction['store_show_vip_info'] != 1) {
|
||
//门店无显示所有会员权限时,限制门店ID
|
||
$param['store_id'] = $this->store_id;
|
||
}
|
||
$param['is_need_count'] = true;
|
||
$param['user_type'] = 2;
|
||
$PlusVip = new PlusVip();
|
||
|
||
$this->ajaxReturn($PlusVip->getPlusVipList($param));
|
||
}
|
||
|
||
/**
|
||
* 门店-PLUS会员挂失
|
||
*/
|
||
public function storeLossVip()
|
||
{
|
||
$VipEditClass = new VipEdit();
|
||
|
||
$this->ajaxReturn($VipEditClass->operateVipStatus([
|
||
'merchant_id' => $this->merchant_id,
|
||
'vip_id' => I('post.vip_id'),
|
||
'status' => 4,//1恢复 3冻结 4挂失
|
||
'plus_type' => 2,
|
||
'scene' => 4,//3商户 4门店
|
||
]));
|
||
}
|
||
|
||
/**
|
||
* 门店-PLUS会员冻结
|
||
*/
|
||
public function storeFrozenVip()
|
||
{
|
||
$VipEditClass = new VipEdit();
|
||
|
||
$this->ajaxReturn($VipEditClass->operateVipStatus([
|
||
'merchant_id' => $this->merchant_id,
|
||
'vip_id' => I('post.vip_id'),
|
||
'status' => 3,//1恢复 3冻结 4挂失
|
||
'plus_type' => 2,
|
||
'scene' => 4,//3商户 4门店
|
||
]));
|
||
}
|
||
|
||
/**
|
||
* 门店-PLUS会员恢复
|
||
*/
|
||
public function storeThawVip()
|
||
{
|
||
$VipEditClass = new VipEdit();
|
||
|
||
$this->ajaxReturn($VipEditClass->operateVipStatus([
|
||
'merchant_id' => $this->merchant_id,
|
||
'vip_id' => I('post.vip_id'),
|
||
'status' => 1,//1恢复 3冻结 4挂失
|
||
'plus_type' => 2,
|
||
'scene' => 4,//3商户 4门店
|
||
]));
|
||
}
|
||
|
||
/**
|
||
* 门店-修改PLUS会员密码
|
||
*/
|
||
public function storeModifyPassword()
|
||
{
|
||
$VipEditClass = new VipEdit();
|
||
$this->ajaxReturn($VipEditClass->editVipPassword([
|
||
'vip_id' => I('post.vip_id'),
|
||
'password' => I('post.password'),
|
||
'operator_type' => 1,
|
||
'user_type' => 4,
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'operator_id' => $this->login_user['id'],
|
||
]));
|
||
}
|
||
|
||
/**
|
||
* 门店-修改PLUS会员信息
|
||
*/
|
||
public function storeModifyVipInfo()
|
||
{
|
||
$data = I('post.');
|
||
$data['operator_type'] = 1;
|
||
$data['user_type'] = 4;
|
||
$data['operator_id'] = session("jurisdiction_user")['id'];
|
||
$data['merchant_id'] = $this->merchant_id;
|
||
$data['store_id'] = $this->store_id;
|
||
$data['platform_type'] = $this->role_info['platform_type']?$this->role_info['platform_type']:1;
|
||
$VipEditClass = new VipEdit();
|
||
$this->ajaxReturn($VipEditClass->editInfo($data));
|
||
}
|
||
|
||
/**
|
||
* 门店-导出PLUS会员信息
|
||
*/
|
||
public function storeExportVip()
|
||
{
|
||
$param = I('get.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
if (self::$global_store_jurisdiction['store_show_vip_info'] != 1) {
|
||
//门店无显示所有会员权限时,限制门店ID
|
||
$param['store_id'] = $this->store_id;
|
||
}
|
||
$param['is_export'] = true;
|
||
$param['user_type'] = 2;
|
||
$PlusVip = new PlusVip();
|
||
$result = $PlusVip->getPlusVipList($param);
|
||
$filename = 'Plus成员';
|
||
$hearArr = array(
|
||
array('index', '序号'),
|
||
array('name', '会员姓名'),
|
||
array('nickname', '会员昵称'),
|
||
array('mobile_phone', '手机号'),
|
||
array('integral', '积分'),
|
||
array('balance', '余额(元)'),
|
||
array('card_key', '实体卡号'),
|
||
array('birthday', '生日'),
|
||
array('add_time', '注册时间'),
|
||
array('start_time', '开始时间'),
|
||
array('end_time', '到期时间'),
|
||
array('user_label', '会员标签'),
|
||
array('guide_name', '所属导购'),
|
||
array('store_name', '门店'),
|
||
array('state_name', '状态'),
|
||
);
|
||
$str = $filename . '导出时间' . date('Y-m-d', time());
|
||
getExcel($filename, $hearArr, $result['data']['list'], $str);
|
||
}
|
||
|
||
// 付费记录
|
||
public function store_plus_record($vip_id)
|
||
{
|
||
$this->assign('vip_id', $vip_id);
|
||
$this->display();
|
||
}
|
||
|
||
/*
|
||
* 套餐模块****************************************************************************************
|
||
*/
|
||
public function plus_meal_group_goods_show()
|
||
{
|
||
$merchantid = session("ls_userinfo")['merchantid'];
|
||
$meal_name = I('post.meal_name');
|
||
$store_id = I('post.store_id');
|
||
if (!empty($meal_name)) {
|
||
$where['m.meal_name'] = array('like', '%' . $meal_name . '%');
|
||
}
|
||
if (!empty($store_id)) {
|
||
$where['m.storeid'] = $store_id;
|
||
}
|
||
$p = I('post.page');
|
||
$l = I('post.limit');
|
||
$where['m.merchantid'] = $merchantid;
|
||
$where['m.status'] = 1;
|
||
$plus_group_info = M('retail_plus_meal_group as m')
|
||
->join('ls_retail_store as s on m.storeid=s.id')
|
||
->where($where)
|
||
->page($p, $l)
|
||
->field('m.*,s.storetag')
|
||
->select();
|
||
if ($plus_group_info) {
|
||
$count = M('retail_plus_meal_group as m')
|
||
->join('ls_retail_store as s on m.storeid=s.id')
|
||
->where($where)
|
||
->count();
|
||
} else {
|
||
$count = 0;
|
||
}
|
||
$res['status'] = 1;
|
||
$res['info'] = $plus_group_info;
|
||
$res['count'] = $count ? (int)$count : 0;
|
||
$res['page'] = (int)$p;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//套餐图片上传
|
||
public function image_upload()
|
||
{
|
||
$merchantid = session("ls_userinfo")['merchantid'];
|
||
$data = I('post.');
|
||
$meal_name = $data['meal_name'];
|
||
$image_id = $data['logo_id'];
|
||
if (!$meal_name) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请输入套餐名称';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
if ((empty($_FILES) || $_FILES['logo']['error'] !== 0) && !$data['logo_id']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '未上传图片';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
if ($_FILES['logo']['error'] == 0) {
|
||
$item = array(
|
||
'add_time' => time(),
|
||
'from_type_id' => 39,
|
||
'localUrl' => 'Merchant/Plus',
|
||
'user_type' => 3,
|
||
'merchant_id' => $merchantid
|
||
);
|
||
$uploads = uploadFiles($item);
|
||
if (empty($uploads['logo']['savePath'])) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '图片上传失败';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$image_id = $uploads['logo']['id'];
|
||
}
|
||
$res['image_id'] = $image_id;
|
||
$res['meal_name'] = $meal_name;
|
||
$res['status'] = 1;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//保存
|
||
public function shop_goods_group_deposit()
|
||
{
|
||
$merchant_id = session("ls_userinfo")['merchantid'];
|
||
$store_id = I('post.store_id');
|
||
$shop_goods_id = I('post.shop_goods_id');
|
||
$meal_name = I('post.meal_name');
|
||
$image_id = I('post.image_id');
|
||
$goods_time = I('post.goods_time');
|
||
$time = time();
|
||
if (!$merchant_id || !$store_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (!$meal_name) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请输入套餐名称';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (!verifyNumber($goods_time, 0, 1, 9999)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请输入正确的天数';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (!$shop_goods_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请选择商品';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$map = array(
|
||
'merchantid' => $merchant_id,
|
||
'storeid' => $store_id,
|
||
'status' => 1,
|
||
);
|
||
$count = M('retail_plus_meal_group')->where($map)->count();
|
||
if ($count > 10) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '每个门店只能添加10个套餐组';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$content = array(
|
||
'merchantid' => $merchant_id,
|
||
'storeid' => $store_id,
|
||
'meal_name' => $meal_name,
|
||
'image_id' => $image_id,
|
||
'status' => 1,
|
||
'addtime' => $time,
|
||
'time' => $goods_time,
|
||
);
|
||
$add = M('retail_plus_meal_group')->add($content);
|
||
if ($add) {
|
||
$goods_data = array(
|
||
'merchantid' => $merchant_id,
|
||
'storeid' => $store_id,
|
||
'status' => 1,
|
||
'addtime' => $time,
|
||
'group_id' => $add,
|
||
);
|
||
foreach ($shop_goods_id as $key => &$val) {
|
||
$goods_data['goods_id'] = $val;
|
||
M('retail_meal_plus_goods')->add($goods_data);
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = 'Plus会员管理-添加购买商品套餐成为Plus会员'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '保存失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//套餐删除
|
||
public function delMealGroup()
|
||
{
|
||
$id = I('post.id');
|
||
$group_save = M('retail_plus_meal_group')->where(array('id' => $id))->save(array('status' => 2));
|
||
if ($group_save) {
|
||
$goods_save = M('retail_meal_plus_goods')->where(array('group_id' => $id))->save(array('status' => 2));
|
||
if ($goods_save) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = 'Plus会员管理-套餐删除成功'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '套餐删除成功,商品删除失败';
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = 'Plus会员管理-套餐删除成功,商品删除失败'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//查看套餐中的商品
|
||
public function groupGoods()
|
||
{
|
||
$merchantid = session("ls_userinfo")['merchantid'];
|
||
$id = I('post.id');
|
||
$p = I('post.page');
|
||
$l = I('post.limit');
|
||
if (!$merchantid || !$id) {
|
||
$res['status'] = 0;
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$where['m.status'] = 1;
|
||
$where['m.merchantid'] = $merchantid;
|
||
$where['m.group_id'] = $id;
|
||
$info = M('retail_meal_plus_goods as m')
|
||
->join('ls_retail_goods as g on m.goods_id=g.id')
|
||
->where($where)
|
||
->page($p, $l)
|
||
->field('m.*,g.goods_name,g.goods_number,g.goods_code,g.online_state')
|
||
->select();
|
||
if ($info) {
|
||
$count = M('retail_meal_plus_goods as m')
|
||
->join('ls_retail_goods as g on m.goods_id=g.id')
|
||
->where($where)
|
||
->count();
|
||
} else {
|
||
$count = 0;
|
||
}
|
||
$res['status'] = 1;
|
||
$res['info'] = $info;
|
||
$res['len'] = $count ? (int)$count : 0;
|
||
$res['page'] = (int)$p;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//删除套餐中的商品
|
||
public function delete_group_goods()
|
||
{
|
||
$id = I('post.id');
|
||
$group_id = I('post.group_id');
|
||
if (!$id || !$group_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$where['group_id'] = $group_id;
|
||
$where['status'] = 1;
|
||
$group_count = M('retail_meal_plus_goods')->where($where)->count();
|
||
if ($group_count == 1) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '套餐中至少有一件商品';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$save = M('retail_meal_plus_goods')->where(array('id' => $id))->save(array('status' => 2));
|
||
if ($save) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '操作失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//添加套餐中的商品
|
||
public function group_goods_add()
|
||
{
|
||
$time = time();
|
||
$group_id = I('post.group_id');
|
||
$shop_goods_id = I('post.shop_goods_id');
|
||
$store_id = I('post.store_id');
|
||
if (!$group_id || !$shop_goods_id || !$store_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时,请刷新重试';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$meal_info = M('retail_plus_meal_group')->where(array('id' => $group_id, 'status' => 1))->find();
|
||
if ($meal_info) {
|
||
if ($meal_info['storeid'] != $store_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请选择该套餐所在门店的商品';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$meal_goods_count = M('retail_meal_plus_goods')->where(array('group_id' => $group_id, 'status' => 1))->count(); //套餐中的商品
|
||
if ($meal_goods_count >= 10) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '套餐最多添加10件商品';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$taotal_count = $meal_goods_count + count($shop_goods_id); //套餐中商品与添加的商品总数量
|
||
if ($taotal_count > 10) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '套餐最多添加10件商品';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$group_old_goods = M('retail_meal_plus_goods')->where(array('group_id' => $group_id, 'status' => 1, 'goods_id' => array('in', $shop_goods_id)))->select();
|
||
if ($group_old_goods) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '该套餐已存在该商品';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$goods_data = array();
|
||
$goods_data['merchantid'] = $meal_info['merchantid'];
|
||
$goods_data['storeid'] = $meal_info['storeid'];
|
||
$goods_data['status'] = 1;
|
||
$goods_data['addtime'] = $time;
|
||
$goods_data['group_id'] = $meal_info['id'];
|
||
foreach ($shop_goods_id as $key => &$val) {
|
||
$goods_data['goods_id'] = $val;
|
||
M('retail_meal_plus_goods')->add($goods_data);
|
||
}
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时,请刷新重试';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 获取plus会员活动
|
||
*/
|
||
public function getPlusActivity()
|
||
{
|
||
$merchant_id = session('merchant_userinfo')['id'];
|
||
$page = I('post.page');
|
||
$limit = I('post.limit');
|
||
$activityType = I('post.activityType');
|
||
if (!$page || !$limit || !empty($activityType) && !in_array($activityType, array('1', '2'))) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请求参数有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$PlusActivityModel = D('PlusActivity');
|
||
$map = array(
|
||
$PlusActivityModel::MERCHANT_ID => $merchant_id,
|
||
$PlusActivityModel::STATE => 1,
|
||
);
|
||
if (!empty($activityType)) {
|
||
$map[$PlusActivityModel::TYPE] = $activityType;
|
||
}
|
||
$list = $PlusActivityModel->getSelect($map, '*', $PlusActivityModel::ID . ' desc', $page . ',' . $limit);
|
||
$count = $PlusActivityModel->getCount($map);
|
||
foreach ($list as &$value) {
|
||
$value[$PlusActivityModel::ADD_TIME] = date('Y-m-d H:i:s', $value[$PlusActivityModel::ADD_TIME]);
|
||
}
|
||
$res['count'] = $count;
|
||
$res['data'] = $list;
|
||
$res['status'] = 1;
|
||
$res['msg'] = '获取成功';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 添加plus会员活动
|
||
*/
|
||
public function addActivity()
|
||
{
|
||
$merchant_id = session('merchant_userinfo')['id'];
|
||
$time = I('post.time');
|
||
$time_name = I('post.time_name');
|
||
$type = I('post.type');
|
||
$price = I('post.price');
|
||
$status = I('post.status');
|
||
if (!$time_name || !$type || !in_array($status, array('0', '1')) || !$time || !$price) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (!preg_match("/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d{0,2})$/", $price)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '价格有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if (!preg_match("/(^[1-9]{1,4}$)|(^[1-9]{0,1}[0-9]{0,3}$)/", $time)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '天数有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$PlusActivityModel = D('PlusActivity');
|
||
if ($status == 1) {
|
||
$map = array(
|
||
$PlusActivityModel::MERCHANT_ID => $merchant_id,
|
||
$PlusActivityModel::STATE => 1,
|
||
$PlusActivityModel::STATUS => 1,
|
||
$PlusActivityModel::TYPE => $type,
|
||
$PlusActivityModel::TIME => $time,
|
||
);
|
||
$old = $PlusActivityModel->getFind($map);
|
||
if (!empty($old)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '不能开启相同时间的套餐哦';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
$item = array(
|
||
$PlusActivityModel::MERCHANT_ID => $merchant_id,
|
||
$PlusActivityModel::STATE => 1,
|
||
$PlusActivityModel::STATUS => $status,
|
||
$PlusActivityModel::PRICE => $price,
|
||
$PlusActivityModel::TIME => $time,
|
||
$PlusActivityModel::TYPE => $type,
|
||
$PlusActivityModel::TIME_NAME => $time_name,
|
||
$PlusActivityModel::ADD_TIME => time(),
|
||
);
|
||
$add = $PlusActivityModel->addOrder($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 = 'Plus会员管理-添加直接购买Plus会员套餐'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '添加失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 开启关闭plus会员套餐
|
||
*/
|
||
public function changeActivity()
|
||
{
|
||
$merchant_id = session('merchant_userinfo')['id'];
|
||
$id = I('post.id');
|
||
$status = I('post.status');
|
||
if (!$id || !in_array($status, array('0', '1'))) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$PlusActivityModel = D('PlusActivity');
|
||
$cMap = array(
|
||
$PlusActivityModel::MERCHANT_ID => $merchant_id,
|
||
$PlusActivityModel::STATE => 1,
|
||
$PlusActivityModel::ID => $id,
|
||
);
|
||
$activity = $PlusActivityModel->getFind($cMap);
|
||
if (empty($activity)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '操作有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
if ($status == 1) {
|
||
$oMap = array(
|
||
$PlusActivityModel::MERCHANT_ID => $merchant_id,
|
||
$PlusActivityModel::STATE => 1,
|
||
$PlusActivityModel::STATUS => 1,
|
||
$PlusActivityModel::TYPE => $activity[$PlusActivityModel::TYPE],
|
||
$PlusActivityModel::TIME => $activity[$PlusActivityModel::TIME],
|
||
);
|
||
$old = $PlusActivityModel->getFind($oMap);
|
||
if (!empty($old)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '不能开启相同时间的套餐哦';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
$save = array(
|
||
$PlusActivityModel::STATUS => $status,
|
||
);
|
||
$update = $PlusActivityModel->updateOrder($cMap, $save);
|
||
if ($update) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '修改成功';
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = 'Plus会员管理-修改Plus会员套餐状态'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '修改失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 删除plus会员套餐
|
||
*/
|
||
public function delActivity()
|
||
{
|
||
$merchant_id = session('merchant_userinfo')['id'];
|
||
$id = I('post.id');
|
||
if (!$id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '参数有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$PlusActivityModel = D('PlusActivity');
|
||
$cMap = array(
|
||
$PlusActivityModel::MERCHANT_ID => $merchant_id,
|
||
$PlusActivityModel::STATE => 1,
|
||
$PlusActivityModel::ID => $id,
|
||
);
|
||
$old = $PlusActivityModel->getFind($cMap);
|
||
if (empty($old)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '操作有误';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$save = array(
|
||
$PlusActivityModel::STATE => 0,
|
||
);
|
||
$update = $PlusActivityModel->updateOrder($cMap, $save);
|
||
if ($update) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '删除成功';
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = 'Plus会员管理-删除Plus会员套餐'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '删除失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|