employee->root_id; //加微类型 $where[] = ['root_id', '=', $root_id]; $where[] = ['name', '=', 'customerWechatSetting']; $wechat = Setting::where($where)->findOrEmpty(); $wechat = $wechat->isEmpty() ? ['常规加微'] : explode(',', $wechat->content); View::assign('wechat1', in_array('常规加微', $wechat)); View::assign('wechat2', in_array('社群加微', $wechat)); View::assign('wechat3', in_array('历史加微', $wechat)); //量房图片类型 $where1[] = ['root_id', '=', $root_id]; $where1[] = ['name', '=', 'customerLfSetting']; $lf = Setting::where($where1)->findOrEmpty(); $lf = $lf->isEmpty() ? ['量房图片'] : explode(',', $lf->content); View::assign('lf1', in_array('量房图片', $lf)); View::assign('lf2', in_array('量房报告图片', $lf)); View::assign('lf3', in_array('客户需求图片', $lf)); //下次回访时间是否必传 $where2[] = ['root_id', '=', $root_id]; $where2[] = ['name', '=', 'nextVisitTimeIsOk']; $visit = Setting::where($where2)->findOrEmpty(); $visit = !$visit->isEmpty() ? (int)$visit->content : 1; View::assign('visit_save', $visit); $where3[] = ['root_id', '=', $root_id]; $where3[] = ['name', '=', 'addWechatDay']; $visit = Setting::where($where3)->findOrEmpty(); $visit = !$visit->isEmpty() ? explode('@', $visit->content) : [1, 0]; View::assign('addWechatDay', $visit[0]); View::assign('addWechatDaySwitch', isset($visit[1]) ? $visit[1] : 0); //默认打开签单规则 $where4[] = ['root_id', '=', $root_id]; $where4[] = ['name', '=', 'forbiddenState']; $visit = Setting::where($where4)->findOrEmpty(); if ($visit->isEmpty()) { $visit = Setting::create([ 'name' => 'forbiddenState', 'content' => '交定', 'root_id' => $root_id ]); } $visit = !$visit->isEmpty() && $visit->content ? explode(',', $visit->content) : []; // 确认设置 $confirmSetting = Setting::where([['root_id', '=', $root_id], ['name', 'in', ['visitShopConfirm', 'visitSiteConfirm', 'measureConfirm', 'depositConfirm', 'signConfirm', 'assign_type']]])->column('content', 'name'); foreach (['visitShopConfirm', 'visitSiteConfirm', 'measureConfirm', 'depositConfirm', 'signConfirm', 'assign_type'] as $v) { View::assign($v, isset($confirmSetting[$v]) ? json_decode($confirmSetting[$v], 'true') : []); } // 指派人数设置 $designerNum = Setting::where(['name' => 'designerNum', 'root_id' => $root_id])->value('content'); View::assign('designerNum', $designerNum); View::assign('l1', in_array('确认到店', $visit)); View::assign('l2', in_array('确认到场', $visit)); View::assign('l3', in_array('确认量房', $visit)); View::assign('l4', in_array('交定', $visit)); View::assign('l5', in_array('签单', $visit)); View::assign('jiaoding', '签单'); View::assign('qiandan', '转单'); View::assign('root_id', request()->employee->root_id); // 运营后台资源分配设置 $resourcefp = Setting::where([['root_id', '=', $root_id], ['name', '=', 'resource_fp']])->findOrEmpty(); $visit = !$resourcefp->isEmpty() ? (int)$resourcefp->content : 1; View::assign('resource_fp', $visit); // 客户回收后是否重置 $visitReset = Setting::where([['root_id', '=', $root_id], ['name', '=', 'visit_reset']])->findOrEmpty(); $visitResetSetting = !$visitReset->isEmpty() ? (int)$visitReset->content : 1; View::assign('visit_reset', $visitResetSetting); //只展示员工跟进记录不展示修改客户扩展字段信息设置 $showEmpVistlog = Setting::where([['root_id', '=', $root_id], ['name', '=', 'showEmpVistlog']])->findOrEmpty(); $visit = !$showEmpVistlog->isEmpty() ? (int)$showEmpVistlog->content : 0; View::assign('showEmpVistlog', $visit); //控制管理层消息通知 $magnotify = Setting::where([['root_id', '=', $root_id], ['name', '=', 'magnotify']])->findOrEmpty(); $visit = !$magnotify->isEmpty() ? (int)$magnotify->content : 0; View::assign('magnotify', $visit); // 网销端客户池控制统计控制显示不显示 $empcrm_pool_statistics = Setting::where([['root_id', '=', $root_id], ['name', '=', 'empcrm_pool_statistics']])->findOrEmpty(); $emp_pool = !$empcrm_pool_statistics->isEmpty() ? (int)$empcrm_pool_statistics->content : 0; View::assign('empcrm_pool_statistics', $emp_pool); // 网销端同部门下客户能否重复录入 $empcrm_customer_repeat = Setting::where([['root_id', '=', $root_id], ['name', '=', 'empcrm_customer_repeat']])->findOrEmpty(); $emp_pool = !$empcrm_customer_repeat->isEmpty() ? (int)$empcrm_customer_repeat->content : 1; View::assign('empcrm_customer_repeat', $emp_pool); // 跟进时候设计师必填 $need_designer_setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'add_visit_log_need_designer']])->findOrEmpty(); $need_designer = !$need_designer_setting->isEmpty() ? explode(',', $need_designer_setting['content']) : []; View::assign('need_designer', $need_designer); // 设计师能否报备或者获取客户 $designer_get_customer = Setting::where([['root_id', '=', $root_id], ['name', '=', 'designer_get_customer']])->findOrEmpty(); $designer_get_customer = !$designer_get_customer->isEmpty() ? (int)$designer_get_customer->content : 1; View::assign('designer_get_customer', $designer_get_customer); // 未跟进提醒 $no_follow_tips = Setting::where([['root_id', '=', $root_id], ['name', '=', 'no_follow_tips']])->findOrEmpty(); $no_follow_tips = !$no_follow_tips->isEmpty() ? (int)$no_follow_tips->content : 0; View::assign('no_follow_tips', $no_follow_tips); $is_all_manager_oprate_able = Setting::where([['root_id', '=', $root_id], ['name', '=', 'is_all_manager_oprate_able']])->findOrEmpty(); View::assign('is_all_manager_oprate_able', $is_all_manager_oprate_able->content); // 有效申请人设置 $valid_check_person_setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'valid_check_person']])->findOrEmpty(); $valid_check_person = !$valid_check_person_setting->isEmpty() ? explode(',', $valid_check_person_setting['content']) : []; View::assign('valid_check_person', $valid_check_person); return View::fetch(); } /** * 设置加微类型,量房设置 */ public function setting() { $root_id = request()->employee->root_id; $value = input('value/a', []); //加微设置 $value1 = input('value1/a', []); //量房设置 $value2 = input('value2', 0); //下次回访时间是否必传 $value3 = input('value3', 0); //最迟加微时间 $value33 = input('value33', 0); //最迟加微时间开关 $value4 = input('value4/a', []); //跟进保护规则 $showEmpVistlog = input('showEmpVistlog', 0); $magnotify = input('magnotify', 0); $empcrm_pool_statistics = input('empcrm_pool_statistics', 0, 'intval'); // 网销端客户池 $empcrm_customer_repeat = input('empcrm_customer_repeat/a', []); // 网销端客户重复报备 $need_designer = input('need_designer/a', []); // 添加跟进时候,选中的状态需要先选择设计师 $designer_get_customer = input('designer_get_customer', '', 'intval'); // 设计师能否获取客户 $no_follow_tips = input('no_follow_tips', '', 'intval'); // 未跟进提醒 $is_all_manager_oprate_able = input('is_all_manager_oprate_able', 0, 'intval'); // 未跟进提醒 if (!is_array($value) || count($value) == 0) { return json(['code' => 1, 'data' => '请至少选择一条加微设置', 'msg' => '请至少选择一条加微设置']); } if (!is_array($value1) || count($value1) == 0) { return json(['code' => 1, 'data' => '请至少选择一条量房设置', 'msg' => '请至少选择一条量房设置']); } // $where[] = ['root_id', '=', $root_id]; $where[] = ['name', '=', 'customerWechatSetting']; $info = Setting::where($where)->findOrEmpty(); if ($info->isEmpty()) { Setting::insertGetId([ 'name' => 'customerWechatSetting', 'content' => implode(',', $value), 'root_id' => $root_id ]); } else { $info->content = implode(',', $value); $info->save(); } $where1[] = ['root_id', '=', $root_id]; $where1[] = ['name', '=', 'customerLfSetting']; $info1 = Setting::where($where1)->findOrEmpty(); if ($info1->isEmpty()) { Setting::insertGetId([ 'name' => 'customerLfSetting', 'content' => implode(',', $value1), 'root_id' => $root_id ]); } else { $info1->content = implode(',', $value1); $info1->save(); } $where2[] = ['root_id', '=', $root_id]; $where2[] = ['name', '=', 'nextVisitTimeIsOk']; $info2 = Setting::where($where2)->findOrEmpty(); if ($info2->isEmpty()) { Setting::insertGetId([ 'name' => 'nextVisitTimeIsOk', 'content' => $value2, 'root_id' => $root_id ]); } else { $info2->content = $value2; $info2->save(); } $where3[] = ['root_id', '=', $root_id]; $where3[] = ['name', '=', 'addWechatDay']; $info3 = Setting::where($where3)->findOrEmpty(); if ($info3->isEmpty()) { Setting::insertGetId([ 'name' => 'addWechatDay', 'content' => $value3 . '@' . $value33, 'root_id' => $root_id ]); } else { $info3->content = $value3 . '@' . $value33; $info3->save(); } //跟进保护规则 $value4 = $value4 ? implode(',', $value4) : ''; $where4[] = ['root_id', '=', $root_id]; $where4[] = ['name', '=', 'forbiddenState']; $info4 = Setting::where($where4)->findOrEmpty(); if ($info4->isEmpty()) { Setting::insertGetId([ 'name' => 'forbiddenState', 'content' => $value4, 'root_id' => $root_id ]); } else { $info4->content = $value4; $info4->save(); } //只展示员工跟进记录 $where5[] = ['root_id', '=', $root_id]; $where5[] = ['name', '=', 'showEmpVistlog']; $info5 = Setting::where($where5)->findOrEmpty(); if ($info5->isEmpty()) { Setting::insertGetId([ 'name' => 'showEmpVistlog', 'content' => $showEmpVistlog, 'root_id' => $root_id ]); } else { $info5->content = $showEmpVistlog; $info5->save(); } //管理层消息通知开关 $where6[] = ['root_id', '=', $root_id]; $where6[] = ['name', '=', 'magnotify']; $info6 = Setting::where($where6)->findOrEmpty(); if ($info6->isEmpty()) { Setting::insertGetId([ 'name' => 'magnotify', 'content' => $magnotify, 'root_id' => $root_id ]); } else { $info6->content = $magnotify; $info6->save(); } // 确认设置 $param = request()->only(['visitShopConfirm', 'visitSiteConfirm', 'measureConfirm', 'depositConfirm', 'signConfirm', 'assign_type']); foreach (['visitShopConfirm', 'visitSiteConfirm', 'measureConfirm', 'depositConfirm', 'signConfirm', 'assign_type'] as $name) { $data = ['root_id' => $root_id, 'name' => $name]; $setObj = Setting::where($data)->findOrEmpty(); $data['content'] = json_encode($param[$name] ?? []); $setObj->save($data); } // 设置设计可获得分配人数 $designerNum = input('designerNum/d', 0); $designerNumSetting = ['root_id' => $root_id, 'name' => 'designerNum']; $designerSetObj = Setting::where($designerNumSetting)->findOrEmpty(); $designerNumSetting['content'] = $designerNum; $designerSetObj->save($designerNumSetting); // 设置设计可获得分配人数 $fp = input('resource_fp/d', 1); $designerNumSetting = ['root_id' => $root_id, 'name' => 'resource_fp']; $designerSetObj = Setting::where($designerNumSetting)->findOrEmpty(); $designerNumSetting['content'] = $fp; $designerSetObj->save($designerNumSetting); // 设置回收后是否重置 $re = input('visit_reset/d', 1); $designerNumSetting = ['root_id' => $root_id, 'name' => 'visit_reset']; $designerSetObj = Setting::where($designerNumSetting)->findOrEmpty(); $designerNumSetting['content'] = $re; $designerSetObj->save($designerNumSetting); // 控制网销端客户池统计的展示不展示 $empcrm_pool[] = ['root_id', '=', $root_id]; $empcrm_pool[] = ['name', '=', 'empcrm_pool_statistics']; $info_pool = Setting::where($empcrm_pool)->findOrEmpty(); if ($info_pool->isEmpty()) { Setting::insertGetId([ 'name' => 'empcrm_pool_statistics', 'content' => (int)$empcrm_pool_statistics, 'root_id' => $root_id ]); } else { $info_pool->content = (int)$empcrm_pool_statistics; $info_pool->save(); } // 控制网销端客户池统计的展示不展示 $empcrm_repeat[] = ['root_id', '=', $root_id]; $empcrm_repeat[] = ['name', '=', 'empcrm_customer_repeat']; $info_repeat = Setting::where($empcrm_repeat)->findOrEmpty(); if ($info_repeat->isEmpty()) { Setting::insertGetId([ 'name' => 'empcrm_customer_repeat', 'content' => !empty($empcrm_customer_repeat) ? implode(',', $empcrm_customer_repeat) : '', 'root_id' => $root_id ]); } else { $info_repeat->content = !empty($empcrm_customer_repeat) ? implode(',', $empcrm_customer_repeat) : ''; $info_repeat->save(); } // 设计师必填 $designer_need_where[] = ['root_id', '=', $root_id]; $designer_need_where[] = ['name', '=', 'add_visit_log_need_designer']; $designer_need_info = Setting::where($designer_need_where)->findOrEmpty(); if ($designer_need_info->isEmpty()) { Setting::insertGetId([ 'name' => 'add_visit_log_need_designer', 'content' => !empty($need_designer) ? implode(',', $need_designer) : '', 'root_id' => $root_id ]); } else { $designer_need_info->content = !empty($need_designer) ? implode(',', $need_designer) : ''; $designer_need_info->save(); } // 设计师能否报备或者获取客户 $de_where[] = ['root_id', '=', $root_id]; $de_where[] = ['name', '=', 'designer_get_customer']; $info_de_where = Setting::where($de_where)->findOrEmpty(); if ($info_de_where->isEmpty()) { Setting::insertGetId([ 'name' => 'designer_get_customer', 'content' => (int)$designer_get_customer, 'root_id' => $root_id ]); } else { $info_de_where->content = (int)$designer_get_customer; $info_de_where->save(); } // PC-CRM未跟进三天、七天颜色显示 $tip_where[] = ['root_id', '=', $root_id]; $tip_where[] = ['name', '=', 'no_follow_tips']; $info_tips = Setting::where($tip_where)->findOrEmpty(); if ($info_tips->isEmpty()) { Setting::insertGetId([ 'name' => 'no_follow_tips', 'content' => (int)$no_follow_tips, 'root_id' => $root_id ]); } else { $info_tips->content = (int)$no_follow_tips; $info_tips->save(); } // 设置是否管理层及以上都能跟进 $condition = [ ['root_id', '=', $root_id], ['name', '=', 'is_all_manager_oprate_able'] ]; $setting = Setting::where($condition)->findOrEmpty(); $setting->save([ 'root_id' => $root_id, 'name' => 'is_all_manager_oprate_able', 'content' => $is_all_manager_oprate_able ]); // 有效申请人设置 $valid_check_person_select = input('valid_check_person/a', []); // 添加跟进时候,选中的状态需要先选择设计师 $valid_check_person_condition[] = ['root_id', '=', $root_id]; $valid_check_person_condition[] = ['name', '=', 'valid_check_person']; $valid_check_person = Setting::where($valid_check_person_condition)->findOrEmpty(); if ($valid_check_person->isEmpty()) { Setting::insertGetId([ 'name' => 'valid_check_person', 'content' => !empty($valid_check_person_select) ? implode(',', $valid_check_person_select) : '', 'root_id' => $root_id ]); } else { $valid_check_person->content = !empty($valid_check_person_select) ? implode(',', $valid_check_person_select) : ''; $valid_check_person->save(); } return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']); } private function tree($data, $pid = 0, $setting) { $new_arr = []; foreach ($data as $k => $v) { if ($v['pid'] == $pid) { $children = $this->tree($data, $v['id'], $setting); $v['children'] = $children; $v['selected'] = false; if (in_array($v['id'], $setting)) { $v['selected'] = true; } $new_arr[] = $v; } } return $new_arr; } /* * 人员树 */ public function get_person() { $root_id = request()->employee->root_id; $empcrm_repeat[] = ['root_id', '=', $root_id]; $empcrm_repeat[] = ['name', '=', 'empcrm_customer_repeat']; $info_repeat = Setting::where($empcrm_repeat)->findOrEmpty(); $setting = []; if (!empty($info_repeat)) { $setting = explode(',', $info_repeat['content']); } //树形 $where = [ ['path', 'like', $root_id . '-%'], ['status', '=', 1] ]; $allnodes = Org::where($where)->field('id value,id,pid,name')->order('level asc, id asc')->select()->toArray(); $tree = $this->tree($allnodes, 0, $setting); return json($tree); } /** * 自定义设置 */ public function getCustom() { $root_id = request()->employee->root_id; $info = CustomerPortrait::where('root_id', $root_id)->findOrEmpty(); $data = $info->fields; $arr = $this->settingArr(); $res['source']['arr'] = CustomerSource::where('root_id', $root_id)->column('source'); $res['source']['title'] = '客户来源'; foreach ($arr as $k => $v) { $res[$k]['arr'] = (array)$data[$v][$k]['select']; $res[$k]['title'] = $data[$v][$k]['title']; } return json(['code' => 0, 'data' => $res, 'msg' => '保存成功']); } /** * 编辑自定义设置 * key 关键词 * type 类型 客户来源 【客户关注点】 客户痛点 户型 房屋用途 周边配套 房屋结构 装修方式 客户喜欢的色调 家庭结构 【决策人】 【关注的工艺】 关注房屋的空间 * y_key 原数据 */ public function editCustom() { $arr = $this->settingArr(); $arr = array_merge(['source' => ''], $arr); $param = Request()->only(['key' => '', 'type' => '', 'y_key' => '']); if (!isset($arr[$param['type']])) return json(['code' => 1, 'data' => '编辑失败', 'msg' => '编辑失败']); $root_id = request()->employee->root_id; if ($param['type'] == 'source') { $info = CustomerSource::where([['root_id', '=', $root_id], ['source', '=', $param['key']]])->findOrEmpty(); if (!$info->isEmpty()) return json(['code' => 1, 'data' => '来源已存在', 'msg' => '来源已存在']); CustomerSource::where([['root_id', '=', $root_id], ['source', '=', $param['y_key']]])->update(['source' => $param['key']]); } else { if (trim($param['y_key']) == trim($param['key'])) return json(['code' => 1, 'data' => '未改变原值', 'msg' => '未改变原值']); $info = CustomerPortrait::where('root_id', $root_id)->findOrEmpty(); $data = $info->fields; $array = $data[$arr[$param['type']]][$param['type']]['select']; if ($array && in_array($param['key'], $array)) return json(['code' => 1, 'data' => '数据重复', 'msg' => '数据重复']); $key = array_search($param['y_key'], $array); $array[$key] = $param['key']; $data[$arr[$param['type']]][$param['type']]['select'] = array_values($array); !$info->isEmpty() ?: $info->root_id = $root_id; $info->fields = $data; $info->save(); } return json(['code' => 0, 'data' => '编辑成功', 'msg' => '编辑成功']); } /** * 新增自定义设置 */ public function addCustom() { $arr = $this->settingArr(); $arr = array_merge(['source' => ''], $arr); $param = Request()->only(['key' => '', 'type' => '']); if (!isset($arr[$param['type']])) return json(['code' => 1, 'data' => '添加失败', 'msg' => '添加失败']); $root_id = request()->employee->root_id; if ($param['type'] == 'source') { $info = CustomerSource::where([['root_id', '=', $root_id], ['source', '=', $param['key']]])->findOrEmpty(); if (!$info->isEmpty()) return json(['code' => 1, 'data' => '数据重复', 'msg' => '数据重复']); CustomerSource::insert(['source' => $param['key'], 'root_id' => $root_id]); } else { $info = CustomerPortrait::where('root_id', $root_id)->findOrEmpty(); $data = $info->fields; $array = $data[$arr[$param['type']]][$param['type']]['select']; if ($array && in_array($param['key'], $array)) return json(['code' => 1, 'data' => '数据重复', 'msg' => '数据重复']); $array[] = $param['key']; $data[$arr[$param['type']]][$param['type']]['select'] = array_values($array); !$info->isEmpty() ?: $info->root_id = $root_id; $info->fields = $data; $info->save(); } return json(['code' => 0, 'data' => '添加成功', 'msg' => '添加成功']); } /** * 删除自定义设置 */ public function deleteCustom() { $arr = $this->settingArr(); $arr = array_merge(['source' => ''], $arr); $param = Request()->only(['key' => '', 'type' => '']); if (!isset($arr[$param['type']])) return json(['code' => 1, 'data' => '删除失败', 'msg' => '删除失败']); $root_id = request()->employee->root_id; if ($param['type'] == 'source') { $info = CustomerSource::where([['root_id', '=', $root_id], ['source', '=', $param['key']]])->findOrEmpty(); if ($info->isEmpty()) return json(['code' => 1, 'data' => '数据不存在', 'msg' => '数据不存在']); CustomerSource::where([['root_id', '=', $root_id], ['source', '=', $param['key']]])->delete(); } else { $info = CustomerPortrait::where('root_id', $root_id)->findOrEmpty(); $data = $info->fields; $array = $data[$arr[$param['type']]][$param['type']]['select']; $array = array_diff($array, [$param['key']]); $data[$arr[$param['type']]][$param['type']]['select'] = array_values($array); !$info->isEmpty() ?: $info->root_id = $root_id; $info->fields = $data; $info->save(); } return json(['code' => 0, 'data' => '删除成功', 'msg' => '删除成功']); } /** * 类型 */ private function settingArr() { $arr = [ 'follow' => 'basic_info', 'point' => 'basic_info', 'housetype_arrow' => 'house_info', 'housing_use' => 'house_info', 'peripheral_supporting' => 'house_info', 'house_structure' => 'house_info', 'decoration_mode' => 'house_info', 'like_color' => 'house_info', 'family_structure' => 'family_info', 'decision_maker' => 'family_info', 'workmanship' => 'behavioral_info', 'space_design' => 'behavioral_info' ]; return $arr; } /** * 产品设置 */ public function package() { $pageParam = request()->only(['page', 'limit']); $data = CustomerPackage::field('id, name, total_price')->where(['root_id' => request()->employee->root_id])->page($pageParam['page'], $pageParam['limit'])->select(); $count = CustomerPackage::where(['root_id' => request()->employee->root_id])->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /** * 产品添加 */ public function editPackage($name, $value, $id = null) { if ($id) { $package = CustomerPackage::where(['root_id' => request()->employee->root_id, 'id' => $id])->find(); } else { $package = new CustomerPackage(); } $package->save([ 'name' => $name, 'total_price' => $value, 'root_id' => request()->employee->root_id ]); return json(['code' => 0, 'msg' => $id ? '修改成功' : '添加成功']); } /** * 产品删除 */ public function delPackage($id) { $package = CustomerPackage::where(['root_id' => request()->employee->root_id, 'id' => $id])->find(); if (empty($package)) return json(['code' => 1, 'msg' => '删除失败']); $package->delete(); return json(['code' => 0, 'msg' => '删除成功']); } /** * 客户预约保护设置 */ public function subscribe_protected() { if (!request()->isAjax()) { $find = Setting::where(['name' => 'subscribe_protected', 'root_id' => request()->employee->root_id])->findOrEmpty(); if ($find->isEmpty()) { $content['ydaochang'] = ['day' => 0, 'state' => 0, 'name' => '预约到场保护']; $content['daochang'] = ['day' => 0, 'state' => 0, 'name' => '到场保护']; $content['ydaodian'] = ['day' => 0, 'state' => 0, 'name' => '预约到店保护']; $content['daodian'] = ['day' => 0, 'state' => 0, 'name' => '到店保护']; $content['yliangfang'] = ['day' => 0, 'state' => 0, 'name' => '预约量房保护']; $content['liangfang'] = ['day' => 0, 'state' => 0, 'name' => '量房保护']; $data['name'] = 'subscribe_protected'; $data['content'] = json_encode($content); $data['state'] = 1; $data['root_id'] = request()->employee->root_id; Setting::create($data); $contentarr = $content; } else { $content = $find['content']; $contentarr = empty($content) ? null : json_decode($content, true); } View::assign('content', $contentarr); return View::fetch(); } else { $param = request()->only(['ydaodian', 'ydaodian_switch', 'daodian', 'daodian_switch', 'daochang', 'daochang_switch', 'ydaochang', 'ydaochang_switch', 'yliangfang', 'yliangfang_switch', 'liangfang', 'liangfang_switch']); $root_id = request()->employee->root_id; $setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'subscribe_protected']])->findOrEmpty(); if ($setting->isEmpty()) { $data['name'] = 'subscribe_protected'; $data['state'] = 1; //$param['off'] ?? 0; $data['root_id'] = $root_id; $content = [ 'ydaochang' => ['day' => intval($param['ydaochang']), 'state' => $param['ydaochang_switch'] ?? 0, 'name' => '预约到场保护'], 'daochang' => ['day' => intval($param['daochang']), 'state' => $param['daochang_switch'] ?? 0, 'name' => '到场保护'], 'ydaodian' => ['day' => intval($param['ydaodian']), 'state' => $param['ydaodian_switch'] ?? 0, 'name' => '预约到店保护'], 'daodian' => ['day' => intval($param['daodian']), 'state' => $param['daodian_switch'] ?? 0, 'name' => '到店保护'], 'yliangfang' => ['day' => intval($param['yliangfang']), 'state' => $param['yliangfang_switch'] ?? 0, 'name' => '预约量房保护'], 'liangfang' => ['day' => intval($param['liangfang']), 'state' => $param['liangfang_switch'] ?? 0, 'name' => '量房保护'], ]; $data['content'] = json_encode($content); if (isset($param['daochang_switch']) && intval($param['daochang']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } if (isset($param['ydaochang_switch']) && intval($param['ydaochang']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } if (isset($param['ydaodian_switch']) && intval($param['ydaodian']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } if (isset($param['daodian_switch']) && intval($param['daodian']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } if (isset($param['yliangfang_switch']) && intval($param['yliangfang']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } if (isset($param['liangfang_switch']) && intval($param['liangfang']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } $result = Setting::create($data); if ($result) { return json(['code' => 0, 'msg' => '保存成功']); } else { return json(['code' => 1, 'msg' => '保存失败']); } } else { if (isset($param['daochang_switch']) && intval($param['daochang']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } if (isset($param['ydaochang_switch']) && intval($param['ydaochang']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } if (isset($param['ydaodian_switch']) && intval($param['ydaodian']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } if (isset($param['daodian_switch']) && intval($param['daodian']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } if (isset($param['yliangfang_switch']) && intval($param['yliangfang']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } if (isset($param['liangfang_switch']) && intval($param['liangfang']) < 1) { return json(['code' => 1, 'msg' => '天数至少为一天']); } $content = [ 'ydaochang' => ['day' => intval($param['ydaochang']), 'state' => $param['ydaochang_switch'] ?? 0, 'name' => '预约到场保护'], 'daochang' => ['day' => intval($param['daochang']), 'state' => $param['daochang_switch'] ?? 0, 'name' => '到场保护'], 'ydaodian' => ['day' => intval($param['ydaodian']), 'state' => $param['ydaodian_switch'] ?? 0, 'name' => '预约到店保护'], 'daodian' => ['day' => intval($param['daodian']), 'state' => $param['daodian_switch'] ?? 0, 'name' => '到店保护'], 'yliangfang' => ['day' => intval($param['yliangfang']), 'state' => $param['yliangfang_switch'] ?? 0, 'name' => '预约量房保护'], 'liangfang' => ['day' => intval($param['liangfang']), 'state' => $param['liangfang_switch'] ?? 0, 'name' => '量房保护'], ]; $setting->content = json_encode($content); $result = $setting->save(); if ($result) { return json(['code' => 0, 'msg' => '保存成功']); } else { return json(['code' => 1, 'msg' => '保存失败']); } } } } /** * 自定义设置 -- 客户跟踪、信息完善、客户转化、客户预约、报备设置、团队客户 */ public function moduleSetting() { $root_id = request()->employee->root_id; if (!request()->isAjax()) { // 客户信息完善开关 $perfect = Setting::where([['root_id', '=', $root_id], ['name', '=', 'modulePerfectSwitch']])->findOrEmpty(); if ($perfect->isEmpty()) { Setting::create(['root_id' => $root_id, 'name' => 'modulePerfectSwitch', 'content' => 1]); $perfect_content = 1; } else { $perfect_content = $perfect['content']; } View::assign('perfect', $perfect_content); // 客户转化开关 $change = Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleChangeSwitch']])->findOrEmpty(); if ($change->isEmpty()) { Setting::create(['root_id' => $root_id, 'name' => 'moduleChangeSwitch', 'content' => 1]); $change_content = 1; } else { $change_content = $change['content']; } View::assign('change', $change_content); // 客户预约开关 $subscribe = Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleSubscribeSwitch']])->findOrEmpty(); if ($subscribe->isEmpty()) { Setting::create(['root_id' => $root_id, 'name' => 'moduleSubscribeSwitch', 'content' => 1]); $subscribe_content = 1; } else { $subscribe_content = $subscribe['content']; } View::assign('subscribe', $subscribe_content); return View::fetch(); } else { $perfect = input('perfect', '', 'trim'); $change = input('change', '', 'trim'); $subscribe = input('subscribe', '', 'trim'); if ($perfect !== '') { Setting::where([['root_id', '=', $root_id], ['name', '=', 'modulePerfectSwitch']])->save(['content' => $perfect]); } if ($change !== '') { Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleChangeSwitch']])->save(['content' => $change]); } if ($subscribe !== '') { Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleSubscribeSwitch']])->save(['content' => $subscribe]); } return json(['code' => 0, 'msg' => '操作成功']); } } /** * 客户跟踪设置 */ public function moduleVisit() { if (!request()->isAjax()) { return View::fetch(); } else { $root_id = request()->employee->root_id; $content = input('content', '', 'trim'); // 判断保存的字段其他模块是否有使用 if (!empty($content)) { $field_data = $this->moduleFiledDeal('visit'); $other_checked = $field_data['other_checked']; foreach ($content as $k => $v) { if (in_array($v['id'], $other_checked)) { return json(['code' => 1, 'msg' => '字段重复使用']); } } } $s_where[] = ['root_id', '=', $root_id]; $s_where[] = ['name', '=', 'visitSettingField']; $find = Setting::where($s_where)->findOrEmpty(); if ($find->isEmpty()) { $data['name'] = 'visitSettingField'; $data['root_id'] = $root_id; $data['content'] = !empty($content) ? json_encode($content) : ''; $result = Setting::create($data); } else { $find->content = !empty($content) ? json_encode($content) : ''; $result = $find->save(); } if ($result !== false) { return json(['code' => 0, 'msg' => '操作成功']); } else { return json(['code' => 1, 'msg' => '操作失败']); } } } /** * 线索状态 */ public function clueTag() { $where[] = ['name', '=', 'clueTag']; $where[] = ['root_id', '=', request()->employee->root_id]; $find = Setting::where($where)->findOrEmpty(); if ($find->isEmpty()) { $list = ['已装修', '无需求', '有需求', '超地域', '未交房', '在外地', '无购买力', '未接通电话']; } else { $list = array_filter(explode(',', $find['content'])); } return json(['code' => 0, 'data' => $list]); } /** * 线索状态设置 */ public function clueTagEdit() { $content = input('content/a', '', 'trim'); $data = implode(',', $content); $where[] = ['name', '=', 'clueTag']; $where[] = ['root_id', '=', request()->employee->root_id]; $find = Setting::where($where)->findOrEmpty(); if ($find->isEmpty()) { $result = Setting::create(['name' => 'clueTag', 'content' => $data, 'state' => 1, 'root_id' => request()->employee->root_id]); } else { $find->content = $data; $result = $find->save(); } if ($result !== false) { return json(['code' => 0, 'msg' => '操作成功']); } else { return json(['code' => 1, 'msg' => '操作失败']); } } /** * 模块开关 */ public function moduleSwitch() { $content = input('content', '', 'trim'); $type = input('type', '', 'trim'); $root_id = request()->employee->root_id; switch ($type) { case 'perfect': $module = 'perfectSettingSwitch'; break; case 'change': $module = 'changeSettingSwitch'; break; case 'subscribe': $module = 'subscribeSettingSwitch'; break; default: $module = ''; break; } if (empty($module)) { return json(['code' => 1, 'msg' => '操作失败']); } $find = Setting::where([['root_id', '=', $root_id], ['name', '=', $module]])->findOrEmpty(); if ($find->isEmpty()) { $result = Setting::create(['root_id' => $root_id, 'name' => $module, 'content' => $content]); } else { $result = $find->save(['content' => $content]); } if ($result !== false) { return json(['code' => 0, 'msg' => '操作成功']); } else { return json(['code' => 1, 'msg' => '操作失败']); } } protected function moduleFiledDeal($type) { $type_arr = ['visit', 'changeLF', 'changeDD', 'changeHD', 'changeJD', 'changeZD', 'changeMK', 'subscribeHD', 'subscribeDD', 'subscribeLF']; if (!in_array($type, $type_arr)) { return ['all' => [], 'default' => [], 'checked' => [], 'other_checked' => []]; } $root_id = request()->employee->root_id; $a_where[] = ['root_id', '=', $root_id]; $a_where[] = ['pid', '<>', 0]; $a_where[] = ['status', '=', 0]; $all = CustomerPortraitField::where($a_where)->order('sort asc')->select()->toArray(); $default = []; $checked = []; // 客户预约字段设置 $sub_where_hd[] = ['root_id', '=', $root_id]; $sub_where_hd[] = ['name', '=', 'subscribeSettingFieldYYHD']; $subscribeFieldHD = Setting::where($sub_where_hd)->findOrEmpty(); $sub_where_dd[] = ['root_id', '=', $root_id]; $sub_where_dd[] = ['name', '=', 'subscribeSettingFieldYYDD']; $subscribeFieldDD = Setting::where($sub_where_dd)->findOrEmpty(); $sub_where_lf[] = ['root_id', '=', $root_id]; $sub_where_lf[] = ['name', '=', 'subscribeSettingFieldYYLF']; $subscribeFieldLF = Setting::where($sub_where_lf)->findOrEmpty(); //客户转化字段设置 $c_where_lf[] = ['root_id', '=', $root_id]; $c_where_lf[] = ['name', '=', 'changeSettingFieldLF']; $changeFieldLF = Setting::where($c_where_lf)->findOrEmpty(); $c_where_dd[] = ['root_id', '=', $root_id]; $c_where_dd[] = ['name', '=', 'changeSettingFieldDD']; $changeFieldDD = Setting::where($c_where_dd)->findOrEmpty(); $c_where_hd[] = ['root_id', '=', $root_id]; $c_where_hd[] = ['name', '=', 'changeSettingFieldHD']; $changeFieldHD = Setting::where($c_where_hd)->findOrEmpty(); $c_where_jd[] = ['root_id', '=', $root_id]; $c_where_jd[] = ['name', '=', 'changeSettingFieldJD']; $changeFieldJD = Setting::where($c_where_jd)->findOrEmpty(); $c_where_zd[] = ['root_id', '=', $root_id]; $c_where_zd[] = ['name', '=', 'changeSettingFieldZD']; $changeFieldZD = Setting::where($c_where_zd)->findOrEmpty(); $c_where_mk[] = ['root_id', '=', $root_id]; $c_where_mk[] = ['name', '=', 'changeSettingFieldMK']; $changeFieldMK = Setting::where($c_where_mk)->findOrEmpty(); // 客户跟踪字段设置 $v_where[] = ['root_id', '=', $root_id]; $v_where[] = ['name', '=', 'visitSettingField']; $visitField = Setting::where($v_where)->findOrEmpty(); $subscribeFieldHD_decode = []; $subscribeFieldDD_decode = []; $subscribeFieldLF_decode = []; $changeFieldLF_decode = []; $changeFieldDD_decode = []; $changeFieldHD_decode = []; $changeFieldJD_decode = []; $changeFieldZD_decode = []; $changeFieldMK_decode = []; $visitField_decode = []; $all_checked = []; //所有已选中的字段 if (!$subscribeFieldHD->isEmpty()) { $subscribeFieldHD_decode = json_decode($subscribeFieldHD['content'], true); if (!empty($subscribeFieldHD_decode)) { $all_checked = array_merge($all_checked, array_column($subscribeFieldHD_decode, 'id')); } } if (!$subscribeFieldDD->isEmpty()) { $subscribeFieldDD_decode = json_decode($subscribeFieldDD['content'], true); if (!empty($subscribeFieldDD_decode)) { $all_checked = array_merge($all_checked, array_column($subscribeFieldDD_decode, 'id')); } } if (!$subscribeFieldLF->isEmpty()) { $subscribeFieldLF_decode = json_decode($subscribeFieldLF['content'], true); if (!empty($subscribeFieldLF_decode)) { $all_checked = array_merge($all_checked, array_column($subscribeFieldLF_decode, 'id')); } } if (!$changeFieldLF->isEmpty()) { $changeFieldLF_decode = json_decode($changeFieldLF['content'], true); if (!empty($changeFieldLF_decode)) { $all_checked = array_merge($all_checked, array_column($changeFieldLF_decode, 'id')); } } if (!$changeFieldDD->isEmpty()) { $changeFieldDD_decode = json_decode($changeFieldDD['content'], true); if (!empty($changeFieldDD_decode)) { $all_checked = array_merge($all_checked, array_column($changeFieldDD_decode, 'id')); } } if (!$changeFieldHD->isEmpty()) { $changeFieldHD_decode = json_decode($changeFieldHD['content'], true); if (!empty($changeFieldHD_decode)) { $all_checked = array_merge($all_checked, array_column($changeFieldHD_decode, 'id')); } } if (!$changeFieldJD->isEmpty()) { $changeFieldJD_decode = json_decode($changeFieldJD['content'], true); if (!empty($changeFieldJD_decode)) { $all_checked = array_merge($all_checked, array_column($changeFieldJD_decode, 'id')); } } else { $changeFieldJD_default = CustomerPortraitField::where([['root_id', '=', $root_id], ['keyname', 'in', ['drawing_date', 'plan_issuing_date', 'plan_passing_date', 'material_selection_date', 'will_transfer_to_construction_date']]])->order('sort asc')->select()->toArray(); foreach ($changeFieldJD_default as $k => $v) { $changeFieldJD_decode[] = [ 'id' => $v['id'], 'sort' => $k + 1 ]; } $all_checked = array_merge($all_checked, array_column($changeFieldJD_decode, 'id')); } if (!$changeFieldZD->isEmpty()) { $changeFieldZD_decode = json_decode($changeFieldZD['content'], true); if (!empty($changeFieldZD_decode)) { $all_checked = array_merge($all_checked, array_column($changeFieldZD_decode, 'id')); } } if (!$changeFieldMK->isEmpty()) { $changeFieldMK_decode = json_decode($changeFieldMK['content'], true); if (!empty($changeFieldMK_decode)) { $all_checked = array_merge($all_checked, array_column($changeFieldMK_decode, 'id')); } } if (!$visitField->isEmpty()) { $visitField_decode = json_decode($visitField['content'], true); if (!empty($visitField_decode)) { $all_checked = array_merge($all_checked, array_column($visitField_decode, 'id')); } } else { $visit_default = CustomerPortraitField::where([['root_id', '=', $root_id], ['keyname', 'in', ['wechat', 'add_wechat_type', 'add_wechat_time', 'level', 'intention', 'plan_deco_time', 'group_building']]])->order('sort asc')->select()->toArray(); foreach ($visit_default as $k => $v) { $visitField_decode[] = [ 'id' => $v['id'], 'sort' => $k + 1 ]; } $all_checked = array_merge($all_checked, array_column($visitField_decode, 'id')); } $other_checked_ids = []; switch ($type) { case 'visit': $checked = $visitField_decode ?? []; $other_checked_ids = !empty($visitField_decode) ? array_diff($all_checked, array_column($visitField_decode, 'id')) : $all_checked; if (empty($visit_default)) { $visit_default = CustomerPortraitField::where([['root_id', '=', $root_id], ['keyname', 'in', ['wechat', 'add_wechat_type', 'add_wechat_time', 'level', 'intention', 'plan_deco_time', 'group_building']]])->order('sort asc')->select()->toArray(); } foreach ($visit_default as $k => $v) { $default[] = [ 'id' => $v['id'], 'name' => $v['name'], 'sort' => $k + 1, 'type' => $v['type'] ]; } break; case 'changeLF': $checked = $changeFieldLF_decode ?? []; $other_checked_ids = !empty($changeFieldLF_decode) ? array_diff($all_checked, array_column($changeFieldLF_decode, 'id')) : $all_checked; break; case 'changeDD': $checked = $changeFieldDD_decode ?? []; $other_checked_ids = !empty($changeFieldDD_decode) ? array_diff($all_checked, array_column($changeFieldDD_decode, 'id')) : $all_checked; break; case 'changeHD': $checked = $changeFieldHD_decode ?? []; $other_checked_ids = !empty($changeFieldHD_decode) ? array_diff($all_checked, array_column($changeFieldHD_decode, 'id')) : $all_checked; break; case 'changeJD': $checked = $changeFieldJD_decode ?? []; $other_checked_ids = !empty($changeFieldJD_decode) ? array_diff($all_checked, array_column($changeFieldJD_decode, 'id')) : $all_checked; if (empty($changeFieldJD_default)) { $changeFieldJD_default = CustomerPortraitField::where([['root_id', '=', $root_id], ['keyname', 'in', ['drawing_date', 'plan_issuing_date', 'plan_passing_date', 'material_selection_date', 'will_transfer_to_construction_date']]])->order('sort asc')->select()->toArray(); } foreach ($changeFieldJD_default as $k => $v) { $default[] = [ 'id' => $v['id'], 'name' => $v['name'], 'sort' => $k + 1, 'type' => $v['type'] ]; } break; case 'changeZD': $checked = $changeFieldZD_decode ?? []; $other_checked_ids = !empty($changeFieldZD_decode) ? array_diff($all_checked, array_column($changeFieldZD_decode, 'id')) : $all_checked; break; case 'changeMK': $checked = $changeFieldMK_decode ?? []; $other_checked_ids = !empty($changeFieldMK_decode) ? array_diff($all_checked, array_column($changeFieldMK_decode, 'id')) : $all_checked; break; case 'subscribeHD': $checked = $subscribeFieldHD_decode ?? []; $other_checked_ids = !empty($subscribeFieldHD_decode) ? array_diff($all_checked, array_column($subscribeFieldHD_decode, 'id')) : $all_checked; break; case 'subscribeDD': $checked = $subscribeFieldDD_decode ?? []; $other_checked_ids = !empty($subscribeFieldDD_decode) ? array_diff($all_checked, array_column($subscribeFieldDD_decode, 'id')) : $all_checked; break; case 'subscribeLF': $checked = $subscribeFieldLF_decode ?? []; $other_checked_ids = !empty($subscribeFieldLF_decode) ? array_diff($all_checked, array_column($subscribeFieldLF_decode, 'id')) : $all_checked; break; default: break; } $checked_ids = array_column($checked, 'id'); $field_info = CustomerPortraitField::with('select')->where('id', 'in', $checked_ids)->select()->toArray(); $city = Company::where('root_id', request()->employee->root_id)->value('city'); foreach ($field_info as $k => $v) { if ($v['keyname'] == 'current_region') { $field_info[$k]['select'][] = ['id' => request()->employee->root_id, 'name' => $city, 'pid' => $v['pid']]; } if ($v['keyname'] == 'source_id') { $soudata = CustomerSource::field('id,source as name')->where('root_id', request()->employee->root_id)->select()->toArray(); $field_info[$k]['select'] = $soudata; } if ($v['keyname'] == 'deco_style') { $decostyles = Decostyle::field('id,name')->where([['root_id', '=', request()->employee->root_id], ['type', '=', 0]])->select()->toArray(); $field_info[$k]['select'] = $decostyles; } } foreach ($checked as $k => $v) { foreach ($field_info as $kk => $vv) { if ($v['id'] == $vv['id']) { $checked[$k]['name'] = $vv['name']; $checked[$k]['type'] = $vv['type']; $checked[$k]['select'] = $vv['select'] ?? []; } } } foreach ($all as $k => $v) { $all[$k]['other_checked'] = 0; $all[$k]['checked'] = 0; if (in_array($v['id'], $other_checked_ids)) { $all[$k]['other_checked'] = 1; } if (in_array($v['id'], array_column($checked, 'id'))) { $all[$k]['checked'] = 1; } } return ['all' => $all, 'default' => $default, 'checked' => $checked, 'other_checked' => $other_checked_ids]; } /** * 模块字段 */ public function moduleField() { $type = input('type', '', 'trim'); $data = $this->moduleFiledDeal($type); return json(['code' => 0, 'all' => $data['all'], 'default' => $data['default'], 'checked' => $data['checked']]); } /** * 客户转化 */ public function moduleChange() { if (!request()->isAjax()) { $root_id = request()->employee->root_id; // 子模块开关 量房、到店、活动、签单、转单、卖卡 $z_where[] = ['name', 'in', ['changeSettingSwitchLF', 'changeSettingSwitchDD', 'changeSettingSwitchHD', 'changeSettingSwitchJD', 'changeSettingSwitchZD', 'changeSettingSwitchMK', 'changeSettingSwitchDDHD']]; $z_where[] = ['root_id', '=', $root_id]; $z_setting = Setting::where($z_where)->select()->toArray(); $lf_switch = 1; //量房 $dd_switch = 1; //到店 $hd_switch = 1; //活动 $qd_switch = 1; //签单 $zd_switch = 1; //转单 $mk_switch = 1; //卖卡 $ddhd_switch = 1; //到店活动 foreach ($z_setting as $k => $v) { if ($v['name'] == 'changeSettingSwitchLF') $lf_switch = $v['content']; if ($v['name'] == 'changeSettingSwitchDD') $dd_switch = $v['content']; if ($v['name'] == 'changeSettingSwitchHD') $hd_switch = $v['content']; if ($v['name'] == 'changeSettingSwitchJD') $qd_switch = $v['content']; if ($v['name'] == 'changeSettingSwitchZD') $zd_switch = $v['content']; if ($v['name'] == 'changeSettingSwitchMK') $mk_switch = $v['content']; if ($v['name'] == 'changeSettingSwitchDDHD') $ddhd_switch = $v['content']; } View::assign('lf_switch', $lf_switch); View::assign('dd_switch', $dd_switch); View::assign('hd_switch', $hd_switch); View::assign('qd_switch', $qd_switch); View::assign('zd_switch', $zd_switch); View::assign('mk_switch', $mk_switch); View::assign('ddhd_switch', $ddhd_switch); $xinjushang = 0; View::assign('xinjushang', $xinjushang); return View::fetch(); } else { $root_id = request()->employee->root_id; $type = input('type', '', 'trim'); $content = input('content', '', 'trim'); // 字段 $switch = input('switch', '', 'trim'); // 开关 $switch_name = ''; $content_name = ''; $field_module = ''; switch ($type) { case 'LF': $switch_name = 'changeSettingSwitchLF'; $content_name = 'changeSettingFieldLF'; $field_module = 'changeLF'; break; case 'DD': $switch_name = 'changeSettingSwitchDD'; $content_name = 'changeSettingFieldDD'; $field_module = 'changeDD'; break; case 'HD': $switch_name = 'changeSettingSwitchHD'; $content_name = 'changeSettingFieldHD'; $field_module = 'changeHD'; break; case 'QD': $switch_name = 'changeSettingSwitchJD'; $content_name = 'changeSettingFieldJD'; $field_module = 'changeJD'; break; case 'ZD': $switch_name = 'changeSettingSwitchZD'; $content_name = 'changeSettingFieldZD'; $field_module = 'changeZD'; break; case 'MK': $switch_name = 'changeSettingSwitchMK'; $content_name = 'changeSettingFieldMK'; $field_module = 'changeMK'; break; default: break; } if (empty($switch_name)) { return json(['code' => 0, 'msg' => '操作成功']); } // 判断保存的字段其他模块是否有使用 if (!empty($content)) { $field_data = $this->moduleFiledDeal($field_module); $other_checked = $field_data['other_checked']; foreach ($content as $k => $v) { if (in_array($v['id'], $other_checked)) { return json(['code' => 1, 'msg' => '字段重复使用']); } } } $switch_where[] = ['root_id', '=', $root_id]; $switch_where[] = ['name', '=', $switch_name]; $find = Setting::where($switch_where)->findOrEmpty(); if ($find->isEmpty()) { $data['name'] = $switch_name; $data['root_id'] = $root_id; $data['content'] = $switch; Setting::create($data); } else { $find->content = $switch; $find->save(); } $s_where[] = ['root_id', '=', $root_id]; $s_where[] = ['name', '=', $content_name]; $find = Setting::where($s_where)->findOrEmpty(); if ($find->isEmpty()) { $data['name'] = $content_name; $data['root_id'] = $root_id; $data['content'] = !empty($content) ? json_encode($content) : ''; $result = Setting::create($data); } else { $find->content = !empty($content) ? json_encode($content) : ''; $result = $find->save(); } $root_id = request()->employee->root_id; // 子模块开关 量房、到店、活动、签单、转单、卖卡 $z_where[] = ['name', 'in', ['changeSettingSwitchLF', 'changeSettingSwitchDD', 'changeSettingSwitchHD', 'changeSettingSwitchJD', 'changeSettingSwitchZD', 'changeSettingSwitchMK']]; $z_where[] = ['root_id', '=', $root_id]; $z_setting = Setting::where($z_where)->select()->toArray(); if (count($z_setting) == 6) { // 每一项都有保存值,缺少一项都意味着有开启状态 $all_down = true; foreach ($z_setting as $k => $v) { if ($v['content'] == 1) { $all_down = false; break; } } if ($all_down) { Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleChangeSwitch']])->save(['content' => 0]); } } // 到店的活动控制 $ddhd_switch = input('ddhd_switch', '', 'intval'); if ($ddhd_switch !== '') { $ddhd_find = Setting::where([['root_id', '=', $root_id], ['name', '=', 'changeSettingSwitchDDHD']])->findOrEmpty(); if ($ddhd_find->isEmpty()) { $data['name'] = 'changeSettingSwitchDDHD'; $data['root_id'] = $root_id; $data['content'] = $ddhd_switch; $result = Setting::create($data); } else { $ddhd_find->content = $ddhd_switch; $result = $ddhd_find->save(); } } return json(['code' => 0, 'msg' => '操作成功']); } } /** * 客户预约 */ public function moduleSubscribe() { if (!request()->isAjax()) { $root_id = request()->employee->root_id; // 子模块开关 活动、到店、量房 $z_where[] = ['name', 'in', ['subscribeSettingSwitchYYLF', 'subscribeSettingSwitchYYDD', 'subscribeSettingSwitchYYHD']]; $z_where[] = ['root_id', '=', $root_id]; $z_setting = Setting::where($z_where)->select()->toArray(); $hd_switch = 1; //活动 $dd_switch = 1; //到店 $lf_switch = 1; //量房 foreach ($z_setting as $k => $v) { if ($v['name'] == 'subscribeSettingSwitchYYLF') $lf_switch = $v['content']; if ($v['name'] == 'subscribeSettingSwitchYYDD') $dd_switch = $v['content']; if ($v['name'] == 'subscribeSettingSwitchYYHD') $hd_switch = $v['content']; } View::assign('lf_switch', $lf_switch); View::assign('dd_switch', $dd_switch); View::assign('hd_switch', $hd_switch); return View::fetch(); } else { $root_id = request()->employee->root_id; $type = input('type', '', 'trim'); $content = input('content', '', 'trim'); // 字段 $switch = input('switch', '', 'trim'); // 开关 $switch_name = ''; $content_name = ''; $field_module = ''; switch ($type) { case 'HD': $switch_name = 'subscribeSettingSwitchYYHD'; $content_name = 'subscribeSettingFieldYYHD'; $field_module = 'subscribeHD'; break; case 'DD': $switch_name = 'subscribeSettingSwitchYYDD'; $content_name = 'subscribeSettingFieldYYDD'; $field_module = 'subscribeDD'; break; case 'LF': $switch_name = 'subscribeSettingSwitchYYLF'; $content_name = 'subscribeSettingFieldYYLF'; $field_module = 'subscribeLF'; break; default: break; } if (empty($switch_name)) { return json(['code' => 0, 'msg' => '操作成功']); } // 判断保存的字段其他模块是否有使用 if (!empty($content)) { $field_data = $this->moduleFiledDeal($field_module); $other_checked = $field_data['other_checked']; foreach ($content as $k => $v) { if (in_array($v['id'], $other_checked)) { return json(['code' => 1, 'msg' => '字段重复使用']); } } } $switch_where[] = ['root_id', '=', $root_id]; $switch_where[] = ['name', '=', $switch_name]; $find = Setting::where($switch_where)->findOrEmpty(); if ($find->isEmpty()) { $data['name'] = $switch_name; $data['root_id'] = $root_id; $data['content'] = $switch; Setting::create($data); } else { $find->content = $switch; $find->save(); } $s_where[] = ['root_id', '=', $root_id]; $s_where[] = ['name', '=', $content_name]; $find = Setting::where($s_where)->findOrEmpty(); if ($find->isEmpty()) { $data['name'] = $content_name; $data['root_id'] = $root_id; $data['content'] = !empty($content) ? json_encode($content) : '';; $result = Setting::create($data); } else { $find->content = !empty($content) ? json_encode($content) : '';; $result = $find->save(); } $root_id = request()->employee->root_id; // 子模块开关 活动、到店、量房 $z_where[] = ['name', 'in', ['subscribeSettingSwitchYYLF', 'subscribeSettingSwitchYYDD', 'subscribeSettingSwitchYYHD']]; $z_where[] = ['root_id', '=', $root_id]; $z_setting = Setting::where($z_where)->select()->toArray(); if (count($z_setting) == 6) { // 每一项都有保存值,缺少一项都意味着有开启状态 $all_down = true; foreach ($z_setting as $k => $v) { if ($v['content'] == 1) { $all_down = false; break; } } if ($all_down) { Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleSubscribeSwitch']])->save(['content' => 0]); } } return json(['code' => 0, 'msg' => '操作成功']); } } /** * 自定义设置-报备字段设置 */ public function module_report() { if (!request()->isAjax()) { return View::fetch(); } $root_id = request()->employee->root_id; $where = [ ['name', '=', 'settingCustomerReportField'], ['root_id', '=', $root_id] ]; $setting = Setting::where($where)->find(); //默认值 $default_field_array = []; $default_field = CustomerPortraitField::where([['root_id', '=', $root_id], ['status', '=', 0], ['keyname', 'in', ['name', 'phone', 'sex', 'age_range', 'intention', 'consumption_capacity', 'current_region', 'source_id', 'first', 'add_wechat_type', 'add_wechat_time', 'group_building', 'live_broadcast', 'group_building_date', 'follow', 'point', 'wechat', 'talking_about_single_time', 'community_name', 'unit_number', 'house_location', 'square', 'housetype_arrow', 'deco_style', 'house_type', 'house_status', 'plan_deco_time', 'budget', 'housing_use', 'peripheral_supporting', 'house_structure', 'decoration_mode', 'like_color', 'customer_demand', 'remarks_on_other_house_information', 'family_structure', 'decision_maker', 'family_opinion', 'hourse_price', 'car_price', 'buying_community', 'hobby', 'free_time', 'environmental_requirements', 'design', 'workmanship', 'space_design', 'service_satisfaction', 'quotation_satisfaction', 'program_satisfaction']]])->orderRaw('if(isnull(sort),1,0),sort asc')->select()->toArray(); foreach ($default_field as $k => $v) { $default_field_array[] = [ 'id' => $v['id'], 'name' => $v['name'], 'sort' => $k + 1, 'keyname' => $v['keyname'], 'type' => $v['type'] ]; } //选中的值 $checked = []; if ($setting && !empty($setting['content'])) { $checked = json_decode($setting['content'], true); } else { $checked = $default_field_array; } $column_select_id = array_column($checked, 'id'); $select = CustomerPortraitFieldSelect::where('pid', 'in', $column_select_id)->select()->toArray(); $city = Company::where('root_id', $root_id)->value('city'); foreach ($checked as &$item) { $item['select'] = []; foreach ($select as $vv) { if ($item['id'] == $vv['pid']) { $item['select'][] = $vv; } } if ($item['keyname'] == 'current_region') { $item['select'][] = ['id' => $root_id, 'name' => $city, 'pid' => $item['id']]; } if ($item['keyname'] == 'source_id') { $item['select'] = CustomerSource::field('id,source as name')->where('root_id', $root_id)->select()->toArray(); } if ($item['keyname'] == 'deco_style') { $item['select'] = Decostyle::field('id,name')->where([['root_id', '=', $root_id], ['type', '=', 0]])->select()->toArray(); } } //全部值 $all = CustomerPortraitField::where([['root_id', '=', $root_id], ['pid', '<>', 0], ['status', '=', 0]])->orderRaw('if(isnull(sort),1,0),sort asc')->select()->toArray(); return json(['code' => 0, 'all' => $all, 'default' => $default_field_array, 'checked' => $checked]); } /** * 自定义设置-报备字段设置保存 */ public function module_report_save() { //数组包括id、name、sort、keyname $content = input('content'); $root_id = request()->employee->root_id; $where = [ ['name', '=', 'settingCustomerReportField'], ['root_id', '=', $root_id] ]; $data = Setting::where($where)->find(); if ($data) { $data->content = json_encode($content); $data->save(); } else { Setting::create([ 'name' => 'settingCustomerReportField', 'root_id' => $root_id, 'content' => json_encode($content) ]); } return json(['code' => 0, 'msg' => '保存成功']); } /** * 团队客户自定设置页面 */ public function team_statistics_data() { $root_id = request()->employee->root_id; $lf_where[] = ['root_id', '=', $root_id]; $lf_where[] = ['name', '=', 'teamStatisticsJurisdiction']; $find = Setting::where($lf_where)->findOrEmpty(); $type_arr = ['customer_num' => 1, 'visit_num' => 1, 'valid_count' => 1, 'deposit_num' => 1, 'signed_num' => 1, 'yylf_num' => 1, 'lf_num' => 1, 'yydd_num' => 1, 'ydd_num' => 1, 'yyhd_num' => 1, 'ydc_num' => 1]; $arr = (!$find->isEmpty() && !empty($find->content)) ? explode(',', $find->content) : []; foreach ($type_arr as $k => $v) { $type_arr[$k] = in_array($k, $arr) ? 1 : 0; } View::assign('type', $type_arr); return View::fetch(); } /** * 获取团队客户自定义设置api */ public function teamStatisticsSetting() { $root_id = request()->employee->root_id; $lf_where[] = ['root_id', '=', $root_id]; $lf_where[] = ['name', '=', 'teamStatisticsJurisdiction']; $find = Setting::where($lf_where)->findOrEmpty(); $type_arr = ['customer_num' => 1, 'visit_num' => 1, 'deposit_num' => 1, 'signed_num' => 1, 'yylf_num' => 1, 'lf_num' => 1, 'yydd_num' => 1, 'ydd_num' => 1, 'yyhd_num' => 1, 'ydc_num' => 1]; $arr = (!$find->isEmpty() && !empty($find->content)) ? explode(',', $find->content) : []; foreach ($type_arr as $k => $v) { $type_arr[$k] = in_array($k, $arr) ? 1 : 0; } return json(['code' => 1, 'data' => $type_arr]); } /** * 团队客户自定设置保存 */ public function team_statistics_data_save() { $save = input('value/a', []); $value = $save ? implode(',', $save) : ''; $root_id = request()->employee->root_id; $lf_where[] = ['root_id', '=', $root_id]; $lf_where[] = ['name', '=', 'teamStatisticsJurisdiction']; $find = Setting::where($lf_where)->findOrEmpty(); if ($find->isEmpty()) { $data['name'] = 'teamStatisticsJurisdiction'; $data['root_id'] = $root_id; $data['content'] = $value; Setting::create($data); } else { $find->content = $value; $find->save(); } return json(['code' => 0, 'msg' => '保存成功']); } /** * 操作设置 */ public function moduleHandel() { $root_id = request()->employee->root_id; $setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'customerHandel']])->findOrEmpty(); if (!request()->isAjax()) { if (!$setting->isEmpty()) { $content = json_decode($setting['content'], true); } else { $content = [ 'wechat' => 1, 'group_building' => 1, 'live_broadcast' => 1 ]; } View::assign('data', $content); return View::fetch(); } else { $param = request()->only(['wechat', 'group_building', 'live_broadcast']); $content = [ 'wechat' => $param['wechat'], 'group_building' => $param['group_building'], 'live_broadcast' => $param['live_broadcast'] ]; if ($setting->isEmpty()) { $data['name'] = 'customerHandel'; $data['content'] = json_encode($content); $data['state'] = 1; $data['root_id'] = $root_id; $result = Setting::create($data); } else { $setting->content = json_encode($content); $result = $setting->save(); } if ($result !== false) { return json(['code' => 0, 'msg' => '保存成功']); } else { return json(['code' => 1, 'msg' => '保存失败']); } } } public function report() { if (!request()->isAjax()) { return View::fetch(); } $root_id = request()->employee->root_id; $where = [ ['name', '=', 'CustomerReportSettingForPc'], ['root_id', '=', $root_id] ]; $setting = Setting::where($where)->find(); //默认值 $default_field_array = []; $default_field = CustomerPortraitField::where([['root_id', '=', $root_id], ['status', '=', 0], ['keyname', 'in', ['name', 'phone', 'sex', 'age_range', 'intention', 'consumption_capacity', 'current_region', 'source_id', 'first', 'add_wechat_type', 'add_wechat_time', 'group_building', 'live_broadcast', 'group_building_date', 'follow', 'point', 'wechat', 'talking_about_single_time', 'community_name', 'unit_number', 'house_location', 'square', 'housetype_arrow', 'deco_style', 'house_type', 'house_status', 'plan_deco_time', 'budget', 'housing_use', 'peripheral_supporting', 'house_structure', 'decoration_mode', 'like_color', 'customer_demand', 'remarks_on_other_house_information', 'family_structure', 'decision_maker', 'family_opinion', 'hourse_price', 'car_price', 'buying_community', 'hobby', 'free_time', 'environmental_requirements', 'design', 'workmanship', 'space_design', 'service_satisfaction', 'quotation_satisfaction', 'program_satisfaction']]])->orderRaw('if(isnull(sort),1,0),sort asc')->select()->toArray(); foreach ($default_field as $k => $v) { $default_field_array[] = [ 'id' => $v['id'], 'name' => $v['name'], 'sort' => $k + 1, 'keyname' => $v['keyname'], 'type' => $v['type'] ]; } //选中的值 $checked = []; if ($setting && !empty($setting['content'])) { $checked = json_decode($setting['content'], true); } else { $checked = $default_field_array; } $column_select_id = array_column($checked, 'id'); $select = CustomerPortraitFieldSelect::where('pid', 'in', $column_select_id)->select()->toArray(); $city = Company::where('root_id', $root_id)->value('city'); foreach ($checked as &$item) { $item['select'] = []; foreach ($select as $vv) { if ($item['id'] == $vv['pid']) { $item['select'][] = $vv; } } if ($item['keyname'] == 'current_region') { $item['select'][] = ['id' => $root_id, 'name' => $city, 'pid' => $item['id']]; } if ($item['keyname'] == 'source_id') { $item['select'] = CustomerSource::field('id,source as name')->where('root_id', $root_id)->select()->toArray(); } if ($item['keyname'] == 'deco_style') { $item['select'] = Decostyle::field('id,name')->where([['root_id', '=', $root_id], ['type', '=', 0]])->select()->toArray(); } } //全部值 $all = CustomerPortraitField::where([['root_id', '=', $root_id], ['pid', '<>', 0], ['status', '=', 0]])->orderRaw('if(isnull(sort),1,0),sort asc')->select()->toArray(); return json(['code' => 0, 'all' => $all, 'default' => $default_field_array, 'checked' => $checked]); } public function report_save() { $content = input('content'); $root_id = request()->employee->root_id; $where = [ ['name', '=', 'CustomerReportSettingForPc'], ['root_id', '=', $root_id] ]; $data = Setting::where($where)->find(); if ($data) { $data->content = json_encode($content); $data->save(); } else { Setting::create([ 'name' => 'CustomerReportSettingForPc', 'root_id' => $root_id, 'content' => json_encode($content) ]); } return json(['code' => 0, 'msg' => '保存成功']); } /** * 获取数据统计设置 */ public function get_statistics() { $root_id = request()->employee->root_id; $where = [ ['name', '=', 'CustomerStatisticsSettingForMini'], ['root_id', '=', $root_id] ]; $data = Setting::where($where)->findOrEmpty(); if ($data->isEmpty()) { $content = ['valid', 'call', 'jiav', 'contact', 'subscribe', 'measure_room', 'arrival', 'deposit', 'signed', 'maika']; } else { $content = explode(',', $data['content']); } View::assign('data', $content); return View::fetch(); } /** * 设置数据统计展示 */ public function set_statistics() { $content = input('content'); $root_id = request()->employee->root_id; $where = [ ['name', '=', 'CustomerStatisticsSettingForMini'], ['root_id', '=', $root_id] ]; $data = Setting::where($where)->find(); if ($data) { $data->content = $content; $data->save(); } else { Setting::create([ 'name' => 'CustomerStatisticsSettingForMini', 'root_id' => $root_id, 'content' => $content ]); } return json(['code' => 0, 'msg' => '保存成功']); } }