112 行
3.0 KiB
PHP
可执行文件
112 行
3.0 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Common\Business;
|
|
|
|
use Common\Model\RetailGoodsBrandModel;
|
|
|
|
//[1.7.90]
|
|
|
|
/**
|
|
* 商品品牌类
|
|
* Class Brand
|
|
* [
|
|
* 商品品牌的添加 brandAdd
|
|
* 获取品牌名称 getBrandName
|
|
* 获取品牌列表-供选择使用 getSelectBrand
|
|
* ]
|
|
* @package Retail\Business
|
|
*/
|
|
class Brand
|
|
{
|
|
/**
|
|
* 商品品牌的添加
|
|
* @param $parameter
|
|
* [
|
|
* goods_brand 品牌名称
|
|
* merchant_id
|
|
* store_id
|
|
* ]
|
|
* @return array
|
|
* [
|
|
* status
|
|
* message
|
|
* brandId 品牌ID
|
|
* ]
|
|
*/
|
|
public function brandAdd($parameter)
|
|
{
|
|
try {
|
|
$brandModel = new RetailGoodsBrandModel();
|
|
$brandId = $brandModel->getFindField([
|
|
'name' => $parameter['goods_brand'],
|
|
'merchantid' => $parameter['merchant_id'],
|
|
'state' => 0
|
|
], 'id');
|
|
if (empty($brandId)) {
|
|
$content = [
|
|
'name' => $parameter['goods_brand'],
|
|
'merchantid' => $parameter['merchant_id'],
|
|
'storeid' => $parameter['store_id'] ? $parameter['store_id'] : 0,
|
|
'addtime' => time(),
|
|
'state' => 0
|
|
];
|
|
$brandId = $brandModel->addOrder($content); //存入不存在的品牌
|
|
if (!$brandId) {
|
|
return callBack(statusCode()['error'], "操作失败");
|
|
}
|
|
}
|
|
return callBack(statusCode()['success'], "操作成功", ['brandId' => $brandId]);
|
|
} catch (\Exception $e) {
|
|
return callBack(statusCode()['error'], "操作失败");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取品牌名称
|
|
* @param $brand_id 品牌ID
|
|
* @param array $brand_name 已查的品牌名称列表
|
|
* @return mixed
|
|
*/
|
|
public function getBrandName($brand_id = null, &$brand_name = array())
|
|
{
|
|
if (!$brand_id) {
|
|
return '';
|
|
}
|
|
if (!isset($brand_name[$brand_id])) {
|
|
$GoodsBrandModel = new RetailGoodsBrandModel();
|
|
$brand_name[$brand_id] = $GoodsBrandModel->getFindField(array('id' => $brand_id), 'name');
|
|
}
|
|
return $brand_name[$brand_id];
|
|
}
|
|
|
|
/**
|
|
* 获取品牌列表-供选择使用
|
|
* @param $param
|
|
* $param['name'] 品牌名称(模糊搜索)
|
|
* $param['merchant_id'] 商户ID
|
|
* @return mixed
|
|
*/
|
|
public function getSelectBrand($param)
|
|
{
|
|
$GoodsBrandModel = new RetailGoodsBrandModel();
|
|
|
|
$merchant_id = $param['merchant_id'];
|
|
$map = [
|
|
'state' => 0,
|
|
'merchantid' => $merchant_id,
|
|
];
|
|
// if ($store_id) {
|
|
// $map['storeid'] = $param['store_id'];
|
|
// }
|
|
if (trim($param['name'])) {
|
|
$map['name'] = ['like', '%' . trim($param['name']) . '%'];
|
|
}
|
|
|
|
$field = ['name,id'];
|
|
|
|
$data = $GoodsBrandModel->getSelect($map, $field, 'addtime desc');
|
|
|
|
return callBack(statusCode()['success'], $data ? '数据获取成功' : '暂无数据', $data);
|
|
}
|
|
|
|
} |