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

315 行
11 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
//[1.5.66]
use Common\Model\GoodsLabelModel;
/**
* 商品标签
* Class GoodsLabelController
* @package Retail\Controller
*/
class GoodsLabelController extends BaseController
{
public function index()
{
$arr = array(
'labelSet' => '/index.php/Retail/GoodsLabel/labelSet',
'unboundGoods' => '/index.php/Retail/GoodsLabel/unboundGoods',
'deleteLabel' => '/index.php/Retail/GoodsLabel/deleteLabel',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function labelList()
{
//goods_label
$user = session("ls_userinfo");//
$storeid = session("storeid");
if (!$user['storeid']) {
$user['storeid'] = $storeid;
}
// var_dump($user);
$key = I("post.keyword");
$page = I("post.page");
$limit = I("post.limit");
if ($key) {
$map['label_name|sort'] = array("like", "%" . $key . "%");
// //提供序号查找
// if (is_numeric($key)){
// $map['sort'] = $key;
// }else{
// $map['label_name'] = array("like","%".$key."%");
// }
}
$map['storeid'] = $user['storeid'];
$count = M("retail_goods_label")->where($map)->count();
$list = M("retail_goods_label")->where($map)->order("sort desc")->page($page, $limit)->select();
if (!empty($list)) {
foreach ($list as $key => $value) {
$list[$key]['addtime'] = date("Y-m-d H:i:s", $value['addtime']);
$list[$key]['key'] = $key + 1;
}
}
$res['code'] = 0;
$res['count'] = $count;
$res['data'] = $list;
$this->ajaxReturn($res);
}
/**
* 标签编辑
*/
public function labelSet()
{
$user = session("ls_userinfo");
$storeid = session("storeid");
if (!$user['storeid']) {
$user['storeid'] = $storeid;
}
if ($_POST) {
$data = I("post.");
if ($data['id']) {
//编辑
//自身标签名或序号不做修改不会判重
$nameMap['id'] = array("neq", $data['id']);
$nameMap['label_name'] = $data['label_name'];
$nameMap['storeid'] = $user['storeid'];
$findName = M("retail_goods_label")->where($nameMap)->find();
if ($findName) {
//名称已存在
$res['status'] = 2;
$res['msg'] = '该名称已存在';
} else {
//序号
$sortMap['id'] = array("neq", $data['id']);
$sortMap['sort'] = $data['sort'];
$sortMap['storeid'] = $user['storeid'];
$findSort = M("retail_goods_label")->where($sortMap)->find();
if ($findSort) {
$res['status'] = 3;
$res['msg'] = '该序号已存在';
} else {
$create = M("retail_goods_label")->where(array("id" => $data['id']))->save($data);
if ($create) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '商品标签-编辑';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = '修改成功';
} else {
$res['status'] = 0;
$res['msg'] = '修改失败,';
}
}
}
} else {
//创建
//禁止名称和序号重复
$nameMap['label_name'] = $data['label_name'];
$nameMap['storeid'] = $user['storeid'];
$findName = M("retail_goods_label")->where($nameMap)->find();
if ($findName) {
//名称已存在
$res['status'] = 2;
$res['msg'] = '该名称已存在';
} else {
//序号
$sortMap['sort'] = $data['sort'];
$sortMap['storeid'] = $user['storeid'];
$findSort = M("retail_goods_label")->where($sortMap)->find();
if ($findSort) {
$res['status'] = 3;
$res['msg'] = '该序号已存在';
} else {
$data['addtime'] = time();
$data['merchantid'] = $user['merchantid'];
$data['storeid'] = $user['storeid'];
$create = M("retail_goods_label")->add($data);
if ($create) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '商品标签-新增';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = '创建成功';
} else {
$res['status'] = 0;
$res['msg'] = '创建失败';
}
}
}
}
}
$this->ajaxReturn($res);
}
/**
* 删除
*/
public function deleteLabel()
{
if ($_POST) {
$id = $_POST['id'];
if ($id) {
//需要判断是否使用中
$find = M("retail_goods")->where(array('label_id' => $id))->find();
if ($find) {
$res['status'] = 0;
$res['msg'] = '抱歉,该标签正在被使用,无法删除';
} else {
$del = M("retail_goods_label")->where(array('id' => $id))->delete();
if ($del) {
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '商品标签-删除';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = '已删除';
} else {
$res['status'] = 0;
$res['msg'] = '删除失败';
}
}
} else {
$res['status'] = 0;
$res['msg'] = '参数错误,请重试';
}
}
$this->ajaxReturn($res);
}
/**********************************************批量商品绑定标签*************************************************/
public function unboundGoods()
{
$user = session("ls_userinfo");
$storeid = session("storeid");
if (!$user['storeid']) {
$user['storeid'] = $storeid;
}
$map['storeid'] = $user['storeid'];
$map['merchantid'] = $user['merchantid'];
$list = M("retail_goods_label")->field("id,label_name")->where($map)->select();
$cate_map['type'] = 3;
$cate_map['status'] = 0;
$cate_map['merchantid'] = $user['merchantid'];
$cate = M("retail_goods_class")->field("id,class_name")->where($cate_map)->select();
$this->assign('list', $list);
$this->assign('cate', $cate);
$this->display();
}
public function goodsList()
{
$user = session("ls_userinfo");
$storeid = session("storeid");
if (!$user['storeid']) {
$user['storeid'] = $storeid;
}
$map['store_id'] = $user['storeid'];
$map['label_id'] = 0;
$map['status'] = array('neq', 2);
$cateId = I("get.keyword");
if ($cateId) {
$map['goods_class_id'] = $cateId;
}
$page = I("get.page");
$limit = I("get.limit");
$count = M("retail_goods")->where($map)->count();
$list = M("retail_goods")->field("id,goods_name,goods_class_id,status")->where($map)->page($page, $limit)->select();
if (!empty($list)) {
foreach ($list as $key => $value) {
$list[$key]['goods_class_name'] = M("retail_goods_class")->where(array('id' => $value['goods_class_id']))->getField("class_name");
if ($value['status'] == 1) {
$list[$key]['statusName'] = "已下架";
} elseif ($value['status'] == 0) {
$list[$key]['statusName'] = "售卖中";
}
$list[$key]['key'] = $key + 1;
}
}
$res['code'] = 0;
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
/**
* 绑定标签
*/
public function bindGoods()
{
$user = session("ls_userinfo");
$storeid = session("storeid");
if (!$user['storeid']) {
$user['storeid'] = $storeid;
}
if ($_POST) {
$labelId = $_POST['labelid'];
$ids = $_POST['ids'];
if (!$labelId || !$ids) {
$res['status'] = 0;
$res['msg'] = '参数有误';
} else {
$newIds = explode(',', trim($ids, ','));
foreach ($newIds as $key => $value) {
$row = M("retail_goods")->where(array('id' => $value))->save(array('label_id' => $labelId));
}
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '商品标签-绑定标签';//操作行为描述
action_log($source, $type, $request_data, $desc);
$res['status'] = 1;
$res['msg'] = '绑定成功';
}
}
$this->ajaxReturn($res);
}
/**
* 获取商品标签供选择
*/
public function getGoodsLabelList()
{
$LabelModel = new GoodsLabelModel();
$map = array(
'storeid' => $this->store_id,
);
$data = $LabelModel->getSelect($map, 'id,label_name');
$this->ajaxReturn(array(
'status' => 1,
'msg' => $data ? '获取成功' : '暂无标签',
'data' => $data ? $data : array(),
));
}
}