1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619 |
- <?php
- namespace app\sys\controller;
- use app\event\Msg;
- use app\model\TalkskillChosen;
- use app\model\TalkskillContent;
- use app\model\TalkskillSuccess;
- use think\facade\View;
- use think\facade\Request;
- use app\model\Employee;
- use app\model\TalkskillComment;
- use app\model\Talkskill as TalkskillModel;
- use app\model\TalkskillLabel;
- use app\model\TalkskillHotKeyword;
- use app\model\Credits;
- use app\model\CreditsSetting;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use Exception;
- use think\facade\Db;
- use app\model\org;
- use app\model\Company;
- use think\facade\Console;
- use app\model\TalkskillUsersCate;
- use app\model\TalkskillCates;
- use app\model\Customer;
- use app\model\CustomerClue;
- class Talkskill
- {
- /*
- * 话术列表视图
- */
- public function talkskilltable()
- {
- $type = request()->param('type');
- $name = request()->param('name');
- View::assign('type', $type);
- View::assign('name', $name);
- $root_id = request()->employee->root_id;
- $param['id'] = $type;
- //二级分类
- $w[] = ['type','=','cate'];
- $w[] = ['root_id','=',$root_id];
- $w[] = ['pid','=',$param['id']];
- $cate = TalkskillCates::where($w)->field('name,id')->order('id asc')->select()->toArray();
- view::assign('cate', $cate);
- //房屋类型
- $w1[] = ['type','=','house_type'];
- $w1[] = ['root_id','=',$root_id];
- $w1[] = ['pid','=',0];
- $house_type = TalkskillCates::where($w1)->field('name,id')->order('id asc')->select()->toArray();
- view::assign('house_type', $house_type);
- //适用人群
- $w3[] = ['root_id','=',$root_id];
- $user_cate = TalkskillUsersCate::where($w3)->field('name,id')->order('id asc')->select()->toArray();
- view::assign('user_cate', $user_cate);
- // 上传人
- $empIds = TalkskillModel::where([['root_id', '=', $root_id]])->whereRaw("FIND_IN_SET('" . $name . "' , cate1)")->column('employee_id');
- $employee = Employee::where([['id', 'in', $empIds]])->select();
- View::assign('employee', $employee);
- return View::fetch();
- }
- /*
- * 话术列表数据
- */
- public function talkskilllist()
- {
- $param = Request::param();
- $where = [
- ['root_id', '=', request()->employee->root_id],
- ['del', '=', 0],
- ['content', '<>', ''],
- ['approve', '=', 1]
- ];
- if (!empty($param['keyword'])) {
- $where[] = ['title', 'like', '%' . $param['keyword'] . '%'];
- }
- $sql = TalkskillModel::with('employee')->where($where);
- if (!empty($param['name'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['name'] . "' , cate1)");
- }
- if (!empty($param['cate'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['cate'] . "' , cate2)");
- }
- if (!empty($param['house_type'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['house_type'] . "' , house_type)");
- }
- if (!empty($param['user_cate'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['user_cate'] . "' , user_cate)");
- }
- if (!empty($param['addtime'])) {
- list($start_date, $end_date) = explode(' - ', $param['addtime']);
- $sql->whereRaw("addtime >= '".$start_date."'");
- $sql->whereRaw("addtime < '". date('Y-m-d H:i:s', strtotime($end_date) + 86400) ."'");
- }
- if (!empty($param['employee_id'])) {
- $sql->whereRaw("employee_id=".$param['employee_id']);
- }
- // 获取数据
- $list = $sql->page($param['page'], $param['limit'])->order('addtime desc')->select()->toArray();
- $count = $sql->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /*
- * 话术添加页
- */
- public function talkskilladd()
- {
- $root_id = request()->employee->root_id;
- $w[] = ['root_id','=',$root_id];
- $w[] = ['pid','=',0];
- $w[] = ['type','=','cate'];
- $list = TalkskillCates::where($w)->field('id,name')->order('id asc')->select();
- View::assign('type',$list);
- return View::fetch();
- }
- /*
- * 话术分类添加
- */
- public function add_talkskill_label()
- {
- $value = Request::param('value');
- if (empty($value)) return json(['code' => 1, 'msg' => '请输入场景名称']);
- $isAdd = TalkskillLabel::where(['label_name' => $value, 'root_id' => request()->employee->root_id])->count();
- if ($isAdd > 0) return json(['code' => 1, 'msg' => '场景已存在']);
- $objId = TalkskillLabel::insertGetId(['label_name' => $value, 'root_id' => request()->employee->root_id]);
- return json(['code' => 0, 'msg' => '添加成功', 'data' => ['id' => $objId, 'name' => $value]]);
- }
- /*
- * 话术分类列表
- */
- public function label_list()
- {
- $id = request()->param('id');
- $labelArray = [];
- if (!empty($id)) {
- $labelArray = TalkskillModel::where(['id' => $id, 'root_id' => request()->employee->root_id])->value('label');
- $labelArray = explode(',', $labelArray);
- }
- $label = TalkskillLabel::where('root_id', request()->employee->root_id)->select();
- $data = [];
- foreach ($label as $val) {
- $data[] = [
- 'name' => $val['label_name'],
- 'value' => $val['id'],
- 'selected' => in_array($val['id'], $labelArray) ? true : false
- ];
- }
- $data = hanziInitsort($data,'name');
- return json($data);
- }
- /*
- * 话术添加
- */
- public function add_talkskill()
- {
- $param = Request::only(['title', 'user_cate','content', 'label'=>0, 'id', 'type', 'files_data', 'images_data', 'fiels_exist', 'images_exist', 'operationType', 'state','box'=>'','house_type'=>'','cate1'=>'','cate2'=>'']);
- $param['user_cate'] = str_replace(' ','',$param['user_cate']);
- $data = [
- 'title' => $param['title'],
- 'content' => $param['content'],
- 'label' => $param['label'],
- 'root_id' => request()->employee->root_id,
- 'type' => 'admin',
- 'imgs' => isset($param['images_data']) && $param['images_data'] ? implode(',', $param['images_data']) : null,
- 'videos' => isset($param['files_data']) && $param['files_data'] ? implode(',', $param['files_data']) : null,
- 'user_cate' => $param['user_cate'],
- 'house_type' => $param['house_type'],
- 'cate1' => $param['cate1'],
- 'cate2' => $param['cate2'],
- 'employee_id'=>request()->employee->id
- ];
- if (isset($param['images_exist']) && $param['images_exist']) {
- $data['imgs'] = $data['imgs'] ? $data['imgs'] . ',' . implode(',', $param['images_exist']) : implode(',', $param['images_exist']);
- }
- if (isset($param['fiels_exist']) && $param['fiels_exist']) {
- $data['videos'] = $data['videos'] ? $data['videos'] . ',' . implode(',', $param['fiels_exist']) : implode(',', $param['fiels_exist']);
- }
- if (empty($param['id'])) {
- dataStatistics(request()->employee->root_id,'talkskill_count',1,'inc');//manage应用首页统计数据
- TalkskillModel::insert($data);
- } else {
- $data['id'] = $param['id'];
- unset($data['type']);
- $talkill = TalkskillModel::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find();
- $talkill->save($data);
- if ($param['operationType'] == 'submit') {
- event(new Msg($talkill->employee_id, '您提问的“' . $param['title'] . '”问题已有回复,请点击查看', 'talkskill'));
- }
- if ($param['operationType'] == 'share') {
- $approve = $this->approve($param['id'], $param['state'],$param['box']);
- if ($approve == false) return json(['code' => 1, 'msg' => '操作失败']);
- }
- }
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /*
- * 话术编辑查看
- */
- public function talkskilldetail()
- {
- $where = [
- 'id' => Request::param('id'),
- 'root_id' => request()->employee->root_id,
- 'del' => 0
- ];
- $data = TalkskillModel::where($where)->find();
- $data = $data->getData();
- $data['imgs'] = empty($data['imgs']) ? '' : explode(',', $data['imgs']);
- $data['videos'] = empty($data['videos']) ? '' : explode(',', $data['videos']);
- $data['cate1_count'] = $data['cate1'] ? count(array_filter(explode(',',$data['cate1']))) : 0;
- $data['cate2_count'] = $data['cate2'] ? count(array_filter(explode(',',$data['cate2']))) : 0;
- $data['house_type_count'] = $data['house_type'] ? count(array_filter(explode(',',$data['house_type']))) : 0;
- $data['user_cate_count'] = $data['user_cate'] ? count(array_filter(explode(',',$data['user_cate']))) : 0;
- View::assign('data', $data);
- View::assign('ali_oss_bindurl', config('app.ali_oss_bindurl'));
- //操作类型:正常编辑,提问回复,共享修改
- $operationType = Request::param('operationType');
- View::assign('operationType', isset($operationType) ? $operationType : '');
-
- $list = TalkskillUsersCate::where([['root_id', '=', request()->employee->root_id]])->order('id asc')->select();
- View::assign('type',$list);
- return View::fetch();
- }
- /*
- * 话术编辑页面下拉
- */
- public function talkskilldetail_select()
- {
- $id = Request::param('id');
- $root_id = request()->employee->root_id;
- $where = [
- 'id' => $id,
- 'root_id' => $root_id,
- 'del' => 0
- ];
- $data = TalkskillModel::where($where)->find();
- $cate2 = explode(',',$data->cate2);
- $house_types = explode(',',$data->house_type);
- //话术一级
- $root_id = request()->employee->root_id;
- $wc[] = ['type','=','cate'];
- $wc[] = ['root_id','=',$root_id];
- $wc[] = ['pid','=',0];
- $cate1 = TalkskillCates::where($wc)->field('name,name value,id')->order('id asc')->select()->toArray();
- foreach ($cate1 as $k0 => $v0) {
- $cate1[$k0]['selected'] = ($data['cate1'] && strpos($data['cate1'],$v0['name'])!==false) ? true : false;
- }
- $data1['cate'] = $cate1;
- //话术二级下拉
- $root_id = request()->employee->root_id;
- $pid = TalkskillCates::where([['name','=',$data['cate1']],['root_id','=',$root_id],['pid','=',0]])->value('id');
- $w[] = ['type','=','cate'];
- $w[] = ['root_id','=',$root_id];
- $w[] = ['pid','=',$pid];
- $cate = TalkskillCates::where($w)->field('name,name value,id')->order('id asc')->select()->toArray();
-
- foreach ($cate as $k => $v) {
-
- $cate[$k]['selected'] = ($cate2 && in_array($v['name'],$cate2)) ? true : false;
- }
- $data1['cate2'] = $cate;
- //房屋类型
- $w1[] = ['type','=','house_type'];
- $w1[] = ['root_id','=',$root_id];
- $w1[] = ['pid','=',0];
- $house_type = TalkskillCates::where($w1)->field('name,name value,id')->order('id asc')->select()->toArray();
- foreach ($house_type as $k2 => $v2) {
- $house_type[$k2]['selected'] = ($house_type && in_array($v2['name'],$house_types)) ? true : false;
- }
-
- $data1['house_type'] = $house_type;
- //适用人群
- $w3[] = ['root_id','=',$root_id];
- $user_cate = TalkskillUsersCate::where($w3)->field('name,name value,id')->order('id asc')->select()->toArray();
- foreach ($user_cate as $k3 => $v3) {
- $user_cate[$k3]['selected'] = ($data['user_cate'] && strpos($data['user_cate'],$v3['name'])!==false) ? true : false;
- }
- $data1['user_date'] = $user_cate;
- return json(['code' => 0, 'data' => $data1]);
- }
- /**
- * 话术详情
- */
- public function talkskillview(){
- $id = Request::param('id');
- View::assign('id', $id);
- $root_id = !empty(Request::param('root_id')) ? Request::param('root_id') : request()->employee->root_id;
- View::assign('root_id', $root_id);
- $where = [
- 'id' => $id,
- 'root_id' => $root_id,
- 'del' => 0
- ];
- $data = TalkskillModel::where($where)->find()->toArray();
- switch ($data['type']){
- case 'admin':
- $data['type_name'] = '官方创建';
- break;
- case 'submit':
- $employee = Employee::find($data['employee_id']);
- $data['type_name'] = $employee['name'] . '提问';
- break;
- case 'share':
- $data['type_name'] = '共享话术';
- break;
- default:
- $data['type_name'] = '官方创建';
- break;
- }
- View::assign('data', $data);
- return View::fetch();
- }
- /*
- * 话术删除
- */
- public function talkskilldel()
- {
- $where = [
- 'id' => Request::param('id'),
- 'root_id' => request()->employee->root_id
- ];
- TalkskillModel::where($where)->update(['del' => 1]);
- dataStatistics(request()->employee->root_id,'talkskill_count',1,'dec');//manage应用首页统计数据
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /*
- * 话术评论列表
- */
- public function talkskillcomment($id)
- {
- if (!Request()->isAjax()) {
- View::assign('id', $id);
- return View::fetch();
- }
- $param = Request()->param();
- $root_id = !empty(Request::param('root_id')) ? Request::param('root_id') : request()->employee->root_id;
- // 请求条件初始化
- $where = [
- 'root_id' => $root_id,
- 'taid' => $param['id'],
- 'approve' => 1
- ];
- $data = TalkskillComment::with(['User'])->where($where)->page($param['page'], $param['limit'])->order(['approve' => 'asc', 'use' => 'desc', 'praise' => 'desc'])->select()->toArray();
- $count = TalkskillComment::where($where)->count();
- return json(['code' => 0, 'data' => $data, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 评论删除
- */
- public function talkskillCommentDel($id)
- {
- $rs = TalkskillComment::where(['id' => $id, 'root_id' => request()->employee->root_id])->find();
- if ($rs) {
- TalkskillModel::where(['id' => $rs['taid'], 'root_id' => request()->employee->root_id])->dec('commentCount')->update();
- $rs->delete();
- }
- }
- /*
- * 业务员提交的问题
- */
- public function feedbacklist()
- {
- if (!request()->isAjax()) return View::fetch();
- $param = Request::param();
- $where = [
- ['root_id', '=', request()->employee->root_id],
- ['del', '=', 0],
- ['type', '=', 'submit'],
- ['content', '=', '']
- ];
- if (!empty($param['keyword'])) $where[] = ['title|content', 'like', '%' . $param['keyword'] . '%'];
- // 获取数据
- $list = TalkskillModel::with(['employee'])->where($where)->page($param['page'], $param['limit'])->order('addtime desc')->select();
- $count = TalkskillModel::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /*
- * 业务员上传的话术审核列表
- */
- public function approve_talkskill()
- {
- if (!request()->isAjax()) return View::fetch();
- $param = Request::param();
- $where = [
- ['root_id', '=', request()->employee->root_id],
- ['del', '=', 0],
- ['approve', '=', 0],
- ['type', '=', 'share']
- ];
- if (!empty($param['keyword'])) {
- $where[] = ['title', 'like', '%' . $param['keyword'] . '%'];
- }
- // 获取数据
- $list = TalkskillModel::with(['employee'])->where($where)->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select()->toArray();
- $count = TalkskillModel::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /*
- * 话术提问列表
- */
- public function talkskill_questions()
- {
- if (!request()->isAjax()) return View::fetch();
- $param = Request::param();
- $where = [
- ['root_id', '=', request()->employee->root_id],
- ['del', '=', 0],
- ['approve', '=', 0],
- ['type', '=', 'share']
- ];
- if (!empty($param['keyword'])) {
- $where[] = ['title', 'like', '%' . $param['keyword'] . '%'];
- }
- // 获取数据
- $list = TalkskillModel::with(['employee'])->where($where)->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select()->toArray();
- $count = TalkskillModel::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /*
- * 批量审核
- */
- public function talkskill_approve()
- {
- $root_id = request()->employee->root_id;
- $ids = input('ids');
- $approve = input('status', 0);
- $box = input('box','');//驳回原因
- Db::startTrans();
- try {
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['id', 'in', $ids];
- $u['approve'] = $approve == 1 ? 1 : 2; //审批,0待审核,1审核通过,2不通过
- $u['aprove_employee_id'] = request()->employee->id;
- $u['aprove_time'] = date('Y-m-d H:i:s');
- $u['approve_from'] = 0;
- TalkskillModel::where($where)->update($u);
- //查询增加的贡献值
- $contribution = CreditsSetting::where(['code' => 'talkskill_credits', 'root_id' => request()->employee->root_id])->value('value');
- if (empty($contribution)) $contribution = 1;
- //贡献值
- $list = TalkskillModel::where($where)->select();
- foreach ($list as $k => $v) {
- if ($approve == 1) {
- //贡献值入库
- $sum = Credits::where(['root_id' => $root_id, 'employee_id' => $v['employee_id'], 'type' => 1])->sum('credits');
- $array = [
- 'employee_id' => $v['employee_id'],
- 'root_id' => $root_id,
- 'credits' => $contribution,
- 'sum' => $sum + $contribution,
- 'type' => 1,
- 'json' => $v['id'],
- 'remark' => '共享话术审核通过'
- ];
- Credits::create($array);
- }
- $s = $approve == 1 ? '已' : '未';
- if ($s=='已') {
- //累计勋章
- Console::call('medal',['talkskill',(string)$v['employee_id'],(string)$root_id]);
- event(new Msg($v['employee_id'], '您共享的“'.$v['title'].'”' . $s . '审核通过', 'talkskillApprove'));
- }else{
- event(new Msg($v['employee_id'], '您共享的“'.$v['title'].'”' . '被驳回,原因是:'.$box, 'talkskillApprove'));
- }
-
- }
- Db::commit();
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- return json(["code" => 1, 'msg' => '操作失败']);
- }
- return json(["code" => 0, 'msg' => '操作成功']);
- }
- /*
- * 审核业务员上传的话术
- */
- private function approve($id, $state,$box='')
- {
- $data = TalkskillModel::where(['id' => $id, 'del' => 0, 'type' => 'share', 'approve' => 0])->find();
- if (empty($data)) return false;
- $data->approve = $state == 1 ? 1 : 2;
- $data->aprove_employee_id = request()->employee->id;
- $data->aprove_time = date('Y-m-d H:i:s');
- $data->box = $box;
- $data->approve_from = 0;
- $data->save();
- if ($data->employee_id != 0) {
- $s = $data->approve == 1 ? '已' : '未';
- if ($s=='已') {
- //累计勋章
- Console::call('medal',['talkskill',(string)$data->employee_id,(string)$data->root_id]);
- event(new Msg($data->employee_id, '您共享的“'.$data['title'].'”' . $s . '审核通过', 'talkskillApprove'));
- dataStatistics(request()->employee->root_id,'talkskill_count',1,'inc');//manage应用首页统计数据
- }else{
- event(new Msg($data->employee_id, '您共享的“'.$data['title'].'”' . '被驳回,原因是:'.$box, 'talkskillApprove'));
- }
-
- }
- if ($state != 1) return true;
- //查询增加的贡献值
- $contribution = CreditsSetting::where(['code' => 'talkskill_credits', 'root_id' => request()->employee->root_id])->value('value');
- if (empty($contribution)) $contribution = 1;
- //积分入库
- $sum = Credits::where(['root_id' => request()->employee->root_id, 'employee_id' => $data['employee_id'], 'type' => 1])->sum('credits');
- $array = [
- 'employee_id' => $data['employee_id'],
- 'root_id' => request()->employee->root_id,
- 'credits' => $contribution,
- 'sum' => $sum + $contribution,
- 'type' => 1,
- 'remark' => '共享话术'
- ];
- Credits::create($array);
- return true;
- }
- /*
- * 业务员评论的话术审核列表
- */
- public function approve_comment()
- {
- if (!request()->isAjax()) return View::fetch();
- $param = Request::param();
- $where = [
- ['root_id', '=', request()->employee->root_id],
- ['approve', '=', 0],
- ];
- if (!empty($param['keyword'])) {
- $where[] = ['comments', 'like', '%' . $param['keyword'] . '%'];
- }
- // 获取数据
- $list = TalkskillComment::with(['talkskill'])->where($where)->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select()->toArray();
- $uid = array_column($list, 'uid');
- $name = Employee::where([['root_id', '=', request()->employee->root_id], ['uid', 'in', $uid]])->column('name', 'uid');
- foreach ($list as &$item) {
- $item['name'] = isset($name[$item['uid']]) ? $name[$item['uid']] : '';
- }
- $count = TalkskillComment::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /*
- * 业务员评论的话术展示
- */
- public function comment_detail()
- {
- $id = request()->param('id');
- $comment = TalkskillComment::with(['talkskill'])->where(['root_id' => request()->employee->root_id, 'id' => $id])->find();
- View::assign('data', $comment);
- return View::fetch();
- }
- //批量审核回答
- public function all_approve_comment()
- {
- $root_id = request()->employee->root_id;
- $ids = input('ids');
- $approve = input('status', 0);
- Db::startTrans();
- try {
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['id', 'in', $ids];
- $u['approve'] = $approve == 1 ? 1 : 2; //审批,0待审核,1审核通过,2不通过
- $u['aprove_employee_id'] = request()->employee->id;
- $u['aprove_time'] = date('Y-m-d H:i:s');
- $u['approve_from'] = 0;
- TalkskillComment::where($where)->update($u);
- //查询增加的贡献值
- $contribution = CreditsSetting::where(['code' => 'talkskill_contribution_value', 'root_id' => request()->employee->root_id])->value('value');
- if (empty($contribution)) $contribution = 1;
- //贡献值
- $list = TalkskillComment::where($where)->select();
- foreach ($list as $k => $v) {
- //业务员
- $employee_id = Employee::where(['root_id' => request()->employee->root_id, 'uid' => $v['uid'], 'state' => '在职'])->value('id');
- if (empty($employee_id)) continue;
- if ($approve == 1) {
- //审核通过后话术表增加回答数量
- TalkskillModel::where(['id' => $v['taid']])->inc('commentCount')->update();
- //更新最新回答时间
- $this->updateOrderDate($v['taid']);
- //贡献值入库
- $sum = Credits::where(['root_id' => $root_id, 'employee_id' => $employee_id, 'type' => 1])->sum('credits');
- $array = [
- 'employee_id' => $employee_id,
- 'root_id' => $root_id,
- 'credits' => $contribution,
- 'sum' => $sum + $contribution,
- 'type' => 1,
- 'json' => $v['id'],
- 'remark' => '话术评论审核通过增加贡献值'
- ];
- Credits::create($array);
- }
- $s = $approve == 1 ? '已' : '未';
- if ($s=='已') {
- //累计勋章
- Console::call('medal',['comment',(string)$employee_id,(string)request()->employee->root_id]);
- }
- event(new Msg($employee_id, '您提交的话术回答“'.$v['comments'].'”' . $s . '审核通过', 'talkskillApprove'));
- }
- Db::commit();
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- return json(["code" => 1, 'msg' => '操作失败']);
- }
- return json(["code" => 0, 'msg' => '操作成功']);
- }
- /*
- * 审核业务员评论的内容
- */
- public function comment()
- {
- $param = Request::param(['id', 'state', 'comments','box'=>'']);
- $data = TalkskillComment::where(['id' => $param['id'], 'root_id' => request()->employee->root_id, 'approve' => 0])->find();
- if (empty($data)) return json(['code' => 1, 'msg' => '审核失败']);
- $data->approve = $param['state'] == 1 ? 1 : 2;
- $data->comments = $param['comments'];
- $data->aprove_employee_id = request()->employee->id;
- $data->aprove_time = date('Y-m-d H:i:s');
- $data->box = $param['box'];
- $data->approve_from = 0;
- $data->save();
- $employee_id = Employee::where(['root_id' => request()->employee->root_id, 'uid' => $data['uid'], 'state' => '在职'])->value('id');
- if (empty($employee_id)) return json(['code' => 1, 'msg' => '员工不存在']);
- // 添加消息
- $s = $data->approve == 1 ? '已' : '未';
- if ($s=='已') {
- $this->updateOrderDate($data->taid);
- //累计勋章
- Console::call('medal',['comment',(string)$employee_id,(string)request()->employee->root_id]);
- event(new Msg($employee_id, '您提交的话术回答“'.$data->comments.'”' . $s . '审核通过', 'talkskillApprove'));
- }else{
- event(new Msg($employee_id, '您提交的话术回答“'.$data->comments.'”' . '被驳回,原因是:'.$param['box'], 'talkskillApprove'));
- }
-
- if ($param['state'] != 1) return json(['code' => 0, 'msg' => '操作成功']);
- //审核通过后话术表增加回答数量
- TalkskillModel::where(['id' => $data['taid']])->inc('commentCount')->update();
- //查询增加的贡献值
- $contribution = CreditsSetting::where(['code' => 'talkskill_contribution_value', 'root_id' => request()->employee->root_id])->value('value');
- if (empty($contribution)) $contribution = 1;
- //积分入库
- $sum = Credits::where(['root_id' => request()->employee->root_id, 'employee_id' => $employee_id, 'type' => 1])->sum('credits');
- $array = [
- 'employee_id' => $employee_id,
- 'root_id' => request()->employee->root_id,
- 'credits' => $contribution,
- 'sum' => $sum + $contribution,
- 'type' => 1,
- 'remark' => '话术评论审核通过增加贡献值'
- ];
- Credits::create($array);
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /*
- * 更新最新回答时间
- * $id 话术id
- */
- public function updateOrderDate($id)
- {
- $data = TalkskillComment::where(['taid' => $id, 'root_id' => request()->employee->root_id, 'approve' => 1])->order('id desc')->findOrEmpty();
- if (!$data->isEmpty()) {
- TalkskillModel::where('id',$id)->update(['order_date'=>date('Y-m-d H:i:s')]);
- }
- return true;
- }
- /*
- * 分类管理
- */
- public function cate_talkskill()
- {
- $w[] = ['root_id','=',request()->employee->root_id];
- $w[] = ['pid','=',0];
- $w[] = ['type','=','cate'];
- $type = TalkskillCates::where($w)->field('id,name label_name')->order('id asc')->select();
- View::assign('type', $type);
- $root_id = request()->employee->root_id;
- $employee_id = request()->employee->id;
- // echo $root_id;die;
- //话术总数
- $where = [
- ['del','=',0],
- ['approve','=',1],
- ['root_id','=',$root_id]
- ];
- $c = TalkskillModel::where($where)->field('id,root_id,type,employee_id')->select()->toArray();
- //count话术总数,gf_upload官方上传,yewu_upload业务员上传,yewu_tiwen业务员提问
- $data['count'] = $data['gf_upload'] = $data['yewu_upload'] = $data['yewu_tiwen'] = 0;
- $data['count'] = count($c);
- foreach ($c as $k => $v) {
- if ($v['employee_id']==0 && $v['type']=='admin') {
- $data['gf_upload']+=1;
- }elseif ($v['type']=='share') {
- $data['yewu_upload']+=1;
- }elseif ($v['type']=='submit') {
- $data['yewu_tiwen']+=1;
- }
- }
- //label_count应用场景数量,gf_huida官方回答,gf_huashu_grwth官方话术占比, yewu_huida业务员回答, yewu_huashu_grawth业务话术占比
- $data['label_count'] = count($type);
- $w1[] = ['type','=','submit'];
- $w1[] = ['content', 'not null', ''];
- $w1[] = ['content','<>',''];
- $w1 = array_merge($where,$w1);
- $data['gf_huida'] = TalkskillModel::where($w1)->count();
- $data['gf_huashu_grwth'] = $data['count']==0 ? '0%' : round($data['gf_upload']/$data['count']*100,2).'%';
- $w2[] = ['root_id','=',$root_id];
- $w2[] = ['approve','=',1];
- $data['yewu_huida'] = TalkskillComment::where($w2)->count();
- $data['count'] = $data['count']+$data['yewu_huida'];
- $data['yewu_huashu_grawth'] = $data['count']==0 ? '0%' : round($data['yewu_upload']/$data['count']*100,2).'%';
- $data['yewu_tiwen_grawth'] = $data['count']==0 ? '0%' : round($data['yewu_tiwen']/$data['count']*100,2).'%';
- // echo $data['yewu_huida'];die;
- View::assign('data',$data);
- return View::fetch();
- }
- /*
- * 分类管理列表
- */
- public function cate_talkskill_list()
- {
- $param = Request::only(['page' => 1, 'limit' => 10, 'keyword','type'=>'']);
-
- $root_id = request()->employee->root_id;
- $count = 0;
- //一级场景
- $cw[] = ['root_id','=',$root_id];
- $cw[] = ['pid','=',0];
- $cw[] = ['type','=','cate'];
- if (!empty($param['type'])) {
- $cw[] = ['name','=',$param['type']];
- }
- $data = TalkskillCates::where($cw)->field('*,name label_name')->page($param['page'] , $param['limit'])->order('id asc')->select()->toArray();
- $count = TalkskillCates::where($cw)->count();
- if ($data) {
- $where2[] = ['cate1','in',array_column($data, 'name')];
- $where2[] = ['root_id', '=', $root_id];
- $where2[] = ['del', '=', 0];
- $where2[] = ['approve', '=', 1];
- if (isset($param['keyword']) && $param['keyword']) {
- $where2[] = ['title', 'like', '%' . trim($param['keyword']) . '%'];
- }
- // if (!empty($param['type'])) {
- // $where2[] = ['cate1','=',$param['type']];
- // }
- $label_count = TalkskillModel::where($where2)->field('addtime,label label_id,id,use_count,cate1,view_num')->order('id asc')->select()->toArray();
- $label_counts = $dates = $person_count = $viewCount = [];
- foreach ($label_count as $v) {
- //话术数量
- $label_counts[$v['cate1']] = isset($label_counts[$v['cate1']]) ? $label_counts[$v['cate1']] += 1 : 1;
- //最近话术上传时间
- $dates[$v['cate1']] = $v['addtime'];
- //使用人次
- $person_count[$v['cate1']] = isset($person_count[$v['cate1']]) ? $person_count[$v['cate1']] + $v['use_count'] : $v['use_count'];
- //浏览人次
- $viewCount[$v['cate1']] = isset($viewCount[$v['cate1']]) ? $viewCount[$v['cate1']] + $v['view_num'] : $v['view_num'];
- }
- foreach ($data as $k => $v) {
- $data[$k]['talkill_count'] = isset($label_counts[$v['name']]) ? $label_counts[$v['name']] : 0;
- $data[$k]['update_time'] = isset($dates[$v['name']]) ? $dates[$v['name']] : '';
- $data[$k]['use_count'] = isset($person_count[$v['name']]) ? $person_count[$v['name']] : 0;
- $data[$k]['view_num'] = isset($viewCount[$v['name']]) ? $viewCount[$v['name']] : 0;
- //来源
- if($v['from_type'] == 0)
- {
- $data[$k]['from'] = '店面发布';
- }elseif($v['from_type'] == 1){
- $data[$k]['from'] = '集团指派';
- }else{
- $company = Company::where('root_id',$v['from_root_id'])->value('company_name');
- $data[$k]['from'] = $company.'共享';
- }
- }
- }
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $data, 'count' => $count]);
- //旧版
- // $param = Request::param();
- // $condition = [
- // ['root_id', '=', request()->employee->root_id],
- // ['from_type', 'in', [0,2]]
- // ];
- // if (!empty($param['type'])) {
- // $condition[] = ['id', '=', $param['type']];
- // }
- // $data = TalkskillLabel::where($condition)->page($param['page'] , $param['limit'])->order('id desc')->select()->toArray();
- // $count = TalkskillLabel::where($condition)->count();
- // $ids = array_column($data, 'id');
- // $where1 = [];
- // foreach ($ids as $v) {
- // $where1[] = "FIND_IN_SET(" . $v . " , label)";
- // }
- // $where2 = [
- // ['root_id', '=', request()->employee->root_id],
- // ['del', '=', 0],
- // ['approve', '=', 1],
- // ['content', '<>', ''],
- // ];
- // if (isset($param['keyword']) && $param['keyword']) {
- // $where2[] = ['title', 'like', '%' . $param['keyword'] . '%'];
- // }
- // $label_count = TalkskillModel::where($where2)->whereRaw(implode(' or ', $where1))->field('addtime,label label_id,id,use_count')->select()->toArray();
- // $talkill_count = $update_time = $use_count = [];
- // foreach ($label_count as $v) {
- // $label_ids = explode(',', $v['label_id']);
- // foreach ($label_ids as $v2) {
- // //话术数量
- // $talkill_count[$v2] = isset($talkill_count[$v2]) ? $talkill_count[$v2] += 1 : 1;
- // //最近话术上传时间
- // $update_time[$v2] = isset($update_time[$v2]) ? ($update_time[$v2] > $v['addtime'] ? $update_time[$v2] : $v['addtime']) : $v['addtime'];
- // //使用人次
- // $use_count[$v2] = isset($use_count[$v2]) ? $use_count[$v2] + $v['use_count'] : $v['use_count'];
- // }
- // }
- // foreach ($data as $k => $v) {
- // $data[$k]['talkill_count'] = isset($talkill_count[$v['id']]) ? $talkill_count[$v['id']] : 0;
- // $data[$k]['update_time'] = isset($update_time[$v['id']]) ? $update_time[$v['id']] : '';
- // $data[$k]['use_count'] = isset($use_count[$v['id']]) ? $use_count[$v['id']] : 0;
- // }
- // return json(['code' => 0, 'msg' => '获取成功', 'data' => $data, 'count' => $count]);
- }
- /*
- * 分类管理添加
- */
- public function cate_talkskill_add()
- {
- $param = Request::param();
- $condition[] = ['label_name', '=', $param['name']];
- $condition[] = ['root_id', '=', request()->employee->root_id];
- $model = TalkskillLabel::where($condition);
- $models = new TalkskillLabel;
- $info = $model->find();
- if ($info) {
- return json(['code' => 1, 'msg' => '名称已存在']);
- }
- $models->label_name = $param['name'];
- $models->root_id = request()->employee->root_id;
- $models->save();
- return json(['code' => 0, 'msg' => '保存成功', 'data' => '']);
- }
- /*
- * 分类管理编辑
- */
- public function cate_talkskill_edit()
- {
- $param = Request::param();
- $conditions = [['id', '=', $param['id']]];
- $condition[] = ['label_name', '=', $param['name']];
- $condition[] = ['root_id', '=', request()->employee->root_id];
- $data['label_name'] = $param['name'];
- $model = TalkskillLabel::where($condition);
- $models = TalkskillLabel::where($conditions);
- $info = $model->find();
- if ($info) {
- return json(['code' => 1, 'msg' => '名称已存在']);
- }
- $models->update($data);
- return json(['code' => 0, 'msg' => '保存成功', 'data' => '']);
- }
- /*
- * 员工热词搜索列表
- */
- public function hot_word()
- {
- if (!request()->isAjax()) return View::fetch();
- $param = Request::param();
- $condition = [['root_id', '=', request()->employee->root_id]];
- if (!empty($param['keyword'])) $condition[] = ['keyword', 'like', '%' . $param['keyword'] . '%'];
- $list = TalkskillHotKeyword::where($condition)->page($param['page'], $param['limit'])->order('use_count desc')->select()->toArray();
- $count = TalkskillHotKeyword::where($condition)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count]);
- }
- /*
- * 员工热词搜索删除
- */
- public function how_keyword_del()
- {
- $id = Request::param('id');
- TalkskillHotKeyword::where(['id' => $id, 'root_id' => request()->employee->root_id])->delete();
- return json(['code' => 0, 'msg' => '删除成功']);
- }
- private function isEmptyRow($row)
- {
- foreach ($row as $cell) {
- if (null !== $cell) return false;
- }
- return true;
- }
- /*
- * 导入话术
- */
- public function importing()
- {
- $request = request();
- if (!$request->isAjax()) {
- return View::fetch();
- }
- // var_dump(request()->employee->root_id);die;
- $fileExtendName = substr(strrchr($_FILES['file']["name"], '.'), 1);
- $filename = $_FILES['file']['tmp_name'];
- if ($fileExtendName == 'xlsx') {
- $objReader = IOFactory::createReader('Xlsx');
- } else {
- $objReader = IOFactory::createReader('Xls');
- }
- $objPHPExcel = $objReader->load($filename); //$filename可以是上传的表格,或者是指定的表格
- $sheet = $objPHPExcel->getSheet(0); //excel中的第一张sheet
- $highestRow = $sheet->getHighestDataRow();
- $highestColumn = $sheet->getHighestDataColumn();
- //// to make crm import log record
- $fileoriname = $_FILES['file']['name'];
- $a = 0;
- $realnum = 0;
- $badphonenum = 0;
- $saves = $cates = [];
- for ($i = 2; $i <= $highestRow; $i++) {
- $rowData = $sheet->rangeToArray('A' . $i . ':' . $highestColumn . $i, NULL, TRUE, FALSE);
- if ($this->isEmptyRow(reset($rowData))) {
- continue;
- } else {
- $realnum++;
- } // skip empty row
- $save = [];
- $save['title'] = trim((string) $objPHPExcel->getActiveSheet()->getCell('A' . $i)->getValue());
- $save['content'] = trim((string) $objPHPExcel->getActiveSheet()->getCell('B' . $i)->getValue());
- $save['label'] = trim((string) $objPHPExcel->getActiveSheet()->getCell('C' . $i)->getValue());
- $save['user_cate'] = trim((string) $objPHPExcel->getActiveSheet()->getCell('D' . $i)->getValue());
- $save['root_id'] = request()->employee->root_id;
- $saves[] = $save;
- }
- //处理分类
- $cates = array_unique(array_filter(array_column($saves, 'label')));
- $cates = $cates ? explode(',', implode(',', $cates)) : [];
- $f_cates = TalkskillLabel::where([['root_id', '=', request()->employee->root_id]])->column('label_name');
- $cates = $cates ? array_diff($cates, $f_cates) : [];
- $cate_s = [];
- foreach ($cates as $k => $v) {
- $c = [];
- $c['label_name'] = $v;
- $c['root_id'] = request()->employee->root_id;
- $cate_s[] = $c;
- }
- //适用人群
- $user_cates = array_unique(array_filter(array_column($saves,'user_cate')));
- $f_user_cate = TalkskillUsersCate::where([['root_id', '=', request()->employee->root_id]])->column('name');
- $user_cates = $user_cates ? array_diff($user_cates, $f_user_cate) : [];
- $user_cates_s = [];
- foreach ($user_cates as $k5 => $v5) {
- $user_cates_s[] = [
- 'name' => $v5,
- 'root_id' => request()->employee->root_id
- ];
- }
- TalkskillUsersCate::insertAll($user_cates_s);
- $label = new TalkskillLabel;
- $label = $label->saveAll($cate_s)->toArray();
- $f_cates = TalkskillLabel::where([['root_id', '=', request()->employee->root_id]])->column('id', 'label_name');
- foreach ($saves as $k => $v) {
- $label = explode(',', $v['label']);
- $l_label = [];
- foreach ($label as $k2 => $v2) {
- if (isset($f_cates[trim($v2)])) $l_label[] = $f_cates[trim($v2)];
- }
- $saves[$k]['label'] = $l_label ? implode(',', $l_label) : '';
- }
- $taskill = new TalkskillModel;
- $taskill->saveAll($saves);
- return json(["code" => 0, 'msg' => '导入成功']);
- }
- public function talkskill_delete()
- {
- $root_id = request()->employee->root_id;
- $ids = input('ids');
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['id', 'in', $ids];
- TalkskillModel::where($where)->update(['del' => 1]);
- dataStatistics(request()->employee->root_id,'talkskill_count',count(array_filter($ids)),'dec');//manage应用首页统计数据
- return json(["code" => 0, 'msg' => '删除成功']);
- }
- public function get_org_data(){
- $root_id = request()->employee->root_id;
- $org_id = input('org_id',0);
- $org_id = $org_id ?: request()->employee->root_id;
- $type = input('type','talkskill');
- //查询直系子部门
- $org_info = Org::where('id',$org_id)->value('path');
- $orgs = $allnodes = org::where([['path','like',$org_info.'%']])->field('id,name,path')->select()->toArray();
- $where[] = ['pid','=',$org_id];
- $orgids = org::where($where)->column('id');
- //
- $employee_ids = Employee::where([['org_id','in',array_column($orgs,'id')],['root_id','=',request()->employee->root_id],['uid','>',0]])->column('id');
- $w2[] = ['employee_id','in',$employee_ids];
- $w2[] = ['root_id','=',request()->employee->root_id];
- $w2[] = ['del','=',0];
- $w2[] = ['approve','=',1];
- if ($type=='talkskill') {
- $w2[] = ['type','=','share'];
- } elseif ($type=='submit') {
- $w2[] = ['type','=','submit'];
- }
- $employee_talkskill = TalkskillModel::with(['employees'=>function($query){
- $query->visible(['id','name','org_id'])->bind(['eid'=>'id','ename'=>'name','uid','org_id']);
- }])->where($w2)
- ->visible([])
- ->select();
- $w3[] = ['approve','=',1];
- $w3[] = ['root_id','=',request()->employee->root_id];
- $comment = TalkskillComment::where($w3)->group('taid')->column('count(*)','taid');
- $all_comment = array_sum(array_values($comment));
- $org = $count = $t_comment = $employee = [];
- foreach ($employee_talkskill as $k => $v) {
- //话术评论数量
- $employee_talkskill['comment_count'] = $v['comment_count'] = isset($comment[$v['id']]) ? $comment[$v['id']] : 0;
- //部门话术数组
- $org[$v['org_id']][] = $v;
- //部门话术数量
- $count[$v['org_id']] = isset($count[$v['org_id']]) ? $count[$v['org_id']]+=1 : 1;//部门话术数量
- //部门评论数量
- $t_cmment[$v['org_id']] = isset($t_cmment[$v['org_id']]) ? $t_cmment[$v['org_id']]+$v['comment_count'] : $v['comment_count'];
- }
- // var_dump(array_sum(array_values($t_cmment)));die;
- // var_dump(array_column($employee_talkskill,'commentCount'));die;
- foreach ($allnodes as $k => $v) {
- $allnodes[$k]['count'] = isset($count[$v['id']]) ? $count[$v['id']] : 0;//本部门话术数量
- $allnodes[$k]['comment_count'] = isset($t_cmment[$v['id']]) ? $t_cmment[$v['id']] : 0;//本部门评论数量
- $allnodes[$k]['all_count'] = 0;//包含子部门话术总数
- $allnodes[$k]['all_comment_count'] = 0;//包含子部门评论总数
- foreach ($allnodes as $k2 => $v2) {
- if (strpos($v2['path'],$v['path']) !== false) {
- $allnodes[$k]['all_count'] = isset($count[$v2['id']]) ? $count[$v2['id']]+$allnodes[$k]['all_count'] : $allnodes[$k]['all_count'];
- $allnodes[$k]['all_comment_count'] = isset($t_cmment[$v2['id']]) ? $t_cmment[$v2['id']]+$allnodes[$k]['all_comment_count'] : $allnodes[$k]['all_comment_count'];
- }
- }
- }
- $orgs = $allnodes;
- $res = [];
- $res['person'] = $res['data'] = [];
- foreach ($orgs as $k => $v) {
- $orgs[$k]['value'] = $v['value'] = $type=='talkskill'||$type=='submit' ? $v['all_count'] : $v['all_comment_count'];
- if ($v['id']==$org_id) {
- $res['person'] = $v;
- }
- if(in_array($v['id'],$orgids)){
- $res['data'][] = $v;
- }
- }
- $sum = count($employee_talkskill);//全部话术总数
- $html = '<ul class="woverflow layui-data-ul-b">';
- $orgs = $res['data'];
- if ($orgs) {
- foreach ($orgs as $k => $v) {
- $orgs[$k]['grawth'] = '';
- $orgs[$k]['name_grawth'] = $v['name'];
- $orgs[$k]['name'] = $v['name'];
- $index = (int)(mt_rand(100000,9999999).mt_rand(100000,9999999));
- if(in_array($v['id'],$orgids)){
- if ($v['value']) {
- $html .= '<li id="type'.$index.$v['id'].'" type="'.$type.'" onclick="getorgdata('.$v['id'].','.$index.')"><span class="layui_bm">'.$orgs[$k]['name_grawth'].'</span><span> : </span><span class="layui-bolu">'.$v['value'].'条</span></li>';
- }else{//没有数据不能点击
- $html .= '<li id="type'.$index.$v['id'].'" type="'.$type.'" ><span class="layui_bm">'.$orgs[$k]['name_grawth'].'</span><span> : </span><span class="layui-bolux">'.$v['value'].'条</span></li>';
- }
- }
-
- }
- $person_count_type = $type=='talkskill'||$type=='submit' ? $res['person']['all_count'] : ($org_id==$root_id ? $all_comment : $res['person']['all_comment_count']);
- // array_unshift($orgs,['name'=>$res['person']['name'],'value'=>$person_count_type]);
- }else{
- $person_count_type = $type=='talkskill'||$type=='submit' ? $res['person']['all_count'] : ($org_id==$root_id ? $all_comment : $res['person']['all_comment_count']);
- $orgs = [['name'=>$res['person']['name'],'value'=>$person_count_type]];
- $html .= '<span>暂无子部门</span>';
- }
- $res['data'] = $orgs;
- $res['ok'] = $sum==0 ? 0 : 1;
- $html .= '</ul>';
- $res['html'] = $html;
-
- $res['person_html'] = '<p id="person'.$org_id.'" type="'.$type.'" onclick="getperson('.$org_id.')" class="layui-p-bt">'.$res['person']['name'].':<span class="layui-bolu">'.$person_count_type.'条</span></p>';
- $res['html'] = $res['person_html'].$res['html'];
- //导航栏
- $org_info = org::where('id',$org_id)->value('path');
- $path = array_filter(explode('-',$org_info));
- $org_ids = org::where([['id','in',$path]])->field('id,name')->column('id,name','id');
- $paths = [];
- foreach ($path as $k => $v) {
- $arr = $org_ids[$v];
- $index = (int)(mt_rand(100000,9999999).mt_rand(100000,9999999));
- $paths[] = '<span style="color:#249efb;" id="type'.$index.$arr['id'].'" type="'.$type.'" onclick="getorgdata('.$arr['id'].','.$index.')">'.$arr['name'].'</span>';
- }
- // foreach ($org_ids as $k => $v) {
- // $index = (int)(mt_rand(100000,9999999).mt_rand(100000,9999999));
- // $paths[] = '<span style="color:#249efb;" id="type'.$index.$v['id'].'" type="'.$type.'" onclick="getorgdata('.$v['id'].','.$index.')">'.$v['name'].'</span>';
- // }
- $res['path'] = implode('/',$paths);
- $res['html'] = $res['html'].'<br/>'.$res['path'];
- return json_encode($res);
- }
- public function get_person(){
- $org_id = input('org_id',0);
- $org_id = $org_id ?: request()->employee->root_id;
- $type = input('type','talkskill');
- $w2[] = ['employee.org_id','=',$org_id];
- $w2[] = ['employee.root_id','=',request()->employee->root_id];
- $w2[] = ['talkskill.root_id','=',request()->employee->root_id];
- $w2[] = ['employee.state','=','在职'];
- $w2[] = ['del','=',0];
- $w2[] = ['approve','=',1];
- $person1 = TalkskillModel::withJoin(['employee'=>[]],'inner');
- $w3[] = ['org_id','=',$org_id];
- $w3[] = ['root_id','=',request()->employee->root_id];
- $w3[] = ['state','=','在职'];
- $person = Employee::where($w3)->field('name,id')->select()->toArray();
- if ($type=='talkskill') {
- $w2[] = ['talkskill.employee_id','>',0];
- $w2[] = ['talkskill.type','=','share'];
- $person1 = $person1->where($w2)
- // ->field('employee.org_id,talkskill.id,employee.uid,employee.id as eid,employee.name as ename')
- ->group('employee_id')
- ->column('count(*)','employee_id');
- // ->toArray();
- foreach ($person as $k => $v) {
- $person[$k]['value'] = isset($person1[$v['id']]) ? $person1[$v['id']] : 0;
- }
- }elseif ($type=='submit') {
- $w2[] = ['talkskill.employee_id','>',0];
- $w2[] = ['talkskill.type','=','submit'];
- $person1 = $person1->where($w2)
- // ->field('employee.org_id,talkskill.id,employee.uid,employee.id as eid,employee.name as ename')
- ->group('employee_id')
- ->column('count(*)','employee_id');
- // ->toArray();
- foreach ($person as $k => $v) {
- $person[$k]['value'] = isset($person1[$v['id']]) ? $person1[$v['id']] : 0;
- }
- }
- else{
- $person1 = $person1->where($w2)->field('employee.org_id,talkskill.id,employee.uid,employee.id as eid,employee.name as ename')->select()->toArray();
- $taids = $person1 ? array_column($person1,'id') : [];
- $w4[] = ['taid','in',$taids];
- $comment = TalkskillComment::where($w4)->group('taid')->column('count(*)','taid');
- $comment_all = [];
- foreach ($person1 as $k => &$v) {
- $v['comment_count'] = isset($comment[$v['id']]) ? $comment[$v['id']] : 0;
- $comment_all[$v['eid']] = isset($comment_all[$v['eid']]) ? $comment_all[$v['eid']]+$v['comment_count'] : $v['comment_count'];
- }
- foreach ($person as $k => $v) {
- $person[$k]['value'] = isset($comment_all[$v['id']]) ? $comment_all[$v['id']] : 0;
- }
- }
- $res['data'] = $person;
- $html = '';
- foreach ($person as $k => $v) {
- $html .= '<span>'.$v['name'].':'.$v['value'].'条</span> ';
- }
- $res['html'] = $html;
- //导航栏
- $org_info = org::where('id',$org_id)->value('path');
- $path = array_filter(explode('-',$org_info));
- $org_ids = org::where([['id','in',$path]])->field('id,name')->order('id asc')->select()->toArray();
- $paths = [];
- foreach ($org_ids as $k => $v) {
- $paths[] = '<span style="color:#249efb;" id="type'.$v['id'].'" type="'.$type.'" onclick="getorgdata('.$v['id'].')">'.$v['name'].'</span>';
- }
- $res['path'] = implode('/',$paths);
- $res['html'] = $res['html'].'<br/><br/><br/><br/><br/><br/>'.$res['path'];
- return json_encode($res);
- }
- /*
- * 一级获取场景
- */
- public function get_cate1($root_id)
- {
- $w[] = ['root_id','=',$root_id];
- $w[] = ['type','=','cate'];
- $w[] = ['pid','=',0];
- $data = TalkskillCates::where($w)->field('*,name label_name')->select();
- return $data;
- }
- /*
- * 集团后台话术场景
- */
- public function groupTalkskillLabel()
- {
- $param = request()->param();
- $root = isset($param['root_id']) ? $param['root_id'] : request()->employee->root_id;
- if (!Request::isAjax()) {
- $type = $this->get_cate1($root);
- View::assign('type', $type);
- View::assign('from',isset($param['from']) ? $param['from'] : 'add');
- View::assign('root_id',isset($param['root_id']) ? $param['root_id'] : request()->employee->root_id);
- return View::fetch();
- }
- $w[] = ['root_id','=',$root];
- $w[] = ['type','=','cate'];
- $w[] = ['pid','=',0];
- $w[] = ['from_type','=',0];//只能共享自建话术
- if (!empty($param['type'])) $w[] = ['id','=',$param['type']];
- $data = TalkskillCates::where($w)->field('*,name label_name')->page($param['page'] , $param['limit'])->order('id asc')->select()->toArray();
- $count = TalkskillCates::where($w)->count();
- //查询场景下的话术
- $where = [
- ['root_id', '=', $root],
- ['del', '=', 0],
- ['approve', '=', 1],
- ['content', '<>', ''],
- // ['from_type', '=', 0]//只能共享自建话术
- ];
- if (isset($param['keyword']) && $param['keyword']) {
- $where[] = ['title', 'like', '%' . $param['keyword'] . '%'];
- }
- $label_count = TalkskillModel::where($where)->group('cate1')->column('count(id)','cate1');
- $label_Maxtime = TalkskillModel::where($where)->group('cate1')->column('max(addtime)','cate1');
- //查询共享到的店面
- foreach ($data as &$v) {
- $v['talkill_count'] = isset($label_count[$v['name']]) ? $label_count[$v['name']] : 0;
- $v['update_time'] = isset($label_Maxtime[$v['name']]) ? $label_Maxtime[$v['name']] : '';
- $v['shareCompany'] = TalkskillCates::where([['root_id','<>',$root],['text','like','%@'.$v['id'].'%']])->group('root_id')->count();
- }
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $data, 'count' => $count]);
- }
- /*
- * 集团话术列表数据
- */
- public function groupTalkskillList()
- {
- if (!Request::isAjax()) {
- $param = request()->param();
- $root_id = !empty($param['root_id']) ? $param['root_id'] : request()->employee->root_id;
- View::assign('type', $param['type']);
- View::assign('from', $param['from']);
- View::assign('root_id', $param['root_id']);
- //二级分类
- $param['id'] = $param['type'];
- $w[] = ['type','=','cate'];
- $w[] = ['root_id','=',$root_id];
- $w[] = ['pid','=',$param['id']];
- $cate = TalkskillCates::where($w)->field('name,id')->order('id asc')->select()->toArray();
- view::assign('cate', $cate);
- //房屋类型
- $w1[] = ['type','=','house_type'];
- $w1[] = ['root_id','=',$root_id];
- $w1[] = ['pid','=',0];
- $house_type = TalkskillCates::where($w1)->field('name,id')->order('id asc')->select()->toArray();
- view::assign('house_type', $house_type);
- //适用人群
- $w3[] = ['root_id','=',$root_id];
- $user_cate = TalkskillUsersCate::where($w3)->field('name,id')->order('id asc')->select()->toArray();
- view::assign('user_cate', $user_cate);
- return View::fetch();
- }
- $param = Request::param();
- $cate1 = TalkskillCates::where('id',$param['type'])->value('name');
- $root_id = !empty($param['root_id']) ? $param['root_id'] : request()->employee->root_id;
- $where = [
- ['cate1', '=', $cate1],
- ['del', '=', 0],
- ['content', '<>', ''],
- ['approve', '=', 1],
- ['from_type', '=', 0],
- ['root_id', '=', $root_id]
- ];
- if (!empty($param['keyword'])) {
- $where[] = ['title', 'like', '%' . $param['keyword'] . '%'];
- }
- $sql = TalkskillModel::where($where);
- if (!empty($param['cate'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['cate'] . "' , cate2)");
- }
- if (!empty($param['house_type'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['house_type'] . "' , house_type)");
- }
- if (!empty($param['user_cate'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['user_cate'] . "' , user_cate)");
- }
- // 获取数据
- $list = $sql->page($param['page'], $param['limit'])->order('addtime desc')->select()->toArray();
- $count = $sql->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /*
- * 共享的店面
- */
- public function groupShareCompany()
- {
- if (!Request::isAjax()) {
- $id = request()->param('id');
- $from = request()->param('from');
- view::assign('id',$id);
- view::assign('from',$from);
- return View::fetch();
- }
-
-
- $param = request()->param();
- $from = $param['from'] == 'company' ? 'from2' : 'from1';
- $w[] = ['text','like','%@'.$param['id'].'%'];
- $w[] = ['pid','=',0];
- $text = TalkskillCates::where($w)->column('text,root_id');//共享/指派的所有店面和集团;
- $root_ids = [];
- foreach ($text as $k => $v) {
- $text = array_unique(array_filter(explode(',',$v['text'])));
- foreach ($text as $k2 => $v2) {
- $arr = explode('@',$v2);
- if (count($arr)==4 && $arr[3]==$from) {
- $root_ids[$v['root_id']] = $arr[2];//店面id=>时间
- }
- }
- }
- $where[] = ['root_id','in',array_keys($root_ids)];
-
-
- // $where[] = ['root_id','in',$root_ids];
- // if($param['from'] == 'company')
- // {
- // $companyId = Company::where('root_id', request()->employee->root_id)->value('id');
- // $lastCompany = Company::where('company_group',$companyId)->column('root_id');
- // // $where = [
- // // ['from_content_id','=',$param['id']],
- // // ['from_root_id','in',$lastCompany]
- // // ];
- // $where[] = ['root_id','in',$lastCompany];
- // }else{
- // // $where = [
- // // ['from_content_id','=',$param['id']],
- // // ['from_root_id','=',request()->employee->root_id]
- // // ];
- // $where[] = ['root_id','=',request()->employee->root_id];
- // }
- $data = Company::where($where)->page($param['page'],$param['limit'])->select();
- foreach ($data as $k1 => $v1) {
- $data[$k1]['addtime'] = $root_ids[$v1['root_id']];
- }
- $count = Company::where($where)->count();
- // $data = TalkskillLabel::with(['company'])->where($where)->page($param['page'],$param['limit'])->select();
- // $count = TalkskillLabel::with(['company'])->where($where)->count();
- return json(['code' => 0, 'data' => $data,'count'=>$count]);
- }
- /*
- * 集团后台话术店面共享
- */
- public function groupCompanyTalkskill()
- {
- if (!Request::isAjax()) {
- return View::fetch();
- }
- $param = Request::param();
- //查询店面
- $companyId = Company::where('root_id', request()->employee->root_id)->value('id');
- $data = Company::where('company_group',$companyId)->field('root_id,company_name')->page($param['page'],$param['limit'])->select()->toArray();
- $count = Company::where('company_group',$companyId)->count();
- //内容
- $root_id = array_column($data,'root_id');
- $train = TalkskillModel::where([['root_id','in',$root_id],['del','=',0],['approve', '=', 1],['content', '<>', ''],['from_type','=',0]])->group('root_id')->column('count(id)','root_id');
- foreach($data as &$v)
- {
- $v['count'] = isset($train[$v['root_id']])?$train[$v['root_id']]:0;
- }
- return json(['code' => 0, 'data' => $data, 'count' => $count]);
- }
- /*
- * 指派
- */
- public function groupAssign()
- {
- $param = request()->param();
- if (!Request::isAjax()) {
- View::assign('id',$param['id']);
- View::assign('from',$param['from']);
- View::assign('root_id',isset($param['root_id'])?$param['root_id']:'');
- return View::fetch();
- }
- $id = input('id',0);
-
- $companyId = Company::where('root_id', request()->employee->root_id)->value('id');
- $where = [['company_group','=',$companyId]];
- if ($param['from'] == 'company') {
- //排除自己共享给自己的课程
- $companyId = Company::where('root_id', request()->employee->root_id)->value('id');
- $lastCompany = Company::where('company_group',$companyId)->column('root_id');
- $label = TalkskillCates::where([['id','=',$id],['root_id','in',$lastCompany]])->find();
- $where[] = ['root_id','<>',$label->root_id];
- }
-
- $data = Company::where($where)->field('root_id,company_name')->page($param['page'],$param['limit'])->select();
- $count = Company::where($where)->count();
- return json(['code' => 0, 'data' => $data,'count'=>$count]);
- }
- /*
- * 集团指派
- */
- public function groupAssignAdd()
- {
- $param = request()->param();
- //共享时查询关联数据
- if($param['from'] == 'company')//共享
- {
- $companyId = Company::where('root_id', request()->employee->root_id)->value('id');
- $lastCompany = Company::where('company_group',$companyId)->column('root_id');
- $where = [
- ['id','=',$param['id']],
- ['root_id','in',$lastCompany]
- ];
- }else{//指派
- $where = [
- ['id','=',$param['id']],
- ['root_id','=',request()->employee->root_id]
- ];
- }
-
- $talkskillLabel = TalkskillCates::where($where)->find();
- if(!$talkskillLabel) return json(['code' => 1, 'msg' => '数据不存在']);
- Db::startTrans();
- try {
- $ids = explode(',',$param['ids']);//店面id
- //场景,二级分类,话术
- foreach($ids as $v)
- {
- $from = $param['from'] == 'add' ? 1 : 2;
- $this->share_cate1($talkskillLabel,$v,$from);
- }
- Db::commit();
- return json(['code' => 0, 'msg' => '操作成功']);
- } catch (\Exception $e) {
- Db::rollback();
- return json(['code' => 1, 'msg' => '操作失败']);
- }
-
- }
- /*
- * 共享复制场景
- * $data 场景信息
- * $root_id 复制的id
- */
- public function share_cate1($data,$root_id,$from)
- {
- //如果场景名称已存在则修改
- //复制场景
- $w[] = [
- ['root_id','=',$root_id],
- ['name','=',$data->name],
- ['pid','=',0],
- ['type','=','cate']
- ];
- $info = TalkskillCates::where($w)->findOrEmpty();
- $time = '@'.date('Y-m-d H:i:s').'@from'.$from;
- if ($info->isEmpty()) {
- $pid = TalkskillCates::insertGetId([
- 'pid' => 0,
- 'name' => $data->name,
- 'type' => 'cate',
- 'root_id' => $root_id,
- 'from_root_id' => $data->root_id,
- 'from_content_id' => $data->id,
- 'from_type' => $from,
- 'text' => $data->root_id.'@'.$data->id.$time
- ]);
- }else{
- $pid = $info->id;
- $arr = $data->root_id.'@'.$data->id.$time;
- $text = $info->text ? $info->text.','.$arr : $arr;
- $info->text = $text;
- $info->save();
- }
- //共享二级分类
- $cate2 = TalkskillCates::where('pid',$data->id)->column('id,name');//要复制的分类
- $cate2s = TalkskillCates::where('pid',$pid)->column('name');//原有分类
- $save = [];
- foreach ($cate2 as $k9 => $v9) {
- if (!$cate2s || !in_array($v9['name'],$cate2s)) {
- $save[] = [
- 'pid' => $pid,
- 'name' => $v9['name'],
- 'type' => 'cate',
- 'root_id' => $root_id,
- 'from_root_id' => $data->root_id,
- 'from_content_id' => $v9['id'],
- 'from_type' => $from,
- 'text' => $data->root_id.'@'.$v9['id'].$time
- ];
- }elseif ($cate2s && in_array($v9['name'],$cate2s)) {//
- $cate2_info = TalkskillCates::where([['pid','=',$pid],['name','=',$v9['name']]])->findOrEmpty();
- if (!$cate2_info->isEmpty()) {
- $arr = $data->root_id.'@'.$v9['id'].$time;
- $text = $cate2_info->text ? $cate2_info->text.','.$arr : $arr;
- $cate2_info->text = $text;
- $cate2_info->save();
- }
- }
- }
- if($save) TalkskillCates::insertAll($save);
-
- //复制话术
- $n_talk = TalkskillModel::where([['root_id','=',$root_id],['from_content_id','>',0]])->column('from_content_id');//排除已经复制的话术
- $talkskill = TalkskillModel::where([['cate1','=',$data->name],['root_id','=',$data->root_id],['id','not in',$n_talk]])->column('*');
- $talk = [];
- foreach ($talkskill as $k3 => $v3) {
- $talk[] = [
- 'title' => $v3['title'],
- 'content' => $v3['content'],
- 'root_id' => $root_id,
- 'type' => 'admin',
- 'employee_id' => request()->employee->id,
- 'imgs' => $v3['imgs'],
- 'videos' => $v3['videos'],
- 'approve' => 1,
- 'from_type' => $from,
- 'from_root_id' => $data->root_id,
- 'from_content_id' => $v3['id'],
- 'approve_from' => 0,
- 'user_cate' => $v3['user_cate'],
- 'house_type' => $v3['house_type'],
- 'cate1' => $v3['cate1'],
- 'cate2' => $v3['cate2']
- ];
- }
- if($talk) TalkskillModel::insertAll($talk);
- return true;
- }
- /*
- * 集团指派
- */
- // public function groupAssignAdd()
- // {
- // $param = request()->param();
- // //共享时查询关联数据
- // if($param['from'] == 'company')
- // {
- // $companyId = Company::where('root_id', request()->employee->root_id)->value('id');
- // $lastCompany = Company::where('company_group',$companyId)->column('root_id');
- // $where = [
- // ['id','=',$param['id']],
- // ['root_id','in',$lastCompany]
- // ];
- // }else{
- // $where = [
- // ['id','=',$param['id']],
- // ['root_id','=',request()->employee->root_id]
- // ];
- // }
-
- // $talkskillLabel = TalkskillLabel::where($where)->find();
- // if(!$talkskillLabel) return json(['code' => 1, 'msg' => '数据不存在']);
- // Db::startTrans();
- // try {
- // $ids = explode(',',$param['ids']);
- // foreach($ids as $v)
- // {
- // $from = $param['from'] == 'add' ? 1 : 2;
- // //场景共享
- // $newTypeId = TalkskillLabel::insertGetId([
- // 'from_type'=>$from,
- // 'from_root_id'=>$talkskillLabel['root_id'],
- // 'from_content_id'=>$talkskillLabel['id'],
- // 'label_name'=>$talkskillLabel['label_name'] ,
- // 'root_id'=>$v
- // ]);
- // $talkskill = TalkskillModel::where([
- // ['label','=',$talkskillLabel['id']],
- // ['del', '=', 0],
- // ['content', '<>', ''],
- // ['approve', '=', 1],
- // ['from_type', '=', 0],
- // ])->column('*');
- // $newTalkskill = [];
- // //话术数据
- // foreach($talkskill as $val)
- // {
- // $data = [
- // 'title' => $val['title'],
- // 'content' => $val['content'],
- // 'label' => $newTypeId,
- // 'root_id' => $v,
- // 'type' => 'admin',
- // 'approve' => $val['approve'],
- // 'from_type' => $from,
- // 'from_root_id' => $val['root_id'],
- // 'from_content_id' => $val['id'],
- // ];
- // $newTalkskill[] = $data;
- // }
- // TalkskillModel::insertAll($newTalkskill);
- // }
- // Db::commit();
- // return json(['code' => 0, 'msg' => '操作成功']);
- // } catch (\Exception $e) {
- // Db::rollback();
- // return json(['code' => 1, 'msg' => '操作失败']);
- // }
-
- // }
- /*
- * 审核记录
- */
- public function history()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only(['type'=>'share','org_id'=>0,'cate'=>'']);
- View::assign('type', $param['type']);
- $org = Org::where([['path', 'like', request()->employee->root_id . '-%']])->field('id,name,level')->order('path asc')->select()->toArray();
- view::assign('org', $org);
- $w1[] = [['root_id','=',request()->employee->root_id],['uid','>',0]];
- if ($param['type']=='share') {
- $eid = TalkskillModel::where([['del','=',0],['root_id','=',$root_id],['employee_id','>',0],['type','=','share'],['approve','>',0]])->group('employee_id')->column('employee_id');
- $w1[] = ['id','in',$eid];
- }else{
- $tid = TalkskillModel::where([['del','=',0],['root_id','=',$root_id],['employee_id','>',0],['type','=','share'],['approve','>',0]])->column('id');
- $uid = TalkskillComment::where([['root_id','=',$root_id],['uid','>',0],['approve','>',0],['taid','in',$tid]])->group('uid')->column('uid');
- $w1[] = ['uid','in',$uid];
- }
- if ($param['cate']) {
- if ($param['org_id']) {
- $w1[] = ['org_id','=',$param['org_id']];
- }
- $employee = Employee::where($w1)->field('id,name')->select()->toArray();
- return json(['code' => 0,'data'=>$employee]);
- }else{
- $employee = Employee::where($w1)->field('id,name')->select()->toArray();
- }
-
- view::assign('employee', $employee);
- $data['count'] = $data['pass_count'] = $data['no_count'] = 0;
- if ($param['type']=='share') {
- $w[] = ['root_id','=',$root_id];
- $w[] = ['approve','>',0];
- $w[] = ['type','=','share'];
- $w[] = ['employee_id','>',0];
- $w[] = ['del','=',0];
- $data['count'] = TalkskillModel::where($w)->count();
- $data['pass_count'] = TalkskillModel::where($w)->where('approve',1)->count();
- $data['no_count'] = TalkskillModel::where($w)->where('approve',2)->count();
- }else{
- $w[] = ['root_id','=',$root_id];
- $w[] = ['approve','>',0];
- $w[] = ['uid','>',0];
- $data['count'] = TalkskillComment::where($w)->count();
- $data['pass_count'] = TalkskillComment::where($w)->where('approve',1)->count();
- $data['no_count'] = TalkskillComment::where($w)->where('approve',2)->count();
- }
- view::assign('data', $data);
- return View::fetch();
- }
- /*
- * 审核记录数据接口
- */
- public function history_list()
- {
- $param = Request::only(['type'=>'share','page'=>1,'limit'=>10,'org'=>0,'cate'=>0,'employee_id'=>0,'time'=>'']);
- $root_id = request()->employee->root_id;
- if($param['cate']) $w[] = ['approve','=',$param['cate']];
- if($param['time']){
- $time = explode(' - ',$param['time']);
- $w[] = ['addtime','between',[$time[0].' 00:00:00',$time[1].' 23:59:59']];
- }
- $w[] = ['root_id','=',$root_id];
- $w[] = ['approve','>',0];
- //话术审核
- if ($param['type']=='share') {
- if($param['employee_id']) $w[] = ['employee_id','=',$param['employee_id']];
- $w[] = ['type','=','share'];
- $w[] = ['employee_id','>',0];
- $w[] = ['del','=',0];
- if ($param['org']) {
- $eids = Employee::where([['org_id','=',$param['org']]])->column('id');
- $w[] = ['employee_id','in',$eids];
- }
- $res = TalkskillModel::with(['employee','approveEmployee'])->order('id desc')->where($w)->page($param['page'],$param['limit'])->select();
- foreach ($res as $k => $v) {
- $v->status = $v->approve==1 ? '通过' : '驳回';
- $v->org_name = isset($v->employee->org->name) ?$v->employee->org->name : '';
- $v->approve_name = (strtotime($v->aprove_time)<=1656665072 || $v->approve_from==0) ? $v->opt_name : $v->approve_name;
- $v->approve_from = (strtotime($v->aprove_time)<=1656665072 || $v->approve_from==0) ? 0 : 1;
- }
- $count = TalkskillModel::where($w)->count();
-
- }else{//回答审核
- if($param['employee_id']){
- $wx[] = ['id','=',$param['employee_id']];
- $wx[] = ['root_id','=',$root_id];
- $uid = Employee::where($wx)->value('uid');
- $w[] = ['uid','=',$uid];
- }
- if ($param['org']) {
- $eids = Employee::where([['org_id','=',$param['org']]])->column('uid');
- $w[] = ['uid','in',$eids];
- }
- $w[] = ['uid','>',0];
- $res = TalkskillComment::with(['talkskills'=>function($query) use ($root_id){
- $query->where([['root_id','=',$root_id]])->bind(['title']);
- },'approveEmployee','employee'=>function($query) use ($root_id){
- $query->where([['root_id','=',$root_id], ['state', 'in', ['在职']]]);
- }])->where($w)->order('id desc')->page($param['page'],$param['limit'])->field('*,comments content')->visible([
- ])->select();
- $count = TalkskillComment::where($w)->count();
- foreach ($res as $k => $v) {
- $v->name = isset($v->employee->name) ?$v->employee->name : '';
- $v->status = $v->approve==1 ? '通过' : '驳回';
- $v->org_name = isset($v->employee->org->name) ?$v->employee->org->name : '';
- $v->approve_name = (strtotime($v->aprove_time)<=1656665072 || $v->approve_from==0) ? $v->opt_name : $v->approve_name;
- $v->approve_from = (strtotime($v->aprove_time)<=1656665072 || $v->approve_from==0) ? 0 : 1;
- }
- }
- return json(['code' => 0, 'data'=>$res,'count'=>$count,'msg' => '操作成功']);
- }
- /*
- * 使用人群
- */
- public function person()
- {
- return View::fetch();
- }
- /*
- * 使用人群列表
- */
- public function person_list()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only(['page' => 1, 'limit' => 10]);
- $w[] = ['root_id', '=', $root_id];
- $list = TalkskillUsersCate::where($w)->page($param['page'], $param['limit'])->order('id asc')->select();
- $count = TalkskillUsersCate::where($w)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count]);
- }
-
- /*
- * 使用人群添加
- */
- public function person_add()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only(['name' => '']);
- $param['name'] = str_replace(' ','',$param['name']);
- $w[] = ['root_id', '=', $root_id];
- $w[] = ['name', '=', $param['name']];
- $find = TalkskillUsersCate::where($w)->findOrEmpty();
- if (!$find->isEmpty()) return json(['code' => 1, 'data' => '使用人群已存在', 'msg' => '使用人群已存在']);
- $id = TalkskillUsersCate::insertGetId(['root_id' => $root_id, 'name' => $param['name']]);
- return json(['code' => 0, 'data' => '添加成功', 'msg' => '添加成功','id'=>$id]);
- }
- /*
- * 使用人群编辑
- */
- public function person_edit()
- {
- $root_id = request()->employee->root_id;
- $param = Request::only(['id' => 0, 'name' => '']);
- $w[] = ['root_id', '=', $root_id];
- $w[] = ['id', '<>', $param['id']];
- $w[] = ['name', '=', $param['name']];
- $find = TalkskillUsersCate::where($w)->findOrEmpty();
- if (!$find->isEmpty()) return json(['code' => 1, 'data' => '使用人群已存在', 'msg' => '使用人群已存在']);
- $name = TalkskillUsersCate::where('id', $param['id'])->value('name');
- TalkskillUsersCate::where('id', $param['id'])->update(['name' => $param['name']]);
- $w1[] = ['user_cate', '=', $name];
- $w1[] = ['root_id', '=', $root_id];
- TalkskillModel::where($w1)->update(['user_cate' => $param['name']]);
- TalkskillComment::where($w1)->update(['user_cate' => $param['name']]);
- return json(['code' => 0, 'data' => '修改成功', 'msg' => '修改成功']);
- }
- /*
- * 字典管理
- */
- public function dictionary(){
- return View::fetch();
- }
- /*
- * type 1场景 ,2房屋类型,3适用人群,4二级分类,新增页下拉
- */
- public function dictionary_list(){
-
- $root_id = request()->employee->root_id;
- $param = Request::only(['type' => 1, 'page'=>1, 'limit'=>10, 'pid'=>0, 'scene_type'=> '']);
- if ($param['type']==1) {
- //场景列表
- $w[] = ['pid','=',0];
- $w[] = ['type','=','cate'];
- $w[] = ['root_id','=',$root_id];
- if ($param['scene_type']){
- $w[] = ['scene_type', '=', $param['scene_type']];
- }
- $list = TalkskillCates::where($w)->field('name value,name,id')->order('id asc')->page($param['page'],$param['limit'])->select();
- $count = TalkskillCates::where($w)->count();
- } elseif ($param['type']==2) {
- //房屋类型列表
- $w[] = ['pid','=',0];
- $w[] = ['type','=','house_type'];
- $w[] = ['root_id','=',$root_id];
- $list = TalkskillCates::where($w)->field('name value,name,id')->order('id asc')->page($param['page'],$param['limit'])->select();
- $count = TalkskillCates::where($w)->count();
-
- } elseif ($param['type']==3) {
- //适用人群列表
- $w[] = ['root_id','=',$root_id];
- $list = TalkskillUsersCate::where($w)->field('name value,name,id')->page($param['page'],$param['limit'])->select();
- $count = TalkskillUsersCate::where($w)->count();
- } elseif ($param['type']==4 && $param['pid']) {
- //二级分类
- $w[] = ['pid','=',$param['pid']];
- $w[] = ['type','=','cate'];
- $w[] = ['root_id','=',$root_id];
- $list = TalkskillCates::where($w)->field('name value,name,id')->order('id asc')->page($param['page'],$param['limit'])->select();
- $count = TalkskillCates::where($w)->count();
- } else{
- $list = [];
- $count = 0;
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count]);
- }
- /*
- * 字典管理-场景列表
- */
- public function dictionary_ajax_cate(){
-
- $root_id = request()->employee->root_id;
- $param = Request::only(['page'=>1,'limit'=>10]);
- //一级分类和二级分类
- $w[] = ['type','=','cate'];
- $w[] = ['root_id','=',$root_id];
- $w[] = ['pid','=',0];
- $list = TalkskillCates::where($w)->field('name,id,show,scene_type')->page($param['page'],$param['limit'])->order('id asc')->select()->toArray();
- $count = TalkskillCates::where($w)->count();
- $w1[] = ['pid','in',array_column($list,'id')];
- $child = TalkskillCates::where($w1)->group('pid')->column('count(id) count','pid');
- foreach ($list as $k => $v) {
- $list[$k]['count'] = isset($child[$v['id']]) ? $child[$v['id']] : 0;
- }
- return json(['code' => 0, 'data' => $list, 'count' => $count]);
-
- }
- /*
- * 字典管理-房屋类型
- */
- public function dictionary_ajax_house_type(){
-
- $root_id = request()->employee->root_id;
- $param = Request::only(['page'=>1,'limit'=>10]);
- //房屋类型
- $w[] = ['type','=','house_type'];
- $w[] = ['root_id','=',$root_id];
- $w[] = ['pid','=',0];
- $list = TalkskillCates::where($w)->field('name,id,show')->page($param['page'],$param['limit'])->order('id asc')->select()->toArray();
- $count = TalkskillCates::where($w)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count]);
-
- }
- /*
- * 字典管理-适用人群
- */
- public function dictionary_ajax_user_cate(){
-
- $root_id = request()->employee->root_id;
- $param = Request::only(['page'=>1,'limit'=>10]);
- //房屋类型
- $w[] = ['root_id','=',$root_id];
- $list = TalkskillUsersCate::where($w)->field('name,id,show')->page($param['page'],$param['limit'])->order('id asc')->select()->toArray();
- $count = TalkskillUsersCate::where($w)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count]);
- }
- /*
- * 字典管理-新增数据
- */
- public function dictionary_ajax_add(){
-
- $root_id = request()->employee->root_id;
- $param = Request::only(['type'=>0, 'name'=>'', 'is_chosen'=> '']);
- if ($param['type']==0 && $param['name']) {
- //新增场景
- $w = [
- ['type','=','cate'],
- ['pid','=',0],
- ['root_id','=',$root_id],
- ['name','=',$param['name']]
- ];
- $info = TalkskillCates::where($w)->findOrEmpty();
- if(!$info->isEmpty()) return json(['code' => 1, 'data' => '场景已存在','msg'=>'场景已存在']);
- $save = [
- 'pid' => 0,
- 'name' => $param['name'],
- 'type' => 'cate',
- 'root_id' => $root_id
- ];
- if ($param['is_chosen']) {
- $save['scene_type'] = 'chosen';
- }
- TalkskillCates::insertGetId($save);
- }elseif($param['type']==1 && $param['name']){
- //房屋类型
- $w = [
- ['type','=','house_type'],
- ['pid','=',0],
- ['root_id','=',$root_id],
- ['name','=',$param['name']]
- ];
- $info = TalkskillCates::where($w)->findOrEmpty();
- if(!$info->isEmpty()) return json(['code' => 1, 'data' => '房屋类型已存在','msg'=>'房屋类型已存在']);
- $save = [
- 'pid' => 0,
- 'name' => $param['name'],
- 'type' => 'house_type',
- 'root_id' => $root_id
- ];
- TalkskillCates::insertGetId($save);
- } elseif ($param['type']==2 && $param['name']) {
- //适用部门
- $w = [
- ['root_id','=',$root_id],
- ['name','=',$param['name']]
- ];
- $info = TalkskillUsersCate::where($w)->findOrEmpty();
- if(!$info->isEmpty()) return json(['code' => 1, 'data' => '适用部门已存在','msg'=>'适用部门已存在']);
- $save = [
- 'name' => $param['name'],
- 'root_id' => $root_id
- ];
- TalkskillUsersCate::insertGetId($save);
- }else{
- return json(['code' => 1, 'data' => '保存失败','msg'=>'保存失败']);
- }
- return json(['code' => 0, 'data' => '保存成功','msg'=>'保存成功']);
- }
- /*
- * 字典管理-编辑数据
- */
- public function dictionary_ajax_edit(){
-
- $root_id = request()->employee->root_id;
- $param = Request::only(['type'=>0, 'name'=>'', 'id'=>0, 'is_chosen']);
- if ($param['type']==0 && $param['name']) {
- $where = [
- ['root_id','=',$root_id],
- ['id','=',$param['id']]
- ];
- $info = $find = TalkskillCates::where($where)->findOrEmpty();
- if($info->isEmpty()) return json(['code' => 1, 'data' => '数据错误', 'msg' => '数据错误']);
- //新增场景
- $w = [
- ['type','=','cate'],
- ['pid','=',0],
- ['root_id','=',$root_id],
- ['name','=',$param['name']],
- ['id','<>',$param['id']]
- ];
- $info = TalkskillCates::where($w)->findOrEmpty();
- if(!$info->isEmpty()) return json(['code' => 1, 'data' => '场景已存在', 'msg' => '场景已存在']);
- $save['name'] = $param['name'];
- if (isset($param['is_chosen'])) {
- $save['scene_type'] = '';
- if ($param['is_chosen']) {
- $save['scene_type'] = 'chosen';
- }
- }
- TalkskillCates::where('id',$param['id'])->update($save);
- //修改
- $wt = [
- ['root_id','=',$root_id],
- ['cate1','=',$find->name],
- ];
- TalkskillModel::where($wt)->update(['cate1'=>$param['name']]);
- }elseif($param['type']==1 && $param['name']){
- $where = [
- ['root_id','=',$root_id],
- ['id','=',$param['id']]
- ];
- $info = $find = TalkskillCates::where($where)->findOrEmpty();
- if($info->isEmpty()) return json(['code' => 1, 'data' => '数据错误', 'msg' => '数据错误']);
- //
- $w = [
- ['type','=','house_type'],
- ['pid','=',0],
- ['root_id','=',$root_id],
- ['name','=',$param['name']],
- ['id','<>',$param['id']]
- ];
- $info = TalkskillCates::where($w)->findOrEmpty();
- if(!$info->isEmpty()) return json(['code' => 1, 'data' => '房屋类型已存在', 'msg' => '房屋类型已存在']);
- TalkskillCates::where('id',$param['id'])->update(['name'=>$param['name']]);
- //修改话术中的房屋类型
- $talk = TalkskillModel::where([['root_id','=',$root_id],['house_type','like','%'.$find->name.'%']])->column('id,house_type');
- foreach ($talk as $v) {
- $arr = explode(',',$v['house_type']);
- if (in_array($find->name,$arr)) {
- $arr = array_diff($arr,[$find->name]);
- $arr[] = $param['name'];
- TalkskillModel::where('id',$v['id'])->update(['house_type'=>implode(',',$arr)]);
- }
- }
- } elseif ($param['type']==2 && $param['name']) {
- $where = [
- ['root_id','=',$root_id],
- ['id','=',$param['id']]
- ];
- $info = $find = TalkskillUsersCate::where($where)->findOrEmpty();
- if($info->isEmpty()) return json(['code' => 1, 'data' => '数据错误', 'msg' => '数据错误']);
- //适用部门
- $w = [
- ['root_id','=',$root_id],
- ['name','=',$param['name']],
- ['id','<>',$param['id']]
- ];
- $info = TalkskillUsersCate::where($w)->findOrEmpty();
- if(!$info->isEmpty()) return json(['code' => 1, 'data' => '适用部门已存在', 'msg' => '适用部门已存在']);
- TalkskillUsersCate::where('id',$param['id'])->update(['name'=>$param['name']]);
- //修改话术中的适用部门
- $talk = TalkskillModel::where([['root_id','=',$root_id],['user_cate','like','%'.$find->name.'%']])->column('id,user_cate');
- foreach ($talk as $v) {
- $arr = explode(',',$v['user_cate']);
- if (in_array($find->name,$arr)) {
- $arr = array_diff($arr,[$find->name]);
- $arr[] = $param['name'];
- TalkskillModel::where('id',$v['id'])->update(['user_cate'=>implode(',',$arr)]);
- }
- }
- }else{
- return json(['code' => 1, 'data' => '编辑失败','msg'=>'编辑失败']);
- }
- return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
- }
- /*
- * 新增话术新页面
- */
- public function new_add_talkskill(){
- $id = input('id',0);
- View::assign('id',$id);
- $name = input('name','');
- View::assign('name',$name);
- return View::fetch();
- }
- /*
- * 新增话术新页面下拉
- */
- public function new_add_talkskill_select(){
-
- $root_id = request()->employee->root_id;
- $param = Request::only(['id'=>0]);
- //二级分类
- $w[] = ['type','=','cate'];
- $w[] = ['root_id','=',$root_id];
- $w[] = ['pid','=',$param['id']];
- $cate = TalkskillCates::where($w)->field('name,name value,id')->order('id asc')->select()->toArray();
- $data['cate2'] = $cate;
- //房屋类型
- $w1[] = ['type','=','house_type'];
- $w1[] = ['root_id','=',$root_id];
- $w1[] = ['pid','=',0];
- $house_type = TalkskillCates::where($w1)->field('name,name value,id')->order('id asc')->select()->toArray();
- $data['house_type'] = $house_type;
- //适用人群
- $w3[] = ['root_id','=',$root_id];
- $user_cate = TalkskillUsersCate::where($w3)->field('name,name value,id')->order('id asc')->select()->toArray();
- $data['user_cate'] = $user_cate;
- return json(['code' => 0, 'data' => $data]);
- }
- /*
- * 二级分类列表新页面
- */
- public function cate2_view(){
- $id = input('id',0);
- View::assign('id',$id);
- return View::fetch();
- }
- /*
- * 获取二级分类列表
- */
- public function get_cate2_list(){
- $param = Request::only(['page'=>1,'limit'=>10,'id'=>0]);
- $root_id = request()->employee->root_id;
- $w = [
- ['pid','=',$param['id']],
- ['root_id','=',$root_id]
- ];
- $list = TalkskillCates::where($w)->page($param['page'],$param['limit'])->order('id asc')->select()->toArray();
- $count = TalkskillCates::where($w)->count();
- return json(['code' => 0, 'data' => $list,'count'=>$count]);
- }
- /*
- * 二级分类编辑
- */
- public function cate2_edit(){
- $param = Request::only(['name'=>'','id'=>0,'pid'=>0]);
- $root_id = request()->employee->root_id;
- $w = [
- ['root_id','=',$root_id],
- ['type','=','cate'],
- ['pid','>',0]
- ];
- if ($param['id']) {
- $w[] = ['id','=',$param['id']];
- $info = TalkskillCates::where($w)->findOrEmpty();
- if($info->isEmpty()) return json(['code' => 1, 'data' => '数据不存在', 'msg' => '数据不存在']);
- }
- $w1[] = ['name','=',$param['name']];
- $w1[] = ['root_id','=',$root_id];
- $w1[] = ['type','=','cate'];
- $w1[] = ['pid','=',$param['pid']];
- if ($param['id']) {
- $w1[] = ['id','<>',$param['id']];
- }
- $info = TalkskillCates::where($w1)->findOrEmpty();
- if(!$info->isEmpty()) return json(['code' => 1, 'data' => '分类已存在', 'msg' => '分类已存在']);
- if ($param['id']) {
- $cate1 = TalkskillCates::where('id',$param['pid'])->value('name');
- $cate2 = TalkskillCates::where('id',$param['id'])->value('name');
- TalkskillCates::where('id',$param['id'])->update(['name'=>$param['name']]);
-
- //修改话术二级分类
- $talk = TalkskillModel::where([['root_id','=',$root_id],['cate1','=',$cate1],['cate2','like','%'.$cate2.'%']])->column('id,cate2');
- foreach ($talk as $v) {
- $arr = explode(',',$v['cate2']);
- if (in_array($cate2,$arr)) {
- $arr = array_diff($arr,[$cate2]);
- $arr[] = $param['name'];
- TalkskillModel::where('id',$v['id'])->update(['cate2'=>implode(',',$arr)]);
- }
- }
- return json(['code' => 0, 'data' => '修改成功', 'msg' => '修改成功']);
- }else{
- TalkskillCates::insertGetId([
- 'pid' => $param['pid'],
- 'name' => $param['name'],
- 'type' => 'cate',
- 'root_id' => $root_id
- ]);
- return json(['code' => 0, 'data' => '保存成功', 'msg' => '保存成功']);
- }
- }
- /*
- * 场景删除
- */
- public function cate_del()
- {
- $param = Request::param();
- if($param['type'] == 2)
- {
- $data = TalkskillUsersCate::where(['root_id'=>request()->employee->root_id,'id'=>$param['id']])->find();
- }else{
- $data = TalkskillCates::where(['root_id'=>request()->employee->root_id,'id'=>$param['id']])->find();
- }
- if(empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
- Db::startTrans();
- try {
- if($param['type'] == 0)
- {
- //场景是否存在其它分类
- $type_id = TalkskillCates::where(['root_id'=>request()->employee->root_id,'pid'=>0,'show'=>1,'type'=>'cate'])->value('id');
- if(empty($type_id)) $type_id = TalkskillCates::insertGetId(['pid'=>0,'name'=>'其它','root_id'=>request()->employee->root_id,'show'=>1,'type'=>'cate']);
- //更新关联内容
- TalkskillModel::where(['root_id'=>request()->employee->root_id,'cate1'=>$data['name']])->update(['cate1'=>'其它']);
- TalkskillChosen::where(['root_id'=> request()->employee->root_id, 'cate1'=> $data['id']])->update(['cate1'=> $type_id]);
- TalkskillSuccess::where(['root_id'=> request()->employee->root_id, 'cate1'=> $data['id']])->update(['cate1'=> $type_id]);
- TalkskillCates::where(['root_id'=>request()->employee->root_id,'pid'=>$data['id'],'type'=>'cate'])->update(['pid'=>$type_id]);
- //去重
- $groupId = TalkskillCates::where(['root_id'=>request()->employee->root_id,'pid'=>$type_id,'show'=>1,'type'=>'cate'])->min('id');
- TalkskillCates::where([['type','=','cate'],['root_id','=',request()->employee->root_id],['pid','=',$type_id],['show','=',1],['id','<>',$groupId]])->delete();
- //删除分类
- if($data['scene_type']=='chosen'){
- TalkskillCates::where(['root_id'=>request()->employee->root_id,'id'=>$type_id,'type'=>'cate'])->update(['scene_type'=>'chosen']);
- }
- $data->delete();
- }elseif($param['type'] == 1){
- //房屋类型是否存在其它分类
- $type_id = TalkskillCates::where(['root_id'=>request()->employee->root_id,'pid'=>0,'show'=>1,'type'=>'house_type'])->value('id');
- if(empty($type_id)) $type_id = TalkskillCates::insertGetId(['pid'=>0,'name'=>'其它','root_id'=>request()->employee->root_id,'show'=>1,'type'=>'house_type']);
- $for = TalkskillModel::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET('" . $data['name'] . "' , house_type)")->field('id,house_type')->select();
- foreach($for as $item)
- {
- $string = str_replace($data['name'],"其它",$item['house_type']);
- TalkskillModel::where(['root_id'=>request()->employee->root_id,'id'=>$item['id']])->update(['house_type'=>$string]);
- }
- $chosen_for = TalkskillChosen::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET('" . $data['id'] . "' , house_type)")->field('id,house_type')->select();
- foreach($chosen_for as $item)
- {
- $c_old_house_type = explode(',', $item['house_type']);
- foreach ($c_old_house_type as $k => $v){
- if($v == $data['id']){
- $c_old_house_type[$k] = $type_id;
- }
- }
- $string = implode(',', $c_old_house_type);
- TalkskillChosen::where(['root_id'=>request()->employee->root_id, 'id'=> $item['id']])->save(['house_type'=> $string]);
- }
- $success_for = TalkskillSuccess::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET('" . $data['id'] . "' , house_type)")->field('id,house_type')->select();
- foreach($success_for as $item)
- {
- $s_old_house_type = explode(',', $item['house_type']);
- foreach ($s_old_house_type as $k => $v){
- if($v == $data['id']){
- $s_old_house_type[$k] = $type_id;
- }
- }
- $string = implode(',', $s_old_house_type);
- TalkskillSuccess::where(['root_id'=>request()->employee->root_id, 'id'=> $item['id']])->save(['house_type'=> $string]);
- }
- if($data['scene_type']=='chosen'){
- TalkskillCates::where(['root_id'=>request()->employee->root_id,'id'=>$type_id,'type'=>'house_type'])->update(['scene_type'=>'chosen']);
- }
- $data->delete();
- }elseif($param['type'] == 2){
- //适用部门是否存在其它分类
- $type_id = TalkskillUsersCate::where(['root_id'=>request()->employee->root_id,'show'=>1])->value('id');
- if(empty($type_id)) $type_id = TalkskillUsersCate::insertGetId(['name'=>'其它','root_id'=>request()->employee->root_id,'show'=>1]);
- $for = TalkskillModel::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET('" . $data['name'] . "' , user_cate)")->field('id,user_cate')->select();
- foreach($for as $item)
- {
- $string = str_replace($data['name'],"其它",$item['user_cate']);
- TalkskillModel::where(['root_id'=>request()->employee->root_id,'id'=>$item['id']])->update(['user_cate'=>$string]);
- }
- $chosen_for = TalkskillChosen::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET('" . $data['id'] . "' , user_cate)")->field('id,user_cate')->select();
- foreach($chosen_for as $item)
- {
- $c_old_user_cate = explode(',', $item['user_cate']);
- foreach ($c_old_user_cate as $k => $v){
- if($v == $data['id']){
- $c_old_user_cate[$k] = $type_id;
- }
- }
- $string = implode(',', $c_old_user_cate);
- TalkskillChosen::where(['root_id'=>request()->employee->root_id, 'id'=> $item['id']])->save(['user_cate'=> $string]);
- }
- $success_for = TalkskillSuccess::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET('" . $data['id'] . "' , user_cate)")->field('id,user_cate')->select();
- foreach($success_for as $item)
- {
- $s_old_user_cate = explode(',', $item['user_cate']);
- foreach ($s_old_user_cate as $k => $v){
- if($v == $data['id']){
- $s_old_user_cate[$k] = $type_id;
- }
- }
- $string = implode(',', $s_old_user_cate);
- TalkskillSuccess::where(['root_id'=>request()->employee->root_id, 'id'=> $item['id']])->save(['user_cate'=> $string]);
- }
- $data->delete();
- }elseif($param['type'] == 3){
- $label_id = TalkskillCates::where(['root_id'=>request()->employee->root_id,'pid'=>$data['pid'],'show'=>1,'type'=>'cate'])->value('id');
- if(empty($label_id)) $label_id = TalkskillCates::insertGetId(['pid'=>$data['pid'],'name'=>'其它','root_id'=>request()->employee->root_id,'show'=>1,'type'=>'cate']);
- $for = TalkskillModel::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET('" . $data['name'] . "' , cate2)")->field('id,cate2')->select();
- foreach($for as $item)
- {
- $string = str_replace($data['name'],"其它",$item['cate2']);
- TalkskillModel::where(['root_id'=>request()->employee->root_id,'id'=>$item['id']])->update(['cate2'=>$string]);
- }
- $chosen_for = TalkskillChosen::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET('" . $data['id'] . "' , cate2)")->field('id,cate2')->select();
- foreach($chosen_for as $item)
- {
- $c_old_cate2 = explode(',', $item['cate2']);
- foreach ($c_old_cate2 as $k => $v){
- if($v == $data['id']){
- $c_old_cate2[$k] = $label_id;
- }
- }
- $string = implode(',', $c_old_cate2);
- TalkskillChosen::where(['root_id'=>request()->employee->root_id, 'id'=> $item['id']])->save(['cate2'=> $string]);
- }
- $success_for = TalkskillSuccess::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET('" . $data['id'] . "' , cate2)")->field('id,cate2')->select();
- foreach($success_for as $item)
- {
- $s_old_cate2 = explode(',', $item['cate2']);
- foreach ($s_old_cate2 as $k => $v){
- if($v == $data['id']){
- $s_old_cate2[$k] = $label_id;
- }
- }
- $string = implode(',', $s_old_cate2);
- TalkskillSuccess::where(['root_id'=>request()->employee->root_id, 'id'=> $item['id']])->save(['cate2'=> $string]);
- }
- //删除分类
- $data->delete();
- }
-
- Db::commit();
- return json(['code' => 0, 'msg' => '删除成功']);
- } catch (\Exception $e) {
- Db::rollback();
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- }
- /*
- * 精选话术分类场景页面
- */
- public function chosen_cate()
- {
- $where[] = ['root_id', '=', request()->employee->root_id];
- $where[] = ['pid', '=', 0];
- $where[] = ['type', '=', 'cate'];
- $where[] = ['scene_type', '=', 'chosen'];
- $type = TalkskillCates::where($where)->order('id asc')->select();
- View::assign('type', $type);
- return View::fetch();
- }
- /*
- * 精选话术分类场景列表
- */
- public function chosen_cate_list()
- {
- $param = Request::only(['page' => 1, 'limit' => 10, 'keyword', 'type'=> '']);
- $root_id = request()->employee->root_id;
- //一级场景
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['pid', '=', 0];
- $where[] = ['type', '=', 'cate'];
- $where[] = ['scene_type', '=', 'chosen'];
- if (!empty($param['type'])) {
- $where[] = ['id', '=', $param['type']];
- }
- $data = TalkskillCates::where($where)->page($param['page'] , $param['limit'])->order('id asc')->select()->toArray();
- $count = TalkskillCates::where($where)->count();
- if ($data) {
- $condition = [
- ['cate1', 'in', array_column($data, 'id')],
- ['root_id', '=', $root_id],
- ['del', '=', 0]
- ];
- if (isset($param['keyword']) && $param['keyword']) {
- $chosen_id = TalkskillChosen::where(array_merge($condition, [['title', 'like', '%' . trim($param['keyword']) . '%']]))->column('id');
- //同时检索回答内容
- $content_talkskill_id = TalkskillContent::where([
- ['root_id', '=', $root_id],
- ['talkskill_type', '=', 'chosen'],
- ['content', 'like', '%' . trim($param['keyword']) . '%']
- ])->group('talkskill_id')->column('talkskill_id');
- $new_arr = array_merge($chosen_id, $content_talkskill_id);
- $condition[] = ['id', 'in', $new_arr];
- }
- $talkskill_count = TalkskillChosen::where($condition)->group('cate1')->column('count(id)','cate1');
- $talkskill_view = TalkskillChosen::where($condition)->group('cate1')->column('sum(view_times)','cate1');
- $talkskill_addtime = TalkskillChosen::where($condition)->group('cate1')->column('max(addtime)','cate1');
-
- foreach ($data as &$v) {
- //话术数量
- $v['talkskill_count'] = isset($talkskill_count[$v['id']]) ? $talkskill_count[$v['id']] : 0;
- //最近话术上传时间
- $v['update_time'] = isset($talkskill_addtime[$v['id']]) ? $talkskill_addtime[$v['id']] : '';
- //浏览人次
- $v['view_times'] = isset($talkskill_view[$v['id']]) ? $talkskill_view[$v['id']] : 0;
- //搜索值返回
- $v['keyword'] = isset($param['keyword']) ? $param['keyword'] : '';
- }
- }
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $data, 'count' => $count ]);
- }
- /**
- * 精选话术
- * @return string
- */
- public function chosen_index(){
- if (!request()->isAjax()){
- $type = request()->param('type');
- View::assign('type', $type);
- $root_id = request()->employee->root_id;
- //二级分类
- $where[] = ['type', '=', 'cate'];
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['pid', '=', $type];
- $cate = TalkskillCates::where($where)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('cate', $cate);
- //房屋类型
- $where_h[] = ['type', '=', 'house_type'];
- $where_h[] = ['root_id', '=', $root_id];
- $where_h[] = ['pid', '=', 0];
- $house_type = TalkskillCates::where($where_h)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('house_type', $house_type);
- //适用人群
- $where_u[] = ['root_id', '=', $root_id];
- $user_cate = TalkskillUsersCate::where($where_u)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('user_cate', $user_cate);
- //通过场景列表筛选关键进入的带入关键词
- $keyword = request()->param('keyword');
- view::assign('keyword', isset($keyword)?$keyword:'');
- $empIds = TalkskillChosen::where([['root_id', '=', $root_id],['cate1', '=', $type],['del', '=', 0]])->column('employee_id');
- $employee = Employee::where([['id', 'in', $empIds]])->select();
- View::assign('employee', $employee);
- return View::fetch();
- } else {
- $param = Request::param();
- $where = [
- ['root_id', '=', request()->employee->root_id],
- ['del', '=', 0],
- ['cate1', '=', $param['type']]
- ];
- if (!empty($param['keyword'])) {
- $chosen_id = TalkskillChosen::where(array_merge($where, [['title', 'like', '%' . trim($param['keyword']) . '%']]))->column('id');
- //同时检索回答内容
- $content_talkskill_id = TalkskillContent::where([
- ['root_id', '=', request()->employee->root_id],
- ['talkskill_type', '=', 'chosen'],
- ['content', 'like', '%' . trim($param['keyword']) . '%']
- ])->group('talkskill_id')->column('talkskill_id');
- $new_arr = array_merge($chosen_id, $content_talkskill_id);
- $where[] = ['id', 'in', $new_arr];
- }
- $sql = TalkskillChosen::with(['employee'=>function($query){
- $query->field(['id','opt_name']);
- }])->where($where);
- if (!empty($param['cate'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['cate'] . "' , cate2)");
- }
- if (!empty($param['house_type'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['house_type'] . "' , house_type)");
- }
- if (!empty($param['user_cate'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['user_cate'] . "' , user_cate)");
- }
- if (!empty($param['addtime'])) {
- list($start_date, $end_date) = explode(' - ', $param['addtime']);
- $sql->whereRaw("addtime >= '".$start_date."'");
- $sql->whereRaw("addtime < '". date('Y-m-d H:i:s', strtotime($end_date) + 86400) ."'");
- }
- if (!empty($param['employee_id'])) {
- $sql->whereRaw("employee_id=".$param['employee_id']);
- }
- // 获取数据
- $list = $sql->page($param['page'], $param['limit'])->order('addtime desc')->select()->each(function ($item){
- $item->cate1_name = TalkskillCates::where('id', '=', $item['cate1'])->value('name');
- $cate2_name = TalkskillCates::where('id', 'in', $item['cate2'])->column('name');
- $item->cate2_name = implode(',', $cate2_name);
- $house_type_name = TalkskillCates::where('id', 'in', $item['house_type'])->column('name');
- $item->house_type_name = implode(',', $house_type_name);
- $user_cate_name = TalkskillUsersCate::where('id', 'in', $item['user_cate'])->column('name');
- $item->user_cate_name = implode(',', $user_cate_name);
- $content_img = TalkskillContent::where([['talkskill_id','=',$item->id], ['talkskill_type','=','chosen'], ['root_id','=',request()->employee->root_id], ['img','<>','']])->count();
- $item->img = $content_img>0 ? true : false;
- })->toArray();
- $count = $sql->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- }
- /*
- * 精选话术新增新页面
- */
- public function chosen_add_new(){
- $id = input('id',0);
- View::assign('id',$id);
- return View::fetch();
- }
- /*
- * 精选话术添加
- */
- public function chosen_add()
- {
- if (!request()->isAjax()){
- $root_id = request()->employee->root_id;
- //场景
- $where[] = ['type', '=', 'cate'];
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['pid', '=', 0];
- $where[] = ['scene_type', '=', 'chosen'];
- $cate = TalkskillCates::where($where)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('cate', $cate);
- //房屋类型
- $where_h[] = ['type', '=', 'house_type'];
- $where_h[] = ['root_id', '=', $root_id];
- $where_h[] = ['pid', '=', 0];
- $house_type = TalkskillCates::where($where_h)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('house_type', $house_type);
- //适用人群
- $where_u[] = ['root_id', '=', $root_id];
- $user_cate = TalkskillUsersCate::where($where_u)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('user_cate', $user_cate);
- return View::fetch();
- } else {
- $param = Request::only(['id', 'title', 'user_cate', 'content', 'house_type'=> '', 'cate1'=> '', 'cate2'=> '']);
- $data = [
- 'title' => $param['title'],
- 'root_id' => request()->employee->root_id,
- 'user_cate' => $param['user_cate'],
- 'house_type' => $param['house_type'],
- 'cate1' => $param['cate1'],
- 'cate2' => $param['cate2'],
- 'employee_id'=> request()->employee->id
- ];
- $result = TalkskillChosen::create($data);
- dataStatistics(request()->employee->root_id,'talkskill_count',1,'inc');//manage应用首页统计数据
- $id = $result->id;
- if (!empty($param['content'])){
- foreach ($param['content'] as $k => $v){
- $content = [
- 'talkskill_id'=> $id,
- 'content' => $v['content'],
- 'type'=> $v['type'],
- 'talkskill_type'=> 'chosen',
- 'root_id'=> request()->employee->root_id,
- 'img'=> ''
- ];
- $img = Request::param('images_'.$k);
- if(isset($img) && !empty($img)){
- $content['img'] = implode(',',$img);
- }
- TalkskillContent::create($content);
- }
- }
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- }
- /*
- * 精选话术编辑
- */
- public function chosen_edit()
- {
- if (!request()->isAjax()){
- $id = input('id', '', 'intval');
- $where = [
- 'id' => $id,
- 'root_id' => request()->employee->root_id,
- 'del' => 0
- ];
- $data = TalkskillChosen::where($where)->find();
- if (!empty($data)){
- $content = TalkskillContent::where([['talkskill_id', '=', $id], ['talkskill_type', '=', 'chosen']])->order('id asc')->select()->toArray();
- foreach($content as &$val){
- $val['content'] = json_encode($val['content']);
- $val['img'] = $val['img'] ? explode(',',$val['img']) : '';
- }
- $data['content'] = $content;
- }
- View::assign('oss_bindurl', config('app.ali_oss_bindurl'));
- View::assign('data', $data);
- $root_id = request()->employee->root_id;
- //场景
- $where_c[] = ['type', '=', 'cate'];
- $where_c[] = ['root_id', '=', $root_id];
- $where_c[] = ['pid', '=', 0];
- $where_c[] = ['scene_type', '=', 'chosen'];
- $cate = TalkskillCates::where($where_c)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('cate', $cate);
- //房屋类型
- $where_h[] = ['type', '=', 'house_type'];
- $where_h[] = ['root_id', '=', $root_id];
- $where_h[] = ['pid', '=', 0];
- $house_type = TalkskillCates::where($where_h)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('house_type', $house_type);
- //适用人群
- $where_u[] = ['root_id', '=', $root_id];
- $user_cate = TalkskillUsersCate::where($where_u)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('user_cate', $user_cate);
- return View::fetch();
- } else {
- $param = Request::only(['id', 'title', 'user_cate', 'content', 'house_type'=> '', 'cate1'=> '', 'cate2'=> '']);
- $data = [
- 'id' => $param['id'],
- 'title' => $param['title'],
- 'root_id' => request()->employee->root_id,
- 'user_cate' => $param['user_cate'],
- 'house_type' => $param['house_type'],
- 'cate1' => $param['cate1'],
- 'cate2' => $param['cate2'],
- 'employee_id'=> request()->employee->id
- ];
- $talkskill = TalkskillChosen::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find();
- $talkskill->save($data);
- $old_content = TalkskillContent::where([['talkskill_id', '=', $param['id']], ['talkskill_type', '=', 'chosen']])->select();
- if ($old_content->isEmpty()) {
- if (!empty($param['content'])){
- foreach ($param['content'] as $k => $v){
- $content = [
- 'talkskill_id'=> $param['id'],
- 'content' => $v['content'],
- 'type'=> $v['type'],
- 'talkskill_type'=> 'chosen',
- 'root_id'=> request()->employee->root_id,
- 'img'=> ''
- ];
- $img = Request::param('img_'.$k);
- $imgnew = Request::param('imgnew_'.$k);
- if(isset($img) && !empty($img)){
- $content['img'] = implode(',',$img);
- }
- if(isset($imgnew) && !empty($imgnew)){
- $content['img'] = $content['img'] ? $content['img'].','.implode(',',$imgnew) : implode(',',$imgnew) ;
- }
- TalkskillContent::create($content);
- }
- }
- } else {
- if (empty($param['content'])){ //全删
- $old_content->delete();
- } else {
- // 删除去掉的话术
- foreach ($old_content as $k => $v){
- $delete = true;
- foreach ($param['content'] as $kk => $vv) {
- if (!empty($vv['id']) && $v['id'] == $vv['id']){
- $delete = false;
- }
- }
- if ($delete){
- $v->delete();
- }
- }
- // 更新及添加新话术
- foreach ($param['content'] as $k => $v) {
- if (!empty($v['id'])){
- $img = Request::param('img_'.$k);
- $imgnew = Request::param('imgnew_'.$k);
- $v['img'] = '';
- if(isset($img) && !empty($img)){
- $v['img'] = implode(',',$img);
- }
- if(isset($imgnew) && !empty($imgnew)){
- $v['img'] = $v['img'] ? $v['img'].','.implode(',',$imgnew) : implode(',',$imgnew) ;
- }
-
- TalkskillContent::where('id', '=', $v['id'])->save($v);
- } else {
- $content = [
- 'talkskill_id'=> $param['id'],
- 'content' => $v['content'],
- 'type'=> $v['type'],
- 'talkskill_type'=> 'chosen',
- 'root_id'=> request()->employee->root_id,
- 'img'=> ''
- ];
- $img = Request::param('img_'.$k);
- $imgnew = Request::param('imgnew_'.$k);
- if(isset($img) && !empty($img)){
- $content['img'] = implode(',',$img);
- }
- if(isset($imgnew) && !empty($imgnew)){
- $content['img'] = $content['img'] ? $content['img'].','.implode(',',$imgnew) : implode(',',$imgnew) ;
- }
- TalkskillContent::create($content);
- }
- }
- }
- }
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- }
- /*
- * 精选话术删除
- */
- public function chosen_delete()
- {
- $where[] = ['root_id','=',request()->employee->root_id];
- $param = Request::only(['id'=>0,'ids'=>[]]);
- $i = 1;
- if ($param['id']) {
- $where[] = ['id','=',$param['id']];
- }elseif (!empty($param['ids']) && is_array($param['ids'])) {
- $where[] = ['id','in',$param['ids']];
- $i = count(array_filter($param['ids']));
- }else{
- return json(['code' => 1, 'msg' => '操作失败']);
- }
- TalkskillChosen::where($where)->update(['del' => 1]);
- dataStatistics(request()->employee->root_id,'talkskill_count',$i,'dec');//manage应用首页统计数据
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /*
- * 成功案例分类列表页面
- */
- public function success_cate()
- {
- $where[] = ['root_id', '=', request()->employee->root_id];
- $where[] = ['pid', '=', 0];
- $where[] = ['type', '=', 'cate'];
- $type = TalkskillCates::where($where)->order('id asc')->select();
- View::assign('type', $type);
- return View::fetch();
- }
- /**
- * 成功案例分类
- */
- public function success_cate_list(){
- $param = Request::only(['page' => 1, 'limit' => 10, 'keyword', 'type'=> '']);
- $root_id = request()->employee->root_id;
- //一级场景
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['pid', '=', 0];
- $where[] = ['type', '=', 'cate'];
- if (!empty($param['type'])) {
- $where[] = ['id', '=', $param['type']];
- }
- $data = TalkskillCates::where($where)->page($param['page'] , $param['limit'])->order('id asc')->select()->toArray();
- $count = TalkskillCates::where($where)->count();
- if ($data) {
- $where2[] = ['cate1', 'in', array_column($data, 'id')];
- $where2[] = ['root_id', '=', $root_id];
- $where2[] = ['del', '=', 0];
- if (isset($param['keyword']) && $param['keyword']) {
- $where2[] = ['title', 'like', '%' . trim($param['keyword']) . '%'];
- }
- $talkskill = TalkskillSuccess::where($where2)->order('id asc')->select()->toarray();
- $label_counts = $dates = $view_count = [];
- foreach ($talkskill as $v) {
- //话术数量
- $label_counts[$v['cate1']] = isset($label_counts[$v['cate1']]) ? $label_counts[$v['cate1']] += 1 : 1;
- //最近话术上传时间
- $dates[$v['cate1']] = $v['addtime'];
- //浏览人次
- $view_count[$v['cate1']] = isset($view_count[$v['cate1']]) ? $view_count[$v['cate1']] + $v['view_times'] : $v['view_times'];
- }
- foreach ($data as $k => $v) {
- $data[$k]['talkskill_count'] = isset($label_counts[$v['id']]) ? $label_counts[$v['id']] : 0;
- $data[$k]['update_time'] = isset($dates[$v['id']]) ? $dates[$v['id']] : '';
- $data[$k]['view_times'] = isset($view_count[$v['id']]) ? $view_count[$v['id']] : 0;
- }
- }
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $data, 'count' => $count]);
- }
- /**
- * 成功话术首页
- */
- public function success_index(){
- if (!request()->isAjax()){
- $root_id = request()->employee->root_id;
- //一级分类
- $where[] = ['type', '=', 'cate'];
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['pid', '=', 0];
- $cate = TalkskillCates::where($where)->order('id asc')->column('*','id');
- view::assign('cate', $cate);
- //二级分类
- $label = TalkskillCates::where([['pid', '>', 0], ['type', '=', 'cate'], ['root_id', '=', $root_id]])->select()->toArray();
- $joinlabel = [];
- foreach ($label as $val) {
- $joinlabel[$val['pid']][$val['id']] = $val['name'];
- }
- View::assign('cate2', json_encode($joinlabel));
- //房屋类型
- $where_h[] = ['type', '=', 'house_type'];
- $where_h[] = ['root_id', '=', $root_id];
- $where_h[] = ['pid', '=', 0];
- $house_type = TalkskillCates::where($where_h)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('house_type', $house_type);
- //适用人群
- $where_u[] = ['root_id', '=', $root_id];
- $user_cate = TalkskillUsersCate::where($where_u)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('user_cate', $user_cate);
- return View::fetch();
- } else {
- $param = Request::param();
- $where = [
- ['root_id', '=', request()->employee->root_id],
- ['del', '=', 0],
- ];
- if (!empty($param['keyword'])) {
- $column_id = TalkskillContent::where([
- ['root_id', '=', request()->employee->root_id],
- ['content', 'like', '%' . $param['keyword'] . '%'],
- ['talkskill_type', '=', 'success']
- // ['type', '=', 0]
- ])->group('talkskill_id')->column('talkskill_id');
- $success_id = TalkskillSuccess::where(array_merge($where, [['title', 'like', '%' . $param['keyword'] . '%']]))->column('id');
- $new_arr = array_merge($column_id, $success_id);
- $where[] = ['id', 'in', $new_arr];
- }
- if(!empty($param['addtime'])){
- $times = explode(' - ',$param['addtime']);
- $where[] = ['addtime','between',[$times[0].' 00:00:00',$times[1].' 23:59:59']];
- }
- $sql = TalkskillSuccess::where($where);
- if (!empty($param['cate1'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['cate1'] . "' , cate1)");
- }
- if (!empty($param['cate2'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['cate2'] . "' , cate2)");
- }
- if (!empty($param['house_type'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['house_type'] . "' , house_type)");
- }
- if (!empty($param['user_cate'])) {
- $sql->whereRaw("FIND_IN_SET('" . $param['user_cate'] . "' , user_cate)");
- }
- // 获取数据
- $list = $sql->page($param['page'], $param['limit'])->order('addtime desc')->select()->each(function ($item){
- $item->cate1_name = TalkskillCates::where('id', '=', $item['cate1'])->value('name');
- $cate2_name = TalkskillCates::where('id', 'in', $item['cate2'])->column('name');
- $item->cate2_name = implode(',', $cate2_name);
- $house_type_name = TalkskillCates::where('id', 'in', $item['house_type'])->column('name');
- $item->house_type_name = implode(',', $house_type_name);
- $user_cate_name = TalkskillUsersCate::where('id', 'in', $item['user_cate'])->column('name');
- $item->user_cate_name = implode(',', $user_cate_name);
- $content_img = TalkskillContent::where([['talkskill_id','=',$item->id], ['talkskill_type','=','success'], ['root_id','=',request()->employee->root_id], ['img','<>','']])->count();
- $item->img = $content_img>0 ? true : false;
- })->toArray();
- $count = $sql->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- }
- /*
- * 成功话术新增新页面
- */
- public function success_add_new(){
- $id = input('id',0);
- View::assign('id', $id);
- return View::fetch();
- }
- /*
- * 成功案例添加
- */
- public function success_add()
- {
- if (!request()->isAjax()){
- $root_id = request()->employee->root_id;
- //场景
- $where[] = ['type', '=', 'cate'];
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['pid', '=', 0];
- $cate = TalkskillCates::where($where)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('cate', $cate);
- //房屋类型
- $where_h[] = ['type', '=', 'house_type'];
- $where_h[] = ['root_id', '=', $root_id];
- $where_h[] = ['pid', '=', 0];
- $house_type = TalkskillCates::where($where_h)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('house_type', $house_type);
- //适用人群
- $where_u[] = ['root_id', '=', $root_id];
- $user_cate = TalkskillUsersCate::where($where_u)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('user_cate', $user_cate);
- return View::fetch();
- } else {
- $param = Request::only(['title', 'user_cate', 'content', 'house_type'=> '', 'cate1'=> '', 'cate2'=> '']);
- $data = [
- 'title' => $param['title'],
- 'root_id' => request()->employee->root_id,
- 'user_cate' => $param['user_cate'],
- 'house_type' => $param['house_type'],
- 'cate1' => $param['cate1'],
- 'cate2' => $param['cate2'],
- 'employee_id'=> request()->employee->id
- ];
- $result = TalkskillSuccess::create($data);
- dataStatistics(request()->employee->root_id,'talkskill_count',1,'inc');//manage应用首页统计数据
- $id = $result->id;
- if (!empty($param['content'])){
- foreach ($param['content'] as $k => $v){
- $content = [
- 'talkskill_id'=> $id,
- 'content' => $v['content'],
- 'type'=> $v['type'],
- 'talkskill_type'=> 'success',
- 'root_id'=> request()->employee->root_id,
- 'img'=> ''
- ];
- $img = Request::param('images_'.$k);
- if(isset($img) && !empty($img)){
- $content['img'] = implode(',',$img);
- }
- TalkskillContent::create($content);
- }
- }
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- }
- /*
- * 成功案例编辑
- */
- public function success_edit()
- {
- $id = input('id', '', 'intval');
- if (!request()->isAjax()){
- $where = [
- 'id' => $id,
- 'root_id' => request()->employee->root_id,
- 'del' => 0
- ];
- $data = TalkskillSuccess::where($where)->find();
- if (!empty($data)){
- $content = TalkskillContent::where([['talkskill_id', '=', $id], ['talkskill_type', '=', 'success']])->order('id asc')->select()->toArray();
- foreach($content as &$val){
- $val['content'] = json_encode($val['content']);
- $val['img'] = $val['img'] ? explode(',',$val['img']) : '';
- }
- $data['content'] = $content;
- }
- View::assign('oss_bindurl', config('app.ali_oss_bindurl'));
- View::assign('data', $data);
- $root_id = request()->employee->root_id;
- //场景
- $where_c[] = ['type', '=', 'cate'];
- $where_c[] = ['root_id', '=', $root_id];
- $where_c[] = ['pid', '=', 0];
- $cate = TalkskillCates::where($where_c)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('cate', $cate);
- //房屋类型
- $where_h[] = ['type', '=', 'house_type'];
- $where_h[] = ['root_id', '=', $root_id];
- $where_h[] = ['pid', '=', 0];
- $house_type = TalkskillCates::where($where_h)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('house_type', $house_type);
- //适用人群
- $where_u[] = ['root_id', '=', $root_id];
- $user_cate = TalkskillUsersCate::where($where_u)->field('name,id')->order('id asc')->select()->toarray();
- view::assign('user_cate', $user_cate);
- return View::fetch();
- } else {
- $param = Request::only(['id', 'title', 'user_cate', 'content', 'house_type'=> '', 'cate1'=> '', 'cate2'=> '']);
- $data = [
- 'id' => $param['id'],
- 'title' => $param['title'],
- 'root_id' => request()->employee->root_id,
- 'user_cate' => $param['user_cate'],
- 'house_type' => $param['house_type'],
- 'cate1' => $param['cate1'],
- 'cate2' => $param['cate2'],
- 'employee_id'=> request()->employee->id
- ];
- $talkskill = TalkskillSuccess::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find();
- $talkskill->save($data);
- $old_content = TalkskillContent::where([['talkskill_id', '=', $param['id']], ['talkskill_type', '=', 'success']])->select();
- if ($old_content->isEmpty()) {
- if (!empty($param['content'])){
- foreach ($param['content'] as $k => $v){
- $content = [
- 'talkskill_id'=> $param['id'],
- 'content' => $v['content'],
- 'type'=> $v['type'],
- 'talkskill_type'=> 'success',
- 'root_id'=> request()->employee->root_id,
- 'img'=> ''
- ];
- $img = Request::param('img_'.$k);
- $imgnew = Request::param('imgnew_'.$k);
- if(isset($img) && !empty($img)){
- $content['img'] = implode(',',$img);
- }
- if(isset($imgnew) && !empty($imgnew)){
- $content['img'] = $content['img'] ? $content['img'].','.implode(',',$imgnew) : implode(',',$imgnew) ;
- }
- TalkskillContent::create($content);
- }
- }
- } else {
- if (empty($param['content'])){ //全删
- $old_content->delete();
- } else {
- // 删除去掉的话术
- foreach ($old_content as $k => $v){
- $delete = true;
- foreach ($param['content'] as $kk => $vv) {
- if (!empty($vv['id']) && $v['id'] == $vv['id']){
- $delete = false;
- }
- }
- if ($delete){
- $v->delete();
- }
- }
- // 更新及添加新话术
- foreach ($param['content'] as $k => $v) {
- if (!empty($v['id'])){
- $img = Request::param('img_'.$k);
- $imgnew = Request::param('imgnew_'.$k);
- $v['img'] = '';
- if(isset($img) && !empty($img)){
- $v['img'] = implode(',',$img);
- }
- if(isset($imgnew) && !empty($imgnew)){
- $v['img'] = $v['img'] ? $v['img'].','.implode(',',$imgnew) : implode(',',$imgnew) ;
- }
- TalkskillContent::where('id', '=', $v['id'])->save($v);
- } else {
- $content = [
- 'talkskill_id'=> $param['id'],
- 'content' => $v['content'],
- 'type'=> $v['type'],
- 'talkskill_type'=> 'success',
- 'root_id'=> request()->employee->root_id,
- 'img'=> ''
- ];
- $img = Request::param('img_'.$k);
- $imgnew = Request::param('imgnew_'.$k);
- if(isset($img) && !empty($img)){
- $content['img'] = implode(',',$img);
- }
- if(isset($imgnew) && !empty($imgnew)){
- $content['img'] = $content['img'] ? $content['img'].','.implode(',',$imgnew) : implode(',',$imgnew) ;
- }
- TalkskillContent::create($content);
- }
- }
- }
- }
- }
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /*
- * 成功案例删除
- */
- public function success_delete()
- {
- $where[] = ['root_id','=',request()->employee->root_id];
- $param = Request::only(['id'=>0,'ids'=>[]]);
- $i = 1;
- if ($param['id']) {
- $where[] = ['id','=',$param['id']];
- }elseif (!empty($param['ids']) && is_array($param['ids'])) {
- $where[] = ['id','in',$param['ids']];
- $i = count(array_filter($param['ids']));
- }else{
- return json(['code' => 1, 'msg' => '操作失败']);
- }
- dataStatistics(request()->employee->root_id,'talkskill_count',$i,'dec');//manage应用首页统计数据
- TalkskillSuccess::where($where)->update(['del' => 1]);
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /**
- * 此方法用于从某个企业复制<精选话术>至另一个企业
- */
- public function copy_talkskill_chosen($from_root_id = 0 , $new_root_id = 0)
- {
- if (!$from_root_id || !$new_root_id) return '错误';
- if ($from_root_id == $new_root_id) return '错误';
- $company = Company::where([['root_id','in',[$from_root_id,$new_root_id]]])->count();
- if($company != 2) return '错误';
- //使用人群
- $new_user_cate = [];
- $user_cate = TalkskillUsersCate::where(['root_id'=>$from_root_id])->order('addtime')->select();
- foreach($user_cate as $cate){
- $have_usercate = TalkskillUsersCate::where(['root_id'=>$new_root_id,'name'=>$cate['name']])->value('id');
- if(!empty($have_usercate)){
- $uc = $have_usercate;
- }else{
- $uc = TalkskillUsersCate::insertGetId(['root_id'=>$new_root_id,'name'=>$cate['name']]);
- }
- $new_user_cate[$cate['id']] = $uc;
- }
- //房屋类型
- $cates = TalkskillCates::where([['root_id','=',$from_root_id],['type','=','house_type']])->order('addtime')->select();
- $new_cates = [];
- foreach($cates as $item){
- $have_cates = TalkskillCates::where([['root_id','=',$new_root_id],['type','=','house_type'],['name','=',$item['name']]])->value('id');
- if(!empty($have_cates)){
- $add_house_type_id = $have_cates;
- }else{
- $add_house_type_id = TalkskillCates::insertGetId(['root_id'=>$new_root_id,'type'=>'house_type','name'=>$item['name']]);
- }
- $new_cates[$item['id']] = $add_house_type_id;
- }
-
- //分类
- $cate1 = TalkskillCates::where([['pid','=',0],['scene_type','=','chosen'],['root_id','=',$from_root_id],['type','=','cate']])->order('addtime')->select()->toArray();
- $new_cate1 = [];
- $new_cate2 = [];
- foreach($cate1 as $value){
- $have_cate1 = TalkskillCates::where(['scene_type'=>'chosen','root_id'=>$new_root_id,'type'=>'cate','name'=>$value['name'],'pid'=>0])->value('id');
- if(!empty($have_cate1)){
- $add_cate1_id = $have_cate1;
- }else{
- $add_cate1_id = TalkskillCates::insertGetId(['scene_type'=>'chosen','root_id'=>$new_root_id,'type'=>'cate','name'=>$value['name'],'pid'=>0]);
- }
- $new_cate1[$value['id']] = $add_cate1_id;
- $cate2 = TalkskillCates::where([['pid','=',$value['id']],['root_id','=',$from_root_id],['type','=','cate']])->order('addtime')->select();
- foreach($cate2 as $value2){
- $have_cate2 = TalkskillCates::where(['root_id'=>$new_root_id,'type'=>'cate','name'=>$value2['name'],'pid'=>$add_cate1_id])->value('id');
- if(!empty($have_cate2)){
- $add_cate2_id = $have_cate2;
- }else{
- $add_cate2_id = TalkskillCates::insertGetId(['root_id'=>$new_root_id,'type'=>'cate','name'=>$value2['name'],'pid'=>$add_cate1_id]);
- }
- $new_cate2[$value2['id']] = $add_cate2_id;
- }
- }
-
- $data = TalkskillChosen::where([['root_id','=',$from_root_id],['del','=',0]])->select()->toArray();
- foreach($data as $d){
- $user_cate_str = explode(',',$d['user_cate']);
- $create_user_cate = [];
- foreach($user_cate_str as $u){
- $create_user_cate[] = isset($new_user_cate[$u]) ? $new_user_cate[$u] : '';
- }
-
- $house_type_str = explode(',',$d['house_type']);
- $create_house_type = [];
- foreach($house_type_str as $h){
- $create_house_type[] = isset($new_cates[$h]) ? $new_cates[$h] : '';
- }
- $cate2_str = explode(',',$d['cate2']);
- $create_cate2 = [];
- foreach($cate2_str as $c2){
- $create_cate2[] = isset($new_cate2[$c2]) ? $new_cate2[$c2] : '';
- }
- $insert_data = [
- 'root_id'=>$new_root_id,
- 'title'=>$d['title'],
- 'user_cate'=>implode(',',$create_user_cate),
- 'house_type'=>implode(',',$create_house_type),
- 'cate1'=>isset($new_cate1[$d['cate1']]) ? $new_cate1[$d['cate1']] : '',
- 'cate2'=>implode(',',$create_cate2),
- ];
-
- $addChosenId = TalkskillChosen::insertGetId($insert_data);
- $content = TalkskillContent::where(['root_id'=>$d['root_id'],'talkskill_id'=>$d['id'],'talkskill_type'=>'chosen'])->order('addtime')->select();
- $contentSaveAll = [];
- foreach($content as $co){
- $contentSaveAll[] = [
- 'root_id' => $new_root_id,
- 'talkskill_id' => $addChosenId,
- 'content' => $co['content'],
- 'type' => $co['type'],
- 'talkskill_type' => $co['talkskill_type'],
- 'img' => $co['img'],
- ];
- }
- TalkskillContent::insertAll($contentSaveAll);
- }
- return '复制成功';
- }
- /**
- * 此方法用于从某个企业复制<成功案例话术>至另一个企业
- */
- public function copy_talkskill_success($from_root_id = 0 , $new_root_id = 0)
- {
- if (!$from_root_id || !$new_root_id) return '错误';
- if ($from_root_id == $new_root_id) return '错误';
- $company = Company::where([['root_id','in',[$from_root_id,$new_root_id]]])->count();
- if($company != 2) return '错误';
- //使用人群
- $new_user_cate = [];
- $user_cate = TalkskillUsersCate::where(['root_id'=>$from_root_id])->order('addtime')->select();
- foreach($user_cate as $cate){
- $have_usercate = TalkskillUsersCate::where(['root_id'=>$new_root_id,'name'=>$cate['name']])->value('id');
- if(!empty($have_usercate)){
- $uc = $have_usercate;
- }else{
- $uc = TalkskillUsersCate::insertGetId(['root_id'=>$new_root_id,'name'=>$cate['name']]);
- }
- $new_user_cate[$cate['id']] = $uc;
- }
- //房屋类型
- $cates = TalkskillCates::where([['root_id','=',$from_root_id],['type','=','house_type']])->order('addtime')->select();
- $new_cates = [];
- foreach($cates as $item){
- $have_cates = TalkskillCates::where([['root_id','=',$new_root_id],['type','=','house_type'],['name','=',$item['name']]])->value('id');
- if(!empty($have_cates)){
- $add_house_type_id = $have_cates;
- }else{
- $add_house_type_id = TalkskillCates::insertGetId(['root_id'=>$new_root_id,'type'=>'house_type','name'=>$item['name']]);
- }
- $new_cates[$item['id']] = $add_house_type_id;
- }
-
- //分类
- $cate1 = TalkskillCates::where([['pid','=',0],['root_id','=',$from_root_id],['type','=','cate']])->order('addtime')->select()->toArray();
- $new_cate1 = [];
- $new_cate2 = [];
- foreach($cate1 as $value){
- $have_cate1 = TalkskillCates::where(['root_id'=>$new_root_id,'type'=>'cate','name'=>$value['name'],'pid'=>0])->value('id');
- if(!empty($have_cate1)){
- $add_cate1_id = $have_cate1;
- }else{
- $add_cate1_id = TalkskillCates::insertGetId(['root_id'=>$new_root_id,'type'=>'cate','name'=>$value['name'],'pid'=>0]);
- }
- $new_cate1[$value['id']] = $add_cate1_id;
- $cate2 = TalkskillCates::where([['pid','=',$value['id']],['root_id','=',$from_root_id],['type','=','cate']])->order('addtime')->select();
- foreach($cate2 as $value2){
- $have_cate2 = TalkskillCates::where(['root_id'=>$new_root_id,'type'=>'cate','name'=>$value2['name'],'pid'=>$add_cate1_id])->value('id');
- if(!empty($have_cate)){
- $add_cate2_id = $have_cate2;
- }else{
- $add_cate2_id = TalkskillCates::insertGetId(['root_id'=>$new_root_id,'type'=>'cate','name'=>$value2['name'],'pid'=>$add_cate1_id]);
- }
- $new_cate2[$value2['id']] = $add_cate2_id;
- }
- }
-
- $data = TalkskillSuccess::where([['root_id','=',$from_root_id],['del','=',0]])->select()->toArray();
- foreach($data as $d){
- $user_cate_str = explode(',',$d['user_cate']);
- $create_user_cate = [];
- foreach($user_cate_str as $u){
- $create_user_cate[] = isset($new_user_cate[$u]) ? $new_user_cate[$u] : '';
- }
-
- $house_type_str = explode(',',$d['house_type']);
- $create_house_type = [];
- foreach($house_type_str as $h){
- $create_house_type[] = isset($new_cates[$h]) ? $new_cates[$h] : '';
- }
- $cate2_str = explode(',',$d['cate2']);
- $create_cate2 = [];
- foreach($cate2_str as $c2){
- $create_cate2[] = isset($new_cate2[$c2]) ? $new_cate2[$c2] : '';
- }
- $insert_data = [
- 'root_id'=>$new_root_id,
- 'title'=>$d['title'],
- 'user_cate'=>implode(',',$create_user_cate),
- 'house_type'=>implode(',',$create_house_type),
- 'cate1'=>isset($new_cate1[$d['cate1']]) ? $new_cate1[$d['cate1']] : '',
- 'cate2'=>implode(',',$create_cate2),
- ];
-
- $addChosenId = TalkskillSuccess::insertGetId($insert_data);
- $content = TalkskillContent::where(['root_id'=>$d['root_id'],'talkskill_id'=>$d['id'],'talkskill_type'=>'success'])->order('addtime')->select();
- $contentSaveAll = [];
- foreach($content as $co){
- $contentSaveAll[] = [
- 'root_id' => $new_root_id,
- 'talkskill_id' => $addChosenId,
- 'content' => $co['content'],
- 'type' => $co['type'],
- 'talkskill_type' => $co['talkskill_type'],
- 'img' => $co['img'],
- ];
- }
- TalkskillContent::insertAll($contentSaveAll);
- }
- return '复制成功';
- }
- /**
- * 此方法用于从某个企业复制<话术管理>至另一个企业
- */
- public function copy_talkskill($from_root_id = 0 , $new_root_id = 0)
- {
- if (!$from_root_id || !$new_root_id) return '错误';
- if ($from_root_id == $new_root_id) return '错误';
- $company = Company::where([['root_id','in',[$from_root_id,$new_root_id]]])->count();
- if($company != 2) return '错误';
- //使用人群
- $user_cate = TalkskillUsersCate::where(['root_id'=>$from_root_id])->order('addtime')->select();
- foreach($user_cate as $cate){
- $have_usercate = TalkskillUsersCate::where(['root_id'=>$new_root_id,'name'=>$cate['name']])->value('id');
- if(empty($have_usercate)){
- TalkskillUsersCate::insertGetId(['root_id'=>$new_root_id,'name'=>$cate['name']]);
- }
- }
- //房屋类型
- $cates = TalkskillCates::where([['root_id','=',$from_root_id],['type','=','house_type']])->order('addtime')->select();
- foreach($cates as $item){
- $have_cates = TalkskillCates::where([['root_id','=',$new_root_id],['type','=','house_type'],['name','=',$item['name']]])->value('id');
- if(empty($have_cates)){
- TalkskillCates::insertGetId(['root_id'=>$new_root_id,'type'=>'house_type','name'=>$item['name']]);
- }
- }
-
- //分类
- $cate1 = TalkskillCates::where([['pid','=',0],['root_id','=',$from_root_id],['type','=','cate']])->order('addtime')->select()->toArray();
- foreach($cate1 as $value){
- $have_cate1 = TalkskillCates::where(['root_id'=>$new_root_id,'type'=>'cate','name'=>$value['name'],'pid'=>0])->value('id');
- if(empty($have_cate1)){
- $add_cate1_id = TalkskillCates::insertGetId(['root_id'=>$new_root_id,'type'=>'cate','name'=>$value['name'],'pid'=>0]);
- }else{
- $add_cate1_id = $have_cate1;
- }
- $cate2 = TalkskillCates::where([['pid','=',$value['id']],['root_id','=',$from_root_id],['type','=','cate']])->order('addtime')->select();
- foreach($cate2 as $value2){
- $have_cate2 = TalkskillCates::where(['root_id'=>$new_root_id,'type'=>'cate','name'=>$value2['name'],'pid'=>$add_cate1_id])->value('id');
- if(empty($have_cate2)){
- TalkskillCates::insertGetId(['root_id'=>$new_root_id,'type'=>'cate','name'=>$value2['name'],'pid'=>$add_cate1_id]);
- }
- }
- }
-
- //label标签
- $label_arr = [];
- $label = TalkskillLabel::where('root_id',$from_root_id)->order('addtime')->select();
- foreach($label as $item){
- $have_label = TalkskillLabel::where([['root_id','=',$new_root_id],['label_name','=',$item['label_name']]])->value('id');
- if(empty($have_label)){
- $label_id = TalkskillLabel::insertGetId(['root_id'=>$new_root_id,'label_name'=>$item['label_name']]);
- }else{
- $label_id = $have_label;
- }
- $label_arr[] = $label_id;
- }
- $data = TalkskillModel::where([['root_id','=',$from_root_id],['del','=',0],['type','=','admin']])->select()->toArray();
- foreach($data as $d){
- $insert_data = [
- 'root_id'=>$new_root_id,
- 'title'=>$d['title'],
- 'content'=>$d['content'],
- 'label'=>isset($label_arr[$d['label']]) ? $label_arr[$d['label']] : 0,
- 'type'=>'admin',
- 'imgs'=>$d['imgs'],
- 'videos'=>$d['videos'],
- 'media_id'=>$d['media_id'],
- 'weixin_media'=>$d['weixin_media'],
- 'user_cate'=>$d['user_cate'],
- 'house_type'=>$d['house_type'],
- 'cate1'=>$d['cate1'],
- 'cate2'=>$d['cate2'],
- ];
- TalkskillModel::insertGetId($insert_data);
- }
- return '复制成功';
- }
- }
|