CategoryService.php 3.3 KB

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