ItemClassClass.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/1/13 17:12
  5. */
  6. namespace bizGhs\item\classes;
  7. use bizGhs\base\classes\BaseClass;
  8. use bizGhs\product\classes\ProductClass;
  9. use bizGhs\shop\classes\ShopClass;
  10. use common\components\imgUtil;
  11. use common\components\util;
  12. //use bizHd\base\classes\BaseClass;
  13. class ItemClassClass extends BaseClass
  14. {
  15. public static $baseFile = '\bizGhs\item\models\ItemClass';
  16. //特价花材分类
  17. const TJ_CLASS_ID = '-1';
  18. public static function getGhsItemClassList($where)
  19. {
  20. $data = self::getList('*', $where, 'inTurn DESC');
  21. $list = !empty($data['list']) ? $data['list'] : [];
  22. if (empty($list)) {
  23. return $data;
  24. }
  25. foreach ($list as $key => $val) {
  26. $shortCover = $val['cover'] ?? '';
  27. $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  28. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  29. $list[$key]['smallCover'] = $cover;
  30. $list[$key]['bigCover'] = $bigCover;
  31. }
  32. $data['list'] = $list;
  33. return $data;
  34. }
  35. //新增花材分类
  36. public static function addGhsItemClass($masterShop, $data)
  37. {
  38. $mainId = $masterShop->mainId ?? 0;
  39. $name = $data['name'] ?? '';
  40. if (empty($name)) {
  41. util::fail("请输入花材分类");
  42. }
  43. $has = self::getByCondition(['mainId' => $mainId, 'name' => $name]);
  44. if ($has) {
  45. util::fail("花材分类名称已存在");
  46. }
  47. $res = self::add($data);
  48. //在首店添加,则父级下所有直营和加盟店,同步添加分类
  49. if (isset($masterShop->default) && $masterShop->default == 1) {
  50. $sjId = $masterShop->sjId ?? 0;
  51. $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  52. foreach ($shopList as $shop) {
  53. $shopId = $shop->id ?? 0;
  54. if ($shopId == $masterShop->id) {
  55. //前面已经添加过了
  56. continue;
  57. }
  58. $thisMainId = $shop->mainId ?? 0;
  59. $data['shopId'] = $shopId;
  60. $data['mainId'] = $thisMainId;
  61. $has = self::getByCondition(['mainId' => $thisMainId, 'name' => $name]);
  62. if (!empty($has)) {
  63. continue;
  64. }
  65. self::add($data);
  66. }
  67. }
  68. return $res;
  69. }
  70. //批量新增花材分类
  71. public static function batchAddGhsItemClass($data)
  72. {
  73. self::batchAdd($data);
  74. return true;
  75. }
  76. //修改
  77. public static function updateGhsItemClass($data)
  78. {
  79. $id = $data['id'] ?? 0;
  80. $sjId = $data['sjId'] ?? 0;
  81. $name = $data['name'] ?? '';
  82. if (!$sjId) {
  83. util::fail("请选择供货商");
  84. }
  85. if (!$name) {
  86. util::fail("花材分类名称不能为空");
  87. }
  88. $model = self::getById($id);
  89. if (!$model) {
  90. util::fail("该花材分类不存在");
  91. }
  92. if ($model['sjId'] !== $data['sjId']) {
  93. util::fail("参数错误");
  94. }
  95. self::updateById($id, $data);
  96. return true;
  97. }
  98. //花材列表页分类,包含今日特价分类 ssh 20220315
  99. public static function getShopClass($mainId)
  100. {
  101. $class = self::getAllList('id,name,cover', ['mainId' => $mainId], 'inTurn desc');
  102. $itemList = ProductClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0, 'status' => 1], null, 'id,name,reachNum,reachNumDiscount,presell,discountPrice', null, true);
  103. if (!empty($itemList)) {
  104. $arr = [];
  105. //有多处需要同步修改,show_my_item_class_list ssh 20260107
  106. foreach ($itemList as $item) {
  107. $reachNum = $item->reachNum ?? 0;
  108. $reachNumDiscount = $item->reachNumDiscount ?? 0;
  109. if (isset($item->presell) && $item->presell == 1) {
  110. $arr[3] = [
  111. 'id' => -3,
  112. 'name' => '预售专区',
  113. 'shortCover' => 'item_class/mrfl.png',
  114. 'cover' => imgUtil::groupImg('item_class/mrfl.png') . "?x-oss-process=image/resize,m_fill,h_130,w_130"
  115. ];
  116. }
  117. if (isset($item->discountPrice) && $item->discountPrice > 0) {
  118. $arr[1] = [
  119. 'id' => -1,
  120. 'name' => '今日推荐',
  121. 'shortCover' => 'item_class/tj.jpg',
  122. 'cover' => imgUtil::groupImg('item_class/tj.jpg') . "?x-oss-process=image/resize,m_fill,h_130,w_130"
  123. ];
  124. }
  125. if ($reachNum > 0 && $reachNumDiscount > 0) {
  126. $arr[2] = [
  127. 'id' => -2,
  128. 'name' => '满减活动',
  129. 'shortCover' => 'item_class/mrfl.png',
  130. 'cover' => imgUtil::groupImg('item_class/mrfl.png') . "?x-oss-process=image/resize,m_fill,h_130,w_130"
  131. ];
  132. }
  133. }
  134. $arr = array_values($arr);
  135. $class = array_merge($arr, $class);
  136. }
  137. foreach ($class as $key => $item) {
  138. $class[$key]['cover'] = imgUtil::groupImg($item['cover']) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  139. }
  140. return $class;
  141. }
  142. //获取开单页所有的分类
  143. //这里不能取出className,否则会影响前端显示,重要注意事项,请搜索关键词import_class_name!!!!!!!!!!!!!!
  144. public static function getGhsItemClassAll($mainId)
  145. {
  146. $where = ['mainId' => $mainId];
  147. $data = self::getAllList('id,name,cover,print,isDefault', $where, 'inTurn desc');
  148. if (!empty($data)) {
  149. foreach ($data as $key => $val) {
  150. $shortCover = $val['cover'] ?? '';
  151. $data[$key]['shortCover'] = $shortCover;
  152. $data[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_80,w_80";
  153. }
  154. }
  155. return $data;
  156. }
  157. //获取当前供货商下的所有class
  158. public static function getAll($sjId, $select = "*")
  159. {
  160. $where = [
  161. 'sjId' => $sjId
  162. ];
  163. $data = self::getAllList($select, $where);
  164. return $data;
  165. }
  166. //验证分类 ssh 20211015
  167. public static function valid($class, $mainId)
  168. {
  169. if ($class->mainId == $mainId) {
  170. return true;
  171. }
  172. //util::fail('分类不正确');
  173. }
  174. //获取当前商家下默认分类id
  175. public static function getDefaultClassId($mainId)
  176. {
  177. $where = ['mainId' => $mainId, 'isDefault' => 1];
  178. $res = self::getByCondition($where, true);
  179. if (!$res) {
  180. //没有则新增
  181. $classData = ['mainId' => $mainId, 'name' => '默认分类', 'inTurn' => -1, 'isDefault' => 1];
  182. $res = self::add($classData, true);
  183. }
  184. return $res->id ?? 0;
  185. }
  186. }