407 行
14 KiB
PHP
可执行文件
407 行
14 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use Common\Business\GoodsClassify;
|
||
use Common\Model\RetailGoodsClassModel;
|
||
use Common\Model\RetailStoreModel;
|
||
use Common\Model\StoreGoodsClassModel;
|
||
use Retail\Business\GoodsClass;
|
||
use Retail\Model\StoreIndustryModel;
|
||
|
||
//[1.7.90]
|
||
class MerCateController extends BaseController
|
||
{
|
||
public function index()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 获取自动编号
|
||
*/
|
||
public function getAutoClassCode()
|
||
{
|
||
$pid = I('post.pid');
|
||
$ClassModel = new RetailGoodsClassModel();
|
||
if ($pid != 0 && !empty($pid)) {
|
||
$p_class = $ClassModel->getFind(['id' => $pid, 'status' => 0]);
|
||
if (empty($p_class)) {
|
||
$this->ajaxReturn(['status' => 0, 'msg' => '上级分类有误']);
|
||
}
|
||
if (!is_numeric($p_class['code'])) {
|
||
$this->ajaxReturn(['status' => 0, 'msg' => '上级分类序号非数字,无法自动编号']);
|
||
} else {
|
||
$code = $ClassModel->getOrderFindField(['pid' => $pid, 'status' => 0, 'merchantid' => $this->merchant_id], 'code', 'code desc');
|
||
if (!empty($code)) {
|
||
if (!is_numeric($code)) {
|
||
$this->ajaxReturn(['status' => 0, 'msg' => '同级最大编码中存在非数字,无法自动编号']);
|
||
}
|
||
$tempCode = $code + 1;
|
||
} else {
|
||
$tempCode = $p_class['code'] . '1';
|
||
}
|
||
}
|
||
} else {
|
||
$code = $ClassModel->getOrderFindField(['type' => 1, 'status' => 0, 'merchantid' => $this->merchant_id], 'code', 'code desc');
|
||
if (!empty($code)) {
|
||
if (!is_numeric($code)) {
|
||
$this->ajaxReturn(['status' => 0, 'msg' => '一级分类最大编码中存在非数字,无法自动编号']);
|
||
}
|
||
$tempCode = $code + 1;
|
||
} else {
|
||
$tempCode = 1;
|
||
}
|
||
}
|
||
if (!empty($tempCode)) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '获取成功';
|
||
$res['code'] = $tempCode;
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取分类
|
||
*/
|
||
public function getGoodsClass()
|
||
{
|
||
$GoodsClass = new GoodsClass();
|
||
|
||
$param = I('post.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
|
||
$this->ajaxReturn($GoodsClass->getClassList($param));
|
||
}
|
||
|
||
/**
|
||
* 设置分类-商户
|
||
*/
|
||
public function cateSet()
|
||
{
|
||
$GoodsClass = new GoodsClass();
|
||
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['postData'] = I('post.');
|
||
|
||
$result = $GoodsClass->setClassify($param);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 删除分类-商户
|
||
*/
|
||
public function cateDel()
|
||
{
|
||
$GoodsClass = new GoodsClass();
|
||
|
||
$param['id'] = I('post.id');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
|
||
$result = $GoodsClass->delClassify($param);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 获取分类列表接口-门店
|
||
*/
|
||
public function getStoreGoodsClass()
|
||
{
|
||
$GoodsClass = new \Retail\Business\GoodsClass();
|
||
|
||
$param = I('post.');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['store_id'] = $this->store_id;
|
||
|
||
$this->ajaxReturn($GoodsClass->getStoreClassList($param));
|
||
}
|
||
|
||
/**
|
||
* 删除分类-门店
|
||
*/
|
||
public function cateStoreDel()
|
||
{
|
||
$GoodsClass = new \Retail\Business\GoodsClass();
|
||
|
||
$param['id'] = I('post.id');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['store_id'] = $this->store_id;
|
||
|
||
$result = $GoodsClass->delClassify($param);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 设置分类-门店
|
||
*/
|
||
public function cateStoreSet()
|
||
{
|
||
$GoodsClass = new \Retail\Business\GoodsClass();
|
||
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$param['store_id'] = $this->store_id;
|
||
$param['postData'] = I('post.');
|
||
|
||
$result = $GoodsClass->setClassify($param);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
|
||
/**
|
||
* 修改分类线上显示状态
|
||
*/
|
||
public function changeClassOnlineState()
|
||
{
|
||
$id = I('post.id');
|
||
$state = I('post.state');
|
||
if (!$id || !isset($state)) {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '请求参数有误';
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$StoreClassModel = new StoreGoodsClassModel();
|
||
$map = array(
|
||
'store_id' => $this->store_id,
|
||
'class_id' => $id,
|
||
);
|
||
$old = $StoreClassModel->getFind($map);
|
||
if (empty($old)) {
|
||
$item = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $this->store_id,
|
||
'class_id' => $id,
|
||
'online_state' => $state,
|
||
'add_time' => time(),
|
||
);
|
||
$res = $StoreClassModel->addOrder($item);
|
||
} else {
|
||
$save = array(
|
||
'online_state' => $state,
|
||
);
|
||
$res = $StoreClassModel->updateOrder($map, $save);
|
||
}
|
||
if ($res) {
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 4; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
if ($state == 1) {
|
||
$desc = '商品分类-开启商城显示'; //操作行为描述
|
||
} elseif ($state == 0) {
|
||
$desc = '商品分类-关闭商城显示'; //操作行为描述
|
||
}
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
$result['status'] = 1;
|
||
$result['msg'] = '保存成功';
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '保存失败';
|
||
$result['m'] = M()->_sql();
|
||
$result['$old'] = $old;
|
||
}
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 商户分类导出
|
||
*/
|
||
public function exportMerClass()
|
||
{
|
||
$StoreIndustryModel = new StoreIndustryModel();
|
||
$where = [
|
||
'merchantid' => $this->merchant_id,
|
||
'status' => 0,
|
||
'type' => 1,
|
||
];
|
||
$ClassModel = new RetailGoodsClassModel();
|
||
$class1 = $ClassModel->getSelect($where, '*', 'addtime desc');
|
||
$classAll = array();
|
||
if (!empty($class1)) {
|
||
foreach ($class1 as &$value) {
|
||
$value['p_name'] = '一级分类';
|
||
$value['p_name_path'] = $value['class_name'];
|
||
if ($value['industry_id']) {
|
||
$value['industry_name'] = $StoreIndustryModel->getFindField(['id' => $value['industry_id']], 'name');
|
||
} else {
|
||
$value['industry_name'] = '-';
|
||
}
|
||
$classAll[] = $value;
|
||
$where['type'] = 2;
|
||
$where['pid'] = $value['id'];
|
||
$class2 = $ClassModel->getSelect($where, '*', 'addtime desc');
|
||
if (!empty($class2)) {
|
||
foreach ($class2 as &$val) {
|
||
$val['p_name'] = '二级分类';
|
||
$val['p_name_path'] = $value['class_name'] . "/" . $val['class_name'];
|
||
$val['industry_name'] = $value['industry_name'];
|
||
$classAll[] = $val;
|
||
$where['type'] = 3;
|
||
$where['pid'] = $val['id'];
|
||
$class3 = $ClassModel->getSelect($where, '*', 'addtime desc');
|
||
if (!empty($class3)) {
|
||
foreach ($class3 as &$v) {
|
||
$v['p_name'] = '三级分类';
|
||
$v['p_name_path'] = $value['class_name'] . "/" . $val['class_name'] . "/" . $v['class_name'];
|
||
$v['industry_name'] = $value['industry_name'];
|
||
$classAll[] = $v;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
$classAll = array();
|
||
}
|
||
$filename = "分类";
|
||
$arr = array(
|
||
array('class_name', '分类名称'),
|
||
array('p_name', '分类级别'),
|
||
array('p_name_path', '分类详情'),
|
||
array('code', '编码'),
|
||
array('industry_name', '行业')
|
||
);
|
||
$str = $filename . "导出时间" . date('Y-m-d H:i:s', time());
|
||
getExcel($filename, $arr, $classAll, $str);
|
||
}
|
||
|
||
/**
|
||
* 门店分类导出
|
||
*/
|
||
public function exportStoreClass()
|
||
{
|
||
$store_id = $this->store_id;
|
||
$merchant_id = $this->merchant_id;
|
||
|
||
$RetailStoreModel = new RetailStoreModel();
|
||
$industry_id = $RetailStoreModel->getFindField(['id' => $store_id], 'industry_id');
|
||
|
||
$map = array(
|
||
'c1.merchantid' => $merchant_id,
|
||
'c1.status' => 0,
|
||
'c1.type' => 1,
|
||
);
|
||
if ($industry_id) {
|
||
$map['c1.industry_id'] = ['in', [0, $industry_id]];
|
||
}
|
||
$fields = array(
|
||
'c1.class_name as c1_class_name',
|
||
'c2.class_name as c2_class_name',
|
||
'c3.class_name as c3_class_name',
|
||
'c1.code as c1_code',
|
||
'c2.code as c2_code',
|
||
'c3.code as c3_code',
|
||
'c1.type as c1_type',
|
||
'c2.type as c2_type',
|
||
'c3.type as c3_type',
|
||
'c1.id as c1_id',
|
||
'c2.id as c2_id',
|
||
'c3.id as c3_id',
|
||
's1.online_state as s1_online_state',
|
||
's2.online_state as s2_online_state',
|
||
's3.online_state as s3_online_state',
|
||
);
|
||
$class_list = M('retail_goods_class as c1')
|
||
->join('ls_retail_goods_class as c2 on c2.pid=c1.id AND c2.type=2 AND c2.status=0', 'LEFT')
|
||
->join('ls_retail_goods_class as c3 on c3.pid=c2.id AND c3.type=3 AND c3.status=0', 'LEFT')
|
||
->join('ls_store_goods_class as s1 on s1.class_id=c1.id AND s1.store_id=' . $store_id, 'LEFT')
|
||
->join('ls_store_goods_class as s2 on s2.class_id=c2.id AND s2.store_id=' . $store_id, 'LEFT')
|
||
->join('ls_store_goods_class as s3 on s3.class_id=c3.id AND s3.store_id=' . $store_id, 'LEFT')
|
||
->where($map)
|
||
->order('c1.code,c1.id,c2.code,c2.id,c3.code,c3.id')
|
||
->field($fields)
|
||
->select();
|
||
$export_class = array();
|
||
$arrIdList = array();
|
||
if (!empty($class_list)) {
|
||
foreach ($class_list as $value) {
|
||
if (!in_array($value['c1_id'], $arrIdList)) {
|
||
$temp = array(
|
||
'id' => $value['c1_id'],
|
||
'class_name' => $value['c1_class_name'],
|
||
'p_name' => '一级分类',
|
||
'p_name_path' => $value['c1_class_name'],
|
||
'code' => $value['c1_code'],
|
||
'online_state' => $value['s1_online_state'] ? '显示' : '不显示',
|
||
);
|
||
$export_class[] = $temp;
|
||
$arrIdList[] = $value['c1_id'];
|
||
}
|
||
if (!empty($value['c2_id']) && !in_array($value['c2_id'], $arrIdList)) {
|
||
$temp = array(
|
||
'id' => $value['c2_id'],
|
||
'class_name' => $value['c2_class_name'],
|
||
'p_name' => '二级分类',
|
||
'p_name_path' => $value['c1_class_name'] . "/" . $value['c2_class_name'],
|
||
'code' => $value['c2_code'],
|
||
'online_state' => $value['s2_online_state'] ? '显示' : '不显示',
|
||
);
|
||
$export_class[] = $temp;
|
||
$arrIdList[] = $value['c2_id'];
|
||
}
|
||
if (!empty($value['c3_type'])) {
|
||
$temp = array(
|
||
'id' => $value['c3_id'],
|
||
'class_name' => $value['c3_class_name'],
|
||
'p_name' => '三级分类',
|
||
'p_name_path' => $value['c1_class_name'] . "/" . $value['c2_class_name'] . "/" . $value['c3_class_name'],
|
||
'code' => $value['c3_code'],
|
||
'online_state' => $value['s3_online_state'] ? '显示' : '不显示',
|
||
);
|
||
$export_class[] = $temp;
|
||
}
|
||
}
|
||
}
|
||
$file_name = "商品分类明细";
|
||
$header = array(
|
||
array('class_name', '分类名称'),
|
||
array('code', '编码'),
|
||
array('p_name', '分类级别'),
|
||
array('p_name_path', '分类详情'),
|
||
array('online_state', '商城是否显示'),
|
||
);
|
||
$str = $file_name . ',导出日期:' . date('Y-m-d H:i:s');
|
||
getExcel($file_name, $header, $export_class, $str);
|
||
}
|
||
|
||
/**
|
||
* 获取分类 用来筛选 不返回是否含有下一级
|
||
*/
|
||
public function getChooseClassList()
|
||
{
|
||
$user_type = I('post.user_type'); //用户类型 1商户 2门店
|
||
$store_id = I('post.store_id'); //门店ID
|
||
$type = I('post.type'); //分类类型
|
||
$pid = I('post.pid'); //上级分类ID
|
||
$GoodsClass = new \Retail\Business\GoodsClass();
|
||
$this->ajaxReturn($GoodsClass->getChooseClassList([
|
||
'merchant_id' => $this->merchant_id,
|
||
'store_id' => $user_type == 2 ? ($store_id ? $store_id : $this->store_id) : null,
|
||
'type' => $type,
|
||
'pid' => $pid,
|
||
'user_type' => $user_type,
|
||
]));
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取商户分类 并返回分类里是否有下一级
|
||
*/
|
||
public function getGoodsClassify()
|
||
{
|
||
$pid = I('post.pid');//上级分类ID 获取一级分类时传0
|
||
$ClassApi = new GoodsClassify();
|
||
$param = array(
|
||
'pid' => $pid,
|
||
'merchant_id' => $this->merchant_id,
|
||
);
|
||
$list = $ClassApi->getAbsolutelyGoodsClass($param);
|
||
$this->ajaxReturn([
|
||
'status' => 1,
|
||
'message' => $list ? '获取成功' : '暂无数据',
|
||
'data' => $list ? $list : [],
|
||
]);
|
||
}
|
||
}
|