123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- namespace app\admin\service\consultant;
- use app\model\Consultant;
- use app\model\MarketCustomer;
- use app\model\Member;
- use support\Db;
- use support\exception\BusinessException;
- class CustomService
- {
- /**
- * Notes: 处理参数
- * User: yb
- * Date: 2024/8/6
- * Time: 11:43
- * @param $data
- * @return mixed
- */
- protected static function handleNumParams($data)
- {
- $setField = ['require_area', 'requirement', 'age_range', 'focus', 'region'];
- foreach ($data as $k => $v) {
- if (in_array($k, $setField)) {
- if (is_numeric($v)) {
- $data[$k] = $v + 1;
- } else {
- $data[$k] = null;
- }
- }
- }
- if ($data['type'] == 1) {
- //来电
- if (!empty($data['area'])) {
- $area = $data['area'];
- $requireArea = 1;
- if ($area >= 40 && $area < 51) {
- $requireArea = 2;
- } else if ($area >= 51 && $area < 61) {
- $requireArea = 3;
- } else if ($area >= 61 && $area < 81) {
- $requireArea = 4;
- } else if ($area >= 81 && $area < 101) {
- $requireArea = 5;
- } else if ($area >= 101 && $area < 121) {
- $requireArea = 6;
- } else if ($area >= 121 && $area < 151) {
- $requireArea = 7;
- } else if ($area >= 151) {
- $requireArea = 8;
- }
- $data['require_area'] = $requireArea;
- $data['age_range'] = null;
- } else {
- $data['area'] = null;
- }
- } else {
- //来访
- $data['area'] = null;
- }
- if (!empty($data['visit_time'])) {
- $data['visit_time'] = strtotime($data['visit_time']);
- }
- if (empty($data['visit_type'])) {
- $data['visit_type'] = null;
- }
- if (empty($data['level'])) {
- $data['level'] = null;
- }
- if (empty($data['purpose'])) {
- $data['purpose'] = null;
- }
- return $data;
- }
- /**
- * Notes: 返回选项配置信息
- * User: yb
- * Date: 2024/8/5
- * Time: 16:05
- * @return array
- */
- public static function config()
- {
- $config = [
- 'requirement' => ['康养公寓', '颐养公寓', '商业', '其他'],
- 'require_area' => ['40㎡以下', '40㎡-50㎡', '51㎡-60㎡', '61㎡-80㎡', '81㎡-100㎡', '101㎡-120㎡', '121㎡-150㎡', '150㎡以上'],
- 'age_range' => ['40岁以下', '21岁-30岁', '31岁-40岁', '41岁-50岁', '51岁-60岁', '61岁-80岁', '80岁以上'],
- 'visit_type' => [
- 'common' => ['', '路过', '分销', '朋友介绍', '安居客、房天下', '微信朋友圈', '户外', '微信公众号', '工地围挡', '老带新', '圈层营销', '自拓'],
- 'type1' => ['100' => '派单', '101' => '城市展厅', '102' => '活动'],
- 'type2' => ['200' => '内渠', '201' => '自渠']
- ],
- 'focus' => ['位置', '交通', '配套', '价格', '品牌', '适老化', '物业', '医疗', '运营'],
- 'region' => ['唐冶', '历城', '历下', '高新', '天桥', '槐荫', '市中', '其他'],
- 'purpose' => ['自买自用', '自买他用'],
- 'level' => ['A类', 'B类', 'C类', 'D类'],
- 'current_status' => ['首次到访', '已到访', '无效客户', '已成交'],
- ];
- //处理config中的visit_type
- $visitType = [];
- $visitTypeCommon = $config['visit_type']['common'];
- $visitType1 = $config['visit_type']['type1'];
- $visitType2 = $config['visit_type']['type2'];
- foreach ($visitTypeCommon as $key => $item) {
- if (!empty($item)) {
- $visitType['type1']["{$key}"] = $item;
- $visitType['type2']["{$key}"] = $item;
- }
- }
- $visitType['type1'] += $visitType1;
- $visitType['type2'] += $visitType2;
- $config['visit_type'] = $visitType;
- return $config;
- }
- /**
- * Notes: 添加客户
- * User: yb
- * Date: 2024/8/6
- * Time: 11:20
- */
- public static function add($params)
- {
- $params = self::handleNumParams($params);
- $mobile = $params['mobile'];
- //查询客户手机号是否已经存在
- if (MarketCustomer::where('mobile', $mobile)->exists()) {
- return json_fail('客户已经登记过了');
- }
- //查询顾问信息
- $consultantId = $params['consultant_id'];
- $consultantInfo = Consultant::firstWhere(['id' => $consultantId]);
- if (empty($consultantInfo)) {
- return json_fail('顾问信息不存在');
- }
- $deptId = $consultantInfo->dept_id;
- $insertData = [
- 'name' => $params['name'],
- 'mobile' => $mobile,
- 'consultant_id' => $consultantId,
- 'dept_id' => $deptId,
- 'gender' => $params['gender'] ?? null,
- 'visit_type' => $params['visit_type'] ?? null,
- 'require_area' => $params['require_area'] ?? null,
- 'area' => $params['area'] ?? null,
- 'requirement' => $params['requirement'] ?? null,
- 'age_range' => $params['age_range'] ?? null,
- 'focus' => $params['focus'] ?? null,
- 'region' => $params['region'] ?? null,
- 'purpose' => $params['purpose'] ?? null,
- 'level' => $params['level'] ?? null,
- 'type' => $params['type'] ?? null,
- 'visit_time' => $params['visit_time'] ?? null,
- 'note' => $params['note'] ?? '',
- ];
- Db::beginTransaction();
- try {
- //查询会员表中是否存在该客户
- // $memberId = Member::where('member_mobile', $insertData['mobile'])->value('member_id');
- // if (empty($memberId)) {
- // //新增会员信息
- // }
- // $insertData['member_id'] = $memberId;
- $customId = MarketCustomer::insertGetId($insertData);
- Db::commit();
- }catch (BusinessException|\Exception $e){
- Db::rollBack();
- return json_fail($e->getMessage());
- }
- if ($customId) {
- return json_success('添加成功');
- } else {
- return json_fail('添加失败');
- }
- }
- }
|