1
0

PlacingScreen.php 148 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004
  1. <?php
  2. namespace app\api\controller;
  3. use app\model\FishData;
  4. use app\model\FishCampaign;
  5. use app\model\FishCampaignList;
  6. use app\model\Company;
  7. use app\model\Customer;
  8. use app\model\CustomerSource;
  9. use app\model\CustomerVisitLog;
  10. use app\model\Employee;
  11. use app\model\Building as BuildingModel;
  12. use app\model\CustomerClue;
  13. use app\model\FishLive;
  14. use app\model\Org;
  15. use app\model\Setting;
  16. use app\model\ShareLog;
  17. use app\model\Footprints;
  18. use app\model\BuildingHousetype;
  19. use app\model\BuildingDevelopCase;
  20. use app\model\SmartScreenLog;
  21. use app\model\Talkskill;
  22. use app\model\TalkskillChosen;
  23. use app\model\TalkskillSuccess;
  24. use app\model\TalkskillViewLog;
  25. use app\model\OutCallLog;
  26. use think\facade\Db;
  27. use clue\Fish as clueFish;
  28. use clue\FishWh as clueFishWh;
  29. use clue\RSAUtil;
  30. use toolkits\Aec;
  31. use think\exception\HttpException;
  32. use think\facade\Cache;
  33. use app\model\CustomerInvalidLog;
  34. use app\model\Community;
  35. use think\facade\Log;
  36. class PlacingScreen
  37. {
  38. //飞鱼
  39. protected $fish;
  40. protected $fish_wh;
  41. protected $aec;
  42. protected $token;
  43. protected $cache_time = 60;
  44. //加密私钥
  45. protected $private_key = "-----BEGIN RSA PRIVATE KEY-----\n".
  46. "MIICWgIBAAKBgFotKen59EscdMXanzaCsL8rg0nTzpF9XL/Kxd6lCV3fsGfvJ966\n".
  47. "0Oy8DAy4VQ8nyDvoX3mAnvxa6GYXHyujTM9pP2uDvbtQoxeVdRBicqguBPgV49FX\n".
  48. "gLc1Cla74HIR+HGK+knWIvNykojVS70y02nd1oQCSbg2HMxpltVaGbW/AgMBAAEC\n".
  49. "gYBZwskM6Mx+E6Y858BBj1eGAzcdPuNIuQOguaO6Wob3VVkQK+OA9m5Op2RLKRUq\n".
  50. "D8xlrYmTtS8MPSVFsdBKLLOgM8kzB3WP8lErtILX3y5g63wB1y6eMIdfqA/xZNcR\n".
  51. "IAzcfYmj1zzycid48GiWRDGjefKustIVUEZPc/c8p8ULgQJBALDSJJ8bGVkjIaW6\n".
  52. "kTKwH6vibJRgJGcxppVdAnfaes5XiFE43vW83PaWl4ycZdPJZXnXcXWAHpG9zQrL\n".
  53. "SX10JMECQQCCjoku62IZhtoEOApqcEaw4pX6o6Ikd9ReZPi7nh8zd+x+MsLD274j\n".
  54. "AWec7t9lMVj22ZTSdLu5Fbp+iS00V/p/AkBKn/XavGofR4ds1WdwOAq11TK0EDts\n".
  55. "3fSLNxzSjn+j1Cdw+AqJNbMf0wCU1HDZSDcui/GTgIXmRm9h7dfPPZRBAkAwE1a2\n".
  56. "3VyZc8vyg8RqH4AYgMejrP/3F90vCVWCmR56MG34pq6Luu5QK6NA6cF/nOVauRKR\n".
  57. "UQUTicnL8K2hucf3AkB9hPAb50JLc6r6+M5G6yyHiM0vP1Cn0bpXZpNO8NuG59cs\n".
  58. "2teMFSB6rdYlQfe6lPUtUl6oIvfBbV6uTR9auT9Q\n".
  59. "-----END RSA PRIVATE KEY-----";
  60. // //公钥测试
  61. // protected $public_key = "-----BEGIN PUBLIC KEY-----\n".
  62. // "MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgFotKen59EscdMXanzaCsL8rg0nT\n".
  63. // "zpF9XL/Kxd6lCV3fsGfvJ9660Oy8DAy4VQ8nyDvoX3mAnvxa6GYXHyujTM9pP2uD\n".
  64. // "vbtQoxeVdRBicqguBPgV49FXgLc1Cla74HIR+HGK+knWIvNykojVS70y02nd1oQC\n".
  65. // "Sbg2HMxpltVaGbW/AgMBAAE=\n".
  66. // "-----END PUBLIC KEY-----";
  67. /**
  68. * 构造
  69. */
  70. public function __construct()
  71. {
  72. header("Access-Control-Allow-Origin:*");
  73. $this->fish = new clueFish(config('app.fish_clue_appid'), config('app.fish_clue_secret'));
  74. $this->fish_wh = new clueFishWh(config('app.fish_clue_appid_wh'), config('app.fish_clue_secret_wh'));
  75. $this->aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  76. $this->token = input('token');
  77. $rsaUtil = new RSAUtil($this->private_key, '');
  78. if (empty($this->token)) return json(['code' => 0, 'msg' => 'Token失效']);
  79. $this->token = $rsaUtil->privateDecrypt($this->token);
  80. }
  81. /**
  82. * 内容使用大屏-内容使用统计-左侧
  83. */
  84. public function get_left_content_use_total()
  85. {
  86. //内容使用数据
  87. $root_id = $this->aec->decrypt($this->token);
  88. $param = request()->only(['times']);
  89. $orgid = orgSubIds($root_id);
  90. $newlist = Org::where([['id', 'in', $orgid]])->field('id,name,pid')->select()->toArray(); //获取部门
  91. $emp_list = Employee::where([['org_id', 'in', $orgid], ['state', '=', '在职'], ['uid', '<>', 0]])->field('id,org_id')->select()->toArray(); //部门员工
  92. $empid = array_column($emp_list, 'id');
  93. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  94. if (isset($param['times']) && $param['times']) {
  95. $time = explode(' - ', $param['times']);
  96. }
  97. $cache_data_name = 'get_left_content_use_total-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  98. $cache_data_info = Cache::get($cache_data_name);
  99. if($cache_data_info){
  100. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  101. }
  102. //拆分时间
  103. $comtent_list = [];
  104. $tmp_day = 1;
  105. $time_arr = getDateByInterval($time[0], $time[1], 'day');
  106. if (count($time_arr) > 35) {
  107. $tmp_day = 2;
  108. $time_arr = getDateByInterval($time[0], $time[1], 'month');
  109. }
  110. $share_type = ['MaterialCase', 'Video', 'Article', 'CompanyStrength', 'MaterialEvidence', 'Building', 'ToolAll', 'CustomerJsAll', 'weiwang', 'card', 'MaterialCase_vr', 'Building_vr', 'EmployeeCard_vr', 'Company_vr'];
  111. //折线图
  112. foreach ($time_arr as $k => $v) {
  113. if ($tmp_day == 2) {
  114. $count_num = ShareLog::where([['employee_id', 'in', $empid], ['share_time', 'between', [$v['startDate'] . ' 00:00:00', $v['endDate'] . ' 23:59:59']], ['type', 'in', $share_type]])->column('employee_id');
  115. $comtent_list[$k]['times'] = $v['name'];
  116. $comtent_list[$k]['number'] = count($count_num);
  117. } else {
  118. $count_num = ShareLog::where([['employee_id', 'in', $empid], ['share_time', 'between', [$v . ' 00:00:00', $v . ' 23:59:59']], ['type', 'in', $share_type]])->column('employee_id');
  119. $comtent_list[$k]['time'] = $v;
  120. $comtent_list[$k]['number'] = count($count_num);
  121. }
  122. }
  123. $emp_arr = [];
  124. foreach($emp_list as $val){
  125. $emp_arr[$val['org_id']][] = $val['id'];
  126. }
  127. //数据列表
  128. $where_time = [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59'];
  129. foreach ($newlist as &$val) {
  130. $val['people_number'] = 0;
  131. $val['share_count'] = 0;
  132. $val['look_times'] = 0;
  133. $val['clue_num'] = 0;
  134. if (isset($emp_arr[$val['id']]) && $emp_arr[$val['id']]) {
  135. $number = ShareLog::where([['employee_id', 'in', $emp_arr[$val['id']]], ['share_time', 'between', $where_time], ['type', 'in', $share_type]])->column('employee_id');
  136. $val['people_number'] = count(array_unique($number));
  137. $val['share_count'] = count($number);
  138. $visit_due_time = Footprints::where([['employee_id', 'in', $emp_arr[$val['id']]], ['addtime', 'between', $where_time]])->sum('visit_due_time');
  139. $val['look_times'] = round($visit_due_time / 60, 1);
  140. //获取线索
  141. $clue_num = CustomerClue::where([['employee_id', 'in', $number],['addtime', 'between', $where_time]])->count();
  142. $val['clue_num'] = $clue_num;
  143. }
  144. }
  145. Cache::set($cache_data_name,json_encode(['fold_line' => $comtent_list, 'list' => $newlist]), $this->cache_time);
  146. return json(['code' => 0, 'data' => ['fold_line' => $comtent_list, 'list' => $newlist], 'msg' => '获取成功']);
  147. }
  148. /**
  149. * 内容使用情况详情
  150. */
  151. public function get_left_content_user_total_info()
  152. {
  153. $root_id = $this->aec->decrypt($this->token);
  154. $param = request()->only(['times', 'org_id']);
  155. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  156. if (isset($param['times']) && $param['times']) {
  157. $time = explode(' - ', $param['times']);
  158. }
  159. $cache_data_name = 'get_left_content_user_total_info-' . $time[0] . '-' . $time[1] . '_' . $root_id . '_' . $param['org_id'];
  160. $cache_data_info = Cache::get($cache_data_name);
  161. if($cache_data_info){
  162. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  163. }
  164. $emp_list = Employee::where([['org_id', 'in', $param['org_id']], ['state', '=', '在职'], ['uid', '<>', 0], ['root_id', '=', $root_id]])->field('id,org_id,name')->select()->toArray(); //部门员工
  165. $where_time = [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59'];
  166. $share_type = ['MaterialCase', 'Video', 'Article', 'CompanyStrength', 'MaterialEvidence', 'Building', 'ToolAll', 'CustomerJsAll', 'weiwang', 'card', 'MaterialCase_vr', 'Building_vr', 'EmployeeCard_vr', 'Company_vr'];
  167. //数据列表
  168. foreach ($emp_list as &$val) {
  169. $val['people_number'] = 0;
  170. $val['share_count'] = 0;
  171. $val['look_times'] = 0;
  172. $val['clue_num'] = 0;
  173. $number = ShareLog::where([['employee_id', '=', $val['id']], ['share_time', 'between', $where_time], ['type', 'in', $share_type]])->column('employee_id');
  174. $val['people_number'] = count(array_unique($number));
  175. $val['share_count'] = count($number);
  176. $visit_due_time = Footprints::where([['employee_id', '=', $val['id']], ['addtime', 'between', $where_time]])->sum('visit_due_time');
  177. $val['look_times'] = round($visit_due_time / 60, 1);
  178. //获取线索
  179. $clue_num = CustomerClue::where([['employee_id', '=', $val['id']], ['addtime', 'between', $where_time]])->count();
  180. $val['clue_num'] = $clue_num;
  181. }
  182. Cache::set($cache_data_name,json_encode($emp_list), $this->cache_time);
  183. return json(['code' => 0, 'data' => $emp_list, 'msg' => '获取成功']);
  184. }
  185. /**
  186. * 内容使用大屏-智能楼书数据-中间
  187. */
  188. public function get_center_content_use_total()
  189. {
  190. $root_id = $this->aec->decrypt($this->token);
  191. $param = request()->only(['times']);
  192. $orgid = orgSubIds($root_id);
  193. // $org_list = Org::where([['id', 'in', $orgid]])->field('id,name')->select()->toArray();
  194. $emp_list = Employee::where([['org_id', 'in', $orgid], ['state', '=', '在职'], ['uid', '<>', 0]])->field('id,org_id')->select()->toArray(); //部门员工
  195. $empid = array_column($emp_list, 'id');
  196. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  197. if (isset($param['times']) && $param['times']) {
  198. $time = explode(' - ', $param['times']);
  199. }
  200. $between_time = [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59'];
  201. $cache_data_name = 'get_center_content_use_total-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  202. $cache_data_info = Cache::get($cache_data_name);
  203. if($cache_data_info){
  204. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  205. }
  206. $building_vr_all = 0;//楼盘VR
  207. $housetype_all = 0;//户型数
  208. $housetype_vr_all = 0;//户型Vr
  209. $housetype_develop_all = 0;//楼盘案例数
  210. $where[] = ['del', '=', 0];
  211. $where[] = ['root_id', '=', $root_id];
  212. // $where[] = ['addtime', 'between', $between_time];
  213. //查询楼盘信息
  214. $list = BuildingModel::with(['share_log' => function ($query) {// use ($between_time)
  215. $query->where([['type','=','building']])->field('id,data_id,employee_id');//,['share_time', 'between', $between_time]
  216. }])->where($where)->field('id,name,vr_link,community_id,org_id,assign_org_id')->order('addtime desc')->select()->toArray();
  217. $build_list = [];
  218. foreach($list as $k => $v){
  219. $housetype = BuildingHousetype::where('building_id', '=', $v['id'])->select();
  220. $housetype_count = $housetype->count();
  221. $housetype_all += $housetype_count;
  222. $housetype_vr_count = 0;
  223. foreach ($housetype as $h){
  224. if ($h['vr_link']) {
  225. $housetype_vr_count ++;//户型Vr
  226. }
  227. }
  228. $housetype_vr_all += $housetype_vr_count;
  229. $develop = BuildingDevelopCase::where('building_id', '=', $v['id'])->select();
  230. $housetype_develop = 0; //有研发案例的户型
  231. $housetype_have = [];
  232. foreach ($housetype as $h){
  233. foreach ($develop as $d){
  234. if ($d['housetype_id'] == $h['id'] && !in_array($h['id'], $housetype_have)){
  235. $housetype_develop ++;//楼盘案例数
  236. }
  237. }
  238. }
  239. $housetype_develop_all += $housetype_develop;
  240. if (!empty($v['vr_link'])){
  241. $building_vr_all ++;//楼盘VR
  242. }
  243. //分享人数-分享次数
  244. $share_num = 0;
  245. $share_array = [];
  246. foreach ($v['share_log'] as $s) {
  247. if ($s['data_id'] == $v['id']) {
  248. $share_array[$v['id']][] = $s['employee_id'];
  249. $share_num++;
  250. }
  251. }
  252. $share_people = isset($share_array[$v['id']]) ? count(array_unique($share_array[$v['id']])) : 0;
  253. //查询浏览时间
  254. $foot_where[] = ['pipe_type', '=', 'building'];
  255. $foot_where[] = ['employee_id', 'in', $empid];
  256. // $foot_where[] = ['addtime', 'between', $between_time];
  257. $foot_data = Db::name('footprints')->where($foot_where)->whereLike('reg_info','{"id":' . $v['id'] . ',%')->cursor();
  258. $look_time = 0;
  259. foreach ($foot_data as $f) {
  260. if ($f['visit_due_time']){
  261. $look_time += $f['visit_due_time'];
  262. }
  263. }
  264. //获取线索
  265. $clue_num = CustomerClue::where([['employee_id', 'in', $empid],['pipe_id','=',$v['id']], ['pipe_type', '=', 'building']])->count();//,['pipe_type', 'in', ['building', 'buildingvr']],['addtime', 'between', $between_time]
  266. $build_list[$k]['id'] = $v['id'];
  267. $build_list[$k]['name'] = $v['name'];
  268. $build_list[$k]['housetype_vr_percent'] = $housetype_count > 0 ? round($housetype_vr_count * 100 / $housetype_count, 2) : 0;//户型完整度
  269. $build_list[$k]['develop_percent'] = $housetype_count > 0 ? round($housetype_develop * 100 / $housetype_count, 2) : 0;//案例完整度
  270. $build_list[$k]['share_people'] = $share_people;//转发人数
  271. $build_list[$k]['share_num'] = $share_num;//转发次数
  272. $build_list[$k]['look_time'] = $look_time;//浏览时长
  273. $build_list[$k]['clue_num'] = $clue_num;//获取线索
  274. }
  275. $data['building_count'] = count($list); //楼盘数量
  276. $data['housetype_all'] = $housetype_all; //户型数
  277. $data['housetype_vr_all'] = $housetype_vr_all; //户型Vr
  278. $data['housetype_develop_all'] = $housetype_develop_all; //楼盘案例数
  279. $data['building_vr_all'] = $building_vr_all; //楼盘VR
  280. $data['housetype_vr_percent'] = $housetype_all > 0 ? round($housetype_vr_all*100/$housetype_all,2) : 0;//户型vr完整度
  281. $data['housetype_develop_percent'] = $housetype_all > 0 ? round($housetype_develop_all*100/$housetype_all,2) : 0;//楼盘案例完整度
  282. $data['building_share_number'] = 0;//楼书转发数据
  283. $data['building_look_number'] = 0;//楼书浏览数据
  284. $data['building_clue_number'] = 0;//楼书获取线索数据
  285. //拆分时间
  286. $comtent_list = [];
  287. $tmp_day = 1;
  288. $time_arr = getDateByInterval($time[0], $time[1], 'day');
  289. if (count($time_arr) > 35) {
  290. $tmp_day = 2;
  291. $time_arr = getDateByInterval($time[0], $time[1], 'month');
  292. }
  293. //折线图
  294. $tmp_where[] = ['employee_id', 'in', $empid];
  295. $tmp_where[] = ['type','in',['Building', 'Building_vr']];
  296. foreach ($time_arr as $k => $v) {
  297. if ($tmp_day == 2) {
  298. $tmp_add_time = ['addtime', 'between', [$v['startDate'] . ' 00:00:00', $v['endDate'] . ' 23:59:59']];
  299. $tmp_share_time = ['share_time', 'between', [$v['startDate'] . ' 00:00:00', $v['endDate'] . ' 23:59:59']];
  300. $comtent_list[$k]['times'] = $v['name'];
  301. } else {
  302. $tmp_add_time = ['addtime', 'between', [$v . ' 00:00:00', $v . ' 23:59:59']];
  303. $tmp_share_time = ['share_time', 'between', [$v . ' 00:00:00', $v . ' 23:59:59']];
  304. $comtent_list[$k]['time'] = $v;
  305. }
  306. $clue_num = CustomerClue::where([['employee_id', 'in', $empid], ['pipe_type', 'in', ['building', 'buildingvr']], $tmp_add_time])->count();
  307. $look_num = Footprints::where([['employee_id', 'in', $empid], ['pipe_type', 'in', ['building', 'buildingVr']], $tmp_add_time])->count();
  308. $share_num = ShareLog::where($tmp_where)->where([$tmp_share_time])->column('employee_id');
  309. $comtent_list[$k]['share_num'] = count($share_num);
  310. $comtent_list[$k]['look_num'] = $look_num;
  311. $comtent_list[$k]['clue_num'] = $clue_num;
  312. $data['building_share_number'] += count($share_num); //楼书转发数据
  313. $data['building_look_number'] += $look_num; //楼书浏览数据
  314. $data['building_clue_number'] += $clue_num; //楼书获取线索数据
  315. }
  316. Cache::set($cache_data_name,json_encode(['total' => $data, 'fold_line' => $comtent_list, 'build_list' => $build_list]), $this->cache_time);
  317. return json(['code' => 0, 'data' => ['total' => $data, 'fold_line' => $comtent_list, 'build_list' => $build_list], 'msg' => '获取成功']);
  318. }
  319. /**
  320. * 内容使用大屏-AI谈单工具-右侧
  321. */
  322. public function get_right_content_use_total()
  323. {
  324. $root_id = $this->aec->decrypt($this->token);
  325. $param = request()->only(['times']);
  326. //默认本月时间
  327. $time = [date('Y-m-1'), date('Y-m-d')];
  328. if (isset($param['times']) && $param['times']) {
  329. $time = explode(' - ', $param['times']);
  330. }
  331. $cache_data_name = 'get_right_content_use_total-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  332. $cache_data_info = Cache::get($cache_data_name);
  333. if($cache_data_info){
  334. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  335. }
  336. $orgid = orgSubIds($root_id);
  337. $emp_list = Employee::where([['org_id', 'in', $orgid], ['state', '=', '在职'], ['uid', '<>', 0]])->field('id,org_id')->select()->toArray(); //部门员工
  338. $empid = [];
  339. $group_empid = [];
  340. foreach($emp_list as $val){
  341. $empid[] = $val['id'];
  342. $group_empid[$val['org_id']][] = $val['id'];
  343. }
  344. //拆分时间
  345. $fold_line_list = [];
  346. $tmp_day = 1;
  347. $time_arr = getDateByInterval($time[0], $time[1], 'day');
  348. if (count($time_arr) > 35) {
  349. $tmp_day = 2;
  350. $time_arr = getDateByInterval($time[0], $time[1], 'month');
  351. }
  352. //AI谈单数据
  353. $db_where[] = ['CustomerVisitLog.remark', 'like', '%讲解智慧屏##%'];
  354. $db_where[] = ['Customer.employee_id', 'in', $empid];
  355. $db_where[] = ['CustomerVisitLog.is_merge', '=', 0];
  356. foreach($time_arr as $k => $v){
  357. if ($tmp_day == 2) {
  358. $tmp_add_time = ['CustomerVisitLog.addtime', 'between', [$v['startDate'] . ' 00:00:00', $v['endDate'] . ' 23:59:59']];
  359. $fold_line_list[$k]['times'] = $v['name'];
  360. } else {
  361. $tmp_add_time = ['CustomerVisitLog.addtime', 'between', [$v . ' 00:00:00', $v . ' 23:59:59']];
  362. $fold_line_list[$k]['time'] = $v;
  363. }
  364. $count = Db::view('Customer', ['name', 'phone'])->view('CustomerVisitLog', 'customer_id,addtime,remark', 'Customer.id=CustomerVisitLog.customer_id')->where($db_where)->where([$tmp_add_time])->count();
  365. $fold_line_list[$k]['number'] = $count;
  366. }
  367. //获取部门情况
  368. $org_list = [];
  369. $org_where[] = ['CustomerVisitLog.is_merge', '=', 0];
  370. $org_where[] = ['CustomerVisitLog.remark', 'like', '%讲解智慧屏##%'];
  371. $newlist = Org::where([['id', 'in', $orgid]])->field('id,name')->select()->toArray();
  372. foreach ($newlist as $key => $val) {
  373. $org_list[$key]['id'] = $val['id'];
  374. $org_list[$key]['name'] = $val['name'];
  375. $org_list[$key]['people'] = 0; //谈单人数
  376. $org_list[$key]['number'] = 0; //谈单次数
  377. $org_list[$key]['times'] = 0; //总谈单时长
  378. if (isset($group_empid[$val['id']]) && $group_empid[$val['id']]) {
  379. $tmp_employee = ['Customer.employee_id', 'in', $group_empid[$val['id']]];
  380. $tmp_add_time = ['CustomerVisitLog.addtime', 'between', [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59']];
  381. $tmp_data = Db::view('Customer', ['name', 'phone'])->view('CustomerVisitLog', 'customer_id,addtime,remark', 'Customer.id=CustomerVisitLog.customer_id')->where($org_where)->where([$tmp_add_time,$tmp_employee])->select()->toArray();
  382. $org_list[$key]['people'] = count(array_unique(array_column($tmp_data,'customer_id')));
  383. $org_list[$key]['number'] = count(array_column($tmp_data,'customer_id'));
  384. $tmp_times = 0;
  385. foreach($tmp_data as $n){
  386. $tmp_times += explode('分钟;<br/>',explode('谈单时长:',$n['remark'])[1])[0];
  387. }
  388. $org_list[$key]['times'] = $tmp_times;
  389. }
  390. }
  391. //企业话术使用数据
  392. $tmp_where[] = ['root_id', '=', $root_id];
  393. $tmp_where[] = ['employee_id', 'in', $empid];
  394. $tmp_where[] = ['addtime', 'between', [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59']];
  395. $chosen = TalkskillChosen::where($tmp_where)->field('sum(use_count) as use_count,sum(view_times) as view_times')->find();//精选话术的使用次数-和浏览次数
  396. $success = TalkskillSuccess::where($tmp_where)->field('sum(use_count) as use_count,sum(view_times) as view_times')->find();//成功案例的使用次数-和浏览次数
  397. $bai_use_count = Talkskill::where($tmp_where)->sum('use_count');//百问百答的使用次数
  398. $tmp_where[] = ['type', '=', 'talkskill'];
  399. $bai_look_count = TalkskillViewLog::where($tmp_where)->count();//浏览次数
  400. $total = [
  401. 'look_chosen' => $chosen['view_times'] ?? 0,
  402. 'look_uccess' => $success['view_times'] ?? 0,
  403. 'look_bai' => $bai_look_count ?? 0,
  404. 'look_all' => $chosen['view_times'] + $success['view_times'] + $bai_look_count,
  405. 'use_chosen' => $chosen['use_count'] ?? 0,
  406. 'use_uccess' => $success['use_count'] ?? 0,
  407. 'use_bai' => $bai_use_count ?? 0,
  408. 'use_all' => $chosen['use_count'] + $success['use_count'] + $bai_use_count,
  409. ];
  410. Cache::set($cache_data_name,json_encode(['fold_line' => $fold_line_list, 'org_list' => $org_list, 'total' => $total]), $this->cache_time);
  411. return json(['code' => 0, 'data' => ['fold_line' => $fold_line_list, 'org_list' => $org_list, 'total' => $total], 'msg' => '获取成功']);
  412. }
  413. /**
  414. * 内容使用大屏-AI谈单工具-右侧-详情
  415. */
  416. public function get_right_content_use_total_info()
  417. {
  418. $root_id = $this->aec->decrypt($this->token);
  419. $param = request()->only(['times', 'org_id']);
  420. //默认本月时间
  421. $time = [date('Y-m-1'), date('Y-m-d')];
  422. if (isset($param['times']) && $param['times']) {
  423. $time = explode(' - ', $param['times']);
  424. }
  425. $cache_data_name = 'get_right_content_use_total_info-' . $time[0] . '-' . $time[1] . '_' . $root_id . '_' . $param['org_id'];
  426. $cache_data_info = Cache::get($cache_data_name);
  427. if($cache_data_info){
  428. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  429. }
  430. $emp_list = Employee::where([['org_id', '=', $param['org_id']], ['state', '=', '在职'], ['uid', '<>', 0], ['root_id', '=', $root_id]])->field('id,org_id,name')->select()->toArray(); //部门员工
  431. //获取部门情况
  432. $org_list = [];
  433. $org_where[] = ['CustomerVisitLog.is_merge', '=', 0];
  434. $org_where[] = ['CustomerVisitLog.remark', 'like', '%讲解智慧屏##%'];
  435. foreach ($emp_list as $key => $val) {
  436. $org_list[$key]['name'] = $val['name'];
  437. $tmp_employee = ['Customer.employee_id', '=', $val['id']];
  438. $tmp_add_time = ['CustomerVisitLog.addtime', 'between', [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59']];
  439. $tmp_data = Db::view('Customer', ['name', 'phone'])->view('CustomerVisitLog', 'customer_id,addtime,remark', 'Customer.id=CustomerVisitLog.customer_id')->where($org_where)->where([$tmp_add_time, $tmp_employee])->select()->toArray();
  440. $org_list[$key]['people'] = count(array_unique(array_column($tmp_data, 'customer_id')));
  441. $org_list[$key]['number'] = count(array_column($tmp_data, 'customer_id'));
  442. $tmp_times = 0;
  443. foreach ($tmp_data as $n) {
  444. $tmp_times += explode('分钟;<br/>', explode('谈单时长:', $n['remark'])[1])[0];
  445. }
  446. $org_list[$key]['times'] = $tmp_times;
  447. }
  448. Cache::set($cache_data_name,json_encode($org_list), $this->cache_time);
  449. return json(['code' => 0, 'data' => $org_list, 'msg' => '获取成功']);
  450. }
  451. /**
  452. * 投放大屏-当前时间范围内所有数据-跨月则按月份查找-左上角折线图
  453. */
  454. public function get_fish_campaign_all_day()
  455. {
  456. $root_id = $this->aec->decrypt($this->token);
  457. $param = request()->only(['times']);
  458. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  459. if (isset($param['times']) && $param['times']) {
  460. $time = explode(' - ', $param['times']);
  461. }
  462. $cache_data_name = 'get_fish_campaign_all_day-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  463. $cache_data_info = Cache::get($cache_data_name);
  464. if($cache_data_info){
  465. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  466. }
  467. $list = $tx_list = [];
  468. $tmp_day = 1;
  469. $time_arr = getDateByInterval($time[0], $time[1], 'day');
  470. if (count($time_arr) > 35) {
  471. $tmp_day = 2;
  472. $time_arr = getDateByInterval($time[0], $time[1], 'month');
  473. }
  474. $where[] = ['root_id', '=', $root_id];
  475. foreach ($time_arr as $k => $v) {
  476. if ($tmp_day == 2) {
  477. $list[$k]['time'] = $v['name'];
  478. $tx_list[$k]['time'] = $v['name'];
  479. $data = FishCampaign::where($where)->where([['type', 'in', [1]]])->whereTime('data_time', 'between', [$v['startDate'], $v['endDate']])->field('sum(`show`) as shows,sum(`click`) as click,sum(`convert`) as converts')->find();
  480. $tx_data = FishCampaign::where($where)->where([['type', '=', 2]])->whereTime('data_time', 'between', [$v['startDate'], $v['endDate']])->field('sum(`show`) as shows,sum(`click`) as click,sum(`convert`) as converts')->find();
  481. //todo 直播
  482. $live_clue_where[] = ['type', '=', 4];
  483. $live_clue_where[] = ['root_id', '=', $root_id];
  484. $zhibo_clue_count = FishData::where($live_clue_where)->whereTime('create_time', 'between', [$v['startDate'], $v['endDate']])->count();
  485. //todo 腾讯
  486. $tx_clue_where[] = ['type', '=', 2];
  487. $tx_clue_where[] = ['root_id', '=', $root_id];
  488. $tx_clue_count = FishData::where($tx_clue_where)->whereTime('create_time', 'between', [$v['startDate'], $v['endDate']])->count();
  489. } else {
  490. $data = FishCampaign::where($where)->where([['type', 'in', [1]]])->where(['data_time' => $v])->field('sum(`show`) as shows,sum(`click`) as click,sum(`convert`) as converts')->find();
  491. $tx_data = FishCampaign::where($where)->where([['type', '=', 2]])->where(['data_time' => $v])->field('sum(`show`) as shows,sum(`click`) as click,sum(`convert`) as converts')->find();
  492. $list[$k]['time'] = $v;
  493. $tx_list[$k]['time'] = $v;
  494. //todo 直播
  495. $live_clue_where[] = ['type', '=', 4];
  496. $live_clue_where[] = ['root_id', '=', $root_id];
  497. $zhibo_clue_count = FishData::where($live_clue_where)->where('create_time', $v)->count();
  498. //todo 腾讯
  499. $tx_clue_where[] = ['type', '=', 2];
  500. $tx_clue_where[] = ['root_id', '=', $root_id];
  501. $tx_clue_count = FishData::where($tx_clue_where)->where('create_time',$v)->count();
  502. }
  503. $list[$k]['shows'] = $data['shows'] ?? 0;
  504. $list[$k]['click'] = $data['click'] ?? 0;
  505. $list[$k]['converts'] = $zhibo_clue_count+$data['converts'] ?? 0;
  506. $tx_list[$k]['shows'] = $tx_data['shows'] ?? 0;
  507. $tx_list[$k]['click'] = $tx_data['click'] ?? 0;
  508. $tx_list[$k]['converts'] = $tx_clue_count ?? 0;
  509. }
  510. Cache::set($cache_data_name,json_encode(['fish' => $list, 'tx' => $tx_list]), $this->cache_time);
  511. return json(['code' => 0, 'data' => ['fish' => $list, 'tx' => $tx_list], 'msg' => '获取成功']);
  512. }
  513. /**
  514. * 投放大屏-查询本日广告组数据-单独日期-左下角列表
  515. */
  516. public function get_fish_campaign_day()
  517. {
  518. $root_id = $this->aec->decrypt($this->token);
  519. $param = request()->only(['times']);
  520. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  521. if (isset($param['times']) && $param['times']) {
  522. $time = explode(' - ', $param['times']);
  523. }
  524. $cache_data_name = 'get_fish_campaign_day-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  525. $cache_data_info = Cache::get($cache_data_name);
  526. if($cache_data_info){
  527. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  528. }
  529. $where[] = ['root_id', '=', $root_id];
  530. $where[] = ['data_time', 'between', $time];
  531. $where[] = ['type', 'in', [1,4]];
  532. $list = FishCampaign::where($where)->field('campaign_id,campaign_name,cost,show,click,avg_click_cost,ctr,convert,convert_cost,convert_rate,data_time')->order('id desc')->select();
  533. $tx_where[] = ['root_id', '=', $root_id];
  534. $tx_where[] = ['data_time', 'between', $time];
  535. $tx_where[] = ['type', '=', 2];
  536. $tx_list = FishCampaign::where($tx_where)->field('campaign_id,campaign_name,cost,show,click,avg_click_cost,ctr,convert,convert_cost,convert_rate,data_time')->order('id desc')->select();
  537. Cache::set($cache_data_name,json_encode(['fish' => $list, 'tx' => $tx_list]), $this->cache_time);
  538. return json(['code' => 0, 'data' => ['fish' => $list, 'tx' => $tx_list], 'msg' => '获取成功']);
  539. }
  540. /**
  541. * 获取今日广告组更新的线索
  542. */
  543. public function get_fish_top_campaign_data()
  544. {
  545. $root_id = $this->aec->decrypt($this->token);
  546. $channel_setting = Company::where(['root_id' => $root_id])->value('channel_setting');
  547. $fish_change =[];
  548. if (!empty($channel_setting)){
  549. $tmp_data = json_decode($channel_setting, true);
  550. $time = date('Y-m-d');
  551. //查询今天的数据
  552. $tmp_data = $this->refreshToken($tmp_data, $root_id);
  553. $advertiser_id = explode(',', $tmp_data['fish_adv']);
  554. foreach ($advertiser_id as $va) {
  555. $number = 0;
  556. $data = $this->fish->getCampaignList($tmp_data['fish_access_token'], ['advertiser_id' => $va, 'start_date' => $time, 'end_date' => $time, 'page' => 1]);
  557. if ($data['code'] == 0) {
  558. foreach ($data['data']['list'] as $val) {
  559. //需要比是否有新的线索
  560. $info = FishCampaign::where(['root_id' => $root_id, 'data_time' => $time, 'advertiser_id' => $va, 'campaign_id' => $val['campaign_id']])->field('id,campaign_name,convert')->find();
  561. if (isset($info) && $info) {
  562. $tmp_number = $val['convert'] > $info['convert'] ? $val['convert'] - $info['convert'] : 0; //比之前存的记录多出多少线索
  563. $number += $tmp_number;
  564. $val['id'] = $info['id'];
  565. FishCampaign::update($val);
  566. }
  567. }
  568. }
  569. if ($number > 0) {
  570. $fish_change[] = "字节跳动账号-获取线索" . $number . '个';
  571. }
  572. }
  573. }
  574. return json(['code' => 0, 'data' => $fish_change, 'msg' => '获取成功']);
  575. }
  576. /**
  577. * 投放大屏-获取广告投放总数据-中间部分
  578. */
  579. public function get_adv_total_data()
  580. {
  581. $root_id = $this->aec->decrypt($this->token);
  582. $param = request()->only(['times']); //时间区间
  583. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  584. if (isset($param['times']) && $param['times']) {
  585. $time = explode(' - ', $param['times']);
  586. }
  587. $cache_data_name = 'get_adv_total_data-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  588. $cache_data_info = Cache::get($cache_data_name);
  589. if($cache_data_info){
  590. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  591. }
  592. //飞鱼数据
  593. $where[] = ['type', 'in', [1,4]];
  594. $where[] = ['root_id', '=', $root_id];
  595. $where[] = ['data_time', 'between', $time];
  596. $data = FishCampaign::where($where)->field("sum(cost) as cost,sum(`show`) as shows,sum(click) as click,sum(`convert`) as converts")->find();
  597. //todo 直播计算
  598. $feiyu_where[] = ['type', 'in', [1]];
  599. $feiyu_where[] = ['root_id', '=', $root_id];
  600. $feiyu_where[] = ['create_time', 'between', $time];
  601. // $feiyu_clue_count = FishCampaign::where($feiyu_where)->sum('convert');
  602. $feiyu_clue_count = FishData::where($feiyu_where)->count();
  603. $zhibo_where[] = ['type', 'in', [4]];
  604. $zhibo_where[] = ['root_id', '=', $root_id];
  605. $zhibo_where[] = ['create_time', 'between', $time];
  606. // $zhibo_where[] = ['advertiser_id', '<>', '0'];
  607. $zhibo_clue_count = FishData::where($zhibo_where)->count();
  608. $tx_clue_where[] = ['type', 'in', [2]];
  609. $tx_clue_where[] = ['root_id', '=', $root_id];
  610. $tx_clue_where[] = ['create_time', 'between', $time];
  611. $tx_clue_count = FishData::where($tx_clue_where)->count();
  612. $toufang_clue_count = $feiyu_clue_count+$zhibo_clue_count;
  613. $customer_id = FishData::where([['type', 'in', [1,4]], ['root_id', '=', $root_id], ['create_time', 'between', $time], ['is_allocation', '=', 1]])->column('customer_id');
  614. //查询有效线索
  615. $source_id = CustomerSource::where(['root_id' => $root_id, 'source' => '飞鱼线索'])->value('id');
  616. $customer_data = Customer::where([['source_id', '=', $source_id], ['id', 'in', $customer_id]])->field('id,deposit_money as deposit_moneys,signed_money as signed_moneys')->select()->toArray();
  617. $fish_count = $fish_money = 0;
  618. foreach ($customer_data as $val) {
  619. $fish_count++;
  620. if (isset($val['signed_moneys']) && $val['signed_moneys']) {
  621. $fish_money += $val['signed_moneys'];
  622. }
  623. if (!isset($val['signed_moneys']) && isset($val['deposit_moneys'])) {
  624. $fish_money += $val['deposit_moneys'];
  625. }
  626. }
  627. $fish_count = count($customer_id);
  628. //腾讯数据
  629. $tx_where[] = ['type', '=', 2];
  630. $tx_where[] = ['root_id', '=', $root_id];
  631. $tx_where[] = ['data_time', 'between', $time];
  632. $tx_data = FishCampaign::where($tx_where)->field("sum(cost) as cost,sum(`show`) as shows,sum(click) as click,sum(`convert`) as converts")->find();
  633. $tx_customer_id = FishData::where([['type', '=', 2], ['root_id', '=', $root_id], ['create_time', 'between', $time], ['is_allocation', '=', 1]])->column('customer_id');
  634. //查询有效线索
  635. $tx_source_id = CustomerSource::where(['root_id' => $root_id, 'source' => '腾讯线索'])->value('id');
  636. $tx_customer_data = Customer::where([['source_id', '=', $tx_source_id], ['id', 'in', $tx_customer_id]])->field('id,deposit_money as deposit_moneys,signed_money as signed_moneys')->select()->toArray();
  637. $tx_count = $tx_money = 0;
  638. foreach ($tx_customer_data as $val) {
  639. $tx_count++;
  640. if (isset($val['signed_moneys']) && $val['signed_moneys']) {
  641. $tx_money += $val['signed_moneys'];
  642. }
  643. if (!isset($val['signed_moneys']) && isset($val['deposit_moneys'])) {
  644. $tx_money += $val['deposit_moneys'];
  645. }
  646. }
  647. $info = [
  648. //飞鱼转化成本 = 总消耗 / 转商机线索量
  649. //飞鱼总投放金额
  650. 'fish_cost' => $data['cost']??0,
  651. //飞鱼展示数
  652. 'fish_show' => $data['shows']??0,
  653. //飞鱼点击数
  654. 'fish_click' => $data['click']??0,
  655. //飞鱼点击率
  656. 'fish_click_lv' => $data['click'] > 0 && $data['shows'] > 0 ? round($data['click'] / $data['shows'] * 100, 2) : 0,
  657. //飞鱼转化数
  658. 'fish_convert' => $toufang_clue_count??0,
  659. //飞鱼转化率
  660. 'fish_convert_lv' => $toufang_clue_count > 0 && $data['click'] > 0 ? round($toufang_clue_count / $data['click'] * 100, 2) : 0,
  661. //飞鱼有效数
  662. 'fish_count' => $fish_count,
  663. //飞鱼有效率
  664. 'fish_count_lv' => $fish_count > 0 && $toufang_clue_count > 0 ? round($fish_count / $toufang_clue_count * 100, 2) : 0,
  665. //飞鱼广告线索成本 = 广告总消耗 / 广告线索量
  666. 'fish_convert_cost' => $toufang_clue_count > 0 ? round($data['cost'] / $toufang_clue_count, 2) : 0,
  667. //飞鱼产值
  668. 'fish_signed_money' => $fish_money,
  669. ];
  670. //腾讯数据
  671. $tx = [
  672. 'fish_cost' => $tx_data['cost'] ?? 0,
  673. 'fish_show' => $tx_data['shows'] ?? 0,
  674. 'fish_click' => $tx_data['click'] ?? 0,
  675. 'fish_click_lv' => $tx_data['click'] > 0 && $tx_data['shows'] > 0 ? round($tx_data['click'] / $tx_data['shows'] * 100, 2) : 0,
  676. 'fish_convert' => $tx_clue_count ?? 0,
  677. 'fish_convert_lv' => $tx_clue_count > 0 && $tx_data['click'] > 0 ? round($tx_clue_count / $tx_data['click'] * 100, 2) : 0,
  678. 'fish_count' => $tx_count,
  679. 'fish_count_lv' => $tx_count > 0 && $tx_clue_count > 0 ? round($tx_count / $tx_clue_count * 100, 2) : 0,
  680. 'fish_convert_cost' => $tx_clue_count > 0 ? round($tx_data['cost'] / $tx_clue_count, 2) : 0,
  681. 'fish_signed_money' => $tx_money,
  682. ];
  683. //总数据-飞鱼数据+腾讯数据+欧派数据
  684. $cost = bcadd($info['fish_cost'], $tx['fish_cost'],2);
  685. $show = bcadd($info['fish_show'], $tx['fish_show'],0);
  686. $click = bcadd($info['fish_click'], $tx['fish_click'],0);
  687. $converts = bcadd($info['fish_convert'], $tx['fish_convert'],0);
  688. $customer_data_count = bcadd($info['fish_count'], $tx['fish_count'],0);
  689. $customer_data_signed_money = bcadd($fish_money, $tx_money,2); //$info['fish_signed_money'] + $tx['fish_signed_money'];
  690. $all = [
  691. //总投放金额
  692. 'cost' => $cost,
  693. //展示数
  694. 'shows' => $show,
  695. //点击数
  696. 'click' => $click,
  697. //点击率
  698. 'click_lv' => $click > 0 && $show > 0? round($click / $show * 100, 2) : 0,
  699. //总转化数
  700. 'converts' => $converts,
  701. //转化率
  702. 'convert_lv' => $converts > 0 && $click > 0 ? round($converts / $click * 100, 2) : 0,
  703. //有效线索
  704. 'count' => $customer_data_count,
  705. //有效率
  706. 'count_lv' => $customer_data_count > 0 && $converts > 0 ? round($customer_data_count / $converts * 100, 2) : 0,
  707. //获客成本
  708. 'convert_cost' => $converts > 0 ? round($cost / $converts, 2) : 0,
  709. //产值
  710. 'signed_money' => $customer_data_signed_money,
  711. ];
  712. Cache::set($cache_data_name,json_encode(['all' => $all, 'fish' => $info, 'tx' => $tx]), $this->cache_time);
  713. return json(['code' => 0, 'data' => ['all' => $all, 'fish' => $info, 'tx' => $tx], 'msg' => '获取成功']);
  714. }
  715. /**
  716. * 获取企业设置的广告主
  717. */
  718. public function get_company_channel_setting()
  719. {
  720. $root_id = $this->aec->decrypt($this->token);
  721. $channel_setting = Company::where(['root_id' => $root_id])->value('channel_setting');
  722. $data = [
  723. 'root_id' => $root_id,
  724. 'fish_adv' => '',
  725. 'tx_adv' => '',
  726. ];
  727. if (isset($channel_setting) && $channel_setting) {
  728. $tmp_data = json_decode($channel_setting, true);
  729. $data['fish_adv'] = $tmp_data['fish_adv'];
  730. $data['tx_adv'] = $tmp_data['tx_adv'];
  731. }
  732. return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
  733. }
  734. /**
  735. * 更新企业设置的广告主
  736. */
  737. public function set_company_channel_setting()
  738. {
  739. $root_id = $this->aec->decrypt($this->token);
  740. $param = request()->only(['fish_adv', 'tx_adv']);
  741. $channel_setting = Company::where(['root_id' => $root_id])->value('channel_setting');
  742. if (isset($channel_setting) && $channel_setting) {
  743. $tmp_data = json_decode($channel_setting, true);
  744. $tmp_data['fish_adv'] = $param['fish_adv'];
  745. $tmp_data['tx_adv'] = $param['tx_adv'];
  746. Company::where(['root_id' => $root_id])->update(['channel_setting' => json_encode($tmp_data)]);
  747. }
  748. return json(['code' => 0, 'msg' => '更新成功']);
  749. }
  750. /**
  751. * 投放大屏-获取飞鱼的广告组下的详细广告计划
  752. */
  753. public function get_fish_campaign_list()
  754. {
  755. $root_id = $this->aec->decrypt($this->token);
  756. $param = request()->only(['times', 'campaign_id']);
  757. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  758. if (isset($param['times']) && $param['times']) {
  759. $time = explode(' - ', $param['times']);
  760. }
  761. $cache_data_name = 'get_fish_campaign_list-' . $time[0] . '-' . $time[1] . '_' . $root_id . '_' . $param['campaign_id'];
  762. $cache_data_info = Cache::get($cache_data_name);
  763. if($cache_data_info){
  764. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  765. }
  766. //如果是今天则查最新的接口数据
  767. $wheres[] = ['type', 'in', [1,4]];
  768. $wheres[] = ['root_id', '=', $root_id];
  769. $wheres[] = ['campaign_id', '=', $param['campaign_id']];
  770. $wheres[] = ['data_time', 'between', $time];
  771. $list = FishCampaignList::where($wheres)->field('ad_name,cost,show,click,avg_click_cost,ctr,convert,convert_cost,convert_rate,data_time')->order('id desc')->select();
  772. Cache::set($cache_data_name,json_encode($list), $this->cache_time);
  773. return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']);
  774. }
  775. /**
  776. * 投放大屏-获取腾讯的广告组下的详细广告计划
  777. */
  778. public function get_tx_campaign_list()
  779. {
  780. $root_id = $this->aec->decrypt($this->token);
  781. $param = request()->only(['times', 'campaign_id']);
  782. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  783. if (isset($param['times']) && $param['times']) {
  784. $time = explode(' - ', $param['times']);
  785. }
  786. $cache_data_name = 'get_tx_campaign_list-' . $time[0] . '-' . $time[1] . '_' . $root_id . '_' . $param['campaign_id'];
  787. $cache_data_info = Cache::get($cache_data_name);
  788. if($cache_data_info){
  789. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  790. }
  791. //如果是今天则查最新的接口数据
  792. $wheres[] = ['type', '=', 2];
  793. $wheres[] = ['root_id', '=', $root_id];
  794. $wheres[] = ['campaign_id', '=', $param['campaign_id']];
  795. $wheres[] = ['data_time', 'between', $time];
  796. $list = FishCampaignList::where($wheres)->field('ad_name,cost,show,click,avg_click_cost,ctr,convert,convert_cost,convert_rate,data_time')->order('id desc')->select();
  797. Cache::set($cache_data_name,json_encode($list), $this->cache_time);
  798. return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']);
  799. }
  800. /**
  801. * 刷新token
  802. */
  803. public function refreshToken($tmp_data, $root_id)
  804. {
  805. $fish_refresh_time = $tmp_data['fish_refresh_time']; //上次token更新时间
  806. if ($fish_refresh_time + 80000 < time()) {
  807. $token = $this->fish->getRefreshToken($tmp_data['fish_refresh_token']);
  808. if ($token['code'] == 0) {
  809. $tmp_data['fish_access_token'] = $token['data']['access_token'];
  810. $tmp_data['fish_refresh_token'] = $token['data']['refresh_token'];
  811. $tmp_data['fish_refresh_time'] = time();
  812. Company::where(['root_id' => $root_id])->update(['channel_setting' => json_encode($tmp_data)]);
  813. } else {
  814. $tmp_data['fish_access_token'] = '';
  815. $tmp_data['fish_refresh_token'] = '';
  816. Company::where(['root_id' => $root_id])->update(['channel_setting' => json_encode($tmp_data)]);
  817. }
  818. }
  819. return $tmp_data;
  820. }
  821. /**
  822. * 刷新token
  823. */
  824. public function refreshToken2($tmp_data, $root_id)
  825. {
  826. $fish_refresh_time = $tmp_data['fish_refresh_time']; //上次token更新时间
  827. if ($fish_refresh_time + 80000 < time()) {
  828. $token = $this->fish_wh->getRefreshToken($tmp_data['fish_refresh_token']);
  829. if ($token['code'] == 0) {
  830. $tmp_data['fish_access_token'] = $token['data']['access_token'];
  831. $tmp_data['fish_refresh_token'] = $token['data']['refresh_token'];
  832. $tmp_data['fish_refresh_time'] = time();
  833. Company::where(['root_id' => $root_id])->update(['channel_setting_wh' => json_encode($tmp_data)]);
  834. } else {
  835. $tmp_data['fish_access_token'] = '';
  836. $tmp_data['fish_refresh_token'] = '';
  837. Company::where(['root_id' => $root_id])->update(['channel_setting_wh' => json_encode($tmp_data)]);
  838. }
  839. }
  840. return $tmp_data;
  841. }
  842. /**
  843. * 转化大屏部门排行统计
  844. */
  845. public function org_statistics()
  846. {
  847. if (empty($this->token)) return json(['code' => 0, 'msg' => 'Token失效']);
  848. $root_id = $this->aec->decrypt($this->token);
  849. $param = request()->only(['times']);
  850. // if (empty($param['times'])) return json(['code' => 1, 'msg' => '时间参数错误']);
  851. $orgids = [];
  852. foreach (orgSubIds($root_id) as $key => $val) {
  853. if (!Org::where([['pid', '=', $val], ['status', '=', 1]])->value('id')) {
  854. $orgids[] = $val;
  855. }
  856. }
  857. //$orgids = orgSubIds($root_id);
  858. $orglist = Org::with(['employee' => function ($query) {
  859. $query->where([['state', '=', '在职'], ['uid', '<>', 0]])->field('id,org_id');
  860. }])->where([['id', 'in', orgSubIds($root_id)],['org_type','=',1],['id','not in',[2471,2320,2321,2322]]])->field('id,name,pid')->select()->toArray();
  861. $orgids = array_column($orglist,'id');
  862. $where[] = ['org_id', 'in', $orgids];
  863. //var_dump($orglist);exit;
  864. if (!empty($param['times'])) {
  865. $time = explode(' - ', $param['times']);
  866. } else {
  867. $start = date('Y-m') . '-01';
  868. $end = date('Y-m-d', strtotime("$start +1 month -1 day"));
  869. $time = [$start, $end];
  870. }
  871. if (!empty($time[0])) {
  872. $time[0] = date('Y-m-d 00:00:00', strtotime($time[0]));
  873. }
  874. if (!empty($time[1])) {
  875. $time[1] = date('Y-m-d 23:59:59', strtotime($time[1]));
  876. }
  877. $where[] = ['sign_time', 'between', $time];
  878. //查询企业是否有飞鱼跟腾讯的来源id
  879. $tx_customer_id = FishData::where([['type', 'in', [1, 2, 4]], ['root_id', '=', $root_id], ['create_time_detail', 'between', $time]])->column('customer_id');
  880. $sourceids = CustomerSource::where([['root_id', '=', $root_id], ['source', 'in', ['飞鱼线索', '腾讯线索', '欧派线索']]])->column('id');
  881. if (empty($sourceids)) return json(['code' => 0, 'data' => '', 'msg' => '获取成功']);
  882. $state1 = Customer::changeState('待确认', 'chaos');
  883. $state2 = Customer::changeState('无效', 'chaos');
  884. $state3 = CustomerVisitLog::changeState('已交定', 'chaos');
  885. $state4 = CustomerVisitLog::changeState('已签单', 'chaos');
  886. $state5 = CustomerVisitLog::changeState('确认到店', 'chaos');
  887. $state6 = CustomerVisitLog::changeState('已到场', 'chaos');
  888. $state7 = CustomerVisitLog::changeState('已量房', 'chaos');
  889. //$where[] = ['source_id', 'in', $sourceids];
  890. $where[] = ['id', 'in', $tx_customer_id];
  891. //$where[] = ['state','not in',array_merge($state1,$state2)];
  892. //查询缓存值是否过期
  893. $ceche_data = Cache::get("org_statistics_data_root_id_1_{$root_id}_".$time[0].$time[1]);
  894. if (empty($ceche_data)) {
  895. $cuslist = Customer::where($where)->column('id,org_id,state,add_wechat_time');
  896. $wherev[] = ['CustomerVisitLog.state', 'in', array_merge($state3, $state4, $state5, $state6, $state7)];
  897. $wherev[] = ['CustomerVisitLog.confirm_date', 'between', $time];
  898. $wherev[] = ['CustomerVisitLog.customer_org_id', 'in', $orgids];
  899. $w = Customer::where([['source_id', 'in', $sourceids],['id', 'in', $tx_customer_id]]);
  900. $visitlog_list = CustomerVisitLog::hasWhere('customer', $w)->where($wherev)
  901. ->group('state,customer_id')
  902. ->column('CustomerVisitLog.customer_id,CustomerVisitLog.state,CustomerVisitLog.money,CustomerVisitLog.customer_org_id');
  903. $signids = $metids = [];
  904. $all_assign_cont = $all_valid_percen = $all_clue_cont = $all_jv = $all_meet = $all_deposit = $all_sign = 0;
  905. foreach ($visitlog_list as $key => $val) {
  906. if (in_array($val['state'], array_merge($state5, $state6, $state7))) $metids[] = $val['customer_id'];
  907. if (in_array($val['state'],$state4)) $signids[] = $val['customer_id'];
  908. $newvslog[$val['customer_org_id']][] = $val;
  909. if (in_array($val['state'], $state3, true)) $all_deposit++;
  910. if (in_array($val['state'], $state4, true)) $all_sign++;
  911. }
  912. $yesids = !empty(array_unique($metids)) ? $this->selBeforelog(array_unique($metids), $time[0] . ' 00:00:00') : [];
  913. $all_meet = count($yesids);
  914. $wx_where[] = ['root_id', '=', $root_id];
  915. $wx_where[] = ['org_id', 'in', $orgids];
  916. $wx_where[] = ['cus_addtime', 'between', $time];
  917. $wx_where[] = ['source_id', 'in', $sourceids];
  918. $wx_where[] = ['customer_id', 'in', $tx_customer_id];
  919. $wuxiaolog_list = CustomerInvalidLog::where($wx_where)->column('customer_id,org_id,status');
  920. //获取所有的有效id
  921. $jvids = $validids = [];
  922. foreach ($cuslist as $key => $val) {
  923. $all_clue_cont++;
  924. if (!in_array($val['state'], array_merge($state1, $state2), true)) {
  925. $validids[] = $val['id'];
  926. }
  927. if (!in_array($val['state'],$state2) && $val['add_wechat_time'] >= $time[0] && $val['add_wechat_time'] <= $time[1]){
  928. $all_jv++;
  929. $jvids[] = $val['id'];
  930. }
  931. }
  932. trace(implode(',',$yesids),'infos');
  933. $cusids = array_column($cuslist, 'id');
  934. //trace(implode(',',$cusids),'infos1');
  935. $wxids = array_column($wuxiaolog_list, 'customer_id');
  936. $wcha = array_diff($wxids, $cusids);
  937. if (!empty($wcha)) $all_clue_cont += count($wcha);
  938. $all_assign_cont = FishData::where([['org_id', 'in', $orgids], ['create_time_detail', 'between', $time]])->count();
  939. $all_valid_percen = !empty($validids) && !empty($all_assign_cont) ? round(count($validids) / $all_assign_cont * 100, 2) : 0;
  940. $all = ['all_clue_cont' => $all_assign_cont, 'all_jv' => $all_jv, 'all_meet' => $all_meet, 'all_deposit' => $all_deposit, 'all_sign' => $all_sign, 'all_valid_percen' => $all_valid_percen];
  941. $bmp = $meetids = [];
  942. foreach ($orglist as $key => $val) {
  943. $dd = $meas_house = $valid = $clue_cont = $meet = $deposit = $sign = $basic_money = 0;
  944. foreach ($cuslist as $k => $v) {
  945. if ($v['org_id'] == $val['id'] && !in_array($v['state'], array_merge($state1, $state2))) {
  946. $valid++;
  947. }
  948. if ($v['org_id'] == $val['id']) $clue_cont++;
  949. }
  950. //处理无效的客户还原到员工身上为有效
  951. foreach ($wuxiaolog_list as $k => $v) {
  952. // if ($v['org_id'] == $val['id'] && !in_array($v['customer_id'], $validids) && $v['status'] == 1) {
  953. // $valid++;
  954. // $validids[] = $v['customer_id'];
  955. // }
  956. if ($v['org_id'] == $val['id'] && !in_array($v['customer_id'], $cusids)) {
  957. $clue_cont++;
  958. $cusids[] = $v['customer_id'];
  959. }
  960. }
  961. if (!empty($newvslog[$val['id']])) {
  962. foreach ($newvslog[$val['id']] as $k => $v) {
  963. if (in_array($v['state'], array_merge($state5, $state6, $state7), true) && !in_array($v['customer_id'], $meetids) && in_array($v['customer_id'], $yesids)) {
  964. $meet++;
  965. $meetids[] = $v['customer_id'];
  966. }
  967. if (in_array($v['state'], $state5, true)) $dd++;
  968. if (in_array($v['state'], $state3, true)){
  969. $deposit++;
  970. if(!in_array($v['customer_id'],$signids)) $basic_money += $v['money'];
  971. }
  972. if (in_array($v['state'], $state7, true)) $meas_house++;
  973. if (in_array($v['state'], $state4, true)) {
  974. $basic_money += $v['money'];
  975. $sign++;
  976. }
  977. }
  978. unset($newvslog[$val['id']]);
  979. }
  980. //unset($cusids,$depositids,$wuxiao);
  981. $assign_cont = FishData::where([['org_id', '=', $val['id']], ['create_time_detail', 'between', $time]])->count();
  982. $orglist[$key]['assign_cont'] = $assign_cont;
  983. $orglist[$key]['valid_cont'] = $valid;
  984. $orglist[$key]['valid_percen'] = $valid && $assign_cont ? round($valid / $assign_cont * 100, 2) : 0;
  985. $orglist[$key]['meas_house'] = $meas_house;
  986. $orglist[$key]['meas_house_percen'] = !empty($meas_house) && $valid ? round($meas_house / $valid * 100, 2) : 0;
  987. $orglist[$key]['dd_cont'] = $dd;
  988. $orglist[$key]['dd_percen'] = !empty($dd) && !empty($valid) ? round($dd / $valid * 100, 2) : 0;
  989. $orglist[$key]['deposit_cont'] = $deposit;
  990. $orglist[$key]['deposit_percen'] = !empty($deposit) && !empty($meet) ? round($deposit / $meet * 100, 2) : 0;
  991. $orglist[$key]['sign_cont'] = $sign;
  992. $orglist[$key]['sign_percen'] = !empty($sign) && !empty($meet) ? round($sign / $meet * 100, 2) : 0;
  993. $orglist[$key]['basic_money'] = $basic_money;
  994. $orglist[$key]['sign_agv_money'] = !empty($sign) && !empty($basic_money) ? floor($basic_money / $sign) : 0;
  995. $bmp[] = $basic_money;
  996. }
  997. if (!empty($orglist)) {
  998. array_multisort($bmp, SORT_DESC, $orglist);
  999. }
  1000. $data = ['orglist' => $orglist, 'all' => $all];
  1001. Cache::set('org_statistics_data_'.$time[0].$time[1].$root_id, json_encode($data), $this->cache_time);
  1002. } else {
  1003. $data = json_decode($ceche_data);
  1004. }
  1005. return json(['code' => 0, 'data' => empty($data)?[]:$data, 'msg' => '获取成功']);
  1006. }
  1007. //处理查询客户之前的见面记录
  1008. public function selBeforelog($metids, $firstday)
  1009. {
  1010. $statday = '2021-12-01 00:00:00';
  1011. $state1 = CustomerVisitLog::changeState('确认到店', 'chaos');
  1012. $state2 = CustomerVisitLog::changeState('已到场', 'chaos');
  1013. $state3 = CustomerVisitLog::changeState('已量房', 'chaos');
  1014. $q_where[] = ['customer_id', 'in', $metids];
  1015. $q_where[] = ['state', 'in', array_merge($state1, $state2, $state3)];
  1016. $q_where[] = ['addtime', 'between', [$statday, $firstday]];
  1017. $qianvslog = CustomerVisitLog::where($q_where)->group('customer_id')->column('customer_id');
  1018. $yesids = array_diff($metids, $qianvslog);
  1019. return $yesids;
  1020. }
  1021. /**
  1022. * 转化大屏部门员工数据统计
  1023. */
  1024. public function org_emp_statistics()
  1025. {
  1026. if (empty($this->token)) return json(['code' => 0, 'msg' => 'Token失效']);
  1027. $root_id = $this->aec->decrypt($this->token);
  1028. $param = request()->only(['times','org_id']);
  1029. if (empty($param['times'])) return json(['code' => 1, 'msg' => '时间参数错误']);
  1030. if (empty($param['org_id'])) return json(['code' => 1, 'msg' => '部门参数错误']);
  1031. //$team_orgs = orgSubIds($param['org_id']);
  1032. $emplist = Employee::where([['org_id', '=', $param['org_id']], ['state', '=', '在职'], ['uid', '>', 0]])->column('id,name');
  1033. $empids = array_column($emplist,'id');
  1034. $where[] = ['employee_id','in',$empids];
  1035. //var_dump($orglist);exit;
  1036. if (!empty($param['times'])) {
  1037. $time = explode(' - ', $param['times']);
  1038. $where[] = ['addtime', 'between', [$time[0].' 00:00:00', $time[1].' 23:59:59']];
  1039. }
  1040. //查询企业是否有飞鱼跟腾讯的来源id
  1041. $tx_customer_id = FishData::where([['type', 'in', [1,2,4]], ['root_id', '=', $root_id], ['create_time', 'between', $time], ['is_allocation', '=', 1]])->column('customer_id');
  1042. $sourceids = CustomerSource::where([['root_id', '=', $root_id], ['source', 'in', ['飞鱼线索', '腾讯线索', '欧派线索']]])->column('id');
  1043. if (empty($sourceids)) return json(['code' => 0, 'data' => '', 'msg' => '获取成功']);
  1044. $state1 = Customer::changeState('待确认', 'chaos');
  1045. $state2 = Customer::changeState('无效', 'chaos');
  1046. $state3 = CustomerVisitLog::changeState('已交定', 'chaos');
  1047. $state4 = CustomerVisitLog::changeState('已签单', 'chaos');
  1048. $state5 = CustomerVisitLog::changeState('确认到店', 'chaos');
  1049. $state6 = CustomerVisitLog::changeState('已到场', 'chaos');
  1050. $state7 = CustomerVisitLog::changeState('已量房', 'chaos');
  1051. $where[] = ['source_id', 'in', $sourceids];
  1052. $where[] = ['id','in',$tx_customer_id];
  1053. //$where[] = ['state','not in',array_merge($state1,$state2)];
  1054. //查询缓存值是否过期
  1055. $ceche_data = Cache::get("org_emp_statistics_data_{$root_id}_".$time[0].$time[1].$param['org_id']);
  1056. //$ceche_data = null;
  1057. if (empty($ceche_data)) {
  1058. $cuslist = Customer::where($where)->column('id,employee_id,state,add_wechat_time');
  1059. $wherev[] = ['CustomerVisitLog.state', 'in', array_merge($state3, $state4, $state5, $state6, $state7)];
  1060. $wherev[] = ['CustomerVisitLog.confirm_date', 'between', [$time[0], $time[1]]];
  1061. $wherev[] = ['CustomerVisitLog.customer_employee_id', 'in', $empids];
  1062. $w = Customer::where([['source_id', 'in', $sourceids],['id','in',$tx_customer_id]]);
  1063. $visitlog_list = CustomerVisitLog::hasWhere('customer', $w)->where($wherev)
  1064. ->group('state,customer_id')
  1065. ->column('CustomerVisitLog.customer_id,CustomerVisitLog.state,CustomerVisitLog.money,CustomerVisitLog.customer_employee_id');
  1066. $metids = $signids = [];
  1067. foreach ($visitlog_list as $key => $val) {
  1068. if (in_array($val['state'], array_merge($state5, $state6, $state7))) $metids[] = $val['customer_id'];
  1069. if (in_array($val['state'],$state4)) $signids[] = $val['customer_id'];
  1070. $newvslog[$val['customer_employee_id']][] = $val;
  1071. }
  1072. $yesids = !empty(array_unique($metids)) ? $this->selBeforelog(array_unique($metids), $time[0] . ' 00:00:00') : [];
  1073. $wx_where[] = ['root_id', '=', $root_id];
  1074. $wx_where[] = ['employee_id', 'in', $empids];
  1075. $wx_where[] = ['cus_addtime', 'between', [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59']];
  1076. $wx_where[] = ['source_id', 'in', $sourceids];
  1077. $wx_where[] = ['customer_id', 'in', $tx_customer_id];
  1078. $wuxiaolog_list = CustomerInvalidLog::where($wx_where)->column('customer_id,employee_id,status');
  1079. //获取所有的有效id
  1080. $validids = [];
  1081. foreach ($cuslist as $key => $val) {
  1082. if (!in_array($val['state'], array_merge($state1, $state2), true)) {
  1083. $validids[] = $val['id'];
  1084. }
  1085. }
  1086. $cusids = array_column($cuslist, 'id');
  1087. $wxids = array_column($wuxiaolog_list, 'customer_id');
  1088. $wcha = array_diff($wxids, $cusids);
  1089. $bmp = $meetids = [];
  1090. foreach ($emplist as $key => $val) {
  1091. $dd = $meas_house = $valid = $clue_cont = $meet = $deposit = $sign = $basic_money = 0;
  1092. foreach ($cuslist as $k => $v) {
  1093. if ($v['employee_id'] == $val['id'] && !in_array($v['state'], array_merge($state1, $state2))) {
  1094. $valid++;
  1095. }
  1096. if ($v['employee_id'] == $val['id']) $clue_cont++;
  1097. }
  1098. //处理无效的客户还原到员工身上为有效
  1099. foreach ($wuxiaolog_list as $k => $v) {
  1100. // if ($v['employee_id'] == $val['id'] && !in_array($v['customer_id'], $validids) && $v['status'] == 1) {
  1101. // $valid++;
  1102. // $validids[] = $v['customer_id'];
  1103. // }
  1104. if ($v['employee_id'] == $val['id'] && !in_array($v['customer_id'], $cusids)) {
  1105. $clue_cont++;
  1106. $cusids[] = $v['customer_id'];
  1107. }
  1108. }
  1109. if (!empty($newvslog[$val['id']])) {
  1110. foreach ($newvslog[$val['id']] as $k => $v) {
  1111. if (in_array($v['state'], array_merge($state5, $state6, $state7), true) && !in_array($v['customer_id'], $meetids) && in_array($v['customer_id'], $yesids)) {
  1112. $meet++;
  1113. $meetids[] = $v['customer_id'];
  1114. }
  1115. if (in_array($v['state'], $state5, true)) $dd++;
  1116. if (in_array($v['state'], $state3, true)){
  1117. $deposit++;
  1118. if(!in_array($v['customer_id'],$signids)) $basic_money += $v['money'];
  1119. }
  1120. if (in_array($v['state'], $state7, true)) $meas_house++;
  1121. if (in_array($v['state'], $state4, true)) {
  1122. $basic_money += $v['money'];
  1123. $sign++;
  1124. }
  1125. }
  1126. unset($newvslog[$val['id']]);
  1127. }
  1128. //unset($cusids,$depositids,$wuxiao);
  1129. $assign_cont = FishData::where([['employee_id', '=', $val['id']], ['create_time_detail', 'between', [$time[0], $time[1]]]])->count();
  1130. $emplist[$key]['assign_cont'] = $assign_cont;
  1131. $emplist[$key]['valid_cont'] = $valid;
  1132. $emplist[$key]['valid_percen'] = $valid && $assign_cont ? round($valid / $assign_cont * 100, 2) : 0;
  1133. $emplist[$key]['meas_house'] = $meas_house;
  1134. $emplist[$key]['meas_house_percen'] = !empty($meas_house) && $valid ? round($meas_house / $valid * 100, 2) : 0;
  1135. $emplist[$key]['dd_cont'] = $dd;
  1136. $emplist[$key]['dd_percen'] = !empty($dd) && !empty($valid) ? round($dd / $valid * 100, 2) : 0;
  1137. $emplist[$key]['deposit_cont'] = $deposit;
  1138. $emplist[$key]['deposit_percen'] = !empty($deposit) && !empty($meet) ? round($deposit / $meet * 100, 2) : 0;
  1139. $emplist[$key]['sign_cont'] = $sign;
  1140. $emplist[$key]['sign_percen'] = !empty($sign) && !empty($meet) ? round($sign / $meet * 100, 2) : 0;
  1141. $emplist[$key]['basic_money'] = $basic_money;
  1142. $emplist[$key]['sign_agv_money'] = !empty($sign) && !empty($basic_money) ? floor($basic_money / $sign) : 0;
  1143. $bmp[] = $basic_money;
  1144. }
  1145. if (!empty($emplist)) {
  1146. array_multisort($bmp, SORT_DESC, $emplist);
  1147. }
  1148. Cache::set('org_emp_statistics_data_'.$time[0].$time[1].$param['org_id'], json_encode($emplist), $this->cache_time);
  1149. } else {
  1150. $emplist = json_decode($ceche_data);
  1151. }
  1152. return json(['code' => 0, 'data' => $emplist, 'msg' => '获取成功']);
  1153. }
  1154. /**
  1155. * 转化大屏拆线图统计
  1156. */
  1157. public function clearing_statistics()
  1158. {
  1159. if (empty($this->token)) return json(['code' => 0, 'msg' => 'Token失效']);
  1160. $root_id = $this->aec->decrypt($this->token);
  1161. $param = request()->only(['times']);
  1162. $orgids = Org::where([['id','in',orgSubIds($root_id)],['org_type','=',1]])->column('id');
  1163. if (empty($param['times'])) return json(['code' => 1, 'msg' => '时间参数错误']);
  1164. $time = explode(' - ', $param['times']);
  1165. $cha = (strtotime($time[1]) - strtotime($time[0])) / 86400;
  1166. if ($cha > 35) $type = 'month';
  1167. if ($cha <= 35) $type = 'day';
  1168. $list = getDateByInterval($time[0], $time[1], $type);
  1169. if ($type == 'day') {
  1170. foreach ($list as $key => $val) {
  1171. $new[] = ['name' => $val, 'startDate' => $val . ' 00:00:00', 'endDate' => $val . ' 23:59:59'];
  1172. }
  1173. $list = $new;
  1174. }
  1175. //查询企业是否有飞鱼跟腾讯的来源id
  1176. $tx_customer_id = FishData::where([['type', 'in', [1,2,4]], ['root_id', '=', $root_id], ['create_time', 'between', $time], ['is_allocation', '=', 1]])->column('customer_id');
  1177. $sourceids = CustomerSource::where([['root_id', '=', $root_id], ['source', 'in', ['飞鱼线索', '腾讯线索', '欧派线索']]])->column('id');
  1178. if (empty($sourceids)) return json(['code' => 0, 'data' => '', 'msg' => '获取成功']);
  1179. $cache_data = Cache::get('clearing_statistics_data_'.$time[0].$time[1].$root_id);
  1180. if (empty($cache_data)) {
  1181. $state1 = Customer::changeState('待确认', 'chaos');
  1182. $state2 = Customer::changeState('无效', 'chaos');
  1183. $state3 = CustomerVisitLog::changeState('已交定', 'chaos');
  1184. $state4 = CustomerVisitLog::changeState('已签单', 'chaos');
  1185. $state5 = CustomerVisitLog::changeState('确认到店', 'chaos');
  1186. $state6 = CustomerVisitLog::changeState('已到场', 'chaos');
  1187. $state7 = CustomerVisitLog::changeState('已量房', 'chaos');
  1188. $where[] = ['addtime', 'between', [$time[0], $time[1]]];
  1189. $where[] = ['org_id', 'in', $orgids];
  1190. $where[] = ['source_id', 'in', $sourceids];
  1191. $where[] = ['id','in',$tx_customer_id];
  1192. //$where[] = ['state', 'not in', array_merge($state1, $state2)];
  1193. $cuslist = Customer::where($where)->column('id,addtime,state,org_id');
  1194. //获取所有有效的客户id
  1195. $validids = [];
  1196. foreach($cuslist as $key=>$val){
  1197. if(!in_array($val['state'],array_merge($state1,$state2))) $validids[] = $val['id'];
  1198. }
  1199. $wherev[] = ['CustomerVisitLog.state', 'in', array_merge($state3, $state4, $state5, $state6, $state7)];
  1200. $wherev[] = ['CustomerVisitLog.confirm_date', 'between', [$time[0], $time[1]]];
  1201. $wherev[] = ['CustomerVisitLog.customer_org_id', 'in', $orgids];
  1202. $w = Customer::where([['source_id', 'in', $sourceids],['id','in',$tx_customer_id]]);
  1203. $visitlog_list = CustomerVisitLog::hasWhere('customer', $w)->where($wherev)
  1204. ->group('state,customer_id')
  1205. ->column('CustomerVisitLog.customer_id,CustomerVisitLog.state,CustomerVisitLog.money,CustomerVisitLog.customer_org_id,CustomerVisitLog.confirm_date');
  1206. $metids = [];
  1207. foreach ($visitlog_list as $key => $val) {
  1208. if (in_array($val['state'], array_merge($state5, $state6, $state7))) $metids[] = $val['customer_id'];
  1209. }
  1210. $yesids = !empty(array_unique($metids)) ? $this->selBeforelog(array_unique($metids), $time[0] . ' 00:00:00') : [];
  1211. $wx_where[] = ['root_id', '=', $root_id];
  1212. $wx_where[] = ['org_id', 'in', $orgids];
  1213. $wx_where[] = ['cus_addtime', 'between', [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59']];
  1214. $wx_where[] = ['source_id', 'in', $sourceids];
  1215. $wx_where[] = ['status', '=', 1];
  1216. $wx_where[] = ['customer_id', 'in', $tx_customer_id];
  1217. $wuxiaolog_list = CustomerInvalidLog::where($wx_where)->column('customer_id,cus_addtime');
  1218. //$cluelist = FishData::where([['root_id', '=', $root_id]])->column('create_time_detail');
  1219. foreach ($list as $key => $val) {
  1220. $clue_cont = $valid = $meet = $sign = $basic_money = 0;
  1221. $meetids = [];
  1222. foreach ($cuslist as $k => $v) {
  1223. if ($v['addtime'] >= $val['startDate'] && $v['addtime'] <= $val['endDate']){
  1224. if(!in_array($v['state'],array_merge($state1,$state2))) $valid++;
  1225. $clue_cont++;
  1226. }
  1227. }
  1228. foreach ($wuxiaolog_list as $k => $v) {
  1229. if ($v['cus_addtime'] >= $val['startDate'] && $v['cus_addtime'] <= $val['endDate'] && !in_array($v['customer_id'],$validids)) $valid++;
  1230. }
  1231. // foreach ($cluelist as $k => $v) {
  1232. // if ($v >= $val['startDate'] && $v <= $val['endDate']) $clue_cont++;
  1233. // }
  1234. foreach ($visitlog_list as $k => $v) {
  1235. if ($v['confirm_date'] >= $val['startDate'] && $v['confirm_date'] <= $val['endDate']) {
  1236. if (in_array($v['state'], $state4, true)) {
  1237. $sign++;
  1238. $basic_money += $v['money'];
  1239. }
  1240. if (in_array($v['state'], array_merge($state5, $state6, $state7)) && !in_array($v['customer_id'], $meetids) && in_array($v['customer_id'], $yesids)) {
  1241. $meet++;
  1242. $meetids[] = $v['customer_id'];
  1243. }
  1244. }
  1245. }
  1246. $assign_cont = FishData::where([['root_id', '=', $root_id], ['create_time_detail', 'between', [$val['startDate'], $val['endDate']]]])->count();
  1247. $list[$key]['valid_percen'] = $valid && !empty($assign_cont) ? round($valid / $assign_cont * 100, 2) : 0;
  1248. $list[$key]['meet_percen'] = !empty($meet) && !empty($clue_cont) ? round($meet / $clue_cont * 100, 2) : 0;
  1249. $list[$key]['sign_percen'] = !empty($sign) && !empty($meet) ? round($sign / $meet * 100, 2) : 0;
  1250. }
  1251. Cache::set('clearing_statistics_data_'.$time[0].$time[1].$root_id, json_encode($list), $this->cache_time);
  1252. } else {
  1253. $list = json_decode($cache_data, true);
  1254. }
  1255. return json(['code' => 0, 'data' => empty($list)?[]:$list, 'msg' => '获取成功']);
  1256. }
  1257. /**
  1258. * 社群数据大屏-楼盘交定签单列表
  1259. */
  1260. public function community_depsig_list()
  1261. {
  1262. if (empty($this->token)) return json(['code' => 0, 'msg' => 'Token失效']);
  1263. $root_id = $this->aec->decrypt($this->token);
  1264. //$root_id = 994;
  1265. $param = request()->only(['times']);
  1266. $time = [date('2023-04-01'), date('Y-m-d')]; //默认本月时间
  1267. if (!empty($param['times'])) {
  1268. $time = explode(' - ', $param['times']);
  1269. }
  1270. // if (empty($param['times'])) return json(['code' => 1, 'msg' => '时间参数错误']);
  1271. // $time = explode(' - ', $param['times']);
  1272. $state1 = CustomerVisitLog::changeState('已到店','chaos');
  1273. $state2 = CustomerVisitLog::changeState('已交定','chaos');
  1274. $state3 = CustomerVisitLog::changeState('已签单','chaos');
  1275. $state4 = CustomerVisitLog::changeState('已量房','chaos');
  1276. $state5 = CustomerVisitLog::changeState('已到场','chaos');
  1277. $cache_data = Cache::get('community_depsig_list_'.$time[0].$time[1].$root_id);
  1278. $cache_data = null;
  1279. if (empty($cache_data)) {
  1280. $building_where[] = ['del', '=', 0];
  1281. $building_where[] = ['root_id', '=', $root_id];
  1282. $community_id = BuildingModel::where($building_where)->group('community_id')->column('community_id');
  1283. //小区列表
  1284. $community_list = Community::where([['root_id','=',$root_id],['show','=',0],['id', 'in', $community_id]])->column('id,name,households');
  1285. //社群员工
  1286. $sqempids = Employee::where([['root_id','=',$root_id],['state', '=', '在职'], ['uid', '>', 0],['community_disable','=',0]])->column('id');
  1287. //所有客户
  1288. //$where[] = ['addtime','between',[$time[0],$time[1]]];
  1289. $where[] = ['employee_id','in',$sqempids];
  1290. $where[] = ['community_name','in',array_column($community_list,'name')];
  1291. $cuslist = Customer::where($where)->column('id,community_name');
  1292. //加微的客户
  1293. //$jv_where[] = ['add_wechat_time','between',[$time[0].' 00:00:00',$time[1].' 23:59:59']];
  1294. $jv_where[] = ['add_wechat_time','NOTNULL',null];
  1295. $jv_where[] = ['employee_id','in',$sqempids];
  1296. $jv_where[] = ['community_name','in',array_column($community_list,'name')];
  1297. $jvcuslist = Customer::where($jv_where)->column('id,community_name');
  1298. //$jqcuslist = $kbcuslist = [];
  1299. //进群的客户
  1300. //$jq_where[] = ['into_owner_group','between',[$time[0],$time[1]]];
  1301. $jq_where[] = ['into_owner_group','NOTNULL',null];
  1302. $jq_where[] = ['employee_id','in',$sqempids];
  1303. $jq_where[] = ['community_name','in',array_column($community_list,'name')];
  1304. $jqcuslist = Customer::where($jq_where)->column('id,community_name');
  1305. //口碑的客户
  1306. //$kb_where[] = ['reputation_gather','between',[$time[0],$time[1]]];
  1307. $kb_where[] = ['reputation_gather','NOTNULL',null];
  1308. $kb_where[] = ['employee_id','in',$sqempids];
  1309. $kb_where[] = ['community_name','in',array_column($community_list,'name')];
  1310. $kbcuslist = Customer::where($kb_where)->column('id,community_name');
  1311. //无效的客户
  1312. $wx_where[] = ['root_id','=',$root_id];
  1313. $wx_where[] = ['employee_id','in',$sqempids];
  1314. //$wx_where[] = ['cus_addtime', 'between', [$time[0].' 00:00:00',$time[1].' 23:59:59']];
  1315. $wuxiaoids = CustomerInvalidLog::where($wx_where)->column('customer_id');
  1316. $wxw = !empty($wuxiaoids) ? implode(',',$wuxiaoids) : [];
  1317. $comnames = !empty($community_list) ? array_column($community_list,'name') : [];
  1318. $comids = '';
  1319. if(!empty($comnames)){
  1320. foreach($comnames as $k=>$v){
  1321. $comids.="'".$v."',";
  1322. }
  1323. $comids = trim($comids,',');
  1324. }
  1325. $wuxiaolog_list = !empty($wxw) ? $this->cus_recycle($wxw,$comids) : [];
  1326. //所有跟进记录
  1327. $vs_where[] = ['CustomerVisitLog.state','in',array_merge($state1,$state2,$state3,$state4,$state5)];
  1328. //$vs_where[] = ['confirm_date', 'between', [$time[0].' 00:00:00',$time[1].' 23:59:59']];
  1329. $vs_where[] = ['customer_employee_id','in',$sqempids];
  1330. $w = Customer::where('community_name','in',array_column($community_list,'name'));
  1331. $vsloglist = CustomerVisitLog::hasWhere('customer',$w)
  1332. ->where($vs_where)->group('state,customer_id')->column('Customer.community_name,CustomerVisitLog.customer_id,CustomerVisitLog.state,CustomerVisitLog.money');
  1333. $signids = [];
  1334. foreach($vsloglist as $key=>$val){
  1335. $newvslog[$val['community_name']][] = $val;
  1336. if(in_array($val['state'],$state4)) $signids[] = $val['customer_id'];
  1337. }
  1338. $cusids = array_column($cuslist,'id');
  1339. $t=['all_households'=>0,'alljq'=>0,'allkb'=>0,'alllp'=>0,'alljv'=>0,'alldd'=>0,'allclue'=>0,'all_meas_house'=>0,'all_deposit'=>0,'all_trans_percen'=>0,'all_sign'=>0,'all_basic_money'=>0,'all_money'=>0];
  1340. foreach($community_list as $key=>$val){
  1341. $jq = $kb = $jv = $dd = $meas_house = $valid = $clue_cont = $deposit = $sign = $dep_money = $basic_money = 0;
  1342. foreach ($cuslist as $k => $v) {
  1343. if ($v['community_name'] == $val['name']) $clue_cont++;
  1344. }
  1345. //加微数量
  1346. foreach($jvcuslist as $k=>$v){
  1347. if ($v['community_name'] == $val['name']) $jv++;
  1348. }
  1349. //进群数量
  1350. foreach($jqcuslist as $k=>$v){
  1351. if ($v['community_name'] == $val['name']) $jq++;
  1352. }
  1353. //口碑数量
  1354. foreach($kbcuslist as $k=>$v){
  1355. if ($v['community_name'] == $val['name']) $kb++;
  1356. }
  1357. //处理无效的客户还原到员工身上为有效
  1358. foreach ($wuxiaolog_list as $k => $v) {
  1359. if ($v['community_name'] == $val['name'] && !in_array($v['id'], $cusids)) {
  1360. $clue_cont++;
  1361. $cusids[] = $v['id'];
  1362. if(!empty($v['add_wechat_time'])) $jv++;
  1363. if(!empty($v['into_owner_group'])) $jq++;
  1364. if(!empty($v['reputation_gather'])) $kb++;
  1365. }
  1366. }
  1367. if (!empty($newvslog[$val['name']])) {
  1368. foreach ($newvslog[$val['name']] as $k => $v) {
  1369. if (in_array($v['state'], $state1, true)) $dd++;
  1370. if (in_array($v['state'], $state2, true)){
  1371. $deposit++;
  1372. if(!in_array($v['customer_id'],$signids)) $dep_money += $v['money'];
  1373. }
  1374. if (in_array($v['state'], $state4, true)) $meas_house++;
  1375. if (in_array($v['state'], $state3, true)) {
  1376. $basic_money += $v['money'];
  1377. $sign++;
  1378. }
  1379. }
  1380. unset($newvslog[$val['name']]);
  1381. }
  1382. $community_list[$key]['clue_cont'] = $clue_cont;
  1383. $community_list[$key]['jq'] = $jq;
  1384. $community_list[$key]['kb'] = $kb;
  1385. $community_list[$key]['jv_cont'] = $jv;
  1386. $community_list[$key]['jv_percen'] = $jv && $clue_cont ? round($jv / $clue_cont * 100, 2) : 0;
  1387. $community_list[$key]['meas_house'] = $meas_house;
  1388. $community_list[$key]['dd_cont'] = $dd;
  1389. $community_list[$key]['dd_percen'] = !empty($dd) && !empty($valid) ? round($dd / $valid * 100, 2) : 0;
  1390. $community_list[$key]['deposit_cont'] = $deposit;
  1391. $community_list[$key]['trans_percen'] = !empty($deposit) && !empty($dd) ? round($deposit / $dd * 100, 2) : 0;
  1392. $community_list[$key]['sign_cont'] = $sign;
  1393. $community_list[$key]['basic_money'] = $basic_money;
  1394. $bmp[] = $basic_money;
  1395. //总数
  1396. $t['allclue'] += $clue_cont;
  1397. $t['alljv'] += $jv;
  1398. $t['alljq'] += $jq;
  1399. $t['allkb'] += $kb;
  1400. $t['alldd'] += $dd;
  1401. $t['all_sign'] += $sign;
  1402. $t['all_deposit'] += $deposit;
  1403. $t['all_basic_money'] += $basic_money;
  1404. $t['all_money'] += $basic_money+$dep_money;
  1405. $t['all_meas_house'] += $meas_house;
  1406. $t['all_households'] += $val['households'];
  1407. }
  1408. if (!empty($community_list)) {
  1409. array_multisort($bmp, SORT_DESC, $community_list);
  1410. }
  1411. $t['alllp'] = count($community_list);
  1412. //$t['allsq'] = count($sqempids);
  1413. $t['jv_percen'] = !empty($t['alljv']) && !empty($t['allclue']) ? round($t['alljv'] / $t['allclue'] * 100, 2) : 0;
  1414. $t['sign_agv_money'] = !empty($t['all_sign']) && !empty($all_basic_money) ? floor($all_basic_money / $sign) : 0;
  1415. $t['all_trans_percen'] = !empty($t['all_deposit']) && !empty($t['alldd']) ? floor($t['all_deposit'] / $t['alldd']) : 0;
  1416. $data = ['list'=>$community_list,'all'=>$t];
  1417. Cache::set('community_depsig_list_'.$time[0].$time[1].$root_id, json_encode($data), $this->cache_time);
  1418. }else{
  1419. $data = json_decode($cache_data, true);
  1420. }
  1421. return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
  1422. }
  1423. /**
  1424. * 客户表加回收站查询
  1425. */
  1426. public function cus_recycle($condition,$comids)
  1427. {
  1428. $sql = "( SELECT id,name,community_name,add_wechat_time,into_owner_group,reputation_gather FROM `fl_customer` WHERE `id` in (".$condition.") and community_name in (".$comids.")) UNION
  1429. ( SELECT customer_id as id,name,community_name,add_wechat_time,into_owner_group,reputation_gather FROM `fl_customer_recycle` WHERE `customer_id` in (".$condition.") and community_name in (".$comids.")) ";
  1430. $data = Db::query($sql);
  1431. return $data;
  1432. }
  1433. /**
  1434. * 首页谈单记录 (开始 + 异常)
  1435. * 三分钟之内的
  1436. */
  1437. public function get_index_smart_screen_log(){
  1438. $root_id = $this->aec->decrypt($this->token);
  1439. $three = date('Y-m-d H:i:s', time() - 180);
  1440. $where[] = ['root_id', '=', $root_id];
  1441. $where[] = ['addtime|endtime', '>', $three];
  1442. $list = SmartScreenLog::where($where)->select()->toArray();
  1443. $setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'smartScreenValidMinutes']])->findOrEmpty();
  1444. $valid_long = 0;
  1445. if (!$setting->isEmpty()) {
  1446. $valid_long = $setting['content'] * 60;
  1447. }
  1448. $tips = [];
  1449. foreach ($list as $k => $v) {
  1450. // 谈单异常判断
  1451. if ($v['endtime']) {
  1452. if ($valid_long && $v['time'] < $valid_long) {
  1453. // 异常结束
  1454. $tips[] = ['employee_id'=> $v['employee_id'], 'customer_id'=> $v['customer_id'], 'type'=> 'bad'];
  1455. }
  1456. } else { // 谈单正常判断
  1457. $tips[] = ['employee_id'=> $v['employee_id'], 'customer_id'=> $v['customer_id'], 'type'=> 'start'];
  1458. }
  1459. }
  1460. $tips_list = [];
  1461. foreach ($tips as $k => $v) {
  1462. $employee = Employee::find($v['employee_id']);
  1463. $customer = Customer::find($v['customer_id']);
  1464. $employee_type = '';
  1465. $employee_name = '';
  1466. $customer_name = '';
  1467. if (!empty($employee)) {
  1468. if ($employee['org_type'] == 2) {
  1469. $employee_type = '设计师';
  1470. } else {
  1471. $employee_type = '销售';
  1472. }
  1473. $employee_name = $employee['name'];
  1474. }
  1475. if (!empty($customer)) {
  1476. $customer_name = $customer['name'];
  1477. }
  1478. if ($v['type'] == 'bad') {
  1479. $msg = '谈单异常';
  1480. } else {
  1481. $msg = '开始谈单';
  1482. }
  1483. $one = '[' . $customer_name . '客户已经到店 | ' . $employee_type . $employee_name . $msg . ']';
  1484. $tips_list[] = $one;
  1485. }
  1486. return json(['code'=> 0, 'data'=> $tips_list, 'msg'=> 'success']);
  1487. }
  1488. /**
  1489. * 首页总业绩
  1490. */
  1491. public function get_index_total(){
  1492. $root_id = $this->aec->decrypt($this->token);
  1493. $sub_orgs = orgSubIds($root_id);
  1494. $state1 = CustomerVisitLog::changeState('已到店', 'chaos');
  1495. $state2 = CustomerVisitLog::changeState('已量房', 'chaos');
  1496. $state3 = CustomerVisitLog::changeState('已到场', 'chaos');
  1497. $state4 = CustomerVisitLog::changeState('已交定', 'chaos');
  1498. $state5 = CustomerVisitLog::changeState('已签单', 'chaos');
  1499. /*----- 投放转化 直播转化 -----*/
  1500. $f_where[] = ['FishData.root_id', '=', $root_id];
  1501. $f_where[] = ['FishData.type', 'in', [1, 2, 4]];
  1502. $f_customer_log = Db::view('FishData', ['type'])
  1503. ->view('CustomerVisitLog', 'id,customer_id,state,customer_employee_id,confirm_date', 'CustomerVisitLog.customer_id=FishData.customer_id')
  1504. ->view('Customer', 'deposit_money,signed_money', 'Customer.id=FishData.customer_id')
  1505. ->where($f_where)
  1506. ->select()
  1507. ->toArray();
  1508. // 直播数据
  1509. $zhibo_data = [
  1510. 'clue'=> [], // 线索量
  1511. 'visit'=> [], // 见面
  1512. 'deposit'=> [], // 交定id
  1513. 'signed'=> [], // 签单id
  1514. 'signed_money'=> 0, // 签单金额
  1515. 'total_money'=> 0 // 业绩总和
  1516. ];
  1517. // 投放数据
  1518. $put_data = [
  1519. 'clue'=> [],
  1520. 'visit'=> [],
  1521. 'deposit'=> [],
  1522. 'signed'=> [],
  1523. 'signed_money'=> 0,
  1524. 'total_money'=> 0
  1525. ];
  1526. $visit_state = array_merge($state1, $state2, $state3, $state4, $state5);
  1527. foreach ($f_customer_log as $k => $v){
  1528. // 投放
  1529. if (in_array($v['type'], [1, 2])) {
  1530. // 线索量
  1531. if (!in_array($v['customer_id'], $put_data['clue'])) {
  1532. $put_data['clue'][] = $v['customer_id'];
  1533. }
  1534. // 见面
  1535. if (in_array($v['state'], $visit_state, true) && !in_array($v['customer_id'], $put_data['visit'])) {
  1536. $put_data['visit'][] = $v['customer_id'];
  1537. }
  1538. // 签单
  1539. if (in_array($v['state'], $state5, true) && !in_array($v['customer_id'], $put_data['signed'])) {
  1540. $put_data['signed'][] = $v['customer_id'];
  1541. $put_data['signed_money'] += $v['signed_money'];
  1542. $put_data['total_money'] += $v['signed_money'];
  1543. }
  1544. }
  1545. // 直播
  1546. if ($v['type'] == 4) {
  1547. // 线索量
  1548. if (!in_array($v['customer_id'], $zhibo_data['clue'])) {
  1549. $zhibo_data['clue'][] = $v['customer_id'];
  1550. }
  1551. // 见面
  1552. if (in_array($v['state'], $visit_state, true) && !in_array($v['customer_id'], $zhibo_data['visit'])) {
  1553. $zhibo_data['visit'][] = $v['customer_id'];
  1554. }
  1555. // 签单
  1556. if (in_array($v['state'], $state5, true) && !in_array($v['customer_id'], $zhibo_data['signed'])) {
  1557. $zhibo_data['signed'][] = $v['customer_id'];
  1558. $zhibo_data['signed_money'] += $v['signed_money'];
  1559. $zhibo_data['total_money'] += $v['signed_money'];
  1560. }
  1561. }
  1562. }
  1563. // 处理总业绩 签单 +交定(未签单)
  1564. foreach ($f_customer_log as $k => $v){
  1565. // 投放
  1566. if (in_array($v['type'], [1, 2])) {
  1567. // 交定
  1568. if (in_array($v['state'], $state4, true) && !in_array($v['customer_id'], $put_data['deposit'])) {
  1569. $put_data['deposit'][] = $v['customer_id'];
  1570. // 判断是否签单
  1571. if (!in_array($v['customer_id'], $put_data['signed'])) {
  1572. $put_data['total_money'] += $v['deposit_money'];
  1573. }
  1574. }
  1575. }
  1576. // 直播
  1577. if ($v['type'] == 4) {
  1578. // 交定
  1579. if (in_array($v['state'], $state4, true) && !in_array($v['customer_id'], $zhibo_data['deposit'])) {
  1580. $zhibo_data['deposit'][] = $v['customer_id'];
  1581. // 判断是否签单
  1582. if (!in_array($v['customer_id'], $zhibo_data['signed'])) {
  1583. $zhibo_data['total_money'] += $v['deposit_money'];
  1584. }
  1585. }
  1586. }
  1587. }
  1588. $put['clue'] = FishData::where([['root_id', '=', $root_id],['type', 'in', [1]]])->count();
  1589. //todo 直播计算
  1590. $zhibo_where[] = ['type', 'in', [4]];
  1591. $zhibo_where[] = ['root_id', '=', $root_id];
  1592. $zhibo_clue_count = FishData::where($zhibo_where)->count();
  1593. $tx_clue_where[] = ['type', 'in', [2]];
  1594. $tx_clue_where[] = ['root_id', '=', $root_id];
  1595. $tx_clue_count = FishData::where($tx_clue_where)->count();
  1596. $put['clue'] = $put['clue'] + $zhibo_clue_count+$tx_clue_count;
  1597. $put['visit_count'] = count(array_unique(array_merge($put_data['visit'], $zhibo_data['visit'])));
  1598. $put['signed_count'] = count($put_data['signed']) + count($zhibo_data['signed']);
  1599. $put['signed_money'] = $put_data['signed_money'] + $zhibo_data['signed_money'];
  1600. $put['total_money'] = $put_data['total_money'] + $zhibo_data['total_money'];
  1601. $put['signed_average'] = $put['signed_count'] > 0 ? round($put['signed_money'] / $put['signed_count'], 0) : 0;
  1602. $data['put'] = $put;
  1603. $zhibo['clue'] = $zhibo_clue_count;//FishCampaign::where([['root_id', '=', $root_id],['type', '=', 4]])->sum('convert');
  1604. $zhibo['visit_count'] = count($zhibo_data['visit']);
  1605. $zhibo['signed_count'] = count($zhibo_data['signed']);
  1606. $zhibo['signed_money'] = $zhibo_data['signed_money'];
  1607. $zhibo['total_money'] = $zhibo_data['total_money'];
  1608. $zhibo['signed_average'] = $zhibo['signed_count'] > 0 ? round($zhibo['signed_money'] / $zhibo['signed_count'], 0) : 0;
  1609. $data['broadcast'] = $zhibo;
  1610. /*----- 投放转化 -----*/
  1611. /*----- 社群数据 -----*/
  1612. // 社群员工
  1613. $emp_list = Employee::where([['org_id', 'in', $sub_orgs], ['community_disable', '=', 0], ['state', '=', '在职'], ['uid', '>', 0]])->column('id');
  1614. $community_ids = BuildingModel::where([['root_id', '=', $root_id], ['del', '=', 0]])->column('community_id');
  1615. $community_list = Community::where('id', 'in', $community_ids)->column('name');
  1616. $she_where[] = ['Customer.community_name', 'in', $community_list];
  1617. $she_where[] = ['CustomerVisitLog.customer_employee_id', 'in', $emp_list];
  1618. $she_customer = Db::view('Customer')
  1619. ->view('CustomerVisitLog', 'id', 'Customer.id=CustomerVisitLog.customer_id')
  1620. ->where($she_where)
  1621. ->column('Customer.id,Customer.signed_money,Customer.deposit_money,CustomerVisitLog.state');
  1622. // 回收站
  1623. $recycle_where[] = ['CustomerRecycle.community_name', 'in', $community_list];
  1624. $recycle_where[] = ['CustomerVisitLog.customer_employee_id', 'in', $emp_list];
  1625. $recycle_customer = Db::view('CustomerRecycle')
  1626. ->view('CustomerVisitLog', 'id', 'CustomerRecycle.customer_id=CustomerVisitLog.customer_id')
  1627. ->where($recycle_where)
  1628. ->column('CustomerRecycle.customer_id id,CustomerRecycle.signed_money,CustomerRecycle.deposit_money,CustomerVisitLog.state');
  1629. // 自动回收库
  1630. $drop_where[] = ['CustomerDropPool.community_name', 'in', $community_list];
  1631. $drop_where[] = ['CustomerVisitLog.customer_employee_id', 'in', $emp_list];
  1632. $drop_customer = Db::view('CustomerDropPool')
  1633. ->view('CustomerVisitLog', 'id', 'CustomerDropPool.customer_id=CustomerVisitLog.customer_id')
  1634. ->where($drop_where)
  1635. ->column('CustomerDropPool.customer_id id,CustomerDropPool.signed_money,CustomerDropPool.deposit_money,CustomerVisitLog.state');
  1636. $she_customer = array_merge($she_customer, $recycle_customer, $drop_customer);
  1637. $she_data['clue'] = [];
  1638. $she_data['signed'] = [];
  1639. $she_data['deposit'] = [];
  1640. $she_data['visit'] = [];
  1641. $she_data['signed_money'] = 0;
  1642. $she_data['total_money'] = 0;
  1643. foreach ($she_customer as $k => $v) {
  1644. if (!in_array($v['id'], $she_data['clue'])) {
  1645. $she_data['clue'][] = $v['id'];
  1646. }
  1647. // 见面
  1648. if (!in_array($v['id'], $she_data['visit']) && in_array($v['state'], $visit_state, true)) {
  1649. $she_data['visit'][] = $v['id'];
  1650. }
  1651. // 签单
  1652. if (in_array($v['state'], $state5, true) && !in_array($v['id'], $she_data['signed'])) {
  1653. $she_data['signed'][] = $v['id'];
  1654. $she_data['signed_money'] += $v['signed_money'];
  1655. $she_data['total_money'] += $v['signed_money'];
  1656. }
  1657. }
  1658. // 处理业绩
  1659. foreach ($she_customer as $k => $v) {
  1660. // 交定
  1661. if (in_array($v['state'], $state4, true) && !in_array($v['id'], $she_data['deposit'])) {
  1662. $she_data['deposit'][] = $v['id'];
  1663. // 判断是否签单
  1664. if (!in_array($v['id'], $she_data['signed'])) {
  1665. $she_data['total_money'] += $v['deposit_money'];
  1666. }
  1667. }
  1668. }
  1669. $group['clue'] = count($she_data['clue']);
  1670. $group['visit_count'] = count($she_data['visit']);
  1671. $group['signed_count'] = count($she_data['signed']);
  1672. $group['signed_money'] = $she_data['signed_money'];
  1673. $group['total_money'] = $she_data['total_money'];
  1674. $group['signed_average'] = $group['signed_count'] > 0 ? round($group['signed_money'] / $group['signed_count'], 0) : 0;
  1675. $data['group'] = $group;
  1676. /*----- 社群数据 -----*/
  1677. $total['clue'] = $put['clue'] + $group['clue']; //+ $zhibo['clue'];
  1678. $total['visit_count'] = $put['visit_count'] + $group['visit_count'];// + $zhibo['visit_count'];
  1679. $total['signed_count'] = $put['signed_count'] + $group['signed_count'];// + $zhibo['signed_count'];
  1680. $total['signed_money'] = $put['total_money'] + $group['total_money'];// + $zhibo['total_money'];
  1681. $total_signed_money = $put['signed_money'] + $group['signed_money'];
  1682. $total['signed_average'] = $total['signed_count'] > 0 ? round($total_signed_money / $total['signed_count'], 0) : 0; // 平均业绩 = 签单总额/签单数
  1683. $ratio_group = $total['clue'] > 0 ? round($group['clue'] / $total['clue'] * 100, 0) : 0;
  1684. $ratio_put = $total['clue'] > 0 ? round($put['clue'] / $total['clue'] * 100, 0) : 0;
  1685. $ratio_zhibo = $total['clue'] > 0 ? round($zhibo['clue'] / $total['clue'] * 100, 0) : 0;
  1686. $total['ratio'] = [
  1687. 'group'=> $ratio_group,
  1688. 'put'=> $ratio_put,
  1689. 'zhibo'=> $ratio_zhibo
  1690. ];
  1691. $data['total'] = $total;
  1692. return json(['code'=> 0, 'data'=> $data, 'msg'=> 'success']);
  1693. }
  1694. /**
  1695. * 首页右侧不同业绩类型的排行数据
  1696. */
  1697. public function get_index_performance(){
  1698. $root_id = $this->aec->decrypt($this->token);
  1699. $param = request()->only(['times']);
  1700. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  1701. if (!empty($param['times'])) {
  1702. $time = explode(' - ', $param['times']);
  1703. }
  1704. $cache_data_name = 'get_index_performance-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  1705. $cache_data_info = Cache::get($cache_data_name);
  1706. if($cache_data_info){
  1707. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  1708. }
  1709. if (!empty($time[0])) {
  1710. $time[0] = date('Y-m-d 00:00:00', strtotime($time[0]));
  1711. }
  1712. if (!empty($time[1])) {
  1713. $time[1] = date('Y-m-d 23:59:59', strtotime($time[1]));
  1714. }
  1715. $sub_org = orgSubIds($root_id);
  1716. // 客服
  1717. $state1 = CustomerVisitLog::changeState('已交定', 'chaos');
  1718. $state2 = CustomerVisitLog::changeState('已签单', 'chaos');
  1719. $where1[] = ['Employee.org_id', 'in', $sub_org];
  1720. $where1[] = ['Employee.uid', '>', 0];
  1721. $where1[] = ['Employee.state', '=', '在职'];
  1722. $where1[] = ['CustomerVisitLog.state', 'in', array_merge($state1, $state2)];
  1723. $where1[] = ['CustomerVisitLog.confirm_date', 'between', $time];
  1724. $where1[] = ['FishData.type', 'in', [1, 2, 4]];
  1725. $list1 = Db::view('Employee')
  1726. ->view('CustomerVisitLog', 'id lid', 'CustomerVisitLog.customer_employee_id=Employee.id')
  1727. ->view('Customer', 'id cid', 'CustomerVisitLog.customer_id=Customer.id')
  1728. ->view('FishData','customer_id','FishData.customer_id=Customer.id')
  1729. ->where($where1)
  1730. ->column('Customer.id,Customer.deposit_money,Customer.signed_money,Customer.employee_id,CustomerVisitLog.state,CustomerVisitLog.customer_employee_id,Employee.name employee_name,Employee.community_disable');
  1731. $employee_data = []; // 员工数据
  1732. $log1 = []; // 有效的数据
  1733. foreach ($list1 as $k => $v) {
  1734. if ($v['employee_id'] == $v['customer_employee_id']) { // 防止交定之后又置为无效的,所以客户所属员工和跟踪记录创建时客户所属员工保持一致
  1735. if (empty($employee_data[$v['employee_id']])) {
  1736. $employee_data[$v['employee_id']]['name'] = $v['employee_name'];
  1737. $employee_data[$v['employee_id']]['community_disable'] = $v['community_disable'];
  1738. $employee_data[$v['employee_id']]['signed'] = [];
  1739. $employee_data[$v['employee_id']]['deposit'] = [];
  1740. $employee_data[$v['employee_id']]['signed_money'] = 0;
  1741. }
  1742. $log1[] = $v;
  1743. // 签单
  1744. if (in_array($v['state'], $state2, true) && !in_array($v['id'], $employee_data[$v['employee_id']]['signed'])) {
  1745. $employee_data[$v['employee_id']]['signed'][] = $v['id'];
  1746. $employee_data[$v['employee_id']]['signed_money'] += $v['signed_money'];
  1747. }
  1748. }
  1749. }
  1750. foreach ($log1 as $k => $v) {
  1751. // 交定
  1752. if (empty($employee_data[$v['employee_id']])) {
  1753. $employee_data[$v['employee_id']]['name'] = $v['employee_name'];
  1754. $employee_data[$v['employee_id']]['community_disable'] = $v['community_disable'];
  1755. $employee_data[$v['employee_id']]['signed'] = [];
  1756. $employee_data[$v['employee_id']]['deposit'] = [];
  1757. $employee_data[$v['employee_id']]['signed_money'] = 0;
  1758. }
  1759. if (in_array($v['state'], $state1, true) && !in_array($v['id'], $employee_data[$v['employee_id']]['deposit'])) {
  1760. $employee_data[$v['employee_id']]['deposit'][] = $v['id'];
  1761. if (!in_array($v['id'], $employee_data[$v['employee_id']]['signed'])) {
  1762. $employee_data[$v['employee_id']]['signed_money'] += $v['deposit_money'];
  1763. }
  1764. }
  1765. }
  1766. $employee_data = array_values($employee_data);
  1767. $group_list1 = []; // 社群
  1768. $service_list1 = []; // 客服
  1769. foreach ($employee_data as $k => $v){
  1770. if ($v['community_disable'] == 1) {
  1771. $service_list1[] = $v;
  1772. }
  1773. if ($v['community_disable'] == 0) {
  1774. $group_list1[] = $v;
  1775. }
  1776. }
  1777. array_multisort(array_column($group_list1, 'signed_money'), SORT_DESC, $group_list1);
  1778. array_multisort(array_column($service_list1, 'signed_money'), SORT_DESC, $service_list1);
  1779. $service = array_slice($service_list1, 0, 3);
  1780. $group = array_slice($group_list1, 0, 3);
  1781. $service_list = [];
  1782. foreach ($service as $k => $v){
  1783. $v_one['name'] = $v['name'];
  1784. $v_one['money'] = $v['signed_money'];
  1785. $service_list[] = $v_one;
  1786. }
  1787. $data['service'] = $service_list;
  1788. // 社群
  1789. $group_list = [];
  1790. foreach ($group as $k => $v){
  1791. $v_one['name'] = $v['name'];
  1792. $v_one['money'] = $v['signed_money'];
  1793. $group_list[] = $v_one;
  1794. }
  1795. $data['group'] = $group_list;
  1796. Cache::set($cache_data_name, json_encode($data), $this->cache_time);
  1797. return json(['code'=> 0, 'data'=> $data, 'msg'=> 'success']);
  1798. }
  1799. /**
  1800. * 首页社群数据
  1801. */
  1802. public function get_index_group(){
  1803. $root_id = $this->aec->decrypt($this->token);
  1804. /*$param = request()->only(['times']);
  1805. $time = [date('2023-04-01'), date('Y-m-d')]; //默认本月时间
  1806. if (!empty($param['times'])) {
  1807. $time = explode(' - ', $param['times']);
  1808. }
  1809. $cache_data_name = 'get_index_group-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  1810. $cache_data_info = Cache::get($cache_data_name);
  1811. if($cache_data_info){
  1812. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  1813. }
  1814. if (!empty($time[0])) {
  1815. $time[0] = date('Y-m-d 00:00:00', strtotime($time[0]));
  1816. }
  1817. if (!empty($time[1])) {
  1818. $time[1] = date('Y-m-d 23:59:59', strtotime($time[1]));
  1819. }*/
  1820. $community_ids = BuildingModel::where([['root_id', '=', $root_id], ['del', '=', 0]])->group('community_id')->column('community_id');
  1821. $community_list = Community::where([['root_id', '=', $root_id], ['id', 'in', $community_ids]])->column('id,name,households');
  1822. $community_count = array_column($community_list,'households');
  1823. $community_name = array_column($community_list,'name');
  1824. $data['community_count'] = count($community_list); // 小区数
  1825. $data['households'] = array_sum($community_count); // 户型数
  1826. $sub_org = orgSubIds($root_id);
  1827. // 总产值
  1828. $state1 = CustomerVisitLog::changeState('已交定', 'chaos');
  1829. $state2 = CustomerVisitLog::changeState('已签单', 'chaos');
  1830. $where[] = ['Employee.org_id', 'in', $sub_org];
  1831. $where[] = ['Employee.uid', '>', 0];
  1832. $where[] = ['Employee.state', '=', '在职'];
  1833. $where[] = ['Employee.community_disable', '=', 0];
  1834. $where[] = ['CustomerVisitLog.state', 'in', array_merge($state1, $state2)];
  1835. // 小区的条件
  1836. $where[] = ['Customer.community_name', 'in', $community_name];
  1837. $log_list = Db::view('Customer')
  1838. ->view('CustomerVisitLog', 'id vid', 'Customer.id=CustomerVisitLog.customer_id')
  1839. ->view('Employee', 'id eid', 'CustomerVisitLog.customer_employee_id=Employee.id')
  1840. ->where($where)
  1841. ->column('Customer.id,Customer.employee_id,Customer.deposit_money,Customer.signed_money,CustomerVisitLog.customer_employee_id,CustomerVisitLog.state');
  1842. $she_data['signed'] = [];
  1843. $she_data['deposit'] = [];
  1844. $she_data['total_money'] = 0;
  1845. foreach ($log_list as $k => $v) {
  1846. // 签单
  1847. if (in_array($v['state'], $state2, true) && !in_array($v['id'], $she_data['signed'])) {
  1848. $she_data['signed'][] = $v['id'];
  1849. $she_data['total_money'] += $v['signed_money'];
  1850. }
  1851. }
  1852. // 处理业绩
  1853. foreach ($log_list as $k => $v) {
  1854. // 交定
  1855. if (in_array($v['state'], $state1, true) && !in_array($v['id'], $she_data['deposit'])) {
  1856. $she_data['deposit'][] = $v['id'];
  1857. // 判断是否签单
  1858. if (!in_array($v['id'], $she_data['signed'])) {
  1859. $she_data['total_money'] += $v['deposit_money'];
  1860. }
  1861. }
  1862. }
  1863. $data['total_money'] = $she_data['total_money'];
  1864. // 折线图
  1865. // 信息量 进群量 加微量
  1866. // 有效的
  1867. $valid_where[] = ['Employee.org_id', 'in', $sub_org];
  1868. $valid_where[] = ['Employee.uid', '>', 0];
  1869. $valid_where[] = ['Employee.state', '=', '在职'];
  1870. $valid_where[] = ['Employee.community_disable', '=', 0];
  1871. $valid_where[] = ['Customer.community_name', 'in', $community_name];
  1872. $valid_list = Db::view('Employee')
  1873. ->view('Customer', 'id cid', 'Customer.employee_id=Employee.id')
  1874. ->where($valid_where)
  1875. ->group('Customer.id')
  1876. ->column('Customer.id,Customer.sign_time,Customer.into_owner_group,Customer.add_wechat_time');
  1877. // 无效的客户
  1878. $invalid_where[] = ['Employee.org_id', 'in', $sub_org];
  1879. $invalid_where[] = ['Employee.uid', '>', 0];
  1880. $invalid_where[] = ['Employee.state', '=', '在职'];
  1881. $invalid_where[] = ['Employee.community_disable', '=', 0];
  1882. $invalid_where[] = ['Customer.community_name', 'in', $community_name];
  1883. $invalid_where[] = ['Customer.employee_id', 'NULL', null];
  1884. $invalid_list = Db::view('Employee')
  1885. ->view('CustomerInvalidLog', 'id lid', 'Employee.id=CustomerInvalidLog.employee_id')
  1886. ->view('Customer', 'id cid', 'Customer.id=CustomerInvalidLog.customer_id')
  1887. ->where($invalid_where)
  1888. ->group('Customer.id')
  1889. ->column('Customer.id,Customer.sign_time,Customer.into_owner_group,Customer.add_wechat_time');
  1890. // 自动回收库表
  1891. $drop_where[] = ['Employee.org_id', 'in', $sub_org];
  1892. $drop_where[] = ['Employee.uid', '>', 0];
  1893. $drop_where[] = ['Employee.state', '=', '在职'];
  1894. $drop_where[] = ['Employee.community_disable', '=', 0];
  1895. $drop_where[] = ['CustomerDropPool.community_name', 'in', $community_name];
  1896. $drop_list = Db::view('Employee')
  1897. ->view('CustomerDropPool', 'id lid', 'Employee.id=CustomerDropPool.employee_id')
  1898. ->where($drop_where)
  1899. ->group('CustomerDropPool.id')
  1900. ->column('CustomerDropPool.id,CustomerDropPool.sign_time,CustomerDropPool.into_owner_group,CustomerDropPool.add_wechat_time');
  1901. // 回收站表
  1902. $recycle_where[] = ['Employee.org_id', 'in', $sub_org];
  1903. $recycle_where[] = ['Employee.uid', '>', 0];
  1904. $recycle_where[] = ['Employee.state', '=', '在职'];
  1905. $recycle_where[] = ['Employee.community_disable', '=', 0];
  1906. $recycle_where[] = ['CustomerRecycle.community_name', 'in', $community_name];
  1907. $recycle_list = Db::view('Employee')
  1908. ->view('CustomerInvalidLog', 'id lid', 'Employee.id=CustomerInvalidLog.employee_id')
  1909. ->view('CustomerRecycle', 'id cid', 'CustomerRecycle.id=CustomerInvalidLog.customer_id')
  1910. ->where($recycle_where)
  1911. ->group('CustomerRecycle.id')
  1912. ->column('CustomerRecycle.id,CustomerRecycle.sign_time,CustomerRecycle.into_owner_group,CustomerRecycle.add_wechat_time');
  1913. $merge_list = array_merge($valid_list, $invalid_list, $drop_list, $recycle_list);
  1914. $sign_time_list = array_filter(array_column($merge_list, 'sign_time', 'id'));
  1915. $into_owner_group_list = array_filter(array_column($merge_list, 'into_owner_group', 'id'));
  1916. $add_wechat_time_list = array_filter(array_column($merge_list, 'add_wechat_time', 'id'));
  1917. $sign_time = [];
  1918. foreach ($sign_time_list as $k => $v) {
  1919. $v_date = date('Y-m-d', strtotime($v));
  1920. if (empty($sign_time[$v_date])) {
  1921. $sign_time[$v_date] = 0;
  1922. }
  1923. $sign_time[$v_date] ++;
  1924. }
  1925. $into_owner_group = [];
  1926. foreach ($into_owner_group_list as $k => $v) {
  1927. if (empty($into_owner_group[$v])) {
  1928. $into_owner_group[$v] = 0;
  1929. }
  1930. $into_owner_group[$v] ++;
  1931. }
  1932. $add_wechat_time = [];
  1933. foreach ($add_wechat_time_list as $k => $v) {
  1934. if (empty($add_wechat_time[$v])) {
  1935. $add_wechat_time[$v] = 0;
  1936. }
  1937. $add_wechat_time[$v] ++;
  1938. }
  1939. //拆分时间
  1940. $tmp_day = 1;
  1941. $time = [date('2023-04-01'), date('Y-m-d')]; //默认本月时间
  1942. $time_arr = getDateByInterval($time[0], $time[1], 'day');
  1943. if (count($time_arr) > 35) {
  1944. $tmp_day = 2;
  1945. $time_arr = getDateByInterval($time[0], $time[1], 'month');
  1946. }
  1947. //折线图
  1948. $line_data = []; //折线图数据
  1949. foreach ($time_arr as $k => $v) {
  1950. if ($tmp_day == 2) {
  1951. if (empty($line_data[$v['name']])) {
  1952. $line_data[$v['name']] = [];
  1953. $line_data[$v['name']]['customer'] = 0; // 信息量
  1954. $line_data[$v['name']]['group'] = 0; // 进群数量
  1955. $line_data[$v['name']]['wechat'] = 0; // 加微数量
  1956. }
  1957. $v_start = strtotime($v['startDate'] . ' 00:00:00');
  1958. $v_end = strtotime($v['endDate'] . ' 23:59:59');
  1959. foreach ($sign_time as $kk => $vv) {
  1960. $kk_str = strtotime($kk);
  1961. if ($kk_str >= $v_start && $kk_str <= $v_end) {
  1962. $line_data[$v['name']]['customer'] += $vv;
  1963. }
  1964. }
  1965. foreach ($into_owner_group as $kk => $vv) {
  1966. $kk_str = strtotime($kk);
  1967. if ($kk_str >= $v_start && $kk_str <= $v_end) {
  1968. $line_data[$v['name']]['group'] += $vv;
  1969. }
  1970. }
  1971. foreach ($add_wechat_time as $kk => $vv) {
  1972. $kk_str = strtotime($kk);
  1973. if ($kk_str >= $v_start && $kk_str <= $v_end) {
  1974. $line_data[$v['name']]['wechat'] += $vv;
  1975. }
  1976. }
  1977. } else {
  1978. if (empty($line_data[$v])) {
  1979. $line_data[$v] = [];
  1980. $line_data[$v]['customer'] = 0; // 信息量
  1981. $line_data[$v]['group'] = 0; // 进群数量
  1982. $line_data[$v]['wechat'] = 0; // 加微数量
  1983. }
  1984. $v_start = strtotime($v . ' 00:00:00');
  1985. $v_end = strtotime($v . ' 23:59:59');
  1986. foreach ($sign_time as $kk => $vv) {
  1987. $kk_str = strtotime($kk);
  1988. if ($kk_str >= $v_start && $kk_str <= $v_end) {
  1989. $line_data[$v]['customer'] += $vv;
  1990. }
  1991. }
  1992. foreach ($into_owner_group as $kk => $vv) {
  1993. $kk_str = strtotime($kk);
  1994. if ($kk_str >= $v_start && $kk_str <= $v_end) {
  1995. $line_data[$v]['group'] += $vv;
  1996. }
  1997. }
  1998. foreach ($add_wechat_time as $kk => $vv) {
  1999. $kk_str = strtotime($kk);
  2000. if ($kk_str >= $v_start && $kk_str <= $v_end) {
  2001. $line_data[$v]['wechat'] += $vv;
  2002. }
  2003. }
  2004. }
  2005. }
  2006. foreach ($line_data as $k => $v) {
  2007. $v['time'] = $k;
  2008. $line_data[$k] = $v;
  2009. }
  2010. $data['line'] = array_values($line_data);
  2011. // Cache::set($cache_data_name, json_encode($data), $this->cache_time);
  2012. return json(['code'=> 0, 'data'=> $data, 'msg'=> 'success']);
  2013. }
  2014. /**
  2015. * 首页多个模块的使用数据(内容使用数据)
  2016. */
  2017. public function get_index_use_content(){
  2018. $root_id = $this->aec->decrypt($this->token);
  2019. $param = request()->only(['times']);
  2020. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  2021. if (!empty($param['times'])) {
  2022. $time = explode(' - ', $param['times']);
  2023. }
  2024. $cache_data_name = 'get_index_use_content-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  2025. $cache_data_info = Cache::get($cache_data_name);
  2026. if($cache_data_info){
  2027. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  2028. }
  2029. if (!empty($time[0])) {
  2030. $time[0] = date('Y-m-d 00:00:00', strtotime($time[0]));
  2031. }
  2032. if (!empty($time[1])) {
  2033. $time[1] = date('Y-m-d 23:59:59', strtotime($time[1]));
  2034. }
  2035. $employee = Employee::where([['root_id', '=', $root_id], ['uid', '>', 0], ['state', '=', '在职']])->column('id');
  2036. $clue_type = ['materialCase', 'video', 'article', 'CompanyStrength', 'companyStrength', 'materialEvidence', 'building', 'buildingVr', 'toolAll', 'companyVr', 'lottery', 'styleTest', 'likeTest', 'priceCalculation', 'spellgroup', 'agents', 'weiwang', 'card'];
  2037. $share_type = ['MaterialCase', 'Video', 'Article', 'CompanyStrength', 'MaterialEvidence', 'Building', 'ToolAll', 'CustomerJsAll', 'weiwang', 'card', 'MaterialCase_vr', 'Building_vr', 'EmployeeCard_vr', 'Company_vr'];
  2038. // 转发次数
  2039. $where[] = ['employee_id', 'in', $employee];
  2040. $where[] = ['share_time', 'between', $time];
  2041. $where[] = ['type', 'in', $share_type];
  2042. $share_count = ShareLog::where($where)->count();
  2043. $data['share_count'] = $share_count;
  2044. // 浏览次数
  2045. $where1[] = ['employee_id', 'in', $employee];
  2046. $where1[] = ['addtime', 'between', $time];
  2047. //$where1[] = ['pipe_type', 'in', $clue_type];
  2048. $foot_count = Footprints::where($where1)->select();
  2049. $data['footprints_count'] = $foot_count->count();
  2050. $visit_long = array_sum(array_column($foot_count->toArray(), 'visit_due_time'));
  2051. $data['long_time'] = round($visit_long / 60, 2);
  2052. // 获取线索数
  2053. $where2[] = ['employee_id', 'in', $employee];
  2054. $where2[] = ['addtime', 'between', $time];
  2055. //$where2[] = ['pipe_type', 'in', $clue_type];
  2056. $clue_list = CustomerClue::where($where2)->count();
  2057. $data['clue_count'] = $clue_list;
  2058. Cache::set($cache_data_name,json_encode($data), $this->cache_time);
  2059. return json(['code'=> 0, 'data'=> $data, 'msg'=> 'success']);
  2060. }
  2061. /**
  2062. * 智慧屏使用数据
  2063. *
  2064. */
  2065. public function get_index_use_smartscreen(){
  2066. $root_id = $this->aec->decrypt($this->token);
  2067. $param = request()->only(['times']);
  2068. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  2069. if (!empty($param['times'])) {
  2070. $time = explode(' - ', $param['times']);
  2071. }
  2072. $cache_data_name = 'get_index_use_smartscreen-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  2073. $cache_data_info = Cache::get($cache_data_name);
  2074. if($cache_data_info){
  2075. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  2076. }
  2077. if (!empty($time[0])) {
  2078. $time[0] = date('Y-m-d 00:00:00', strtotime($time[0]));
  2079. }
  2080. if (!empty($time[1])) {
  2081. $time[1] = date('Y-m-d 23:59:59', strtotime($time[1]));
  2082. }
  2083. // 浏览次数
  2084. $suborg = orgSubIds($root_id);
  2085. $where[] = ['org_id', 'in', $suborg];
  2086. $where[] = ['addtime', 'between', $time];
  2087. $where[] = ['remark', 'like', '%' . '讲解智慧屏##'];
  2088. $log_list = CustomerVisitLog::where($where)->select();
  2089. $data['count'] = $log_list->count();
  2090. $tmp_times = 0;
  2091. foreach($log_list as $n){
  2092. $tmp_times += explode('分钟;<br/>',explode('谈单时长:',$n['remark'])[1])[0];
  2093. }
  2094. $data['long_time'] = $tmp_times;
  2095. Cache::set($cache_data_name,json_encode($data), $this->cache_time);
  2096. return json(['code'=> 0, 'data'=> $data, 'msg'=> 'success']);
  2097. }
  2098. /**
  2099. * 楼书使用数据
  2100. */
  2101. public function get_index_use_building(){
  2102. $root_id = $this->aec->decrypt($this->token);
  2103. $param = request()->only(['times']);
  2104. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  2105. if (!empty($param['times'])) {
  2106. $time = explode(' - ', $param['times']);
  2107. }
  2108. $cache_data_name = 'get_index_use_building-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  2109. $cache_data_info = Cache::get($cache_data_name);
  2110. if($cache_data_info){
  2111. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  2112. }
  2113. if (!empty($time[0])) {
  2114. $time[0] = date('Y-m-d 00:00:00', strtotime($time[0]));
  2115. }
  2116. if (!empty($time[1])) {
  2117. $time[1] = date('Y-m-d 23:59:59', strtotime($time[1]));
  2118. }
  2119. $employee = Employee::where([['root_id', '=', $root_id], ['uid', '>', 0], ['state', '=', '在职']])->column('id');
  2120. // 转发次数
  2121. $where[] = ['employee_id', 'in', $employee];
  2122. $where[] = ['share_time', 'between', $time];
  2123. $where[] = ['type', 'in', ['Building', 'Building_vr']];
  2124. $share_count = ShareLog::where($where)->count();
  2125. $data['share_count'] = $share_count;
  2126. // 浏览次数
  2127. $where1[] = ['employee_id', 'in', $employee];
  2128. $where1[] = ['addtime', 'between', $time];
  2129. $where1[] = ['pipe_type', 'in', ['building', 'buildingVr']];
  2130. $foot_count = Footprints::where($where1)->select();
  2131. $data['footprints_count'] = $foot_count->count();
  2132. $visit_long = array_sum(array_column($foot_count->toArray(), 'visit_due_time'));
  2133. $data['long_time'] = round($visit_long / 60, 2);
  2134. // 获取线索数
  2135. $where2[] = ['employee_id', 'in', $employee];
  2136. $where2[] = ['addtime', 'between', $time];
  2137. $where2[] = ['pipe_type', 'in', ['building', 'buildingVr']];
  2138. $clue_list = CustomerClue::where($where2)->count();
  2139. $data['clue_count'] = $clue_list;
  2140. Cache::set($cache_data_name,json_encode($data), $this->cache_time);
  2141. return json(['code'=> 0, 'data'=> $data, 'msg'=> 'success']);
  2142. }
  2143. /**
  2144. * 话术使用数据
  2145. */
  2146. public function get_index_use_talk(){
  2147. $root_id = $this->aec->decrypt($this->token);
  2148. $param = request()->only(['times']);
  2149. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  2150. if (!empty($param['times'])) {
  2151. $time = explode(' - ', $param['times']);
  2152. }
  2153. $cache_data_name = 'get_index_use_talk-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  2154. $cache_data_info = Cache::get($cache_data_name);
  2155. if($cache_data_info){
  2156. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  2157. }
  2158. if (!empty($time[0])) {
  2159. $time[0] = date('Y-m-d 00:00:00', strtotime($time[0]));
  2160. }
  2161. if (!empty($time[1])) {
  2162. $time[1] = date('Y-m-d 23:59:59', strtotime($time[1]));
  2163. }
  2164. $suborg = orgSubIds($root_id);
  2165. $where[] = ['org_id', 'in', $suborg];
  2166. $where[] = ['addtime', 'between', $time];
  2167. $count = TalkskillViewLog::where($where)->count();
  2168. $data['view_count'] = $count;
  2169. // 话术使用次数
  2170. $where1[] = ['root_id', '=', $root_id];
  2171. $where1[] = ['addtime', 'between', $time];
  2172. // 百问百答
  2173. $use1 = Talkskill::where($where1)->sum('use_count');
  2174. // 精选话术
  2175. $use2 = TalkskillChosen::where($where1)->sum('use_count');
  2176. // 成功案例
  2177. $use3 = TalkskillSuccess::where($where1)->sum('use_count');
  2178. $data['use_count'] = $use1 + $use2 + $use3;
  2179. Cache::set($cache_data_name,json_encode($data), $this->cache_time);
  2180. return json(['code'=> 0, 'data'=> $data, 'msg'=> 'success']);
  2181. }
  2182. /**
  2183. * 直播间数据列表
  2184. */
  2185. public function get_live_data()
  2186. {
  2187. $root_id = $this->aec->decrypt($this->token);
  2188. $param = request()->only(['times']);
  2189. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  2190. if (isset($param['times']) && $param['times']) {
  2191. $time = explode(' - ', $param['times']);
  2192. }
  2193. //拆分时间
  2194. $comtent_list = [];
  2195. $tmp_day = 1;
  2196. $time_arr = getDateByInterval($time[0], $time[1], 'day');
  2197. if (count($time_arr) > 35) {
  2198. $tmp_day = 2;
  2199. $time_arr = getDateByInterval($time[0], $time[1], 'month');
  2200. }
  2201. //条件
  2202. $where[] = ['type', '=', 1];
  2203. $where[] = ['root_id', '=', $root_id];
  2204. $where_time = [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59'];
  2205. $cache_line_key = "cache_line_data_root_id_{$root_id}_time_$time[0].'_'.$time[1]}";
  2206. $cache_total_data_key = "cache_total_data_root_id_{$root_id}_time_$time[0].'_'.$time[1]}";
  2207. $cache_live_dongtai_data_key = "cache_live_dongtai_data_root_id_{$root_id}_time_$time[0].'_'.$time[1]}";
  2208. $ttl = $this->cache_time;
  2209. // Cache::set($cache_line_key,null);
  2210. // Cache::set($cache_total_data_key,null);
  2211. // Cache::set($cache_live_dongtai_data_key,null);
  2212. if (Cache::get($cache_line_key)) {
  2213. $comtent_list = json_decode(Cache::get($cache_line_key), true);
  2214. } else {
  2215. $max_count = FishLive::where($where)->group('root_id,anchor_id,room_title')->count();
  2216. //todo 留资折线图
  2217. $empty_count = FishLive::where($where)
  2218. ->group('root_id,anchor_id,room_title')
  2219. ->column('room_title,anchor_id');
  2220. foreach ($time_arr as $k => $v) {
  2221. if ($tmp_day == 2) {
  2222. $count_data = FishLive::where([
  2223. ['type', '=', 1],
  2224. ['root_id', '=', $root_id],
  2225. ['room_create_time', 'between', [$v['startDate'] . ' 00:00:00', $v['endDate'] . ' 23:59:59']]
  2226. ])
  2227. ->group('root_id,anchor_id,room_title')
  2228. ->field('live_form_submit_count as s_count,room_title,anchor_id')->select()->toArray();
  2229. $comtent_list[$k]['time'] = $v['name'];
  2230. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  2231. for ($i = 0; $i < $max_count; $i++) {
  2232. if (empty($count_data)) {
  2233. $comtent_list[$k]['number_' . $i] = 0;
  2234. $comtent_list[$k]['room_title_' . $i] = $empty_count[$i]['room_title'] . "【{$empty_count[$i]['anchor_id']}】";
  2235. } else {
  2236. if (empty($count_data[$i])) {
  2237. $comtent_list[$k]['number_' . $i] = 0;
  2238. $comtent_list[$k]['room_title_' . $i] = $empty_count[$i]['room_title'] . "【{$empty_count[$i]['anchor_id']}】";
  2239. } else {
  2240. $comtent_list[$k]['number_' . $i] = $count_data[$i]['s_count'];
  2241. $comtent_list[$k]['room_title_' . $i] = $count_data[$i]['room_title'] . "【{$empty_count[$i]['anchor_id']}】";
  2242. }
  2243. }
  2244. }
  2245. } else {
  2246. $count_data = FishLive::where([
  2247. ['type', '=', 1],
  2248. ['root_id', '=', $root_id],
  2249. ['room_create_time', 'between', [$v . ' 00:00:00', $v . ' 23:59:59']]
  2250. ])
  2251. ->group('root_id,anchor_id,room_title')
  2252. ->field('live_form_submit_count as s_count,room_title,anchor_id')->select()->toArray();
  2253. $comtent_list[$k]['time'] = $v;
  2254. for ($i = 0; $i < $max_count; $i++) {
  2255. if (empty($count_data)) {
  2256. $comtent_list[$k]['number_' . $i] = 0;
  2257. $comtent_list[$k]['room_title_' . $i] = $empty_count[$i]['room_title'] . "【{$empty_count[$i]['anchor_id']}】";
  2258. } else {
  2259. if (empty($count_data[$i])) {
  2260. $comtent_list[$k]['number_' . $i] = 0;
  2261. $comtent_list[$k]['room_title_' . $i] = $empty_count[$i]['room_title'] . "【{$empty_count[$i]['anchor_id']}】";
  2262. } else {
  2263. $comtent_list[$k]['number_' . $i] = $count_data[$i]['s_count'];
  2264. $comtent_list[$k]['room_title_' . $i] = $count_data[$i]['room_title'] . "【{$empty_count[$i]['anchor_id']}】";
  2265. }
  2266. }
  2267. }
  2268. }
  2269. }
  2270. //写入缓存
  2271. Cache::set($cache_line_key, json_encode($comtent_list), $ttl);
  2272. }
  2273. //todo 左上角統計
  2274. $total_data = [];
  2275. if (Cache::get($cache_total_data_key)) {
  2276. $total_data = json_decode(Cache::get($cache_total_data_key), true);
  2277. } else {
  2278. //总直播间数
  2279. $total_data['live_total'] = FishLive::where($where)->group('root_id,anchor_id,room_title')->where([['room_create_time', 'between', $where_time]])->count();
  2280. //todo 飞鱼数据
  2281. // $channel_setting_wh = Company::where(['root_id' => $root_id])->value('channel_setting_wh');
  2282. // if (empty($channel_setting_wh)){
  2283. // $data = [
  2284. // 'cost' => 0,
  2285. // 'shows' => 0,
  2286. // 'click' => 0,
  2287. // 'converts' => 0,
  2288. // ];
  2289. // $customer_id = [];
  2290. // }
  2291. // else{
  2292. // $tmp_data = json_decode($channel_setting_wh, true);
  2293. $FishCampaign_where[] = ['type', '=', 4];
  2294. $FishCampaign_where[] = ['root_id', '=', $root_id];
  2295. // $FishCampaign_where[] = ['advertiser_id', 'in', $tmp_data['fish_adv']];
  2296. $FishCampaign_where[] = ['data_time', 'between', $time];
  2297. $data = FishCampaign::where($FishCampaign_where)
  2298. ->field("sum(cost) as cost,sum(`show`) as shows,sum(click) as click,sum(`convert`) as converts")
  2299. ->find();
  2300. $FishCampaign_where1[] = ['type', '=', 4];
  2301. $FishCampaign_where1[] = ['root_id', '=', $root_id];
  2302. // $FishCampaign_where1[] = ['advertiser_id', 'in', $tmp_data['fish_adv']];
  2303. $FishCampaign_where1[] = ['create_time', 'between', $time];
  2304. $zhibo_clue = FishData::where($FishCampaign_where1)->count();
  2305. $customer_id = FishData::where([
  2306. ['type', '=', 4],
  2307. ['root_id', '=', $root_id],
  2308. ['create_time', 'between', $time],
  2309. ['is_allocation', '=', 1],
  2310. // ['advertiser_id', 'in', $tmp_data['fish_adv']],
  2311. ])->column('customer_id');
  2312. // }
  2313. //查询有效线索
  2314. $source_id = CustomerSource::where(['root_id' => $root_id, 'source' => '飞鱼线索'])->value('id');
  2315. // $company = Company::where([['root_id', '=', $root_id]])->find();
  2316. // $source_id = $company->channelSource['fish'];
  2317. $customer_data = Customer::where([
  2318. ['source_id', 'in', $source_id],
  2319. ['id', 'in', $customer_id]
  2320. ])
  2321. ->field('id,deposit_money as deposit_moneys,signed_money as signed_moneys')
  2322. ->select()->toArray();
  2323. $fish_count = $fish_money = 0;
  2324. foreach ($customer_data as $val) {
  2325. $fish_count++;
  2326. if (isset($val['signed_moneys']) && $val['signed_moneys']) {
  2327. $fish_money += $val['signed_moneys'];
  2328. }
  2329. if (!isset($val['signed_moneys']) && isset($val['deposit_moneys'])) {
  2330. $fish_money += $val['deposit_moneys'];
  2331. }
  2332. }
  2333. $fish_count = count(FishData::where($FishCampaign_where1)->where(['is_allocation' => 1])->column('customer_id'));
  2334. //总投放费用
  2335. $total_data['live_cost'] = $data['cost'] ?? 0;
  2336. //总曝光人数
  2337. $live_watch_count = FishLive::where($where)->where([['room_create_time', 'between', $where_time]])->sum('live_watch_count');
  2338. $total_data['live_watch_count'] = $live_watch_count ?? 0;
  2339. //总观看人数
  2340. $live_watch_ucount = FishLive::where($where)->where([['room_create_time', 'between', $where_time]])->sum('live_watch_ucount');
  2341. $total_data['live_watch_ucount'] = $live_watch_ucount ?? 0;
  2342. //总点击人数
  2343. $live_card_icon_component_show_count = FishLive::where($where)->where([['room_create_time', 'between', $where_time]])->sum('live_card_icon_component_show_count');
  2344. $total_data['live_d_click_count'] = $live_card_icon_component_show_count ?? 0;
  2345. //总线索
  2346. $total_data['total_converts'] = $zhibo_clue ?? 0;
  2347. //有效线索
  2348. $total_data['total_valid_clue_count'] = $fish_count ?? 0;
  2349. //总飞鱼广告线索成本 = 广告总消耗 / 广告线索量
  2350. $total_data['total_converts_cb'] = $zhibo_clue > 0 ? round($data['cost'] / $zhibo_clue, 2) : 0;
  2351. //总产值
  2352. $total_data['total_signed_money'] = $fish_money ?? 0;
  2353. //飞鱼有效率
  2354. $total_data['fish_count_lv'] = $fish_count > 0 && $zhibo_clue > 0 ? round($fish_count / $zhibo_clue * 100, 2) : 0;
  2355. //写入缓存
  2356. Cache::set($cache_total_data_key, json_encode($total_data), $ttl);
  2357. }
  2358. //todo 直播动态
  2359. $live_dongtai = [];
  2360. if (Cache::get($cache_live_dongtai_data_key)) {
  2361. $live_dongtai = json_decode(Cache::get($cache_live_dongtai_data_key), true);
  2362. } else {
  2363. foreach ($time_arr as $k => $v) {
  2364. if ($tmp_day == 2) {
  2365. $count_num = FishLive::where([
  2366. ['type', '=', 1],
  2367. ['root_id', '=', $root_id],
  2368. ['room_create_time', 'between', [$v['startDate'] . ' 00:00:00', $v['endDate'] . ' 23:59:59']]
  2369. ])->field('sum(live_watch_count) as w_count,sum(live_card_icon_component_show_count) as cs_count')->find()->toArray();
  2370. $live_dongtai[$k]['times'] = $v['name'];
  2371. $live_dongtai[$k]['baoguang_number'] = $count_num['w_count'] ?? 0;
  2372. $live_dongtai[$k]['click_number'] = $count_num['cs_count'] ?? 0;
  2373. // $channel_setting_wh = Company::where(['root_id' => $root_id])->value('channel_setting_wh');
  2374. //
  2375. //
  2376. // if(empty($channel_setting_wh)){
  2377. // $FishCampaign['converts'] = 0;
  2378. // }else{
  2379. // $tmp_data = json_decode($channel_setting_wh, true);
  2380. $FishCampaign_where_dontai[] = ['type', '=', 4];
  2381. $FishCampaign_where_dontai[] = ['root_id', '=', $root_id];
  2382. // $FishCampaign_where_dontai[] = ['advertiser_id', 'in', $tmp_data['fish_adv']];
  2383. $zhibo_clue = FishData::where($FishCampaign_where_dontai)->whereTime('create_time', 'between', [$v['startDate'], $v['endDate']])->count();
  2384. // }
  2385. $live_dongtai[$k]['converts'] = $zhibo_clue ?? 0;
  2386. } else {
  2387. $count_num = FishLive::where([
  2388. ['type', '=', 1],
  2389. ['root_id', '=', $root_id],
  2390. ['room_create_time', 'between', [$v . ' 00:00:00', $v . ' 23:59:59']]
  2391. ])->field('sum(live_watch_count) as w_count,sum(live_card_icon_component_show_count) as cs_count')->find()->toArray();
  2392. $live_dongtai[$k]['time'] = $v;
  2393. $live_dongtai[$k]['baoguang_number'] = $count_num['w_count'] ?? 0;
  2394. $live_dongtai[$k]['click_number'] = $count_num['cs_count'] ?? 0;
  2395. $channel_setting_wh = Company::where(['root_id' => $root_id])->value('channel_setting_wh');
  2396. if (empty($channel_setting_wh)) {
  2397. $FishCampaign['converts'] = 0;
  2398. } else {
  2399. // $tmp_data = json_decode($channel_setting_wh, true);
  2400. $FishCampaign_where_dontai[] = ['type', '=', 4];
  2401. $FishCampaign_where_dontai[] = ['root_id', '=', $root_id];
  2402. // $FishCampaign_where_dontai[] = ['advertiser_id', 'in', $tmp_data['fish_adv']];
  2403. $zhibo_clue = FishData::where($FishCampaign_where_dontai)->where('create_time', $v)->count();
  2404. }
  2405. $live_dongtai[$k]['converts'] = $zhibo_clue ?? 0;
  2406. }
  2407. }
  2408. //写入缓存
  2409. Cache::set($cache_live_dongtai_data_key, json_encode($live_dongtai), $ttl);
  2410. }
  2411. // todo 返回数据
  2412. return json(['code' => 0, 'data' => [
  2413. 'left_total_data' => $total_data,
  2414. 'live_dongtai' => $live_dongtai,
  2415. 'line_data' => $comtent_list,
  2416. ], 'msg' => '获取成功']);
  2417. }
  2418. /**
  2419. * 直播间数据列表
  2420. */
  2421. public function get_live_room_data()
  2422. {
  2423. $root_id = $this->aec->decrypt($this->token);
  2424. $param = request()->only(['times']);
  2425. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  2426. if (isset($param['times']) && $param['times']) {
  2427. $time = explode(' - ', $param['times']);
  2428. }
  2429. $where[] = ['type', '=', 1];
  2430. $where[] = ['root_id', '=', $root_id];
  2431. $ttl = $this->cache_time;//3分钟缓存
  2432. $return_data = [];
  2433. $cache_live_room_data_key = "cache_live_room_data_root_id_{$root_id}_time_$time[0].'_'.$time[1]}";
  2434. if (Cache::get($cache_live_room_data_key)){
  2435. $return_data = json_decode(Cache::get($cache_live_room_data_key),true);
  2436. }else{
  2437. //todo 直播列表
  2438. $where_time = [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59'];
  2439. $live_data = FishLive::where($where)
  2440. ->where([['room_create_time', 'between', $where_time]])
  2441. ->field('id,anchor_id,data_create,advertiser_id,room_id,room_title,room_create_time,live_watch_count,live_watch_ucount,live_form_submit_count,live_card_icon_component_show_count,live_avg_watch_duration,live_comment_count,live_follow_count,live_share_count,live_count')
  2442. ->order('room_create_time desc')
  2443. ->group('root_id,anchor_id,data_create')
  2444. ->select()
  2445. ->toArray();
  2446. foreach ($live_data as $k=> $v){
  2447. $return_data[$k]['id'] = $v['id'] ?? 0;
  2448. $return_data[$k]['anchor_id'] = $v['anchor_id'] ?? 0;
  2449. $return_data[$k]['data_create'] = $v['data_create'] ?? '';
  2450. //时间
  2451. $return_data[$k]['data_time'] = date('Y/m/d',strtotime($v['room_create_time'])) ?? '';
  2452. //名称
  2453. $return_data[$k]['room_title'] = $v['room_title'] ?? '';
  2454. //todo 飞鱼数据
  2455. $channel_setting_wh = Company::where(['root_id' => $root_id])->value('channel_setting_wh');
  2456. if (empty($channel_setting_wh)){
  2457. $data = [
  2458. 'cost' => 0,
  2459. 'shows' => 0,
  2460. 'click' => 0,
  2461. 'converts' => 0,
  2462. ];
  2463. }
  2464. else {
  2465. $tmp_data = json_decode($channel_setting_wh, true);
  2466. $FishCampaign_where[] = ['type', '=', 4];
  2467. $FishCampaign_where[] = ['root_id', '=', $root_id];
  2468. $FishCampaign_where[] = ['advertiser_id', 'in', $tmp_data['fish_adv']];
  2469. $FishCampaign_where[] = ['data_time', 'between', $time];
  2470. $data = FishCampaign::where($FishCampaign_where)
  2471. ->field("sum(cost) as cost,sum(`show`) as shows,sum(click) as click,sum(`convert`) as converts")
  2472. ->find();
  2473. }
  2474. //投放费用
  2475. $return_data[$k]['cost'] = $data['cost'] ?? 0;
  2476. //曝光人数
  2477. $return_data[$k]['live_watch_count'] = $v['live_watch_count'] ?? 0;
  2478. //观看人数
  2479. $return_data[$k]['live_watch_ucount'] = $v['live_watch_ucount'] ?? 0;
  2480. //点击数
  2481. $return_data[$k]['live_d_click_count'] = $v['live_card_icon_component_show_count'] ?? 0;
  2482. $return_data[$k]['live_avg_watch_duration'] = round($v['live_avg_watch_duration'] / 60, 1) ?? 0;
  2483. $return_data[$k]['live_comment_count'] = $v['live_comment_count'] ?? 0;
  2484. $return_data[$k]['live_follow_count'] = $v['live_follow_count'] ?? 0;
  2485. $return_data[$k]['live_form_submit_count'] = $v['live_form_submit_count'] ?? 0;
  2486. }
  2487. //写入缓存
  2488. Cache::set($cache_live_room_data_key,json_encode($return_data),$ttl);
  2489. }
  2490. // todo 返回数据
  2491. return json(['code' => 0, 'data' => [
  2492. 'live_room_list'=>$return_data,
  2493. ], 'msg' => '获取成功']);
  2494. }
  2495. /**
  2496. * 直播间数据列表
  2497. */
  2498. public function get_live_room_info()
  2499. {
  2500. $root_id = $this->aec->decrypt($this->token);
  2501. $param = request()->only(['id','times','anchor_id','data_create']);
  2502. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  2503. if (isset($param['times']) && $param['times']) {
  2504. $time = explode(' - ', $param['times']);
  2505. }
  2506. $where[] = ['type', '=', 1];
  2507. $where[] = ['root_id', '=', $root_id];
  2508. if (empty($param['anchor_id']) || empty($param['data_create'])){
  2509. return json(['code' => 1, 'msg' => '参数错误!']);
  2510. }
  2511. $ttl = $this->cache_time;//3分钟缓存
  2512. $return_data = [];
  2513. $cache_live_room_info_param_key = "cache_live_room_info_param_root_id_{$root_id}_data_create_{$param['data_create']}_anchor_id_{$param['anchor_id']}";
  2514. if (Cache::get($cache_live_room_info_param_key)){
  2515. $return_data = json_decode(Cache::get($cache_live_room_info_param_key),true);
  2516. }else{
  2517. //todo 直播列表
  2518. // $where_time = [$time[0] . ' 00:00:00', $time[1] . ' 23:59:59'];
  2519. $live_data = FishLive::where($where)
  2520. ->where('anchor_id',$param['anchor_id'])
  2521. ->where('data_create',$param['data_create'])
  2522. // ->where([['room_create_time', 'between', $where_time]])
  2523. ->field('id,anchor_id,anchor_nick,data_create,advertiser_id,room_id,room_title,room_create_time,live_watch_count,live_watch_ucount,live_form_submit_count,live_card_icon_component_show_count,live_avg_watch_duration,live_comment_count,live_follow_count,live_share_count,live_count')
  2524. ->order('room_create_time desc')
  2525. // ->group('root_id,anchor_id,data_create')
  2526. ->select()
  2527. ->toArray();
  2528. foreach ($live_data as $k=> $v){
  2529. $return_data[$k]['id'] = $v['id'] ?? 0;
  2530. $return_data[$k]['anchor_id'] = $v['anchor_id'] ?? 0;
  2531. $return_data[$k]['anchor_nick'] = $v['anchor_nick'] ?? '';
  2532. $return_data[$k]['data_create'] = $v['data_create'] ?? '';
  2533. $return_data[$k]['room_create_time'] = $v['room_create_time'] ?? '';
  2534. //时间
  2535. $return_data[$k]['data_time'] = date('Y/m/d',strtotime($v['room_create_time'])) ?? '';
  2536. //名称
  2537. $return_data[$k]['room_title'] = $v['room_title'] ?? '';
  2538. //todo 飞鱼数据
  2539. $channel_setting_wh = Company::where(['root_id' => $root_id])->value('channel_setting_wh');
  2540. if (empty($channel_setting_wh)){
  2541. $data = [
  2542. 'cost' => 0,
  2543. 'shows' => 0,
  2544. 'click' => 0,
  2545. 'converts' => 0,
  2546. ];
  2547. }
  2548. else {
  2549. $tmp_data = json_decode($channel_setting_wh, true);
  2550. $FishCampaign_where[] = ['type', '=', 4];
  2551. $FishCampaign_where[] = ['root_id', '=', $root_id];
  2552. $FishCampaign_where[] = ['advertiser_id', 'in', $tmp_data['fish_adv']];
  2553. $FishCampaign_where[] = ['data_time', 'between', $time];
  2554. $data = FishCampaign::where($FishCampaign_where)
  2555. ->field("sum(cost) as cost,sum(`show`) as shows,sum(click) as click,sum(`convert`) as converts")
  2556. ->find();
  2557. }
  2558. //投放费用
  2559. $return_data[$k]['cost'] = $data['cost'] ?? 0;
  2560. //曝光人数
  2561. $return_data[$k]['live_watch_count'] = $v['live_watch_count'] ?? 0;
  2562. //观看人数
  2563. $return_data[$k]['live_watch_ucount'] = $v['live_watch_ucount'] ?? 0;
  2564. //点击数
  2565. $return_data[$k]['live_d_click_count'] = $v['live_card_icon_component_show_count'] ?? 0;
  2566. $return_data[$k]['live_avg_watch_duration'] = round($v['live_avg_watch_duration'] / 60, 1) ?? 0;
  2567. $return_data[$k]['live_comment_count'] = $v['live_comment_count'] ?? 0;
  2568. $return_data[$k]['live_follow_count'] = $v['live_follow_count'] ?? 0;
  2569. $return_data[$k]['live_form_submit_count'] = $v['live_form_submit_count'] ?? 0;
  2570. }
  2571. //写入缓存
  2572. Cache::set($cache_live_room_info_param_key,json_encode($return_data),$ttl);
  2573. }
  2574. // todo 返回数据
  2575. return json(['code' => 0, 'data' => $return_data, 'msg' => '获取成功']);
  2576. }
  2577. /**
  2578. * 获取今日广告组更新的线索
  2579. * todo 威弘
  2580. */
  2581. public function get_fish_top_live_data_wh()
  2582. {
  2583. $root_id = $this->aec->decrypt($this->token);
  2584. $channel_setting = Company::where(['root_id' => $root_id])->value('channel_setting_wh');//todo 威弘
  2585. $fish_change =[];
  2586. if (!empty($channel_setting)){
  2587. $tmp_data = json_decode($channel_setting, true);
  2588. $time = date('Y-m-d');
  2589. //查询今天的数据
  2590. $tmp_data = $this->refreshToken2($tmp_data, $root_id);
  2591. $advertiser_id = explode(',', $tmp_data['fish_adv']);
  2592. foreach ($advertiser_id as $va) {
  2593. $number = 0;
  2594. $data = $this->fish_wh->getCampaignList($tmp_data['fish_access_token'], ['advertiser_id' => $va, 'start_date' => $time, 'end_date' => $time, 'page' => 1]);
  2595. if ($data['code'] == 0) {
  2596. $save_data = [];
  2597. foreach ($data['data']['list'] as $val) {
  2598. //需要比是否有新的线索
  2599. $info = FishCampaign::where(['root_id' => $root_id, 'data_time' => $time, 'advertiser_id' => $va, 'campaign_id' => $val['campaign_id']])->field('id,campaign_name,convert')->find();
  2600. if (isset($info) && $info) {
  2601. $tmp_number = $val['convert'] > $info['convert'] ? $val['convert'] - $info['convert'] : 0; //比之前存的记录多出多少线索
  2602. $number += $tmp_number;
  2603. $val['id'] = $info['id'];
  2604. FishCampaign::update($val);
  2605. } else {
  2606. $val['data_time'] = $time;
  2607. $val['advertiser_id'] = $va;
  2608. $val['root_id'] = $root_id;
  2609. unset($val['id']);
  2610. $save_data[] = $val;
  2611. $number += $val['convert'];
  2612. }
  2613. }
  2614. FishCampaign::insertAll($save_data);
  2615. }
  2616. if ($number > 0) {
  2617. $fish_change[] = "直播间获取线索" . $number . '个';
  2618. }
  2619. }
  2620. }
  2621. return json(['code' => 0, 'data' => $fish_change, 'msg' => '获取成功']);
  2622. }
  2623. /**
  2624. * 投放大屏-获取广告投放总数据-中间部分
  2625. */
  2626. public function get_transform_left_total_data()
  2627. {
  2628. $root_id = $this->aec->decrypt($this->token);
  2629. $param = request()->only(['times']); //时间区间
  2630. $time = [date('Y-m-1'), date('Y-m-d')]; //默认本月时间
  2631. if (isset($param['times']) && $param['times']) {
  2632. $time = explode(' - ', $param['times']);
  2633. }
  2634. $cache_data_name = 'get_transform_left_total_data-' . $time[0] . '-' . $time[1] . '_' . $root_id;
  2635. $cache_data_info = Cache::get($cache_data_name);
  2636. if($cache_data_info){
  2637. return json(['code' => 0, 'data' => json_decode($cache_data_info), 'msg' => '获取成功', 'leble' => '缓存']);
  2638. }
  2639. //飞鱼数据
  2640. $where[] = ['type', 'in', [1,2,4]];
  2641. $where[] = ['root_id', '=', $root_id];
  2642. $where[] = ['data_time', 'between', $time];
  2643. $data = FishCampaign::where($where)->field("sum(cost) as cost,sum(`show`) as shows,sum(click) as click,sum(`convert`) as converts")->find();
  2644. $customer_id = FishData::where([['root_id', '=', $root_id], ['create_time', 'between', $time], ['is_allocation', '=', 1]])->column('customer_id');
  2645. //todo 直播计算
  2646. $zhibo_where[] = ['type', 'in', [4]];
  2647. $zhibo_where[] = ['root_id', '=', $root_id];
  2648. $zhibo_where[] = ['create_time', 'between', $time];
  2649. $zhibo_clue_count = FishData::where($zhibo_where)->count();
  2650. $live_number = $zhibo_clue_count;//FishCampaign::where([['root_id', '=', $root_id], ['data_time', 'between', $time], ['type', '=', 4]])->sum('convert');//直播总线索
  2651. // $tx_number = FishCampaign::where([['root_id', '=', $root_id], ['data_time', 'between', $time], ['type', '=', 2]])->sum('convert');//腾讯总转化
  2652. $tx_clue_where[] = ['type', 'in', [2]];
  2653. $tx_clue_where[] = ['root_id', '=', $root_id];
  2654. $tx_clue_where[] = ['create_time', 'between', $time];
  2655. $tx_clue_count = FishData::where($tx_clue_where)->count();
  2656. //查询有效线索
  2657. $source_id = CustomerSource::where([['root_id' ,'=', $root_id], ['source' ,'in', ['飞鱼线索','腾讯线索']]])->column('id');
  2658. $customer_data = Customer::where([['source_id', 'in', $source_id], ['id', 'in', $customer_id]])->field('id,deposit_money as deposit_moneys,signed_money as signed_moneys')->select()->toArray();
  2659. $fish_count = $fish_money = $signed_number = 0;
  2660. foreach ($customer_data as $val) {
  2661. $fish_count++;
  2662. if (isset($val['signed_moneys']) && $val['signed_moneys']) {
  2663. $signed_number++;
  2664. $fish_money += $val['signed_moneys'];
  2665. }
  2666. if (!isset($val['signed_moneys']) && isset($val['deposit_moneys'])) {
  2667. $fish_money += $val['deposit_moneys'];
  2668. }
  2669. }
  2670. $end_clue_where[] = ['type', 'in', [1,2,4]];
  2671. $end_clue_where[] = ['root_id', '=', $root_id];
  2672. $end_clue_where[] = ['create_time', 'between', $time];
  2673. $total_converts = FishData::where($end_clue_where)->count();
  2674. $all = [
  2675. //总投放金额
  2676. 'cost' => $data['cost']??0,
  2677. //展示数
  2678. 'shows' => $data['shows']??0,
  2679. //总转化数
  2680. 'converts' => $total_converts??0,
  2681. //点击数
  2682. 'click' => $data['click']??0,
  2683. //转化率
  2684. 'convert_lv' => $total_converts > 0 && $data['click'] > 0 ? round($total_converts / $data['click'] * 100, 2) : 0,
  2685. //总派单数
  2686. 'count' => $total_converts??0,// $fish_count,
  2687. //有效率=总派单数/总转化数
  2688. 'count_lv' => $fish_count > 0 && $total_converts > 0 ? round($fish_count / $total_converts * 100, 2) : 0,
  2689. //产值
  2690. 'signed_money' => $fish_money,
  2691. //均单值=产值/有效
  2692. 'signed_money_one' => $fish_money > 0 && $fish_count > 0 ? round($fish_money / $fish_count * 100, 2) : 0,
  2693. //直播派单
  2694. 'count_live' => $live_number,
  2695. //投放派单
  2696. 'count_other' => $total_converts ??0,
  2697. //合同数
  2698. 'signed_number' => $signed_number,
  2699. //腾讯总转化
  2700. 'tx_number' => $tx_clue_count
  2701. ];
  2702. Cache::set($cache_data_name,json_encode($all), $this->cache_time);
  2703. return json(['code' => 0, 'data' => $all, 'msg' => '获取成功']);
  2704. }
  2705. }