request->get(); $id = $get['id'] ?? 0; $ghs = GhsClass::getById($id, true); if (empty($ghs)) { util::fail('没有找到供货商'); } if ($ghs->ownMainId != $this->mainId) { util::fail('不是你的供货商'); } $newLocation = $ghs->location == 0 ? 1 : 0; $ghs->location = $newLocation; $ghs->save(); util::complete('修改成功'); } public function actionModifyName() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $name = $get['name'] ?? ''; $ghs = GhsClass::getById($id, true); if (empty($ghs)) { util::fail('没有找到供货商'); } if ($ghs->ownMainId != $this->mainId) { util::fail('不是你的供货商'); } if (empty($name)) { util::fail('请填写名称'); } if (stringUtil::getWordNum($name) > 27) { util::fail('名称不能超过27个汉字'); } $ghs->name = $name; $ghs->py = stringUtil::py($name); $ghs->save(); util::complete('修改成功'); } //添加供货商 ssh 20210611 public function actionAdd() { $post = Yii::$app->request->post(); $location = $post['location'] ?? ''; $mobile = $post['mobile'] ?? ''; $name = $post['name'] ?? ''; if (empty($name)) { util::fail('名称不能为空'); } if (stringUtil::getWordNum($name) > 27) { util::fail('名称不能超过27个汉字'); } $hasGhsList = GhsClass::getAllByCondition(['ownShopId' => $this->shopId], null, '*', null, true); if (!empty($hasGhsList)) { foreach ($hasGhsList as $hasGhs) { $hasGhsName = $hasGhs->name ?? ''; if ($hasGhsName == $name) { util::fail('名称已经存在了'); } } } if (!empty($mobile)) { $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 = \biz\ghs\classes\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 { if (empty($mobile)) { //获取虚拟手机号 $mobile = orderSn::getMobileSn(); } $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 = \biz\ghs\classes\GhsClass::build($currentShopId, $shopId, 1); $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']); if (is_numeric($location)) { //本地批发商的标记 $ghsId = $ghs['id'] ?? 0; \biz\ghs\classes\GhsClass::updateById($ghsId, ['location' => $location]); } $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]; } } $location = $get['location'] ?? ''; if (is_numeric($location)) { $where['location'] = $location; } //采购限制访问,有多处要同步修改,关键词cg_limit_access if (getenv('YII_ENV') == 'production') { //纯彩花艺 if ($this->mainId == 10) { if (in_array($this->adminId, [37, 988, 14346]) == false) { util::fail('没有数据哦4'); } } //天天鲜花十堰店 if ($this->mainId == 7184) { if (in_array($this->adminId, [8340, 8345, 9433]) == false) { util::fail('没有数据哦5'); } } //小向花卉采购控制 if ($this->mainId == 23390) { if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4])) { util::fail('没有数据哦6'); } } //贴心鲜花批发,只有老板可以查看 if ($this->mainId == 15144) { if (!in_array($this->adminId, [16163])) { util::fail('暂时不能查看哦,编号6868'); } } } $list = GhsClass::getGhsList($where); $staff = $this->shopAdmin; if (isset($staff->finance) == false || $staff->finance == 0) { $totalDebtAmount = 0; //没有财务权限的人不让看到欠款多少 if (!empty($list['list'])) { foreach ($list['list'] as $key => $val) { $list['list'][$key]['debtAmount'] = 0; } } } else { //累计总欠款 $totalDebtAmount = PurchaseOrderClass::sum(['mainId' => $this->mainId, 'status' => 4, 'debt' => PurchaseOrderClass::DEBT_YES], 'actPrice'); } $list['totalDebtAmount'] = $totalDebtAmount; util::success($list); } //下载供货商 ssh 20240506 public function actionDownloadGhs() { //$get = Yii::$app->request->get(); $mainId = $this->mainId; $respond = GhsClass::getGhsFile($mainId); $file = $respond['file'] ?? ''; $shortFile = $respond['shortFile'] ?? ''; $fileUrl = Yii::$app->params['ghsHost'] . $file; util::success(['file' => $fileUrl, 'shortFile' => $shortFile]); } }