| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace bizGhs\custom\classes;
- use bizGhs\shop\classes\ShopClass;
- use bizHd\base\classes\BaseClass;
- class DistClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\custom\models\Dist';
- public static function getDistList($where)
- {
- return self::getList('*', $where, null);
- }
- //新增花材分类
- public static function addDist($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;
- }
- }
|