$hdShopId, 'shopId' => $ghsShopId]); if (!empty($ghs)) { return $ghs; } } else { $custom = CustomClass::getByCondition(['ownShopId' => $ghsShopId, 'shopId' => $hdShopId]); if (!empty($custom)) { return $custom; } } $ghsShop = ShopClass::getShopInfo($ghsShopId); $ghsSjId = $ghsShop['sjId'] ?? 0; $ghsMainId = $ghsShop['mainId'] ?? 0; $ghsDefault = $ghsShop['default'] ?? 0; $name = $ghsDefault == 1 ? $ghsShop['merchantName'] : $ghsShop['merchantName'] . ' ' . $ghsShop['shopName']; $py = stringUtil::py($name); $hdShopInfo = ShopClass::getShopInfo($hdShopId); $hdSjId = $hdShopInfo['sjId'] ?? 0; $hdMainId = $hdShopInfo['mainId'] ?? 0; $data = [ 'sjId' => $ghsSjId, 'shopId' => $ghsShopId, 'mainId' => $ghsMainId, 'ownSjId' => $hdSjId, 'ownShopId' => $hdShopId, 'ownMainId' => $hdMainId, 'name' => $name, 'py' => $py, 'mobile' => $ghsShop['mobile'] ?? '', 'province' => $ghsShop['province'] ?? '', 'city' => $ghsShop['city'] ?? '', 'dist' => $ghsShop['dist'] ?? '', 'address' => $ghsShop['address'] ?? '', 'floor' => $ghsShop['floor'] ?? '', 'fullAddress' => $ghsShop['fullAddress'] ?? '', 'lat' => $ghsShop['lat'] ?? '', 'long' => $ghsShop['long'] ?? '', ]; $ghs = self::addGhs($data); $ghsId = $ghs['id'] ?? 0; $shop = ShopClass::getShopInfo($hdShopId); $default = $shop['default'] ?? 0; $name = $default == 1 ? $shop['merchantName'] : $shop['merchantName'] . ' ' . $shop['shopName']; $py = stringUtil::py($name); $mobile = $shop['mobile'] ?? ''; $uniGhsId = $shop['uniGhsId'] ?? 0; $hasManyGhs = $shop['hasManyGhs'] ?? 0; if ($uniGhsId == 0 && $hasManyGhs == 0) { ShopClass::updateById($hdShopId, ['uniGhsId' => $ghsId]); } else { //从只有一个供应商变成有多个供应商 ShopClass::updateById($hdShopId, ['hasManyGhs' => 1]); } $debtLimit = 5000;//欠款额度 $customData = [ 'sjId' => $hdSjId, 'ghsId' => $ghsId, 'shopId' => $hdShopId, 'mainId' => $hdMainId, 'ownSjId' => $ghsSjId, 'ownShopId' => $ghsShopId, 'ownMainId' => $ghsMainId, 'name' => $name, 'py' => $py, 'mobile' => $mobile, 'province' => $shop['province'] ?? '', 'city' => $shop['city'] ?? '', 'dist' => $shop['dist'] ?? '', 'address' => $shop['address'] ?? '', 'fullAddress' => $shop['fullAddress'] ?? '', 'long' => $shop['long'] ?? '', 'lat' => $shop['lat'] ?? '', 'debtLimit' => $debtLimit, ]; $custom = CustomClass::addCustom($customData); $customId = $custom['id'] ?? 0; self::updateById($ghsId, ['customId' => $customId]); $customSjId = $custom['sjId'] ?? 0; $customSj = SjClass::getById($customSjId, true); $parentShopId = $customSj->parentShopId ?? 0; $introduce = []; if (!empty($parentShopId)) { $introduce = CustomClass::getByCondition(['ownShopId' => $ghsShopId, 'shopId' => $parentShopId], true); } //有新客户提醒供货商 WxMessageClass::newGhsCustomInform($ghsShop, $custom, $introduce); //新客户加入app通知 NoticeClass::newCustomNotice($ghsShop, $custom); if ($type == 1) { return $ghs; } return $custom; } //增加供应商 ssh 2021.3.29 public static function addGhs($data) { return self::add($data); } //供应商列表 ssh 2021.1.24 public static function getGhsList($where) { $data = self::getList('*', $where, 'inTurn DESC,addTime DESC'); $data['list'] = self::groupBaseInfo($data['list']); return $data; } //根据xhSupplier的id数组 取供应商信息 ssh 2021.1.18 public static function getGhsByIds($ids) { $list = self::getByIds($ids, null, 'id'); if (empty($list)) { return []; } $list = self::groupBaseInfo($list); return $list; } public static function groupBaseInfo($list) { if (empty($list)) { return $list; } $ids = array_column($list, 'shopId'); $shopInfo = ShopClass::getByIds($ids, null, 'id'); foreach ($list as $key => $val) { $avatar = $val['avatar'] ?? ''; $list[$key]['avatar'] = imgUtil::groupImg($avatar); $currentShopId = $val['shopId'] ?? 0; //新人福利和推荐福利 $xrFl = $shopInfo[$currentShopId]['xrFl'] ?? 0; $xrFlAmount = $shopInfo[$currentShopId]['xrFlAmount'] ?? 0; $tjFl = $shopInfo[$currentShopId]['tjFl'] ?? 0; $tjFlAmount = $shopInfo[$currentShopId]['tjFlAmount'] ?? 0; $list[$key]['xrFl'] = $xrFl; $list[$key]['xrFlAmount'] = $xrFlAmount; $list[$key]['tjFl'] = $tjFl; $list[$key]['tjFlAmount'] = $tjFlAmount; $list[$key]['miniKilo'] = $shopInfo[$currentShopId]['miniKilo'] ?? 0; $list[$key]['kiloFee'] = $shopInfo[$currentShopId]['kiloFee'] ?? 0; $isOpen = 0; if (isset($shopInfo[$currentShopId])) { $isOpen = ShopClass::isOpen($shopInfo[$currentShopId]); } //营业状态 $list[$key]['isOpen'] = $isOpen; $list[$key]['openStartTime'] = $shopInfo[$currentShopId]['openStartTime'] ?? ''; $list[$key]['openEndTime'] = $shopInfo[$currentShopId]['openEndTime'] ?? ''; } return $list; } //根据供应商信息 ssh 2021.1.18 public static function getGhsInfo($id) { $info = self::getById($id); if (empty($info)) { return []; } $list = self::groupBaseInfo([$info]); return current($list); } //待结款列表 ssh 2021.126 public static function getDebtList($where) { $sjId = $where['sjId'] ?? 0; if (empty($sjId)) { util::fail('没有找到商家'); } $data = self::getList('*', $where, 'debtAmount DESC'); $data['list'] = self::groupBaseInfo($data['list']); $asset = MerchantAssetClass::getBySjId($sjId); $data['debtAmount'] = $asset['cgDebtAmount'] ?? 0.00; $data['debtNum'] = $asset['cgDebtNum'] ?? 0; return $data; } //验证权限 ssh 2021.4.11 public static function valid($info, $shopId) { if (empty($info)) { util::fail('没有供应商'); } if ($info['ownShopId'] == $shopId) { return true; } util::fail('您没有权限访问的供应商'); } }