request->post(); $post['style'] = SjClass::STYLE_RETAIL; $post['introSjId'] = $this->sjId; $post['introStyle'] = SjClass::STYLE_SUPPLIER; $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 = SjClass::getByCondition(['name' => $name, 'style' => ApplyClass::FROM_GHS]); if (!empty($has)) { util::fail('名称已经存在'); } $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => ApplyClass::FROM_GHS]); if (!empty($has)) { 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 ?? ''; $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' => 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']); $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]; switch ($type) { case 1: //已开店 $where['isOpen'] = 1; break; default: } if (!empty($name)) { if (stringUtil::isMobile($name)) { $where['mobile'] = $name; } else { $where['name'] = ['like', $name]; } } $list = CustomService::getCustomList($where); 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'] = ''; } 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(); } //欠款客户 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); } }