| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace bizMall\goods\services;
- use bizMall\base\services\BaseService;
- use bizMall\goods\classes\CategoryClass;
- use common\components\imgUtil;
- use common\components\util;
- use Yii;
- use linslin\yii2\curl;
- class CategoryService extends BaseService
- {
- public static $baseFile = '\bizMall\goods\classes\CategoryClass';
- //取所有的分类 ssh 2019.12.7
- public static function getCategoryList($sjId)
- {
- $cat = CategoryClass::getAllByCondition(['sjId' => $sjId, 'delStatus' => 0], '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 getAllCategory($where)
- {
- $cat = CategoryClass::getAllByCondition($where, 'inTurn DESC', '*');
- return $cat;
- }
- //取出可用的分类 ssh 2019.12.2
- public static function getEnableList($mainId)
- {
- $cat = CategoryClass::getAllByCondition(['mainId' => $mainId, '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($sjId)
- {
- $cat = CategoryClass::getAllByCondition(['sjId' => $sjId, 'delStatus' => 0], 'inTurn DESC', '*');
- return empty($cat) ? [] : array_column($cat, 'categoryName');
- }
- //取出商家所有的分类ID ssh 2019.12.7
- public static function getCategoryIdList($mainId)
- {
- return CategoryClass::getCategoryIds($mainId);
- }
- //获取商家最靠前的分类id ssh 2019.12.2
- public static function getTopCategoryId($mainId)
- {
- $cat = CategoryClass::getByCondition(['mainId' => $mainId, 'delStatus' => 0, 'status' => 1], false, 'inTurn DESC');
- $id = isset($cat['id']) ? $cat['id'] : 0;
- return $id;
- }
- //获取前三个分类信息 ssh 2019.12.2
- public static function getTopThreeCategory($mainId)
- {
- $cat = CategoryClass::getLimitList('id,categoryName', ['mainId' => $mainId, 'delStatus' => 0, 'status' => 1], 3, 'inTurn DESC');
- if (empty($cat)) {
- return [];
- }
- return $cat;
- }
- //验证操作权限 ssh 2019.12.8
- public static function valid($category, $sjId)
- {
- if (isset($category['sjId']) == false || $category['sjId'] != $sjId) {
- 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'];
- $sjId = $category['sjId'];
- if ($categoryName != $post['categoryName']) {
- $nameList = self::getNameList($sjId);
- if (in_array($post['categoryName'], $nameList)) {
- util::fail('分类名称已经存在');
- }
- }
- CategoryClass::updateById($categoryId, $post);
- }
- public static function deleteCategory($id)
- {
- return CategoryClass::deleteCategory($id);
- }
- }
|