|
|
@@ -4,6 +4,7 @@ namespace bizHd\goods\services;
|
|
|
|
|
|
use bizHd\base\services\BaseService;
|
|
|
use bizHd\goods\classes\CategoryClass;
|
|
|
+use bizHd\goods\classes\GoodsCategoryClass;
|
|
|
use common\components\imgUtil;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
@@ -13,120 +14,122 @@ class CategoryService extends BaseService
|
|
|
{
|
|
|
|
|
|
|
|
|
- public static $baseFile = '\bizHd\goods\classes\CategoryClass';
|
|
|
-
|
|
|
- //取所有的分类 ssh 2019.12.7
|
|
|
- public static function getCategoryList($merchantId)
|
|
|
- {
|
|
|
- $cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0], 'inTurn DESC', '*');
|
|
|
- if (empty($cat)) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- //处理图片
|
|
|
- $prefix = imgUtil::getPrefix();
|
|
|
- foreach ($cat as $key => $info) {
|
|
|
- $cat[$key]['img'] = $prefix . $info['img'];
|
|
|
- }
|
|
|
- return $cat;
|
|
|
- }
|
|
|
-
|
|
|
- //取出可用的分类 ssh 2019.12.2
|
|
|
- public static function getEnableList($merchantId)
|
|
|
- {
|
|
|
- $cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0, 'status' => 1], 'inTurn DESC', '*');
|
|
|
- if (empty($cat)) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- //处理图片
|
|
|
- $prefix = imgUtil::getPrefix();
|
|
|
- foreach ($cat as $key => $info) {
|
|
|
- $cat[$key]['img'] = $prefix . $info['img'];
|
|
|
- }
|
|
|
- return $cat;
|
|
|
- }
|
|
|
-
|
|
|
- //获取商家所有的分类名称
|
|
|
- public static function getNameList($merchantId)
|
|
|
- {
|
|
|
- $cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0], 'inTurn DESC', '*');
|
|
|
- return empty($cat) ? [] : array_column($cat, 'categoryName');
|
|
|
- }
|
|
|
-
|
|
|
- //获取商家最靠前的分类id ssh 2019.12.2
|
|
|
- public static function getTopCategoryId($merchantId)
|
|
|
- {
|
|
|
- $cat = CategoryClass::getByCondition(['merchantId' => $merchantId, 'delStatus' => 0, 'status' => 1], false, 'inTurn DESC');
|
|
|
- $id = isset($cat['id']) ? $cat['id'] : 0;
|
|
|
- return $id;
|
|
|
- }
|
|
|
-
|
|
|
- //获取前三个分类信息 ssh 2019.12.2
|
|
|
- public static function getTopThreeCategory($merchantId)
|
|
|
- {
|
|
|
- $cat = CategoryClass::getLimitList('id,categoryName', ['merchantId' => $merchantId, 'delStatus' => 0, 'status' => 1], 3, 'inTurn DESC');
|
|
|
- if (empty($cat)) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- return $cat;
|
|
|
- }
|
|
|
-
|
|
|
- //验证操作权限 ssh 2019.12.8
|
|
|
- public static function valid($category, $merchantId)
|
|
|
- {
|
|
|
- if (isset($category['merchantId']) == false || $category['merchantId'] != $merchantId) {
|
|
|
- util::fail('您没有权限操作');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //获取详情 ssh 2019.12.8
|
|
|
- public static function getInfo($id)
|
|
|
- {
|
|
|
- return CategoryClass::getInfo($id);
|
|
|
- }
|
|
|
-
|
|
|
- //添加分类 ssh 2019.12.8
|
|
|
- public static function addCategory($data)
|
|
|
- {
|
|
|
- return CategoryClass::addCategory($data);
|
|
|
- }
|
|
|
-
|
|
|
- public static function changeStatus($categoryId, $status)
|
|
|
- {
|
|
|
- return CategoryClass::changeStatus($categoryId, $status);
|
|
|
- }
|
|
|
-
|
|
|
- //更新分类 ssh 2019.12.8
|
|
|
- public static function updateCategory($category, $post)
|
|
|
- {
|
|
|
- $categoryId = $category['id'];
|
|
|
- $categoryName = $category['categoryName'];
|
|
|
- $merchantId = $category['merchantId'];
|
|
|
- if ($categoryName != $post['categoryName']) {
|
|
|
- $nameList = self::getNameList($merchantId);
|
|
|
- if (in_array($post['categoryName'], $nameList)) {
|
|
|
- util::fail('分类名称已经存在');
|
|
|
- }
|
|
|
- }
|
|
|
- CategoryClass::updateById($categoryId, $post);
|
|
|
- }
|
|
|
-
|
|
|
- public static function deleteCategory($id)
|
|
|
- {
|
|
|
- return CategoryClass::deleteCategory($id);
|
|
|
- }
|
|
|
+ public static $baseFile = '\bizHd\goods\classes\CategoryClass';
|
|
|
+
|
|
|
+ //取所有的分类 ssh 2019.12.7
|
|
|
+ public static function getCategoryList($merchantId)
|
|
|
+ {
|
|
|
+ $cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0], 'inTurn DESC', '*');
|
|
|
+ if (empty($cat)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ //处理图片
|
|
|
+ $prefix = imgUtil::getPrefix();
|
|
|
+ foreach ($cat as $key => $info) {
|
|
|
+ $cat[$key]['img'] = $prefix . $info['img'];
|
|
|
+ }
|
|
|
+ return $cat;
|
|
|
+ }
|
|
|
+
|
|
|
+ //取出可用的分类 ssh 2019.12.2
|
|
|
+ public static function getEnableList($merchantId)
|
|
|
+ {
|
|
|
+ $cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0, 'status' => 1], 'inTurn DESC', '*');
|
|
|
+ if (empty($cat)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ //处理图片
|
|
|
+ $prefix = imgUtil::getPrefix();
|
|
|
+ foreach ($cat as $key => $info) {
|
|
|
+ $cat[$key]['img'] = $prefix . $info['img'];
|
|
|
+ }
|
|
|
+ return $cat;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取商家所有的分类名称
|
|
|
+ public static function getNameList($merchantId)
|
|
|
+ {
|
|
|
+ $cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0], 'inTurn DESC', '*');
|
|
|
+ return empty($cat) ? [] : array_column($cat, 'categoryName');
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取商家最靠前的分类id ssh 2019.12.2
|
|
|
+ public static function getTopCategoryId($merchantId)
|
|
|
+ {
|
|
|
+ $cat = CategoryClass::getByCondition(['merchantId' => $merchantId, 'delStatus' => 0, 'status' => 1], false, 'inTurn DESC');
|
|
|
+ $id = isset($cat['id']) ? $cat['id'] : 0;
|
|
|
+ return $id;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取前三个分类信息 ssh 2019.12.2
|
|
|
+ public static function getTopThreeCategory($merchantId)
|
|
|
+ {
|
|
|
+ $cat = CategoryClass::getLimitList('id,categoryName', ['merchantId' => $merchantId, 'delStatus' => 0, 'status' => 1], 3, 'inTurn DESC');
|
|
|
+ if (empty($cat)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ return $cat;
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证操作权限 ssh 2019.12.8
|
|
|
+ public static function valid($category, $merchantId)
|
|
|
+ {
|
|
|
+ if (isset($category['merchantId']) == false || $category['merchantId'] != $merchantId) {
|
|
|
+ util::fail('您没有权限操作');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取详情 ssh 2019.12.8
|
|
|
+ public static function getInfo($id)
|
|
|
+ {
|
|
|
+ return CategoryClass::getInfo($id);
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加分类 ssh 2019.12.8
|
|
|
+ public static function addCategory($data)
|
|
|
+ {
|
|
|
+ return CategoryClass::addCategory($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function changeStatus($categoryId, $status)
|
|
|
+ {
|
|
|
+ return CategoryClass::changeStatus($categoryId, $status);
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新分类 ssh 2019.12.8
|
|
|
+ public static function updateCategory($category, $post)
|
|
|
+ {
|
|
|
+ $categoryId = $category['id'];
|
|
|
+ $categoryName = $category['categoryName'];
|
|
|
+ $merchantId = $category['merchantId'];
|
|
|
+ if ($categoryName != $post['categoryName']) {
|
|
|
+ $nameList = self::getNameList($merchantId);
|
|
|
+ if (in_array($post['categoryName'], $nameList)) {
|
|
|
+ util::fail('分类名称已经存在');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CategoryClass::updateById($categoryId, $post);
|
|
|
+ //同步更新分类商品表
|
|
|
+ GoodsCategoryClass::updateByCondition(['cId' => $categoryId], ['cName' => $post['categoryName']]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function deleteCategory($id)
|
|
|
+ {
|
|
|
+ return CategoryClass::deleteCategory($id);
|
|
|
+ }
|
|
|
|
|
|
//获取开单页所有的分类:包括、常用
|
|
|
public static function getCategoryClassAll($merchantId)
|
|
|
{
|
|
|
$where = [
|
|
|
- 'merchantId'=>$merchantId
|
|
|
+ 'merchantId' => $merchantId
|
|
|
];
|
|
|
- $data = self::getAllList('id,categoryName as name',$where,'inTurn desc');
|
|
|
+ $data = self::getAllList('id,categoryName as name', $where, 'inTurn desc');
|
|
|
$use = [
|
|
|
- 'id'=>-2,
|
|
|
- 'name'=>'常用'
|
|
|
+ 'id' => -2,
|
|
|
+ 'name' => '常用'
|
|
|
];
|
|
|
- array_unshift($data,$use);
|
|
|
+ array_unshift($data, $use);
|
|
|
return $data;
|
|
|
}
|
|
|
|