request->post(); $mobile = $post['mobile'] ?? ''; $confirmMobile = $post['confirmMobile']; if (stringUtil::isMobile($mobile) == false) { util::fail(' 请填写正确的手机号'); } if ($mobile != $confirmMobile) { util::fail('二次号码填写不一致'); } $name = $post['name'] ?? ''; if (empty($name)) { util::fail('名称不能为空'); } if (stringUtil::getWordNum($name) > 8) { util::fail('名称不能超过8个汉字'); } $has = ApplyClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_KM_SUPPLIER]); if (!empty($has)) { util::fail('名称已经存在'); } $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]); if (!empty($has)) { $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $shopId = $this->shopId; $currentShopId = $has['shopId'] ?? 0; if (empty($currentShopId)) { util::fail('添加失败'); } $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true); if (!empty($hasGhs)) { $name = $hasGhs->name ?? ''; util::fail("手机已添加过了,供货商名称:【{$name}】"); } $ghs = GhsClass::build($currentShopId, $shopId, 1); $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']); $transaction->commit(); util::success($ghs); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("添加供货商没有成功:" . $exception->getMessage()); util::fail('添加供货商没有成功'); } util::fail('添加失败,请联系管理员'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $sjId = $this->sjId; $shopId = $this->shopId; $sjName = $this->sj->name ?? ''; $address = $post['address'] ?? ''; $applyData = [ 'name' => $name, 'licenseNo' => $mobile, 'certType' => ApplyClass::CERT_TYPE_MOBILE, 'mobile' => $mobile, 'introSjId' => $sjId, 'introSjName' => $sjName, 'introShopId' => $shopId, 'introStyle' => SjClass::STYLE_SUPPLIER, 'from' => ApplyClass::FROM_GHS, 'style' => dict::getDict('ptStyle', 'kmGhs'), 'address' => $address, 'status' => ApplyClass::STATUS_PASS, ]; $apply = ApplyService::replaceKmGhs($applyData); $id = $apply['id'] ?? 0; $respond = \bizJd\apply\services\ApplyService::pass($id); $shop = $respond['shop'] ?? []; $sj = $respond['sj'] ?? []; $currentSjId = $sj['id'] ?? 0; $currentShopId = $shop->id ?? 0; ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]); if (empty($currentShopId)) { util::fail('供货商没有添加成功!'); } $ghs = GhsClass::build($currentShopId, $shopId, 1); $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']); $transaction->commit(); util::success($ghs); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("添加供货商没有成功:" . $exception->getMessage()); util::fail('添加供货商没有成功'); } } //供货商列表 ssh 2021.1.18 public function actionList() { $get = Yii::$app->request->get(); $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : ''; $where = ['ownShopId' => $this->shopId]; if (!empty($name)) { if (stringUtil::isLetter($name)) { $where['py'] = ['like', $name]; } else { $where['name'] = ['like', $name]; } } $list = GhsClass::getGhsList($where); util::success($list); } }