| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace bizHd\goods\classes;
- use common\components\business;
- use common\components\imgUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- class CategoryClass extends BaseClass
- {
- public static $baseFile = '\bizHd\goods\models\Category';
- //可以使用的分类:花束 花盒 蝴蝶兰 花篮 植物 永生花 散花 充值卡 花艺课 花礼 瓶器
- public static function getMenuList($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.7
- public static function getCategoryIds($mainId)
- {
- $category = self::getCategory($mainId);
- return empty($category) ? [] : array_keys($category);
- }
- //获取商家分类,id作为键名 ssh 2021.5.4
- public static function getCategory($mainId)
- {
- return $category = self::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, '*', 'id');
- }
- //获取详情 ssh 2019.12.8
- public static function getInfo($id)
- {
- $info = self::getById($id);
- $list = self::groupBaseInfo([$info]);
- return current($list);
- }
- //组合信息 ssh 2019.12.8
- public static function groupBaseInfo($list)
- {
- foreach ($list as $key => $val) {
- $val = business::formatCategoryImg($val);
- $list[$key] = $val;
- }
- return $list;
- }
- //添加分类 ssh 2019.12.8
- public static function addCategory($data)
- {
- $categoryName = $data['categoryName'];
- $mainId = $data['mainId'] ?? 0;
- $exists = self::getByCondition(['mainId' => $mainId, 'delStatus' => 0, 'categoryName' => $categoryName]);
- if (!empty($exists)) {
- util::fail('分类名称已经存在');
- }
- return self::add($data);
- }
- //分类启用与停用 ssh 2019.12.8
- public static function changeStatus($categoryId, $status)
- {
- return self::updateById($categoryId, ['status' => $status]);
- }
- //开店初始化分类和商品 ssh 2020.2.14
- public static function initCategoryGoods($mainId)
- {
- $catList = [['name' => '花束', 'flower' => 1], ['name' => '花篮', 'flower' => 1], ['name' => '永生花', 'flower' => 0], ['name' => '绿植', 'flower' => 0]];
- foreach ($catList as $key => $cat) {
- $name = $cat['name'] ?? '';
- $flower = $cat['flower'];
- $data = ['categoryName' => $name, 'mainId' => $mainId, 'flower' => $flower, 'status' => 1];
- self::add($data);
- }
- }
- //删除分类 ssh 2020.3.3
- public static function deleteCategory($id)
- {
- return self::updateByCondition(['id' => $id], ['goodsNum' => 0, 'delStatus' => 1]);
- }
- }
|