| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace biz\goods\services;
- use biz\base\services\BaseService;
- use biz\goods\classes\CategoryClass;
- use common\components\util;
- use Yii;
- use linslin\yii2\curl;
- class CategoryService extends BaseService
- {
-
- public static $baseFile = '\biz\goods\classes\CategoryClass';
-
- //取所有的分类 shish 2019.12.7
- public static function getCategoryList($merchantId)
- {
- $cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0], 'inTurn DESC', '*');
- if (empty($cat)) {
- return [];
- }
- //处理图片
- $prefix = Yii::$app->params['imgHost'];
- foreach ($cat as $key => $info) {
- $cat[$key]['img'] = $prefix . $info['img'];
- }
- return $cat;
- }
-
- //取出可用的分类 shish 2019.12.2
- public static function getEnableList($merchantId)
- {
- $cat = CategoryClass::getAllByCondition(['merchantId' => $merchantId, 'delStatus' => 0, 'status' => 1], 'inTurn DESC', '*');
- if (empty($cat)) {
- return [];
- }
- //处理图片
- $prefix = Yii::$app->params['imgHost'];
- 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 shish 2019.12.7
- public static function getCategoryIdList($merchantId)
- {
- return CategoryClass::getCategoryIdList($merchantId);
- }
-
-
- //获取商家最靠前的分类id shish 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;
- }
-
- //获取前三个分类信息 shish 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;
- }
-
- //验证操作权限 shish 2019.12.8
- public static function valid($category, $merchantId)
- {
- if (isset($category['merchantId']) == false || $category['merchantId'] != $merchantId) {
- util::fail('您没有权限操作');
- }
- }
-
- //获取详情 shish 2019.12.8
- public static function getInfo($id)
- {
- return CategoryClass::getInfo($id);
- }
-
- //添加分类 shish 2019.12.8
- public static function addCategory($data)
- {
- return CategoryClass::addCategory($data);
- }
-
- public static function changeStatus($categoryId, $status)
- {
- return CategoryClass::changeStatus($categoryId, $status);
- }
-
- //更新分类 shish 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);
- }
-
- }
|