CategoryService.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace bizMall\goods\services;
  3. use bizMall\base\services\BaseService;
  4. use bizMall\goods\classes\CategoryClass;
  5. use common\components\imgUtil;
  6. use common\components\util;
  7. use Yii;
  8. use linslin\yii2\curl;
  9. class CategoryService extends BaseService
  10. {
  11. public static $baseFile = '\bizMall\goods\classes\CategoryClass';
  12. //取所有的分类 ssh 2019.12.7
  13. public static function getCategoryList($sjId)
  14. {
  15. $cat = CategoryClass::getAllByCondition(['sjId' => $sjId, 'delStatus' => 0], 'inTurn DESC', '*');
  16. if (empty($cat)) {
  17. return [];
  18. }
  19. //处理图片
  20. $prefix = imgUtil::getPrefix();
  21. foreach ($cat as $key => $info) {
  22. $cat[$key]['img'] = $prefix . $info['img'];
  23. }
  24. return $cat;
  25. }
  26. public static function getAllCategory($where)
  27. {
  28. $cat = CategoryClass::getAllByCondition($where, 'inTurn DESC', '*');
  29. return $cat;
  30. }
  31. //取出可用的分类 ssh 2019.12.2
  32. public static function getEnableList($mainId)
  33. {
  34. $cat = CategoryClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0, 'status' => 1], 'inTurn DESC', '*');
  35. if (empty($cat)) {
  36. return [];
  37. }
  38. //处理图片
  39. $prefix = imgUtil::getPrefix();
  40. foreach ($cat as $key => $info) {
  41. $cat[$key]['img'] = $prefix . $info['img'];
  42. }
  43. return $cat;
  44. }
  45. //获取商家所有的分类名称
  46. public static function getNameList($sjId)
  47. {
  48. $cat = CategoryClass::getAllByCondition(['sjId' => $sjId, 'delStatus' => 0], 'inTurn DESC', '*');
  49. return empty($cat) ? [] : array_column($cat, 'categoryName');
  50. }
  51. //取出商家所有的分类ID ssh 2019.12.7
  52. public static function getCategoryIdList($mainId)
  53. {
  54. return CategoryClass::getCategoryIds($mainId);
  55. }
  56. //获取商家最靠前的分类id ssh 2019.12.2
  57. public static function getTopCategoryId($mainId)
  58. {
  59. $cat = CategoryClass::getByCondition(['mainId' => $mainId, 'delStatus' => 0, 'status' => 1], false, 'inTurn DESC');
  60. $id = isset($cat['id']) ? $cat['id'] : 0;
  61. return $id;
  62. }
  63. //获取前三个分类信息 ssh 2019.12.2
  64. public static function getTopThreeCategory($mainId)
  65. {
  66. $cat = CategoryClass::getLimitList('id,categoryName', ['mainId' => $mainId, 'delStatus' => 0, 'status' => 1], 3, 'inTurn DESC');
  67. if (empty($cat)) {
  68. return [];
  69. }
  70. return $cat;
  71. }
  72. //验证操作权限 ssh 2019.12.8
  73. public static function valid($category, $sjId)
  74. {
  75. if (isset($category['sjId']) == false || $category['sjId'] != $sjId) {
  76. util::fail('您无法操作');
  77. }
  78. }
  79. //获取详情 ssh 2019.12.8
  80. public static function getInfo($id)
  81. {
  82. return CategoryClass::getInfo($id);
  83. }
  84. //添加分类 ssh 2019.12.8
  85. public static function addCategory($data)
  86. {
  87. return CategoryClass::addCategory($data);
  88. }
  89. public static function changeStatus($categoryId, $status)
  90. {
  91. return CategoryClass::changeStatus($categoryId, $status);
  92. }
  93. //更新分类 ssh 2019.12.8
  94. public static function updateCategory($category, $post)
  95. {
  96. $categoryId = $category['id'];
  97. $categoryName = $category['categoryName'];
  98. $sjId = $category['sjId'];
  99. if ($categoryName != $post['categoryName']) {
  100. $nameList = self::getNameList($sjId);
  101. if (in_array($post['categoryName'], $nameList)) {
  102. util::fail('分类名称已经存在');
  103. }
  104. }
  105. CategoryClass::updateById($categoryId, $post);
  106. }
  107. public static function deleteCategory($id)
  108. {
  109. return CategoryClass::deleteCategory($id);
  110. }
  111. }