CategoryService.php 3.9 KB

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