1
0

CustomerSetting.php 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  1. <?php
  2. namespace app\sys\controller;
  3. use app\model\CustomerPortraitField;
  4. use app\model\Decostyle;
  5. use think\facade\Request;
  6. use think\facade\View;
  7. use app\model\Employee;
  8. use app\model\Org;
  9. use app\model\Company;
  10. use app\model\CustomerPackage;
  11. use app\model\Setting;
  12. use app\model\CustomerPortrait;
  13. use app\model\CustomerSource;
  14. use app\model\CustomerPortraitFieldSelect;
  15. class CustomerSetting
  16. {
  17. /**
  18. * 首页
  19. */
  20. public function index()
  21. {
  22. $root_id = request()->employee->root_id;
  23. //加微类型
  24. $where[] = ['root_id', '=', $root_id];
  25. $where[] = ['name', '=', 'customerWechatSetting'];
  26. $wechat = Setting::where($where)->findOrEmpty();
  27. $wechat = $wechat->isEmpty() ? ['常规加微'] : explode(',', $wechat->content);
  28. View::assign('wechat1', in_array('常规加微', $wechat));
  29. View::assign('wechat2', in_array('社群加微', $wechat));
  30. View::assign('wechat3', in_array('历史加微', $wechat));
  31. //量房图片类型
  32. $where1[] = ['root_id', '=', $root_id];
  33. $where1[] = ['name', '=', 'customerLfSetting'];
  34. $lf = Setting::where($where1)->findOrEmpty();
  35. $lf = $lf->isEmpty() ? ['量房图片'] : explode(',', $lf->content);
  36. View::assign('lf1', in_array('量房图片', $lf));
  37. View::assign('lf2', in_array('量房报告图片', $lf));
  38. View::assign('lf3', in_array('客户需求图片', $lf));
  39. //下次回访时间是否必传
  40. $where2[] = ['root_id', '=', $root_id];
  41. $where2[] = ['name', '=', 'nextVisitTimeIsOk'];
  42. $visit = Setting::where($where2)->findOrEmpty();
  43. $visit = !$visit->isEmpty() ? (int)$visit->content : 1;
  44. View::assign('visit_save', $visit);
  45. $where3[] = ['root_id', '=', $root_id];
  46. $where3[] = ['name', '=', 'addWechatDay'];
  47. $visit = Setting::where($where3)->findOrEmpty();
  48. $visit = !$visit->isEmpty() ? explode('@', $visit->content) : [1, 0];
  49. View::assign('addWechatDay', $visit[0]);
  50. View::assign('addWechatDaySwitch', isset($visit[1]) ? $visit[1] : 0);
  51. //默认打开签单规则
  52. $where4[] = ['root_id', '=', $root_id];
  53. $where4[] = ['name', '=', 'forbiddenState'];
  54. $visit = Setting::where($where4)->findOrEmpty();
  55. if ($visit->isEmpty()) {
  56. $visit = Setting::create([
  57. 'name' => 'forbiddenState',
  58. 'content' => '交定',
  59. 'root_id' => $root_id
  60. ]);
  61. }
  62. $visit = !$visit->isEmpty() && $visit->content ? explode(',', $visit->content) : [];
  63. // 确认设置
  64. $confirmSetting = Setting::where([['root_id', '=', $root_id], ['name', 'in', ['visitShopConfirm', 'visitSiteConfirm', 'measureConfirm', 'depositConfirm', 'signConfirm', 'assign_type']]])->column('content', 'name');
  65. foreach (['visitShopConfirm', 'visitSiteConfirm', 'measureConfirm', 'depositConfirm', 'signConfirm', 'assign_type'] as $v) {
  66. View::assign($v, isset($confirmSetting[$v]) ? json_decode($confirmSetting[$v], 'true') : []);
  67. }
  68. // 指派人数设置
  69. $designerNum = Setting::where(['name' => 'designerNum', 'root_id' => $root_id])->value('content');
  70. View::assign('designerNum', $designerNum);
  71. View::assign('l1', in_array('确认到店', $visit));
  72. View::assign('l2', in_array('确认到场', $visit));
  73. View::assign('l3', in_array('确认量房', $visit));
  74. View::assign('l4', in_array('交定', $visit));
  75. View::assign('l5', in_array('签单', $visit));
  76. View::assign('jiaoding', '签单');
  77. View::assign('qiandan', '转单');
  78. View::assign('root_id', request()->employee->root_id);
  79. // 运营后台资源分配设置
  80. $resourcefp = Setting::where([['root_id', '=', $root_id], ['name', '=', 'resource_fp']])->findOrEmpty();
  81. $visit = !$resourcefp->isEmpty() ? (int)$resourcefp->content : 1;
  82. View::assign('resource_fp', $visit);
  83. // 客户回收后是否重置
  84. $visitReset = Setting::where([['root_id', '=', $root_id], ['name', '=', 'visit_reset']])->findOrEmpty();
  85. $visitResetSetting = !$visitReset->isEmpty() ? (int)$visitReset->content : 1;
  86. View::assign('visit_reset', $visitResetSetting);
  87. //只展示员工跟进记录不展示修改客户扩展字段信息设置
  88. $showEmpVistlog = Setting::where([['root_id', '=', $root_id], ['name', '=', 'showEmpVistlog']])->findOrEmpty();
  89. $visit = !$showEmpVistlog->isEmpty() ? (int)$showEmpVistlog->content : 0;
  90. View::assign('showEmpVistlog', $visit);
  91. //控制管理层消息通知
  92. $magnotify = Setting::where([['root_id', '=', $root_id], ['name', '=', 'magnotify']])->findOrEmpty();
  93. $visit = !$magnotify->isEmpty() ? (int)$magnotify->content : 0;
  94. View::assign('magnotify', $visit);
  95. // 网销端客户池控制统计控制显示不显示
  96. $empcrm_pool_statistics = Setting::where([['root_id', '=', $root_id], ['name', '=', 'empcrm_pool_statistics']])->findOrEmpty();
  97. $emp_pool = !$empcrm_pool_statistics->isEmpty() ? (int)$empcrm_pool_statistics->content : 0;
  98. View::assign('empcrm_pool_statistics', $emp_pool);
  99. // 网销端同部门下客户能否重复录入
  100. $empcrm_customer_repeat = Setting::where([['root_id', '=', $root_id], ['name', '=', 'empcrm_customer_repeat']])->findOrEmpty();
  101. $emp_pool = !$empcrm_customer_repeat->isEmpty() ? (int)$empcrm_customer_repeat->content : 1;
  102. View::assign('empcrm_customer_repeat', $emp_pool);
  103. // 跟进时候设计师必填
  104. $need_designer_setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'add_visit_log_need_designer']])->findOrEmpty();
  105. $need_designer = !$need_designer_setting->isEmpty() ? explode(',', $need_designer_setting['content']) : [];
  106. View::assign('need_designer', $need_designer);
  107. // 设计师能否报备或者获取客户
  108. $designer_get_customer = Setting::where([['root_id', '=', $root_id], ['name', '=', 'designer_get_customer']])->findOrEmpty();
  109. $designer_get_customer = !$designer_get_customer->isEmpty() ? (int)$designer_get_customer->content : 1;
  110. View::assign('designer_get_customer', $designer_get_customer);
  111. // 未跟进提醒
  112. $no_follow_tips = Setting::where([['root_id', '=', $root_id], ['name', '=', 'no_follow_tips']])->findOrEmpty();
  113. $no_follow_tips = !$no_follow_tips->isEmpty() ? (int)$no_follow_tips->content : 0;
  114. View::assign('no_follow_tips', $no_follow_tips);
  115. $is_all_manager_oprate_able = Setting::where([['root_id', '=', $root_id], ['name', '=', 'is_all_manager_oprate_able']])->findOrEmpty();
  116. View::assign('is_all_manager_oprate_able', $is_all_manager_oprate_able->content);
  117. // 有效申请人设置
  118. $valid_check_person_setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'valid_check_person']])->findOrEmpty();
  119. $valid_check_person = !$valid_check_person_setting->isEmpty() ? explode(',', $valid_check_person_setting['content']) : [];
  120. View::assign('valid_check_person', $valid_check_person);
  121. return View::fetch();
  122. }
  123. /**
  124. * 设置加微类型,量房设置
  125. */
  126. public function setting()
  127. {
  128. $root_id = request()->employee->root_id;
  129. $value = input('value/a', []); //加微设置
  130. $value1 = input('value1/a', []); //量房设置
  131. $value2 = input('value2', 0); //下次回访时间是否必传
  132. $value3 = input('value3', 0); //最迟加微时间
  133. $value33 = input('value33', 0); //最迟加微时间开关
  134. $value4 = input('value4/a', []); //跟进保护规则
  135. $showEmpVistlog = input('showEmpVistlog', 0);
  136. $magnotify = input('magnotify', 0);
  137. $empcrm_pool_statistics = input('empcrm_pool_statistics', 0, 'intval'); // 网销端客户池
  138. $empcrm_customer_repeat = input('empcrm_customer_repeat/a', []); // 网销端客户重复报备
  139. $need_designer = input('need_designer/a', []); // 添加跟进时候,选中的状态需要先选择设计师
  140. $designer_get_customer = input('designer_get_customer', '', 'intval'); // 设计师能否获取客户
  141. $no_follow_tips = input('no_follow_tips', '', 'intval'); // 未跟进提醒
  142. $is_all_manager_oprate_able = input('is_all_manager_oprate_able', 0, 'intval'); // 未跟进提醒
  143. if (!is_array($value) || count($value) == 0) {
  144. return json(['code' => 1, 'data' => '请至少选择一条加微设置', 'msg' => '请至少选择一条加微设置']);
  145. }
  146. if (!is_array($value1) || count($value1) == 0) {
  147. return json(['code' => 1, 'data' => '请至少选择一条量房设置', 'msg' => '请至少选择一条量房设置']);
  148. }
  149. //
  150. $where[] = ['root_id', '=', $root_id];
  151. $where[] = ['name', '=', 'customerWechatSetting'];
  152. $info = Setting::where($where)->findOrEmpty();
  153. if ($info->isEmpty()) {
  154. Setting::insertGetId([
  155. 'name' => 'customerWechatSetting',
  156. 'content' => implode(',', $value),
  157. 'root_id' => $root_id
  158. ]);
  159. } else {
  160. $info->content = implode(',', $value);
  161. $info->save();
  162. }
  163. $where1[] = ['root_id', '=', $root_id];
  164. $where1[] = ['name', '=', 'customerLfSetting'];
  165. $info1 = Setting::where($where1)->findOrEmpty();
  166. if ($info1->isEmpty()) {
  167. Setting::insertGetId([
  168. 'name' => 'customerLfSetting',
  169. 'content' => implode(',', $value1),
  170. 'root_id' => $root_id
  171. ]);
  172. } else {
  173. $info1->content = implode(',', $value1);
  174. $info1->save();
  175. }
  176. $where2[] = ['root_id', '=', $root_id];
  177. $where2[] = ['name', '=', 'nextVisitTimeIsOk'];
  178. $info2 = Setting::where($where2)->findOrEmpty();
  179. if ($info2->isEmpty()) {
  180. Setting::insertGetId([
  181. 'name' => 'nextVisitTimeIsOk',
  182. 'content' => $value2,
  183. 'root_id' => $root_id
  184. ]);
  185. } else {
  186. $info2->content = $value2;
  187. $info2->save();
  188. }
  189. $where3[] = ['root_id', '=', $root_id];
  190. $where3[] = ['name', '=', 'addWechatDay'];
  191. $info3 = Setting::where($where3)->findOrEmpty();
  192. if ($info3->isEmpty()) {
  193. Setting::insertGetId([
  194. 'name' => 'addWechatDay',
  195. 'content' => $value3 . '@' . $value33,
  196. 'root_id' => $root_id
  197. ]);
  198. } else {
  199. $info3->content = $value3 . '@' . $value33;
  200. $info3->save();
  201. }
  202. //跟进保护规则
  203. $value4 = $value4 ? implode(',', $value4) : '';
  204. $where4[] = ['root_id', '=', $root_id];
  205. $where4[] = ['name', '=', 'forbiddenState'];
  206. $info4 = Setting::where($where4)->findOrEmpty();
  207. if ($info4->isEmpty()) {
  208. Setting::insertGetId([
  209. 'name' => 'forbiddenState',
  210. 'content' => $value4,
  211. 'root_id' => $root_id
  212. ]);
  213. } else {
  214. $info4->content = $value4;
  215. $info4->save();
  216. }
  217. //只展示员工跟进记录
  218. $where5[] = ['root_id', '=', $root_id];
  219. $where5[] = ['name', '=', 'showEmpVistlog'];
  220. $info5 = Setting::where($where5)->findOrEmpty();
  221. if ($info5->isEmpty()) {
  222. Setting::insertGetId([
  223. 'name' => 'showEmpVistlog',
  224. 'content' => $showEmpVistlog,
  225. 'root_id' => $root_id
  226. ]);
  227. } else {
  228. $info5->content = $showEmpVistlog;
  229. $info5->save();
  230. }
  231. //管理层消息通知开关
  232. $where6[] = ['root_id', '=', $root_id];
  233. $where6[] = ['name', '=', 'magnotify'];
  234. $info6 = Setting::where($where6)->findOrEmpty();
  235. if ($info6->isEmpty()) {
  236. Setting::insertGetId([
  237. 'name' => 'magnotify',
  238. 'content' => $magnotify,
  239. 'root_id' => $root_id
  240. ]);
  241. } else {
  242. $info6->content = $magnotify;
  243. $info6->save();
  244. }
  245. // 确认设置
  246. $param = request()->only(['visitShopConfirm', 'visitSiteConfirm', 'measureConfirm', 'depositConfirm', 'signConfirm', 'assign_type']);
  247. foreach (['visitShopConfirm', 'visitSiteConfirm', 'measureConfirm', 'depositConfirm', 'signConfirm', 'assign_type'] as $name) {
  248. $data = ['root_id' => $root_id, 'name' => $name];
  249. $setObj = Setting::where($data)->findOrEmpty();
  250. $data['content'] = json_encode($param[$name] ?? []);
  251. $setObj->save($data);
  252. }
  253. // 设置设计可获得分配人数
  254. $designerNum = input('designerNum/d', 0);
  255. $designerNumSetting = ['root_id' => $root_id, 'name' => 'designerNum'];
  256. $designerSetObj = Setting::where($designerNumSetting)->findOrEmpty();
  257. $designerNumSetting['content'] = $designerNum;
  258. $designerSetObj->save($designerNumSetting);
  259. // 设置设计可获得分配人数
  260. $fp = input('resource_fp/d', 1);
  261. $designerNumSetting = ['root_id' => $root_id, 'name' => 'resource_fp'];
  262. $designerSetObj = Setting::where($designerNumSetting)->findOrEmpty();
  263. $designerNumSetting['content'] = $fp;
  264. $designerSetObj->save($designerNumSetting);
  265. // 设置回收后是否重置
  266. $re = input('visit_reset/d', 1);
  267. $designerNumSetting = ['root_id' => $root_id, 'name' => 'visit_reset'];
  268. $designerSetObj = Setting::where($designerNumSetting)->findOrEmpty();
  269. $designerNumSetting['content'] = $re;
  270. $designerSetObj->save($designerNumSetting);
  271. // 控制网销端客户池统计的展示不展示
  272. $empcrm_pool[] = ['root_id', '=', $root_id];
  273. $empcrm_pool[] = ['name', '=', 'empcrm_pool_statistics'];
  274. $info_pool = Setting::where($empcrm_pool)->findOrEmpty();
  275. if ($info_pool->isEmpty()) {
  276. Setting::insertGetId([
  277. 'name' => 'empcrm_pool_statistics',
  278. 'content' => (int)$empcrm_pool_statistics,
  279. 'root_id' => $root_id
  280. ]);
  281. } else {
  282. $info_pool->content = (int)$empcrm_pool_statistics;
  283. $info_pool->save();
  284. }
  285. // 控制网销端客户池统计的展示不展示
  286. $empcrm_repeat[] = ['root_id', '=', $root_id];
  287. $empcrm_repeat[] = ['name', '=', 'empcrm_customer_repeat'];
  288. $info_repeat = Setting::where($empcrm_repeat)->findOrEmpty();
  289. if ($info_repeat->isEmpty()) {
  290. Setting::insertGetId([
  291. 'name' => 'empcrm_customer_repeat',
  292. 'content' => !empty($empcrm_customer_repeat) ? implode(',', $empcrm_customer_repeat) : '',
  293. 'root_id' => $root_id
  294. ]);
  295. } else {
  296. $info_repeat->content = !empty($empcrm_customer_repeat) ? implode(',', $empcrm_customer_repeat) : '';
  297. $info_repeat->save();
  298. }
  299. // 设计师必填
  300. $designer_need_where[] = ['root_id', '=', $root_id];
  301. $designer_need_where[] = ['name', '=', 'add_visit_log_need_designer'];
  302. $designer_need_info = Setting::where($designer_need_where)->findOrEmpty();
  303. if ($designer_need_info->isEmpty()) {
  304. Setting::insertGetId([
  305. 'name' => 'add_visit_log_need_designer',
  306. 'content' => !empty($need_designer) ? implode(',', $need_designer) : '',
  307. 'root_id' => $root_id
  308. ]);
  309. } else {
  310. $designer_need_info->content = !empty($need_designer) ? implode(',', $need_designer) : '';
  311. $designer_need_info->save();
  312. }
  313. // 设计师能否报备或者获取客户
  314. $de_where[] = ['root_id', '=', $root_id];
  315. $de_where[] = ['name', '=', 'designer_get_customer'];
  316. $info_de_where = Setting::where($de_where)->findOrEmpty();
  317. if ($info_de_where->isEmpty()) {
  318. Setting::insertGetId([
  319. 'name' => 'designer_get_customer',
  320. 'content' => (int)$designer_get_customer,
  321. 'root_id' => $root_id
  322. ]);
  323. } else {
  324. $info_de_where->content = (int)$designer_get_customer;
  325. $info_de_where->save();
  326. }
  327. // PC-CRM未跟进三天、七天颜色显示
  328. $tip_where[] = ['root_id', '=', $root_id];
  329. $tip_where[] = ['name', '=', 'no_follow_tips'];
  330. $info_tips = Setting::where($tip_where)->findOrEmpty();
  331. if ($info_tips->isEmpty()) {
  332. Setting::insertGetId([
  333. 'name' => 'no_follow_tips',
  334. 'content' => (int)$no_follow_tips,
  335. 'root_id' => $root_id
  336. ]);
  337. } else {
  338. $info_tips->content = (int)$no_follow_tips;
  339. $info_tips->save();
  340. }
  341. // 设置是否管理层及以上都能跟进
  342. $condition = [
  343. ['root_id', '=', $root_id],
  344. ['name', '=', 'is_all_manager_oprate_able']
  345. ];
  346. $setting = Setting::where($condition)->findOrEmpty();
  347. $setting->save([
  348. 'root_id' => $root_id,
  349. 'name' => 'is_all_manager_oprate_able',
  350. 'content' => $is_all_manager_oprate_able
  351. ]);
  352. // 有效申请人设置
  353. $valid_check_person_select = input('valid_check_person/a', []); // 添加跟进时候,选中的状态需要先选择设计师
  354. $valid_check_person_condition[] = ['root_id', '=', $root_id];
  355. $valid_check_person_condition[] = ['name', '=', 'valid_check_person'];
  356. $valid_check_person = Setting::where($valid_check_person_condition)->findOrEmpty();
  357. if ($valid_check_person->isEmpty()) {
  358. Setting::insertGetId([
  359. 'name' => 'valid_check_person',
  360. 'content' => !empty($valid_check_person_select) ? implode(',', $valid_check_person_select) : '',
  361. 'root_id' => $root_id
  362. ]);
  363. } else {
  364. $valid_check_person->content = !empty($valid_check_person_select) ? implode(',', $valid_check_person_select) : '';
  365. $valid_check_person->save();
  366. }
  367. return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
  368. }
  369. private function tree($data, $pid = 0, $setting)
  370. {
  371. $new_arr = [];
  372. foreach ($data as $k => $v) {
  373. if ($v['pid'] == $pid) {
  374. $children = $this->tree($data, $v['id'], $setting);
  375. $v['children'] = $children;
  376. $v['selected'] = false;
  377. if (in_array($v['id'], $setting)) {
  378. $v['selected'] = true;
  379. }
  380. $new_arr[] = $v;
  381. }
  382. }
  383. return $new_arr;
  384. }
  385. /*
  386. * 人员树
  387. */
  388. public function get_person()
  389. {
  390. $root_id = request()->employee->root_id;
  391. $empcrm_repeat[] = ['root_id', '=', $root_id];
  392. $empcrm_repeat[] = ['name', '=', 'empcrm_customer_repeat'];
  393. $info_repeat = Setting::where($empcrm_repeat)->findOrEmpty();
  394. $setting = [];
  395. if (!empty($info_repeat)) {
  396. $setting = explode(',', $info_repeat['content']);
  397. }
  398. //树形
  399. $where = [
  400. ['path', 'like', $root_id . '-%'],
  401. ['status', '=', 1]
  402. ];
  403. $allnodes = Org::where($where)->field('id value,id,pid,name')->order('level asc, id asc')->select()->toArray();
  404. $tree = $this->tree($allnodes, 0, $setting);
  405. return json($tree);
  406. }
  407. /**
  408. * 自定义设置
  409. */
  410. public function getCustom()
  411. {
  412. $root_id = request()->employee->root_id;
  413. $info = CustomerPortrait::where('root_id', $root_id)->findOrEmpty();
  414. $data = $info->fields;
  415. $arr = $this->settingArr();
  416. $res['source']['arr'] = CustomerSource::where('root_id', $root_id)->column('source');
  417. $res['source']['title'] = '客户来源';
  418. foreach ($arr as $k => $v) {
  419. $res[$k]['arr'] = (array)$data[$v][$k]['select'];
  420. $res[$k]['title'] = $data[$v][$k]['title'];
  421. }
  422. return json(['code' => 0, 'data' => $res, 'msg' => '保存成功']);
  423. }
  424. /**
  425. * 编辑自定义设置
  426. * key 关键词
  427. * type 类型 客户来源 【客户关注点】 客户痛点 户型 房屋用途 周边配套 房屋结构 装修方式 客户喜欢的色调 家庭结构 【决策人】 【关注的工艺】 关注房屋的空间
  428. * y_key 原数据
  429. */
  430. public function editCustom()
  431. {
  432. $arr = $this->settingArr();
  433. $arr = array_merge(['source' => ''], $arr);
  434. $param = Request()->only(['key' => '', 'type' => '', 'y_key' => '']);
  435. if (!isset($arr[$param['type']])) return json(['code' => 1, 'data' => '编辑失败', 'msg' => '编辑失败']);
  436. $root_id = request()->employee->root_id;
  437. if ($param['type'] == 'source') {
  438. $info = CustomerSource::where([['root_id', '=', $root_id], ['source', '=', $param['key']]])->findOrEmpty();
  439. if (!$info->isEmpty()) return json(['code' => 1, 'data' => '来源已存在', 'msg' => '来源已存在']);
  440. CustomerSource::where([['root_id', '=', $root_id], ['source', '=', $param['y_key']]])->update(['source' => $param['key']]);
  441. } else {
  442. if (trim($param['y_key']) == trim($param['key'])) return json(['code' => 1, 'data' => '未改变原值', 'msg' => '未改变原值']);
  443. $info = CustomerPortrait::where('root_id', $root_id)->findOrEmpty();
  444. $data = $info->fields;
  445. $array = $data[$arr[$param['type']]][$param['type']]['select'];
  446. if ($array && in_array($param['key'], $array)) return json(['code' => 1, 'data' => '数据重复', 'msg' => '数据重复']);
  447. $key = array_search($param['y_key'], $array);
  448. $array[$key] = $param['key'];
  449. $data[$arr[$param['type']]][$param['type']]['select'] = array_values($array);
  450. !$info->isEmpty() ?: $info->root_id = $root_id;
  451. $info->fields = $data;
  452. $info->save();
  453. }
  454. return json(['code' => 0, 'data' => '编辑成功', 'msg' => '编辑成功']);
  455. }
  456. /**
  457. * 新增自定义设置
  458. */
  459. public function addCustom()
  460. {
  461. $arr = $this->settingArr();
  462. $arr = array_merge(['source' => ''], $arr);
  463. $param = Request()->only(['key' => '', 'type' => '']);
  464. if (!isset($arr[$param['type']])) return json(['code' => 1, 'data' => '添加失败', 'msg' => '添加失败']);
  465. $root_id = request()->employee->root_id;
  466. if ($param['type'] == 'source') {
  467. $info = CustomerSource::where([['root_id', '=', $root_id], ['source', '=', $param['key']]])->findOrEmpty();
  468. if (!$info->isEmpty()) return json(['code' => 1, 'data' => '数据重复', 'msg' => '数据重复']);
  469. CustomerSource::insert(['source' => $param['key'], 'root_id' => $root_id]);
  470. } else {
  471. $info = CustomerPortrait::where('root_id', $root_id)->findOrEmpty();
  472. $data = $info->fields;
  473. $array = $data[$arr[$param['type']]][$param['type']]['select'];
  474. if ($array && in_array($param['key'], $array)) return json(['code' => 1, 'data' => '数据重复', 'msg' => '数据重复']);
  475. $array[] = $param['key'];
  476. $data[$arr[$param['type']]][$param['type']]['select'] = array_values($array);
  477. !$info->isEmpty() ?: $info->root_id = $root_id;
  478. $info->fields = $data;
  479. $info->save();
  480. }
  481. return json(['code' => 0, 'data' => '添加成功', 'msg' => '添加成功']);
  482. }
  483. /**
  484. * 删除自定义设置
  485. */
  486. public function deleteCustom()
  487. {
  488. $arr = $this->settingArr();
  489. $arr = array_merge(['source' => ''], $arr);
  490. $param = Request()->only(['key' => '', 'type' => '']);
  491. if (!isset($arr[$param['type']])) return json(['code' => 1, 'data' => '删除失败', 'msg' => '删除失败']);
  492. $root_id = request()->employee->root_id;
  493. if ($param['type'] == 'source') {
  494. $info = CustomerSource::where([['root_id', '=', $root_id], ['source', '=', $param['key']]])->findOrEmpty();
  495. if ($info->isEmpty()) return json(['code' => 1, 'data' => '数据不存在', 'msg' => '数据不存在']);
  496. CustomerSource::where([['root_id', '=', $root_id], ['source', '=', $param['key']]])->delete();
  497. } else {
  498. $info = CustomerPortrait::where('root_id', $root_id)->findOrEmpty();
  499. $data = $info->fields;
  500. $array = $data[$arr[$param['type']]][$param['type']]['select'];
  501. $array = array_diff($array, [$param['key']]);
  502. $data[$arr[$param['type']]][$param['type']]['select'] = array_values($array);
  503. !$info->isEmpty() ?: $info->root_id = $root_id;
  504. $info->fields = $data;
  505. $info->save();
  506. }
  507. return json(['code' => 0, 'data' => '删除成功', 'msg' => '删除成功']);
  508. }
  509. /**
  510. * 类型
  511. */
  512. private function settingArr()
  513. {
  514. $arr = [
  515. 'follow' => 'basic_info',
  516. 'point' => 'basic_info',
  517. 'housetype_arrow' => 'house_info',
  518. 'housing_use' => 'house_info',
  519. 'peripheral_supporting' => 'house_info',
  520. 'house_structure' => 'house_info',
  521. 'decoration_mode' => 'house_info',
  522. 'like_color' => 'house_info',
  523. 'family_structure' => 'family_info',
  524. 'decision_maker' => 'family_info',
  525. 'workmanship' => 'behavioral_info',
  526. 'space_design' => 'behavioral_info'
  527. ];
  528. return $arr;
  529. }
  530. /**
  531. * 产品设置
  532. */
  533. public function package()
  534. {
  535. $pageParam = request()->only(['page', 'limit']);
  536. $data = CustomerPackage::field('id, name, total_price')->where(['root_id' => request()->employee->root_id])->page($pageParam['page'], $pageParam['limit'])->select();
  537. $count = CustomerPackage::where(['root_id' => request()->employee->root_id])->count();
  538. return json(['code' => 0, 'data' => $data, 'count' => $count]);
  539. }
  540. /**
  541. * 产品添加
  542. */
  543. public function editPackage($name, $value, $id = null)
  544. {
  545. if ($id) {
  546. $package = CustomerPackage::where(['root_id' => request()->employee->root_id, 'id' => $id])->find();
  547. } else {
  548. $package = new CustomerPackage();
  549. }
  550. $package->save([
  551. 'name' => $name,
  552. 'total_price' => $value,
  553. 'root_id' => request()->employee->root_id
  554. ]);
  555. return json(['code' => 0, 'msg' => $id ? '修改成功' : '添加成功']);
  556. }
  557. /**
  558. * 产品删除
  559. */
  560. public function delPackage($id)
  561. {
  562. $package = CustomerPackage::where(['root_id' => request()->employee->root_id, 'id' => $id])->find();
  563. if (empty($package)) return json(['code' => 1, 'msg' => '删除失败']);
  564. $package->delete();
  565. return json(['code' => 0, 'msg' => '删除成功']);
  566. }
  567. /**
  568. * 客户预约保护设置
  569. */
  570. public function subscribe_protected()
  571. {
  572. if (!request()->isAjax()) {
  573. $find = Setting::where(['name' => 'subscribe_protected', 'root_id' => request()->employee->root_id])->findOrEmpty();
  574. if ($find->isEmpty()) {
  575. $content['ydaochang'] = ['day' => 0, 'state' => 0, 'name' => '预约到场保护'];
  576. $content['daochang'] = ['day' => 0, 'state' => 0, 'name' => '到场保护'];
  577. $content['ydaodian'] = ['day' => 0, 'state' => 0, 'name' => '预约到店保护'];
  578. $content['daodian'] = ['day' => 0, 'state' => 0, 'name' => '到店保护'];
  579. $content['yliangfang'] = ['day' => 0, 'state' => 0, 'name' => '预约量房保护'];
  580. $content['liangfang'] = ['day' => 0, 'state' => 0, 'name' => '量房保护'];
  581. $data['name'] = 'subscribe_protected';
  582. $data['content'] = json_encode($content);
  583. $data['state'] = 1;
  584. $data['root_id'] = request()->employee->root_id;
  585. Setting::create($data);
  586. $contentarr = $content;
  587. } else {
  588. $content = $find['content'];
  589. $contentarr = empty($content) ? null : json_decode($content, true);
  590. }
  591. View::assign('content', $contentarr);
  592. return View::fetch();
  593. } else {
  594. $param = request()->only(['ydaodian', 'ydaodian_switch', 'daodian', 'daodian_switch', 'daochang', 'daochang_switch', 'ydaochang', 'ydaochang_switch', 'yliangfang', 'yliangfang_switch', 'liangfang', 'liangfang_switch']);
  595. $root_id = request()->employee->root_id;
  596. $setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'subscribe_protected']])->findOrEmpty();
  597. if ($setting->isEmpty()) {
  598. $data['name'] = 'subscribe_protected';
  599. $data['state'] = 1; //$param['off'] ?? 0;
  600. $data['root_id'] = $root_id;
  601. $content = [
  602. 'ydaochang' => ['day' => intval($param['ydaochang']), 'state' => $param['ydaochang_switch'] ?? 0, 'name' => '预约到场保护'],
  603. 'daochang' => ['day' => intval($param['daochang']), 'state' => $param['daochang_switch'] ?? 0, 'name' => '到场保护'],
  604. 'ydaodian' => ['day' => intval($param['ydaodian']), 'state' => $param['ydaodian_switch'] ?? 0, 'name' => '预约到店保护'],
  605. 'daodian' => ['day' => intval($param['daodian']), 'state' => $param['daodian_switch'] ?? 0, 'name' => '到店保护'],
  606. 'yliangfang' => ['day' => intval($param['yliangfang']), 'state' => $param['yliangfang_switch'] ?? 0, 'name' => '预约量房保护'],
  607. 'liangfang' => ['day' => intval($param['liangfang']), 'state' => $param['liangfang_switch'] ?? 0, 'name' => '量房保护'],
  608. ];
  609. $data['content'] = json_encode($content);
  610. if (isset($param['daochang_switch']) && intval($param['daochang']) < 1) {
  611. return json(['code' => 1, 'msg' => '天数至少为一天']);
  612. }
  613. if (isset($param['ydaochang_switch']) && intval($param['ydaochang']) < 1) {
  614. return json(['code' => 1, 'msg' => '天数至少为一天']);
  615. }
  616. if (isset($param['ydaodian_switch']) && intval($param['ydaodian']) < 1) {
  617. return json(['code' => 1, 'msg' => '天数至少为一天']);
  618. }
  619. if (isset($param['daodian_switch']) && intval($param['daodian']) < 1) {
  620. return json(['code' => 1, 'msg' => '天数至少为一天']);
  621. }
  622. if (isset($param['yliangfang_switch']) && intval($param['yliangfang']) < 1) {
  623. return json(['code' => 1, 'msg' => '天数至少为一天']);
  624. }
  625. if (isset($param['liangfang_switch']) && intval($param['liangfang']) < 1) {
  626. return json(['code' => 1, 'msg' => '天数至少为一天']);
  627. }
  628. $result = Setting::create($data);
  629. if ($result) {
  630. return json(['code' => 0, 'msg' => '保存成功']);
  631. } else {
  632. return json(['code' => 1, 'msg' => '保存失败']);
  633. }
  634. } else {
  635. if (isset($param['daochang_switch']) && intval($param['daochang']) < 1) {
  636. return json(['code' => 1, 'msg' => '天数至少为一天']);
  637. }
  638. if (isset($param['ydaochang_switch']) && intval($param['ydaochang']) < 1) {
  639. return json(['code' => 1, 'msg' => '天数至少为一天']);
  640. }
  641. if (isset($param['ydaodian_switch']) && intval($param['ydaodian']) < 1) {
  642. return json(['code' => 1, 'msg' => '天数至少为一天']);
  643. }
  644. if (isset($param['daodian_switch']) && intval($param['daodian']) < 1) {
  645. return json(['code' => 1, 'msg' => '天数至少为一天']);
  646. }
  647. if (isset($param['yliangfang_switch']) && intval($param['yliangfang']) < 1) {
  648. return json(['code' => 1, 'msg' => '天数至少为一天']);
  649. }
  650. if (isset($param['liangfang_switch']) && intval($param['liangfang']) < 1) {
  651. return json(['code' => 1, 'msg' => '天数至少为一天']);
  652. }
  653. $content = [
  654. 'ydaochang' => ['day' => intval($param['ydaochang']), 'state' => $param['ydaochang_switch'] ?? 0, 'name' => '预约到场保护'],
  655. 'daochang' => ['day' => intval($param['daochang']), 'state' => $param['daochang_switch'] ?? 0, 'name' => '到场保护'],
  656. 'ydaodian' => ['day' => intval($param['ydaodian']), 'state' => $param['ydaodian_switch'] ?? 0, 'name' => '预约到店保护'],
  657. 'daodian' => ['day' => intval($param['daodian']), 'state' => $param['daodian_switch'] ?? 0, 'name' => '到店保护'],
  658. 'yliangfang' => ['day' => intval($param['yliangfang']), 'state' => $param['yliangfang_switch'] ?? 0, 'name' => '预约量房保护'],
  659. 'liangfang' => ['day' => intval($param['liangfang']), 'state' => $param['liangfang_switch'] ?? 0, 'name' => '量房保护'],
  660. ];
  661. $setting->content = json_encode($content);
  662. $result = $setting->save();
  663. if ($result) {
  664. return json(['code' => 0, 'msg' => '保存成功']);
  665. } else {
  666. return json(['code' => 1, 'msg' => '保存失败']);
  667. }
  668. }
  669. }
  670. }
  671. /**
  672. * 自定义设置 -- 客户跟踪、信息完善、客户转化、客户预约、报备设置、团队客户
  673. */
  674. public function moduleSetting()
  675. {
  676. $root_id = request()->employee->root_id;
  677. if (!request()->isAjax()) {
  678. // 客户信息完善开关
  679. $perfect = Setting::where([['root_id', '=', $root_id], ['name', '=', 'modulePerfectSwitch']])->findOrEmpty();
  680. if ($perfect->isEmpty()) {
  681. Setting::create(['root_id' => $root_id, 'name' => 'modulePerfectSwitch', 'content' => 1]);
  682. $perfect_content = 1;
  683. } else {
  684. $perfect_content = $perfect['content'];
  685. }
  686. View::assign('perfect', $perfect_content);
  687. // 客户转化开关
  688. $change = Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleChangeSwitch']])->findOrEmpty();
  689. if ($change->isEmpty()) {
  690. Setting::create(['root_id' => $root_id, 'name' => 'moduleChangeSwitch', 'content' => 1]);
  691. $change_content = 1;
  692. } else {
  693. $change_content = $change['content'];
  694. }
  695. View::assign('change', $change_content);
  696. // 客户预约开关
  697. $subscribe = Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleSubscribeSwitch']])->findOrEmpty();
  698. if ($subscribe->isEmpty()) {
  699. Setting::create(['root_id' => $root_id, 'name' => 'moduleSubscribeSwitch', 'content' => 1]);
  700. $subscribe_content = 1;
  701. } else {
  702. $subscribe_content = $subscribe['content'];
  703. }
  704. View::assign('subscribe', $subscribe_content);
  705. return View::fetch();
  706. } else {
  707. $perfect = input('perfect', '', 'trim');
  708. $change = input('change', '', 'trim');
  709. $subscribe = input('subscribe', '', 'trim');
  710. if ($perfect !== '') {
  711. Setting::where([['root_id', '=', $root_id], ['name', '=', 'modulePerfectSwitch']])->save(['content' => $perfect]);
  712. }
  713. if ($change !== '') {
  714. Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleChangeSwitch']])->save(['content' => $change]);
  715. }
  716. if ($subscribe !== '') {
  717. Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleSubscribeSwitch']])->save(['content' => $subscribe]);
  718. }
  719. return json(['code' => 0, 'msg' => '操作成功']);
  720. }
  721. }
  722. /**
  723. * 客户跟踪设置
  724. */
  725. public function moduleVisit()
  726. {
  727. if (!request()->isAjax()) {
  728. return View::fetch();
  729. } else {
  730. $root_id = request()->employee->root_id;
  731. $content = input('content', '', 'trim');
  732. // 判断保存的字段其他模块是否有使用
  733. if (!empty($content)) {
  734. $field_data = $this->moduleFiledDeal('visit');
  735. $other_checked = $field_data['other_checked'];
  736. foreach ($content as $k => $v) {
  737. if (in_array($v['id'], $other_checked)) {
  738. return json(['code' => 1, 'msg' => '字段重复使用']);
  739. }
  740. }
  741. }
  742. $s_where[] = ['root_id', '=', $root_id];
  743. $s_where[] = ['name', '=', 'visitSettingField'];
  744. $find = Setting::where($s_where)->findOrEmpty();
  745. if ($find->isEmpty()) {
  746. $data['name'] = 'visitSettingField';
  747. $data['root_id'] = $root_id;
  748. $data['content'] = !empty($content) ? json_encode($content) : '';
  749. $result = Setting::create($data);
  750. } else {
  751. $find->content = !empty($content) ? json_encode($content) : '';
  752. $result = $find->save();
  753. }
  754. if ($result !== false) {
  755. return json(['code' => 0, 'msg' => '操作成功']);
  756. } else {
  757. return json(['code' => 1, 'msg' => '操作失败']);
  758. }
  759. }
  760. }
  761. /**
  762. * 线索状态
  763. */
  764. public function clueTag()
  765. {
  766. $where[] = ['name', '=', 'clueTag'];
  767. $where[] = ['root_id', '=', request()->employee->root_id];
  768. $find = Setting::where($where)->findOrEmpty();
  769. if ($find->isEmpty()) {
  770. $list = ['已装修', '无需求', '有需求', '超地域', '未交房', '在外地', '无购买力', '未接通电话'];
  771. } else {
  772. $list = array_filter(explode(',', $find['content']));
  773. }
  774. return json(['code' => 0, 'data' => $list]);
  775. }
  776. /**
  777. * 线索状态设置
  778. */
  779. public function clueTagEdit()
  780. {
  781. $content = input('content/a', '', 'trim');
  782. $data = implode(',', $content);
  783. $where[] = ['name', '=', 'clueTag'];
  784. $where[] = ['root_id', '=', request()->employee->root_id];
  785. $find = Setting::where($where)->findOrEmpty();
  786. if ($find->isEmpty()) {
  787. $result = Setting::create(['name' => 'clueTag', 'content' => $data, 'state' => 1, 'root_id' => request()->employee->root_id]);
  788. } else {
  789. $find->content = $data;
  790. $result = $find->save();
  791. }
  792. if ($result !== false) {
  793. return json(['code' => 0, 'msg' => '操作成功']);
  794. } else {
  795. return json(['code' => 1, 'msg' => '操作失败']);
  796. }
  797. }
  798. /**
  799. * 模块开关
  800. */
  801. public function moduleSwitch()
  802. {
  803. $content = input('content', '', 'trim');
  804. $type = input('type', '', 'trim');
  805. $root_id = request()->employee->root_id;
  806. switch ($type) {
  807. case 'perfect':
  808. $module = 'perfectSettingSwitch';
  809. break;
  810. case 'change':
  811. $module = 'changeSettingSwitch';
  812. break;
  813. case 'subscribe':
  814. $module = 'subscribeSettingSwitch';
  815. break;
  816. default:
  817. $module = '';
  818. break;
  819. }
  820. if (empty($module)) {
  821. return json(['code' => 1, 'msg' => '操作失败']);
  822. }
  823. $find = Setting::where([['root_id', '=', $root_id], ['name', '=', $module]])->findOrEmpty();
  824. if ($find->isEmpty()) {
  825. $result = Setting::create(['root_id' => $root_id, 'name' => $module, 'content' => $content]);
  826. } else {
  827. $result = $find->save(['content' => $content]);
  828. }
  829. if ($result !== false) {
  830. return json(['code' => 0, 'msg' => '操作成功']);
  831. } else {
  832. return json(['code' => 1, 'msg' => '操作失败']);
  833. }
  834. }
  835. protected function moduleFiledDeal($type)
  836. {
  837. $type_arr = ['visit', 'changeLF', 'changeDD', 'changeHD', 'changeJD', 'changeZD', 'changeMK', 'subscribeHD', 'subscribeDD', 'subscribeLF'];
  838. if (!in_array($type, $type_arr)) {
  839. return ['all' => [], 'default' => [], 'checked' => [], 'other_checked' => []];
  840. }
  841. $root_id = request()->employee->root_id;
  842. $a_where[] = ['root_id', '=', $root_id];
  843. $a_where[] = ['pid', '<>', 0];
  844. $a_where[] = ['status', '=', 0];
  845. $all = CustomerPortraitField::where($a_where)->order('sort asc')->select()->toArray();
  846. $default = [];
  847. $checked = [];
  848. // 客户预约字段设置
  849. $sub_where_hd[] = ['root_id', '=', $root_id];
  850. $sub_where_hd[] = ['name', '=', 'subscribeSettingFieldYYHD'];
  851. $subscribeFieldHD = Setting::where($sub_where_hd)->findOrEmpty();
  852. $sub_where_dd[] = ['root_id', '=', $root_id];
  853. $sub_where_dd[] = ['name', '=', 'subscribeSettingFieldYYDD'];
  854. $subscribeFieldDD = Setting::where($sub_where_dd)->findOrEmpty();
  855. $sub_where_lf[] = ['root_id', '=', $root_id];
  856. $sub_where_lf[] = ['name', '=', 'subscribeSettingFieldYYLF'];
  857. $subscribeFieldLF = Setting::where($sub_where_lf)->findOrEmpty();
  858. //客户转化字段设置
  859. $c_where_lf[] = ['root_id', '=', $root_id];
  860. $c_where_lf[] = ['name', '=', 'changeSettingFieldLF'];
  861. $changeFieldLF = Setting::where($c_where_lf)->findOrEmpty();
  862. $c_where_dd[] = ['root_id', '=', $root_id];
  863. $c_where_dd[] = ['name', '=', 'changeSettingFieldDD'];
  864. $changeFieldDD = Setting::where($c_where_dd)->findOrEmpty();
  865. $c_where_hd[] = ['root_id', '=', $root_id];
  866. $c_where_hd[] = ['name', '=', 'changeSettingFieldHD'];
  867. $changeFieldHD = Setting::where($c_where_hd)->findOrEmpty();
  868. $c_where_jd[] = ['root_id', '=', $root_id];
  869. $c_where_jd[] = ['name', '=', 'changeSettingFieldJD'];
  870. $changeFieldJD = Setting::where($c_where_jd)->findOrEmpty();
  871. $c_where_zd[] = ['root_id', '=', $root_id];
  872. $c_where_zd[] = ['name', '=', 'changeSettingFieldZD'];
  873. $changeFieldZD = Setting::where($c_where_zd)->findOrEmpty();
  874. $c_where_mk[] = ['root_id', '=', $root_id];
  875. $c_where_mk[] = ['name', '=', 'changeSettingFieldMK'];
  876. $changeFieldMK = Setting::where($c_where_mk)->findOrEmpty();
  877. // 客户跟踪字段设置
  878. $v_where[] = ['root_id', '=', $root_id];
  879. $v_where[] = ['name', '=', 'visitSettingField'];
  880. $visitField = Setting::where($v_where)->findOrEmpty();
  881. $subscribeFieldHD_decode = [];
  882. $subscribeFieldDD_decode = [];
  883. $subscribeFieldLF_decode = [];
  884. $changeFieldLF_decode = [];
  885. $changeFieldDD_decode = [];
  886. $changeFieldHD_decode = [];
  887. $changeFieldJD_decode = [];
  888. $changeFieldZD_decode = [];
  889. $changeFieldMK_decode = [];
  890. $visitField_decode = [];
  891. $all_checked = []; //所有已选中的字段
  892. if (!$subscribeFieldHD->isEmpty()) {
  893. $subscribeFieldHD_decode = json_decode($subscribeFieldHD['content'], true);
  894. if (!empty($subscribeFieldHD_decode)) {
  895. $all_checked = array_merge($all_checked, array_column($subscribeFieldHD_decode, 'id'));
  896. }
  897. }
  898. if (!$subscribeFieldDD->isEmpty()) {
  899. $subscribeFieldDD_decode = json_decode($subscribeFieldDD['content'], true);
  900. if (!empty($subscribeFieldDD_decode)) {
  901. $all_checked = array_merge($all_checked, array_column($subscribeFieldDD_decode, 'id'));
  902. }
  903. }
  904. if (!$subscribeFieldLF->isEmpty()) {
  905. $subscribeFieldLF_decode = json_decode($subscribeFieldLF['content'], true);
  906. if (!empty($subscribeFieldLF_decode)) {
  907. $all_checked = array_merge($all_checked, array_column($subscribeFieldLF_decode, 'id'));
  908. }
  909. }
  910. if (!$changeFieldLF->isEmpty()) {
  911. $changeFieldLF_decode = json_decode($changeFieldLF['content'], true);
  912. if (!empty($changeFieldLF_decode)) {
  913. $all_checked = array_merge($all_checked, array_column($changeFieldLF_decode, 'id'));
  914. }
  915. }
  916. if (!$changeFieldDD->isEmpty()) {
  917. $changeFieldDD_decode = json_decode($changeFieldDD['content'], true);
  918. if (!empty($changeFieldDD_decode)) {
  919. $all_checked = array_merge($all_checked, array_column($changeFieldDD_decode, 'id'));
  920. }
  921. }
  922. if (!$changeFieldHD->isEmpty()) {
  923. $changeFieldHD_decode = json_decode($changeFieldHD['content'], true);
  924. if (!empty($changeFieldHD_decode)) {
  925. $all_checked = array_merge($all_checked, array_column($changeFieldHD_decode, 'id'));
  926. }
  927. }
  928. if (!$changeFieldJD->isEmpty()) {
  929. $changeFieldJD_decode = json_decode($changeFieldJD['content'], true);
  930. if (!empty($changeFieldJD_decode)) {
  931. $all_checked = array_merge($all_checked, array_column($changeFieldJD_decode, 'id'));
  932. }
  933. } else {
  934. $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();
  935. foreach ($changeFieldJD_default as $k => $v) {
  936. $changeFieldJD_decode[] = [
  937. 'id' => $v['id'],
  938. 'sort' => $k + 1
  939. ];
  940. }
  941. $all_checked = array_merge($all_checked, array_column($changeFieldJD_decode, 'id'));
  942. }
  943. if (!$changeFieldZD->isEmpty()) {
  944. $changeFieldZD_decode = json_decode($changeFieldZD['content'], true);
  945. if (!empty($changeFieldZD_decode)) {
  946. $all_checked = array_merge($all_checked, array_column($changeFieldZD_decode, 'id'));
  947. }
  948. }
  949. if (!$changeFieldMK->isEmpty()) {
  950. $changeFieldMK_decode = json_decode($changeFieldMK['content'], true);
  951. if (!empty($changeFieldMK_decode)) {
  952. $all_checked = array_merge($all_checked, array_column($changeFieldMK_decode, 'id'));
  953. }
  954. }
  955. if (!$visitField->isEmpty()) {
  956. $visitField_decode = json_decode($visitField['content'], true);
  957. if (!empty($visitField_decode)) {
  958. $all_checked = array_merge($all_checked, array_column($visitField_decode, 'id'));
  959. }
  960. } else {
  961. $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();
  962. foreach ($visit_default as $k => $v) {
  963. $visitField_decode[] = [
  964. 'id' => $v['id'],
  965. 'sort' => $k + 1
  966. ];
  967. }
  968. $all_checked = array_merge($all_checked, array_column($visitField_decode, 'id'));
  969. }
  970. $other_checked_ids = [];
  971. switch ($type) {
  972. case 'visit':
  973. $checked = $visitField_decode ?? [];
  974. $other_checked_ids = !empty($visitField_decode) ? array_diff($all_checked, array_column($visitField_decode, 'id')) : $all_checked;
  975. if (empty($visit_default)) {
  976. $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();
  977. }
  978. foreach ($visit_default as $k => $v) {
  979. $default[] = [
  980. 'id' => $v['id'],
  981. 'name' => $v['name'],
  982. 'sort' => $k + 1,
  983. 'type' => $v['type']
  984. ];
  985. }
  986. break;
  987. case 'changeLF':
  988. $checked = $changeFieldLF_decode ?? [];
  989. $other_checked_ids = !empty($changeFieldLF_decode) ? array_diff($all_checked, array_column($changeFieldLF_decode, 'id')) : $all_checked;
  990. break;
  991. case 'changeDD':
  992. $checked = $changeFieldDD_decode ?? [];
  993. $other_checked_ids = !empty($changeFieldDD_decode) ? array_diff($all_checked, array_column($changeFieldDD_decode, 'id')) : $all_checked;
  994. break;
  995. case 'changeHD':
  996. $checked = $changeFieldHD_decode ?? [];
  997. $other_checked_ids = !empty($changeFieldHD_decode) ? array_diff($all_checked, array_column($changeFieldHD_decode, 'id')) : $all_checked;
  998. break;
  999. case 'changeJD':
  1000. $checked = $changeFieldJD_decode ?? [];
  1001. $other_checked_ids = !empty($changeFieldJD_decode) ? array_diff($all_checked, array_column($changeFieldJD_decode, 'id')) : $all_checked;
  1002. if (empty($changeFieldJD_default)) {
  1003. $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();
  1004. }
  1005. foreach ($changeFieldJD_default as $k => $v) {
  1006. $default[] = [
  1007. 'id' => $v['id'],
  1008. 'name' => $v['name'],
  1009. 'sort' => $k + 1,
  1010. 'type' => $v['type']
  1011. ];
  1012. }
  1013. break;
  1014. case 'changeZD':
  1015. $checked = $changeFieldZD_decode ?? [];
  1016. $other_checked_ids = !empty($changeFieldZD_decode) ? array_diff($all_checked, array_column($changeFieldZD_decode, 'id')) : $all_checked;
  1017. break;
  1018. case 'changeMK':
  1019. $checked = $changeFieldMK_decode ?? [];
  1020. $other_checked_ids = !empty($changeFieldMK_decode) ? array_diff($all_checked, array_column($changeFieldMK_decode, 'id')) : $all_checked;
  1021. break;
  1022. case 'subscribeHD':
  1023. $checked = $subscribeFieldHD_decode ?? [];
  1024. $other_checked_ids = !empty($subscribeFieldHD_decode) ? array_diff($all_checked, array_column($subscribeFieldHD_decode, 'id')) : $all_checked;
  1025. break;
  1026. case 'subscribeDD':
  1027. $checked = $subscribeFieldDD_decode ?? [];
  1028. $other_checked_ids = !empty($subscribeFieldDD_decode) ? array_diff($all_checked, array_column($subscribeFieldDD_decode, 'id')) : $all_checked;
  1029. break;
  1030. case 'subscribeLF':
  1031. $checked = $subscribeFieldLF_decode ?? [];
  1032. $other_checked_ids = !empty($subscribeFieldLF_decode) ? array_diff($all_checked, array_column($subscribeFieldLF_decode, 'id')) : $all_checked;
  1033. break;
  1034. default:
  1035. break;
  1036. }
  1037. $checked_ids = array_column($checked, 'id');
  1038. $field_info = CustomerPortraitField::with('select')->where('id', 'in', $checked_ids)->select()->toArray();
  1039. $city = Company::where('root_id', request()->employee->root_id)->value('city');
  1040. foreach ($field_info as $k => $v) {
  1041. if ($v['keyname'] == 'current_region') {
  1042. $field_info[$k]['select'][] = ['id' => request()->employee->root_id, 'name' => $city, 'pid' => $v['pid']];
  1043. }
  1044. if ($v['keyname'] == 'source_id') {
  1045. $soudata = CustomerSource::field('id,source as name')->where('root_id', request()->employee->root_id)->select()->toArray();
  1046. $field_info[$k]['select'] = $soudata;
  1047. }
  1048. if ($v['keyname'] == 'deco_style') {
  1049. $decostyles = Decostyle::field('id,name')->where([['root_id', '=', request()->employee->root_id], ['type', '=', 0]])->select()->toArray();
  1050. $field_info[$k]['select'] = $decostyles;
  1051. }
  1052. }
  1053. foreach ($checked as $k => $v) {
  1054. foreach ($field_info as $kk => $vv) {
  1055. if ($v['id'] == $vv['id']) {
  1056. $checked[$k]['name'] = $vv['name'];
  1057. $checked[$k]['type'] = $vv['type'];
  1058. $checked[$k]['select'] = $vv['select'] ?? [];
  1059. }
  1060. }
  1061. }
  1062. foreach ($all as $k => $v) {
  1063. $all[$k]['other_checked'] = 0;
  1064. $all[$k]['checked'] = 0;
  1065. if (in_array($v['id'], $other_checked_ids)) {
  1066. $all[$k]['other_checked'] = 1;
  1067. }
  1068. if (in_array($v['id'], array_column($checked, 'id'))) {
  1069. $all[$k]['checked'] = 1;
  1070. }
  1071. }
  1072. return ['all' => $all, 'default' => $default, 'checked' => $checked, 'other_checked' => $other_checked_ids];
  1073. }
  1074. /**
  1075. * 模块字段
  1076. */
  1077. public function moduleField()
  1078. {
  1079. $type = input('type', '', 'trim');
  1080. $data = $this->moduleFiledDeal($type);
  1081. return json(['code' => 0, 'all' => $data['all'], 'default' => $data['default'], 'checked' => $data['checked']]);
  1082. }
  1083. /**
  1084. * 客户转化
  1085. */
  1086. public function moduleChange()
  1087. {
  1088. if (!request()->isAjax()) {
  1089. $root_id = request()->employee->root_id;
  1090. // 子模块开关 量房、到店、活动、签单、转单、卖卡
  1091. $z_where[] = ['name', 'in', ['changeSettingSwitchLF', 'changeSettingSwitchDD', 'changeSettingSwitchHD', 'changeSettingSwitchJD', 'changeSettingSwitchZD', 'changeSettingSwitchMK', 'changeSettingSwitchDDHD']];
  1092. $z_where[] = ['root_id', '=', $root_id];
  1093. $z_setting = Setting::where($z_where)->select()->toArray();
  1094. $lf_switch = 1; //量房
  1095. $dd_switch = 1; //到店
  1096. $hd_switch = 1; //活动
  1097. $qd_switch = 1; //签单
  1098. $zd_switch = 1; //转单
  1099. $mk_switch = 1; //卖卡
  1100. $ddhd_switch = 1; //到店活动
  1101. foreach ($z_setting as $k => $v) {
  1102. if ($v['name'] == 'changeSettingSwitchLF') $lf_switch = $v['content'];
  1103. if ($v['name'] == 'changeSettingSwitchDD') $dd_switch = $v['content'];
  1104. if ($v['name'] == 'changeSettingSwitchHD') $hd_switch = $v['content'];
  1105. if ($v['name'] == 'changeSettingSwitchJD') $qd_switch = $v['content'];
  1106. if ($v['name'] == 'changeSettingSwitchZD') $zd_switch = $v['content'];
  1107. if ($v['name'] == 'changeSettingSwitchMK') $mk_switch = $v['content'];
  1108. if ($v['name'] == 'changeSettingSwitchDDHD') $ddhd_switch = $v['content'];
  1109. }
  1110. View::assign('lf_switch', $lf_switch);
  1111. View::assign('dd_switch', $dd_switch);
  1112. View::assign('hd_switch', $hd_switch);
  1113. View::assign('qd_switch', $qd_switch);
  1114. View::assign('zd_switch', $zd_switch);
  1115. View::assign('mk_switch', $mk_switch);
  1116. View::assign('ddhd_switch', $ddhd_switch);
  1117. $xinjushang = 0;
  1118. View::assign('xinjushang', $xinjushang);
  1119. return View::fetch();
  1120. } else {
  1121. $root_id = request()->employee->root_id;
  1122. $type = input('type', '', 'trim');
  1123. $content = input('content', '', 'trim'); // 字段
  1124. $switch = input('switch', '', 'trim'); // 开关
  1125. $switch_name = '';
  1126. $content_name = '';
  1127. $field_module = '';
  1128. switch ($type) {
  1129. case 'LF':
  1130. $switch_name = 'changeSettingSwitchLF';
  1131. $content_name = 'changeSettingFieldLF';
  1132. $field_module = 'changeLF';
  1133. break;
  1134. case 'DD':
  1135. $switch_name = 'changeSettingSwitchDD';
  1136. $content_name = 'changeSettingFieldDD';
  1137. $field_module = 'changeDD';
  1138. break;
  1139. case 'HD':
  1140. $switch_name = 'changeSettingSwitchHD';
  1141. $content_name = 'changeSettingFieldHD';
  1142. $field_module = 'changeHD';
  1143. break;
  1144. case 'QD':
  1145. $switch_name = 'changeSettingSwitchJD';
  1146. $content_name = 'changeSettingFieldJD';
  1147. $field_module = 'changeJD';
  1148. break;
  1149. case 'ZD':
  1150. $switch_name = 'changeSettingSwitchZD';
  1151. $content_name = 'changeSettingFieldZD';
  1152. $field_module = 'changeZD';
  1153. break;
  1154. case 'MK':
  1155. $switch_name = 'changeSettingSwitchMK';
  1156. $content_name = 'changeSettingFieldMK';
  1157. $field_module = 'changeMK';
  1158. break;
  1159. default:
  1160. break;
  1161. }
  1162. if (empty($switch_name)) {
  1163. return json(['code' => 0, 'msg' => '操作成功']);
  1164. }
  1165. // 判断保存的字段其他模块是否有使用
  1166. if (!empty($content)) {
  1167. $field_data = $this->moduleFiledDeal($field_module);
  1168. $other_checked = $field_data['other_checked'];
  1169. foreach ($content as $k => $v) {
  1170. if (in_array($v['id'], $other_checked)) {
  1171. return json(['code' => 1, 'msg' => '字段重复使用']);
  1172. }
  1173. }
  1174. }
  1175. $switch_where[] = ['root_id', '=', $root_id];
  1176. $switch_where[] = ['name', '=', $switch_name];
  1177. $find = Setting::where($switch_where)->findOrEmpty();
  1178. if ($find->isEmpty()) {
  1179. $data['name'] = $switch_name;
  1180. $data['root_id'] = $root_id;
  1181. $data['content'] = $switch;
  1182. Setting::create($data);
  1183. } else {
  1184. $find->content = $switch;
  1185. $find->save();
  1186. }
  1187. $s_where[] = ['root_id', '=', $root_id];
  1188. $s_where[] = ['name', '=', $content_name];
  1189. $find = Setting::where($s_where)->findOrEmpty();
  1190. if ($find->isEmpty()) {
  1191. $data['name'] = $content_name;
  1192. $data['root_id'] = $root_id;
  1193. $data['content'] = !empty($content) ? json_encode($content) : '';
  1194. $result = Setting::create($data);
  1195. } else {
  1196. $find->content = !empty($content) ? json_encode($content) : '';
  1197. $result = $find->save();
  1198. }
  1199. $root_id = request()->employee->root_id;
  1200. // 子模块开关 量房、到店、活动、签单、转单、卖卡
  1201. $z_where[] = ['name', 'in', ['changeSettingSwitchLF', 'changeSettingSwitchDD', 'changeSettingSwitchHD', 'changeSettingSwitchJD', 'changeSettingSwitchZD', 'changeSettingSwitchMK']];
  1202. $z_where[] = ['root_id', '=', $root_id];
  1203. $z_setting = Setting::where($z_where)->select()->toArray();
  1204. if (count($z_setting) == 6) { // 每一项都有保存值,缺少一项都意味着有开启状态
  1205. $all_down = true;
  1206. foreach ($z_setting as $k => $v) {
  1207. if ($v['content'] == 1) {
  1208. $all_down = false;
  1209. break;
  1210. }
  1211. }
  1212. if ($all_down) {
  1213. Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleChangeSwitch']])->save(['content' => 0]);
  1214. }
  1215. }
  1216. // 到店的活动控制
  1217. $ddhd_switch = input('ddhd_switch', '', 'intval');
  1218. if ($ddhd_switch !== '') {
  1219. $ddhd_find = Setting::where([['root_id', '=', $root_id], ['name', '=', 'changeSettingSwitchDDHD']])->findOrEmpty();
  1220. if ($ddhd_find->isEmpty()) {
  1221. $data['name'] = 'changeSettingSwitchDDHD';
  1222. $data['root_id'] = $root_id;
  1223. $data['content'] = $ddhd_switch;
  1224. $result = Setting::create($data);
  1225. } else {
  1226. $ddhd_find->content = $ddhd_switch;
  1227. $result = $ddhd_find->save();
  1228. }
  1229. }
  1230. return json(['code' => 0, 'msg' => '操作成功']);
  1231. }
  1232. }
  1233. /**
  1234. * 客户预约
  1235. */
  1236. public function moduleSubscribe()
  1237. {
  1238. if (!request()->isAjax()) {
  1239. $root_id = request()->employee->root_id;
  1240. // 子模块开关 活动、到店、量房
  1241. $z_where[] = ['name', 'in', ['subscribeSettingSwitchYYLF', 'subscribeSettingSwitchYYDD', 'subscribeSettingSwitchYYHD']];
  1242. $z_where[] = ['root_id', '=', $root_id];
  1243. $z_setting = Setting::where($z_where)->select()->toArray();
  1244. $hd_switch = 1; //活动
  1245. $dd_switch = 1; //到店
  1246. $lf_switch = 1; //量房
  1247. foreach ($z_setting as $k => $v) {
  1248. if ($v['name'] == 'subscribeSettingSwitchYYLF') $lf_switch = $v['content'];
  1249. if ($v['name'] == 'subscribeSettingSwitchYYDD') $dd_switch = $v['content'];
  1250. if ($v['name'] == 'subscribeSettingSwitchYYHD') $hd_switch = $v['content'];
  1251. }
  1252. View::assign('lf_switch', $lf_switch);
  1253. View::assign('dd_switch', $dd_switch);
  1254. View::assign('hd_switch', $hd_switch);
  1255. return View::fetch();
  1256. } else {
  1257. $root_id = request()->employee->root_id;
  1258. $type = input('type', '', 'trim');
  1259. $content = input('content', '', 'trim'); // 字段
  1260. $switch = input('switch', '', 'trim'); // 开关
  1261. $switch_name = '';
  1262. $content_name = '';
  1263. $field_module = '';
  1264. switch ($type) {
  1265. case 'HD':
  1266. $switch_name = 'subscribeSettingSwitchYYHD';
  1267. $content_name = 'subscribeSettingFieldYYHD';
  1268. $field_module = 'subscribeHD';
  1269. break;
  1270. case 'DD':
  1271. $switch_name = 'subscribeSettingSwitchYYDD';
  1272. $content_name = 'subscribeSettingFieldYYDD';
  1273. $field_module = 'subscribeDD';
  1274. break;
  1275. case 'LF':
  1276. $switch_name = 'subscribeSettingSwitchYYLF';
  1277. $content_name = 'subscribeSettingFieldYYLF';
  1278. $field_module = 'subscribeLF';
  1279. break;
  1280. default:
  1281. break;
  1282. }
  1283. if (empty($switch_name)) {
  1284. return json(['code' => 0, 'msg' => '操作成功']);
  1285. }
  1286. // 判断保存的字段其他模块是否有使用
  1287. if (!empty($content)) {
  1288. $field_data = $this->moduleFiledDeal($field_module);
  1289. $other_checked = $field_data['other_checked'];
  1290. foreach ($content as $k => $v) {
  1291. if (in_array($v['id'], $other_checked)) {
  1292. return json(['code' => 1, 'msg' => '字段重复使用']);
  1293. }
  1294. }
  1295. }
  1296. $switch_where[] = ['root_id', '=', $root_id];
  1297. $switch_where[] = ['name', '=', $switch_name];
  1298. $find = Setting::where($switch_where)->findOrEmpty();
  1299. if ($find->isEmpty()) {
  1300. $data['name'] = $switch_name;
  1301. $data['root_id'] = $root_id;
  1302. $data['content'] = $switch;
  1303. Setting::create($data);
  1304. } else {
  1305. $find->content = $switch;
  1306. $find->save();
  1307. }
  1308. $s_where[] = ['root_id', '=', $root_id];
  1309. $s_where[] = ['name', '=', $content_name];
  1310. $find = Setting::where($s_where)->findOrEmpty();
  1311. if ($find->isEmpty()) {
  1312. $data['name'] = $content_name;
  1313. $data['root_id'] = $root_id;
  1314. $data['content'] = !empty($content) ? json_encode($content) : '';;
  1315. $result = Setting::create($data);
  1316. } else {
  1317. $find->content = !empty($content) ? json_encode($content) : '';;
  1318. $result = $find->save();
  1319. }
  1320. $root_id = request()->employee->root_id;
  1321. // 子模块开关 活动、到店、量房
  1322. $z_where[] = ['name', 'in', ['subscribeSettingSwitchYYLF', 'subscribeSettingSwitchYYDD', 'subscribeSettingSwitchYYHD']];
  1323. $z_where[] = ['root_id', '=', $root_id];
  1324. $z_setting = Setting::where($z_where)->select()->toArray();
  1325. if (count($z_setting) == 6) { // 每一项都有保存值,缺少一项都意味着有开启状态
  1326. $all_down = true;
  1327. foreach ($z_setting as $k => $v) {
  1328. if ($v['content'] == 1) {
  1329. $all_down = false;
  1330. break;
  1331. }
  1332. }
  1333. if ($all_down) {
  1334. Setting::where([['root_id', '=', $root_id], ['name', '=', 'moduleSubscribeSwitch']])->save(['content' => 0]);
  1335. }
  1336. }
  1337. return json(['code' => 0, 'msg' => '操作成功']);
  1338. }
  1339. }
  1340. /**
  1341. * 自定义设置-报备字段设置
  1342. */
  1343. public function module_report()
  1344. {
  1345. if (!request()->isAjax()) {
  1346. return View::fetch();
  1347. }
  1348. $root_id = request()->employee->root_id;
  1349. $where = [
  1350. ['name', '=', 'settingCustomerReportField'],
  1351. ['root_id', '=', $root_id]
  1352. ];
  1353. $setting = Setting::where($where)->find();
  1354. //默认值
  1355. $default_field_array = [];
  1356. $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();
  1357. foreach ($default_field as $k => $v) {
  1358. $default_field_array[] = [
  1359. 'id' => $v['id'],
  1360. 'name' => $v['name'],
  1361. 'sort' => $k + 1,
  1362. 'keyname' => $v['keyname'],
  1363. 'type' => $v['type']
  1364. ];
  1365. }
  1366. //选中的值
  1367. $checked = [];
  1368. if ($setting && !empty($setting['content'])) {
  1369. $checked = json_decode($setting['content'], true);
  1370. } else {
  1371. $checked = $default_field_array;
  1372. }
  1373. $column_select_id = array_column($checked, 'id');
  1374. $select = CustomerPortraitFieldSelect::where('pid', 'in', $column_select_id)->select()->toArray();
  1375. $city = Company::where('root_id', $root_id)->value('city');
  1376. foreach ($checked as &$item) {
  1377. $item['select'] = [];
  1378. foreach ($select as $vv) {
  1379. if ($item['id'] == $vv['pid']) {
  1380. $item['select'][] = $vv;
  1381. }
  1382. }
  1383. if ($item['keyname'] == 'current_region') {
  1384. $item['select'][] = ['id' => $root_id, 'name' => $city, 'pid' => $item['id']];
  1385. }
  1386. if ($item['keyname'] == 'source_id') {
  1387. $item['select'] = CustomerSource::field('id,source as name')->where('root_id', $root_id)->select()->toArray();
  1388. }
  1389. if ($item['keyname'] == 'deco_style') {
  1390. $item['select'] = Decostyle::field('id,name')->where([['root_id', '=', $root_id], ['type', '=', 0]])->select()->toArray();
  1391. }
  1392. }
  1393. //全部值
  1394. $all = CustomerPortraitField::where([['root_id', '=', $root_id], ['pid', '<>', 0], ['status', '=', 0]])->orderRaw('if(isnull(sort),1,0),sort asc')->select()->toArray();
  1395. return json(['code' => 0, 'all' => $all, 'default' => $default_field_array, 'checked' => $checked]);
  1396. }
  1397. /**
  1398. * 自定义设置-报备字段设置保存
  1399. */
  1400. public function module_report_save()
  1401. {
  1402. //数组包括id、name、sort、keyname
  1403. $content = input('content');
  1404. $root_id = request()->employee->root_id;
  1405. $where = [
  1406. ['name', '=', 'settingCustomerReportField'],
  1407. ['root_id', '=', $root_id]
  1408. ];
  1409. $data = Setting::where($where)->find();
  1410. if ($data) {
  1411. $data->content = json_encode($content);
  1412. $data->save();
  1413. } else {
  1414. Setting::create([
  1415. 'name' => 'settingCustomerReportField',
  1416. 'root_id' => $root_id,
  1417. 'content' => json_encode($content)
  1418. ]);
  1419. }
  1420. return json(['code' => 0, 'msg' => '保存成功']);
  1421. }
  1422. /**
  1423. * 团队客户自定设置页面
  1424. */
  1425. public function team_statistics_data()
  1426. {
  1427. $root_id = request()->employee->root_id;
  1428. $lf_where[] = ['root_id', '=', $root_id];
  1429. $lf_where[] = ['name', '=', 'teamStatisticsJurisdiction'];
  1430. $find = Setting::where($lf_where)->findOrEmpty();
  1431. $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];
  1432. $arr = (!$find->isEmpty() && !empty($find->content)) ? explode(',', $find->content) : [];
  1433. foreach ($type_arr as $k => $v) {
  1434. $type_arr[$k] = in_array($k, $arr) ? 1 : 0;
  1435. }
  1436. View::assign('type', $type_arr);
  1437. return View::fetch();
  1438. }
  1439. /**
  1440. * 获取团队客户自定义设置api
  1441. */
  1442. public function teamStatisticsSetting()
  1443. {
  1444. $root_id = request()->employee->root_id;
  1445. $lf_where[] = ['root_id', '=', $root_id];
  1446. $lf_where[] = ['name', '=', 'teamStatisticsJurisdiction'];
  1447. $find = Setting::where($lf_where)->findOrEmpty();
  1448. $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];
  1449. $arr = (!$find->isEmpty() && !empty($find->content)) ? explode(',', $find->content) : [];
  1450. foreach ($type_arr as $k => $v) {
  1451. $type_arr[$k] = in_array($k, $arr) ? 1 : 0;
  1452. }
  1453. return json(['code' => 1, 'data' => $type_arr]);
  1454. }
  1455. /**
  1456. * 团队客户自定设置保存
  1457. */
  1458. public function team_statistics_data_save()
  1459. {
  1460. $save = input('value/a', []);
  1461. $value = $save ? implode(',', $save) : '';
  1462. $root_id = request()->employee->root_id;
  1463. $lf_where[] = ['root_id', '=', $root_id];
  1464. $lf_where[] = ['name', '=', 'teamStatisticsJurisdiction'];
  1465. $find = Setting::where($lf_where)->findOrEmpty();
  1466. if ($find->isEmpty()) {
  1467. $data['name'] = 'teamStatisticsJurisdiction';
  1468. $data['root_id'] = $root_id;
  1469. $data['content'] = $value;
  1470. Setting::create($data);
  1471. } else {
  1472. $find->content = $value;
  1473. $find->save();
  1474. }
  1475. return json(['code' => 0, 'msg' => '保存成功']);
  1476. }
  1477. /**
  1478. * 操作设置
  1479. */
  1480. public function moduleHandel()
  1481. {
  1482. $root_id = request()->employee->root_id;
  1483. $setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'customerHandel']])->findOrEmpty();
  1484. if (!request()->isAjax()) {
  1485. if (!$setting->isEmpty()) {
  1486. $content = json_decode($setting['content'], true);
  1487. } else {
  1488. $content = [
  1489. 'wechat' => 1,
  1490. 'group_building' => 1,
  1491. 'live_broadcast' => 1
  1492. ];
  1493. }
  1494. View::assign('data', $content);
  1495. return View::fetch();
  1496. } else {
  1497. $param = request()->only(['wechat', 'group_building', 'live_broadcast']);
  1498. $content = [
  1499. 'wechat' => $param['wechat'],
  1500. 'group_building' => $param['group_building'],
  1501. 'live_broadcast' => $param['live_broadcast']
  1502. ];
  1503. if ($setting->isEmpty()) {
  1504. $data['name'] = 'customerHandel';
  1505. $data['content'] = json_encode($content);
  1506. $data['state'] = 1;
  1507. $data['root_id'] = $root_id;
  1508. $result = Setting::create($data);
  1509. } else {
  1510. $setting->content = json_encode($content);
  1511. $result = $setting->save();
  1512. }
  1513. if ($result !== false) {
  1514. return json(['code' => 0, 'msg' => '保存成功']);
  1515. } else {
  1516. return json(['code' => 1, 'msg' => '保存失败']);
  1517. }
  1518. }
  1519. }
  1520. public function report()
  1521. {
  1522. if (!request()->isAjax()) {
  1523. return View::fetch();
  1524. }
  1525. $root_id = request()->employee->root_id;
  1526. $where = [
  1527. ['name', '=', 'CustomerReportSettingForPc'],
  1528. ['root_id', '=', $root_id]
  1529. ];
  1530. $setting = Setting::where($where)->find();
  1531. //默认值
  1532. $default_field_array = [];
  1533. $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();
  1534. foreach ($default_field as $k => $v) {
  1535. $default_field_array[] = [
  1536. 'id' => $v['id'],
  1537. 'name' => $v['name'],
  1538. 'sort' => $k + 1,
  1539. 'keyname' => $v['keyname'],
  1540. 'type' => $v['type']
  1541. ];
  1542. }
  1543. //选中的值
  1544. $checked = [];
  1545. if ($setting && !empty($setting['content'])) {
  1546. $checked = json_decode($setting['content'], true);
  1547. } else {
  1548. $checked = $default_field_array;
  1549. }
  1550. $column_select_id = array_column($checked, 'id');
  1551. $select = CustomerPortraitFieldSelect::where('pid', 'in', $column_select_id)->select()->toArray();
  1552. $city = Company::where('root_id', $root_id)->value('city');
  1553. foreach ($checked as &$item) {
  1554. $item['select'] = [];
  1555. foreach ($select as $vv) {
  1556. if ($item['id'] == $vv['pid']) {
  1557. $item['select'][] = $vv;
  1558. }
  1559. }
  1560. if ($item['keyname'] == 'current_region') {
  1561. $item['select'][] = ['id' => $root_id, 'name' => $city, 'pid' => $item['id']];
  1562. }
  1563. if ($item['keyname'] == 'source_id') {
  1564. $item['select'] = CustomerSource::field('id,source as name')->where('root_id', $root_id)->select()->toArray();
  1565. }
  1566. if ($item['keyname'] == 'deco_style') {
  1567. $item['select'] = Decostyle::field('id,name')->where([['root_id', '=', $root_id], ['type', '=', 0]])->select()->toArray();
  1568. }
  1569. }
  1570. //全部值
  1571. $all = CustomerPortraitField::where([['root_id', '=', $root_id], ['pid', '<>', 0], ['status', '=', 0]])->orderRaw('if(isnull(sort),1,0),sort asc')->select()->toArray();
  1572. return json(['code' => 0, 'all' => $all, 'default' => $default_field_array, 'checked' => $checked]);
  1573. }
  1574. public function report_save()
  1575. {
  1576. $content = input('content');
  1577. $root_id = request()->employee->root_id;
  1578. $where = [
  1579. ['name', '=', 'CustomerReportSettingForPc'],
  1580. ['root_id', '=', $root_id]
  1581. ];
  1582. $data = Setting::where($where)->find();
  1583. if ($data) {
  1584. $data->content = json_encode($content);
  1585. $data->save();
  1586. } else {
  1587. Setting::create([
  1588. 'name' => 'CustomerReportSettingForPc',
  1589. 'root_id' => $root_id,
  1590. 'content' => json_encode($content)
  1591. ]);
  1592. }
  1593. return json(['code' => 0, 'msg' => '保存成功']);
  1594. }
  1595. /**
  1596. * 获取数据统计设置
  1597. */
  1598. public function get_statistics()
  1599. {
  1600. $root_id = request()->employee->root_id;
  1601. $where = [
  1602. ['name', '=', 'CustomerStatisticsSettingForMini'],
  1603. ['root_id', '=', $root_id]
  1604. ];
  1605. $data = Setting::where($where)->findOrEmpty();
  1606. if ($data->isEmpty()) {
  1607. $content = ['valid', 'call', 'jiav', 'contact', 'subscribe', 'measure_room', 'arrival', 'deposit', 'signed', 'maika'];
  1608. } else {
  1609. $content = explode(',', $data['content']);
  1610. }
  1611. View::assign('data', $content);
  1612. return View::fetch();
  1613. }
  1614. /**
  1615. * 设置数据统计展示
  1616. */
  1617. public function set_statistics()
  1618. {
  1619. $content = input('content');
  1620. $root_id = request()->employee->root_id;
  1621. $where = [
  1622. ['name', '=', 'CustomerStatisticsSettingForMini'],
  1623. ['root_id', '=', $root_id]
  1624. ];
  1625. $data = Setting::where($where)->find();
  1626. if ($data) {
  1627. $data->content = $content;
  1628. $data->save();
  1629. } else {
  1630. Setting::create([
  1631. 'name' => 'CustomerStatisticsSettingForMini',
  1632. 'root_id' => $root_id,
  1633. 'content' => $content
  1634. ]);
  1635. }
  1636. return json(['code' => 0, 'msg' => '保存成功']);
  1637. }
  1638. }