init: import production code mss.nahaichuan.com (exclude Runtime/Uploads/backups/logs)
这个提交包含在:
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace Retail\Business;
|
||||
|
||||
use Common\Model\RetailGoodsClassModel;
|
||||
use Common\Model\RetailStoreModel;
|
||||
use Retail\Model\LabelInventoryModel;
|
||||
use Retail\Model\StoreIndustryModel;
|
||||
|
||||
//[1.7.90]
|
||||
|
||||
/**
|
||||
* 门店行业类
|
||||
* Class StoreIndustry
|
||||
* [
|
||||
* addStoreIndustry 添加行业
|
||||
* editStoreIndustry 编辑行业
|
||||
* delStoreIndustry 删除行业
|
||||
* getIndustryList 获取行业列表
|
||||
* getIndustrySelect 获取行业列表-供选择使用
|
||||
* ]
|
||||
* @package Retail\Business
|
||||
*/
|
||||
class StoreIndustry
|
||||
{
|
||||
/**
|
||||
* 新增行业
|
||||
* @param $param
|
||||
* $param['name'] 行业名称
|
||||
* $param['operate_id'] 操作者ID
|
||||
* $param['merchant_id'] 商户ID
|
||||
* @return array
|
||||
*/
|
||||
public function addStoreIndustry($param)
|
||||
{
|
||||
if (empty($param['name']) || empty($param['operate_id']) || empty($param['merchant_id'])) {
|
||||
return callBack(statusCode()['error'], '缺少必要参数');
|
||||
}
|
||||
$StoreIndustryModel = new StoreIndustryModel();
|
||||
|
||||
$repeat = $StoreIndustryModel->getFind(['name' => $param['name'], 'merchant_id' => $param['merchant_id'], 'status' => 1]);
|
||||
if ($repeat) {
|
||||
return callBack(statusCode()['error'], '此商户下已存在该行业');
|
||||
}
|
||||
$newIndustryData = [
|
||||
'merchant_id' => $param['merchant_id'],
|
||||
'name' => $param['name'],
|
||||
'add_time' => time(),
|
||||
'status' => 1,
|
||||
'operate_id' => $param['operate_id']
|
||||
];
|
||||
$result = $StoreIndustryModel->addOrder($newIndustryData);
|
||||
if ($result) {
|
||||
return callBack(statusCode()['success'], '行业新增成功');
|
||||
} else {
|
||||
return callBack(statusCode()['error'], '行业新增失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑行业
|
||||
* @param $param
|
||||
* $param['id'] 行业id
|
||||
* $param['name'] 行业名称
|
||||
* $param['operate_id'] 操作者ID
|
||||
* $param['merchant_id'] 商户ID
|
||||
* @return array
|
||||
*/
|
||||
public function editStoreIndustry($param)
|
||||
{
|
||||
$StoreIndustryModel = new StoreIndustryModel();
|
||||
|
||||
$id = I('post.id');
|
||||
$name = I('post.name');
|
||||
if (empty($param['id']) || empty($param['name']) || empty($param['operate_id']) || empty($param['merchant_id'])) {
|
||||
return callBack(statusCode()['error'], '缺少必要参数');
|
||||
}
|
||||
$operate_id = session('jurisdiction_user')['id'];
|
||||
$map = [
|
||||
'name' => $param['name'],
|
||||
'id' => ['neq', $param['id']],
|
||||
'merchant_id' => $param['merchant_id'],
|
||||
'status' => 1,
|
||||
];
|
||||
$repeat = $StoreIndustryModel->getFind($map);
|
||||
if ($repeat) {
|
||||
return callBack(statusCode()['error'], '此商户下已存在该行业');
|
||||
}
|
||||
$result = $StoreIndustryModel->updateOrder(['id' => $id], ['name' => $name, 'operate_id' => $operate_id]);
|
||||
if ($result) {
|
||||
//操作日志记录
|
||||
$source = 0; //请求来源: 0pc系统 1小助手
|
||||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||||
$request_data = json_encode($_POST); //请求参数 json数据
|
||||
$desc = '编辑行业'; //操作行为描述
|
||||
action_log($source, $type, $request_data, $desc);
|
||||
return callBack(statusCode()['success'], '行业修改成功');
|
||||
} else {
|
||||
return callBack(statusCode()['error'], '暂无修改');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除行业
|
||||
* @param $param
|
||||
* $param['id'] 行业id
|
||||
* $param['operate_id'] 操作者ID
|
||||
* $param['merchant_id'] 商户ID
|
||||
* @return array
|
||||
*/
|
||||
public function delStoreIndustry($param)
|
||||
{
|
||||
$id = I('post.id');
|
||||
if (empty($param['id']) || empty($param['merchant_id']) || empty($param['operate_id'])) {
|
||||
return callBack(statusCode()['error'], '缺少必要参数');
|
||||
}
|
||||
|
||||
// 检测是否有标签使用行业
|
||||
$LabelInventoryModel = new LabelInventoryModel();
|
||||
$lMap = [
|
||||
'industry_id' => $id,
|
||||
'status' => 1
|
||||
];
|
||||
$labelInUse = $LabelInventoryModel->getFind($lMap, 'name');
|
||||
if ($labelInUse) {
|
||||
return callBack(statusCode()['error'], '删除失败,存在标签【' . $labelInUse['name'] . '】使用此行业');
|
||||
}
|
||||
// 检测是否有分类使用行业
|
||||
$GoodsClassModel = new RetailGoodsClassModel();
|
||||
$cMap = [
|
||||
'industry_id' => $id,
|
||||
'status' => 1,
|
||||
];
|
||||
$ClassInUse = $GoodsClassModel->getFind($cMap, 'class_name');
|
||||
if ($ClassInUse) {
|
||||
return callBack(statusCode()['error'], '删除失败,存在分类【' . $ClassInUse['class_name'] . '】使用此行业');
|
||||
}
|
||||
$StoreIndustryModel = new StoreIndustryModel();
|
||||
$sMap = [
|
||||
'id' => $id,
|
||||
'merchant_id' => $param['merchant_id'],
|
||||
];
|
||||
$delRes = $StoreIndustryModel->updateOrder($sMap, ['status' => 2]);
|
||||
if ($delRes) {
|
||||
//操作日志记录
|
||||
$source = 0; //请求来源: 0pc系统 1小助手
|
||||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||||
$request_data = json_encode($_POST); //请求参数 json数据
|
||||
$desc = '删除行业'; //操作行为描述
|
||||
action_log($source, $type, $request_data, $desc);
|
||||
return callBack(statusCode()['success'], '删除成功');
|
||||
} else {
|
||||
return callBack(statusCode()['error'], '删除失败,请刷新重试');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商户行业列表
|
||||
* @param $param
|
||||
* $param['page'] 页码
|
||||
* $param['limit'] 每页数量
|
||||
* $param['merchant_id'] 商户ID
|
||||
* $param['name'] 行业名称(模糊搜索)
|
||||
* @return array
|
||||
*/
|
||||
public function getIndustryList($param)
|
||||
{
|
||||
if (empty($param['page']) || empty($param['limit']) || empty($param['merchant_id'])) {
|
||||
return callBack(statusCode()['error'], '缺少商户ID');
|
||||
}
|
||||
$StoreIndustryModel = new StoreIndustryModel();
|
||||
$RetailStoreModel = new RetailStoreModel();
|
||||
$page = $param['page'] ? $param['page'] : 1;
|
||||
$limit = $param['limit'] ? $param['limit'] : 10;
|
||||
$map = [
|
||||
'merchant_id' => $param['merchant_id'],
|
||||
'status' => 1,
|
||||
];
|
||||
if (trim($param['name'])) {
|
||||
$map['name'] = ['like', '%' . trim($param['name']) . '%'];
|
||||
}
|
||||
$field = [
|
||||
'id',
|
||||
'name',
|
||||
'add_time',
|
||||
'merchant_id',
|
||||
];
|
||||
$data = $StoreIndustryModel->getSelect($map, $field, 'add_time desc', "{$page},{$limit}");
|
||||
foreach ($data as &$val) {
|
||||
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
||||
$val['store_num'] = $RetailStoreModel->getCount(['industry_id' => $val['id'], 'state' => 0]);
|
||||
}
|
||||
return callBack(statusCode()['success'], $data ? '获取成功' : '暂无数据', [
|
||||
'list' => $data ? $data : [],
|
||||
'count' => $StoreIndustryModel->getCount($map),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商户行业列表-选择
|
||||
* @param $param
|
||||
* $param['merchant_id'] 商户ID
|
||||
* @return array
|
||||
*/
|
||||
public function getIndustrySelect($param)
|
||||
{
|
||||
if (empty($param['merchant_id'])) {
|
||||
return callBack(statusCode()['error'], '缺少商户ID');
|
||||
}
|
||||
$StoreIndustryModel = new StoreIndustryModel();
|
||||
$map = [
|
||||
'merchant_id' => $param['merchant_id'],
|
||||
'status' => 1,
|
||||
];
|
||||
$field = [
|
||||
'id',
|
||||
'name',
|
||||
];
|
||||
$data = $StoreIndustryModel->getSelect($map, $field, 'add_time desc');
|
||||
|
||||
return callBack(statusCode()['success'], $data ? '获取成功' : '暂无数据', [
|
||||
'list' => $data ? $data : [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户