request->get(); $ownSjId = $get['ownSjId'] ?? ''; $sjId = $get['sjId'] ?? ''; if ($ownSjId == $sjId) { util::fail('不能自己绑自己'); } $sj = MerchantClass::getMerchantById($ownSjId); if (isset($sj['style']) == false || $sj['style'] != SjClass::STYLE_SUPPLIER) { util::fail('城市供货商才能发起绑定'); } $ghsSj = MerchantClass::getMerchantById($sjId); if (isset($ghsSj['style']) == false || $ghsSj['style'] != SjClass::STYLE_KM_SUPPLIER) { util::fail('请选择昆明供货商'); } $count = ShopClass::getCount(['delStatus' => 0, 'merchantId' => $sjId]); if ($count > 1) { util::fail('供货商已经不止一家门店,不知道要绑供货商的哪家店,所以不能再进行绑定'); } $currentShop = ShopClass::getByCondition(['merchantId' => $sjId, 'delStatus' => 0]); if (empty($currentShop)) { util::fail('没有找到门店'); } $currentShopId = $currentShop['id'] ?? 0; $list = ShopClass::getAllByCondition(['merchantId' => $ownSjId, 'delStatus' => 0], null, '*'); if (empty($list)) { util::fail('没有找到门店'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { foreach ($list as $current) { $ownShopId = $current['id']; GhsClass::build($currentShopId, $ownShopId); } $transaction->commit(); util::complete(); } catch (Exception $exception) { $transaction->rollBack(); util::fail("绑定失败"); } } }