$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; $ghsOwnPtStyle = $ghsShop['ptStyle'] ?? 1; $ghsAvatar = $ghsShop['shortAvatar'] ?? ''; $ghsDefault = $ghsShop['default'] ?? 0; $allowDebt = $ghsShop['allowDebt'] ?? 0; $needCheck = $ghsShop['needCheck'] ?? 0; $home = $ghsShop['home'] ?? 0; $homeAmount = $ghsShop['homeAmount'] ?? 0; $homeType = $ghsShop['homeType']??0; $passStatus = $needCheck == 1 ? 0 : 1; $live = isset($ghsShop['live']) ? $ghsShop['live'] : 1; $isHd = $ghsShop['isHd'] ?? 1; $showStock = $ghsShop['showStock'] ?? 0; $allowDebtAmount = $ghsShop['allowDebtAmount'] ?? 0; if ($isHd == 1) { $giveLevel = 1; $level = 1; } else { $giveLevel = 0; $level = 0; } $name = $ghsDefault == 1 && $ghsShop['shopName'] == '首店' ? $ghsShop['merchantName'] : $ghsShop['merchantName'] . ' ' . $ghsShop['shopName']; $py = stringUtil::py($name); $hdShopInfo = ShopClass::getShopInfo($hdShopId); $hdSjId = $hdShopInfo['sjId'] ?? 0; $hdMainId = $hdShopInfo['mainId'] ?? 0; $hdOwnPtStyle = $hdShopInfo['ptStyle'] ?? 1; $salt = stringUtil::charsShuffleLowerCase(8); $data = [ 'sjId' => $ghsSjId, 'shopId' => $ghsShopId, 'mainId' => $ghsMainId, 'ownSjId' => $hdSjId, 'ownShopId' => $hdShopId, 'ownMainId' => $hdMainId, 'ownPtStyle' => $hdOwnPtStyle, 'name' => $name, 'py' => $py, 'avatar' => $ghsAvatar, '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'] ?? '', 'live' => $live, 'giveLevel' => $giveLevel, 'showStock' => $showStock, 'salt' => $salt, 'passStatus' => $passStatus, 'home'=>$home, 'homeAmount'=>$homeAmount, 'homeType'=>$homeType, ]; $ghs = self::addGhs($data); $ghsId = $ghs['id'] ?? 0; $shop = ShopClass::getShopInfo($hdShopId); $hdAvatar = $shop['shortAvatar'] ?? ''; $default = $shop['default'] ?? 0; $name = $default == 1 && $shop['shopName'] == '首店' ? $shop['merchantName'] : $shop['merchantName'] . ' ' . $shop['shopName']; //从分店同步客户,客户被修改的名称也要同步过来 $firstName = empty($changeName) ? $name : $changeName; $py = stringUtil::py($firstName); $secondName = $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 = 0;//欠款额度 $customData = [ 'sjId' => $hdSjId, 'ghsId' => $ghsId, 'shopId' => $hdShopId, 'mainId' => $hdMainId, 'ownSjId' => $ghsSjId, 'ownShopId' => $ghsShopId, 'ownMainId' => $ghsMainId, 'ownPtStyle' => $ghsOwnPtStyle, 'name' => $firstName, 'originName' => $secondName, 'py' => $py, 'avatar' => $hdAvatar, 'mobile' => $mobile, 'province' => $shop['province'] ?? '', 'city' => $shop['city'] ?? '', 'dist' => $shop['dist'] ?? '', 'address' => $shop['address'] ?? '', 'fullAddress' => $shop['fullAddress'] ?? '', 'showAddress' => $shop['showAddress'] ?? '', 'long' => $shop['long'] ?? '', 'lat' => $shop['lat'] ?? '', 'debtLimit' => $debtLimit, 'debt' => $allowDebt, 'debtLimit' => $allowDebtAmount, 'live' => $live, 'level' => $level, 'showStock' => $showStock, 'salt' => $salt, 'passStatus' => $passStatus, 'home'=>$home, 'homeAmount'=>$homeAmount, 'homeType'=>$homeType, ]; $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); } //有新客户提醒供货商 $ghsShopObj = ShopClass::getById($ghsShopId, true); $customObj = CustomClass::getById($customId, true); WxMessageClass::newGhsCustomInform($ghsShopObj, $customObj, $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 ASC'); $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]['shortAvatar'] = $avatar; $list[$key]['avatar'] = imgUtil::groupImg($avatar); $list[$key]['smallAvatar'] = imgUtil::groupImg($avatar). "?x-oss-process=image/resize,m_fill,h_80,w_80"; $currentShopId = $val['shopId'] ?? 0; $currentShop = $shopInfo[$currentShopId] ?? []; //新人福利和推荐福利 $xrFl = $currentShop['xrFl'] ?? 0; $xrFlAmount = $currentShop['xrFlAmount'] ?? 0; $tjFl = $currentShop['tjFl'] ?? 0; $tjFlAmount = $currentShop['tjFlAmount'] ?? 0; $list[$key]['xrFl'] = $xrFl; $list[$key]['xrFlAmount'] = $xrFlAmount; $list[$key]['tjFl'] = $tjFl; $list[$key]['tjFlAmount'] = $tjFlAmount; $list[$key]['miniKilo'] = $currentShop['miniKilo'] ?? 0; $list[$key]['kiloFee'] = $currentShop['kiloFee'] ?? 0; $list[$key]['presell'] = $currentShop['presell'] ?? 0; $isOpen = 0; if (!empty($currentShop)) { $isOpen = ShopClass::isOpen($currentShop); } //营业状态 $list[$key]['isOpen'] = $isOpen; $list[$key]['openStartTime'] = $currentShop['openStartTime'] ?? ''; $list[$key]['openEndTime'] = $currentShop['openEndTime'] ?? ''; $list[$key]['meetNum'] = isset($currentShop['meetNum']) ? floatval($currentShop['meetNum']) : 0; $list[$key]['meetAmount'] = isset($currentShop['meetAmount']) ? floatval($currentShop['meetAmount']) : 0; $list[$key]['cutAmount'] = isset($currentShop['cutAmount']) ? floatval($currentShop['cutAmount']) : 0; $list[$key]['cutStyle'] = isset($currentShop['cutStyle']) ? floatval($currentShop['cutStyle']) : 0; $count = PurchaseClass::getCount(['ghsId' => $val['id'], 'debt' => PurchaseClass::DEBT_YES]); $list[$key]['debtNum'] = $count; $telephone = $currentShop['telephone'] ?? ''; $list[$key]['telephone'] = $telephone; $telephone2 = $currentShop['telephone2'] ?? ''; $list[$key]['telephone2'] = $telephone2; $balance = $val['balance'] ?? 0; $debtAmount = $val['debtAmount'] ?? 0; $remainDebtAmount = bcsub($debtAmount, $balance, 2); $list[$key]['remainDebtAmount'] = floatval($remainDebtAmount); //与花神的合作 $openKmCg = $currentShop['openKmCg'] ?? 0; $kmCgAppId = $currentShop['kmCgAppId'] ?? ''; $kmCgUrl = $currentShop['kmCgUrl'] ?? ''; $list[$key]['openKmCg'] = $openKmCg; $list[$key]['kmCgAppId'] = $kmCgAppId; $list[$key]['kmCgUrl'] = $kmCgUrl; $pfLevel = $currentShop['pfLevel'] ?? 0; $list[$key]['pfLevel'] = $pfLevel; if (isset($val['mobile']) == false || empty($val['mobile'])) { $mobile = $currentShop['mobile'] ?? ''; $list[$key]['mobile'] = $mobile; } } 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('找不到供货商'); } }