| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- 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;
- class CategoryService extends BaseService
- {
- public static $baseFile = '\bizHd\goods\classes\CategoryClass';
- //取所有的分类 ssh 2019.12.7
- public static function getCategoryList($mainId)
- {
- $where = ['mainId' => $mainId, 'delStatus' => 0];
- $cat = CategoryClass::getAllByCondition($where, 'inTurn DESC', '*');
- if (empty($cat)) {
- return $cat;
- }
- foreach ($cat as $key => $info) {
- $img = $info['img'] ?? '';
- $cat[$key]['img'] = imgUtil::groupImg($img) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $cat[$key]['bigImg'] = imgUtil::groupImg($img) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- $cat[$key]['shortImg'] = $img;
- }
- 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($mainId)
- {
- $cat = CategoryClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], 'inTurn DESC', '*');
- return empty($cat) ? [] : array_column($cat, 'categoryName');
- }
- //获取商家最靠前的分类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, $mainId)
- {
- if (isset($category['mainId']) == false || $category['mainId'] != $mainId) {
- 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 20220404
- 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);
- //同步更新分类商品表
- GoodsCategoryClass::updateByCondition(['cId' => $categoryId], ['cName' => $post['categoryName']]);
- }
- //获取开单页所有的分类
- public static function getCategoryClassAll($where)
- {
- $data = self::getAllList('id,categoryName as name', $where, 'inTurn desc');
- return $data;
- }
- }
|