12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778 |
- <?php
- namespace app\sys\controller;
- use app\model\CustomerPortraitField;
- use app\model\Decostyle;
- use think\facade\Request;
- use think\facade\View;
- use app\model\Employee;
- use app\model\Org;
- use app\model\Company;
- use app\model\CustomerPackage;
- use app\model\Setting;
- use app\model\CustomerPortrait;
- use app\model\CustomerSource;
- use app\model\CustomerPortraitFieldSelect;
- class CustomerSetting
- {
- /**
- * 首页
- */
- public function index()
- {
- $root_id = request()->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' => '保存成功']);
- }
- }
|