| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/1/13 17:12
- */
- namespace bizGhs\item\classes;
- use bizGhs\base\classes\BaseClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\shop\classes\ShopClass;
- use common\components\imgUtil;
- use common\components\util;
- //use bizHd\base\classes\BaseClass;
- class ItemClassClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\item\models\ItemClass';
- //特价花材分类
- const TJ_CLASS_ID = '-1';
- public static function getGhsItemClassList($where)
- {
- $data = self::getList('*', $where, 'inTurn DESC');
- $list = !empty($data['list']) ? $data['list'] : [];
- if (empty($list)) {
- return $data;
- }
- foreach ($list as $key => $val) {
- $shortCover = $val['cover'] ?? '';
- $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- $list[$key]['smallCover'] = $cover;
- $list[$key]['bigCover'] = $bigCover;
- }
- $data['list'] = $list;
- return $data;
- }
- //新增花材分类
- public static function addGhsItemClass($masterShop, $data)
- {
- $mainId = $masterShop->mainId ?? 0;
- $name = $data['name'] ?? '';
- if (empty($name)) {
- util::fail("请输入花材分类");
- }
- $has = self::getByCondition(['mainId' => $mainId, 'name' => $name]);
- if ($has) {
- util::fail("花材分类名称已存在");
- }
- $res = self::add($data);
- //在首店添加,则父级下所有直营和加盟店,同步添加分类
- if (isset($masterShop->default) && $masterShop->default == 1) {
- $sjId = $masterShop->sjId ?? 0;
- $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
- foreach ($shopList as $shop) {
- $shopId = $shop->id ?? 0;
- if ($shopId == $masterShop->id) {
- //前面已经添加过了
- continue;
- }
- $thisMainId = $shop->mainId ?? 0;
- $data['shopId'] = $shopId;
- $data['mainId'] = $thisMainId;
- $has = self::getByCondition(['mainId' => $thisMainId, 'name' => $name]);
- if (!empty($has)) {
- continue;
- }
- self::add($data);
- }
- }
- return $res;
- }
- //批量新增花材分类
- public static function batchAddGhsItemClass($data)
- {
- self::batchAdd($data);
- return true;
- }
- //修改
- public static function updateGhsItemClass($data)
- {
- $id = $data['id'] ?? 0;
- $sjId = $data['sjId'] ?? 0;
- $name = $data['name'] ?? '';
- if (!$sjId) {
- util::fail("请选择供货商");
- }
- if (!$name) {
- util::fail("花材分类名称不能为空");
- }
- $model = self::getById($id);
- if (!$model) {
- util::fail("该花材分类不存在");
- }
- if ($model['sjId'] !== $data['sjId']) {
- util::fail("参数错误");
- }
- self::updateById($id, $data);
- return true;
- }
- //花材列表页分类,包含今日特价分类 ssh 20220315
- public static function getShopClass($mainId)
- {
- $class = self::getAllList('id,name,cover', ['mainId' => $mainId], 'inTurn desc');
- $itemList = ProductClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0, 'status' => 1], null, 'id,name,reachNum,reachNumDiscount,presell,discountPrice', null, true);
- if (!empty($itemList)) {
- $arr = [];
- //有多处需要同步修改,show_my_item_class_list ssh 20260107
- foreach ($itemList as $item) {
- $reachNum = $item->reachNum ?? 0;
- $reachNumDiscount = $item->reachNumDiscount ?? 0;
- if (isset($item->presell) && $item->presell == 1) {
- $arr[3] = [
- 'id' => -3,
- 'name' => '预售专区',
- 'shortCover' => 'item_class/mrfl.png',
- 'cover' => imgUtil::groupImg('item_class/mrfl.png') . "?x-oss-process=image/resize,m_fill,h_130,w_130"
- ];
- }
- if (isset($item->discountPrice) && $item->discountPrice > 0) {
- $arr[1] = [
- 'id' => -1,
- 'name' => '今日推荐',
- 'shortCover' => 'item_class/tj.jpg',
- 'cover' => imgUtil::groupImg('item_class/tj.jpg') . "?x-oss-process=image/resize,m_fill,h_130,w_130"
- ];
- }
- if ($reachNum > 0 && $reachNumDiscount > 0) {
- $arr[2] = [
- 'id' => -2,
- 'name' => '满减活动',
- 'shortCover' => 'item_class/mrfl.png',
- 'cover' => imgUtil::groupImg('item_class/mrfl.png') . "?x-oss-process=image/resize,m_fill,h_130,w_130"
- ];
- }
- }
- $arr = array_values($arr);
- $class = array_merge($arr, $class);
- }
- foreach ($class as $key => $item) {
- $class[$key]['cover'] = imgUtil::groupImg($item['cover']) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- }
- return $class;
- }
- //获取开单页所有的分类
- //这里不能取出className,否则会影响前端显示,重要注意事项,请搜索关键词import_class_name!!!!!!!!!!!!!!
- public static function getGhsItemClassAll($mainId)
- {
- $where = ['mainId' => $mainId];
- $data = self::getAllList('id,name,cover,print,isDefault', $where, 'inTurn desc');
- if (!empty($data)) {
- foreach ($data as $key => $val) {
- $shortCover = $val['cover'] ?? '';
- $data[$key]['shortCover'] = $shortCover;
- $data[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_80,w_80";
- }
- }
- return $data;
- }
- //获取当前供货商下的所有class
- public static function getAll($sjId, $select = "*")
- {
- $where = [
- 'sjId' => $sjId
- ];
- $data = self::getAllList($select, $where);
- return $data;
- }
- //验证分类 ssh 20211015
- public static function valid($class, $mainId)
- {
- if ($class->mainId == $mainId) {
- return true;
- }
- //util::fail('分类不正确');
- }
- //获取当前商家下默认分类id
- public static function getDefaultClassId($mainId)
- {
- $where = ['mainId' => $mainId, 'isDefault' => 1];
- $res = self::getByCondition($where, true);
- if (!$res) {
- //没有则新增
- $classData = ['mainId' => $mainId, 'name' => '默认分类', 'inTurn' => -1, 'isDefault' => 1];
- $res = self::add($classData, true);
- }
- return $res->id ?? 0;
- }
- }
|