request->post(); $post['style'] = SjClass::STYLE_RETAIL; $post['introSjId'] = $this->sjId; $post['introStyle'] = SjClass::STYLE_SUPPLIER; $mobile = $post['mobile'] ?? ''; $confirmMobile = $post['confirmMobile']; $address = $post['address'] ?? ''; util::fail('功能已停用'); 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 = SjClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_RETAIL]); if (!empty($has)) { util::fail('名称已经存在'); } $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]); if (!empty($has)) { util::fail('手机号已经添加过'); } if (empty($address)) { util::fail('请填写地址'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $shop = $this->shop; $sjId = $this->sjId; $shopId = $this->shopId; $sjName = $this->sj->name ?? ''; $city = $shop->city ?? ''; $dist = $shop->dist ?? ''; $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' => SjClass::STYLE_RETAIL, 'province' => $shop->province ?? '', 'city' => $city, 'dist' => $dist, 'address' => $address, 'status' => ApplyClass::STATUS_PASS, 'replace' => 1,//1表示供应商添加的客户 ]; $apply = ApplyService::replaceRetail($applyData); $id = $apply['id'] ?? 0; $respond = ApplyService::pass($id); $shop = $respond['shop'] ?? []; $sj = $respond['sj'] ?? []; $hdSjId = $sj['id'] ?? 0; $hdShopId = $shop->id ?? 0; ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]); if (empty($hdShopId)) { util::fail('客户没有添加成功!'); } $custom = CustomClass::build($this->shopId, $hdShopId); $custom['avatar'] = imgUtil::groupImg($custom['avatar']); //客户欠款额度设置 $debt = isset($post['debt']) && $post['debt'] == CustomClass::IS_DEBT_YES ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO; $customId = $custom['id'] ?? 0; $debtLimit = isset($post['debtLimit']) && is_numeric($post['debtLimit']) ? $post['debtLimit'] : 5000; CustomClass::updateById($customId, ['debtLimit' => $debtLimit, 'debt' => $debt]); $transaction->commit(); util::success($custom); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("添加客户没有成功:" . $exception->getMessage()); util::fail('添加客户没有成功'); } } //客户列表 ssh 2021.7.8 public function actionList() { $get = Yii::$app->request->get(); $type = isset($get['type']) ? $get['type'] : 0; $name = isset($get['name']) ? $get['name'] : ''; $where = ['ownShopId' => $this->shopId]; //欠款客户 if (!empty($type) && $type == 1) { $where['isDebt'] = 1; } if (!empty($name)) { if (stringUtil::isLetter($name)) { $where['py'] = ['like', $name]; } else { $where['name'] = ['like', $name]; } } if ($type == 2) { $list = CustomService::getCustomOrderList($where, 'buyAmount DESC'); } else { $list = CustomService::getCustomList($where); } $shop = $this->shop; $list['totalUser'] = $shop->totalUser ?? 0; $list['mayGatheringNum'] = $shop->mayGatheringNum ?? 0; util::success($list); } //客户详情 ssh 2021.1.8 public function actionDetail() { $get = Yii::$app->request->get(); $customId = $get['id'] ?? 0; $info = CustomService::getCustomInfo($customId); CustomClass::valid($info, $this->shopId); //手动添加的客户经纬度不完善不显示地址,引导完善客户地址 if (isset($info['lat']) && empty($info['lat'])) { $info['address'] = ''; } if (isset($info['long']) && empty($info['long'])) { $info['address'] = ''; } $shopId = $info['shopId'] ?? 0; //超管的信息 $superInfo = ShopAdminClass::getSuper($shopId); $superName = $superInfo['name'] ?? ''; $currentSuper = ['name' => $superName]; $info['superInfo'] = $currentSuper; util::success($info); } //允许月结开关 ssh 2021.1.8 public function actionDebt() { $get = Yii::$app->request->get(); $debt = isset($get['debt']) ? $get['debt'] : 0; $customId = isset($get['customId']) ? $get['customId'] : 0; $custom = CustomClass::getById($customId); CustomClass::valid($custom, $this->shopId); CustomClass::debt($custom, $debt); util::complete(); } //采购查看权限的黑白名单开关 shizhongqi 2021.08.08 public function actionSetBlack() { $black = Yii::$app->request->get('black', 2); $customId = Yii::$app->request->get('customId', 0); $custom = CustomClass::getById($customId); CustomClass::valid($custom, $this->shopId); CustomClass::black($custom, $black); util::complete(); } //欠款客户 ssh 2021.2.4 public function actionDebtList() { $get = Yii::$app->request->get(); $where = ['ownShopId' => $this->shopId, 'isDebt' => 1]; if (isset($get['name']) && !empty($get['name'])) { $where['name'] = ['like', $get['name']]; } $list = CustomService::getDebtList($where); //共X个客户,合计欠款XXX元 $shop = $this->shop; $list['customNum'] = $shop->mayGatheringNum ?? 0; $list['debtAmount'] = $shop->mayGathering ?? 0.00; util::success($list); } //修改欠款额度 shish 20210625 public function actionUpdateDebtLimit() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('管理员才能操作'); } $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $debtLimit = $get['debtLimit'] ?? 0; if (is_numeric($debtLimit) == false || $debtLimit <= 0) { util::fail('请填写金额'); } $custom = CustomClass::getById($id, true); CustomClass::valid($custom, $this->shopId); $custom->debtLimit = $debtLimit; $custom->save(); util::complete(); } //修改折扣 shish 20210913 public function actionChangeDiscount() { $shopAdmin = $this->shopAdmin; if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) { util::fail('管理员才能操作'); } $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $discount = $get['discount'] ?? 0; if (is_numeric($discount) == false || $discount > 1 || $discount == 0) { util::fail('请填写小数值'); } $custom = CustomClass::getById($id, true); CustomClass::valid($custom, $this->shopId); $custom->discount = $discount; $custom->save(); $ghsId = $custom->ghsId ?? 0; $ghs = GhsClass::getById($ghsId, true); $ghs->giveDiscount = $discount; $ghs->save(); util::complete(); } }