CategoryClass.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace bizMall\goods\classes;
  3. use common\components\business;
  4. use common\components\stringUtil;
  5. use common\components\util;
  6. use Yii;
  7. use bizMall\base\classes\BaseClass;
  8. class CategoryClass extends BaseClass
  9. {
  10. public static $baseFile = '\bizMall\goods\models\Category';
  11. //可以使用的分类:花束 花盒 蝴蝶兰 花篮 植物 永生花 散花 充值卡 花艺课 花礼 瓶器
  12. //取出商家所有的分类 ssh 2019.12.7
  13. public static function getCategoryIdList($sjId)
  14. {
  15. $category = self::getAllByCondition(['sjId' => $sjId, 'delStatus' => 0], null, '*', 'id');
  16. return empty($category) ? [] : array_keys($category);
  17. }
  18. //获取详情 ssh 2019.12.8
  19. public static function getInfo($id)
  20. {
  21. $info = self::getById($id);
  22. $list = self::groupBaseInfo([$info]);
  23. return current($list);
  24. }
  25. //组合信息 ssh 2019.12.8
  26. public static function groupBaseInfo($list)
  27. {
  28. foreach ($list as $key => $val) {
  29. $val = business::formatCategoryImg($val);
  30. $list[$key] = $val;
  31. }
  32. return $list;
  33. }
  34. //添加分类 ssh 2019.12.8
  35. public static function addCategory($data)
  36. {
  37. $categoryName = $data['categoryName'];
  38. $sjId = $data['sjId'];
  39. $exists = self::getByCondition(['sjId' => $sjId, 'delStatus' => 0, 'categoryName' => $categoryName]);
  40. if (!empty($exists)) {
  41. util::fail('分类名称已经存在');
  42. }
  43. return self::add($data);
  44. }
  45. //分类启用与停用 ssh 2019.12.8
  46. public static function changeStatus($categoryId, $status)
  47. {
  48. return self::updateById($categoryId, ['status' => $status]);
  49. }
  50. //删除分类 ssh 2020.3.3
  51. public static function deleteCategory($id)
  52. {
  53. self::updateById($id, ['delStatus' => 1]);
  54. return true;
  55. }
  56. }