123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <?php
- use app\logics\CustomerLogic;
- use app\model\Customer;
- use app\model\CustomerPortraitField;
- use app\model\CustomerSource;
- use app\model\Employee;
- use think\facade\Log;
- use think\migration\Migrator;
- use think\migration\db\Column;
- use toolkits\Aec;
- class GetDeYuBeiYuanSourceBetter extends Migrator
- {
- /**
- * Change Method.
- *
- * Write your reversible migrations using this method.
- *
- * More information on writing migrations is available here:
- * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
- *
- * The following commands can be used in this method and Phinx will
- * automatically reverse them when rolling back:
- *
- * createTable
- * renameTable
- * addColumn
- * renameColumn
- * addIndex
- * addForeignKey
- *
- * Remember to call "create()" or "update()" and NOT "save()" when working
- * with the Table class.
- */
- public function change()
- {
- $list[] = [
- 'name'=> '刘金锁',
- 'customer'=> [
- 'douyin'=> [
- 13653342457,13383143512,17610508860,17703285768,18831406197,15233401178,13623242359,18230041789,17622365549,13785398383,13722419023,13166500923,16619858905,19134149113,15833246199,15803344444,13833412327,13932468167,13931411339,15386467935,13811680391,13831480776,13293226285,15731481055,13191638990,15231690763,18603348042,13603341528,13716999446,15632464599,18932858505,15028920299,15903143216,13131454139,13833412124,18503147825,13932497569,13389830963,13831459944,13832495149,13260380568,19999439999,18701660256,18395721118,13803147262,13831421628,13718188458,13910268630,18131450142,18531430384,18731406951,13343141202,13653149866,13131453168,13703143028,19560343515,13520596555,19912186070,13831416869,18932852125,13831417292,19912181400,13833423685,18632435193,13343147870,18831486688,13903249067,15903344204,13703140502,15354249999,13131474917,13393140197,18131471444,19131695558,18803347878,15033142222,13832466349,13825014418,15512387770,15903347911,13733343266,13663146322,13314041166,18031405015,18732452613,15303145635,13472098765,17600305613,15603149151,15003245285,15350720001,13903141284,13283390229,13333393842,13803149108,13403149993,13722413319,13832458210,13503140314,13161255557,18703341748,19333880014,13785372723,13463340345,13472077959,18531496606,13733348282,15233099433,13832414599,13833400733,13603140177,15076963339,19133085238,15373144906,13803140677,17336461519,13733342884,13831456828,13012000554,18046595619,18073796446,18910621758,13932404021,15233090207,18713451817,13831494777,13832453225,13210523199,17703143830,18932893642,13831443558,18232226809,17333480164,13803145667,18131435296,18715908683,15632400876,18732439604,18632440005,18875621796,13722402775,18232270009,15133888321,13932484920,17633148437,18631432412,18231432021,19958224572,13303146982,18131444433,13832417535,18631400277,13833402385,13131491606,13398666950,13403343505,15512948497,13832420864,15930091976,18247618956,13803140557,15903142179,15028933326,18713456694,13333397174,13832402571,13903242282,18832433334,17610622678,15210341876,18832461509,13831428718,15354140321,13403344518,18713437596,15231433199,18610377110,13803145223,15731402054,15350720446,18931415535,13785377640,13603147868,13903142840,15373148968,17060567788,13831408123,13811574558,15231415003,18395742292,13833406699,18031499925,15711484485,13653141865,15133888704,17332528881,15028966568,15201584663,13315874123,13785375543,13821053219,17746104358,15076362789,15033143435,15732499998,15076993806,13342255333,13932489915,18730429253,13131488404,18232220553,18732407610,13463483400,17730589633,18631461390,18631440510,15133874442
- ],
- 'toutiao'=> [
- 13081894466,19913065503,13091339653,13803141931,18232638225,15333149115,13903241020,13903143868,13903241511,18631480880,13253170979,13831467008,18231451155,18198918690,13831469583,13731412484,13503343829,15512938311,13903144744,13503341108,17798122317,13931403321,18732425059,15028968818,13803140488,13703141588,18231434852,13020895160,13932468615,13803148560
- ],
- 'guanggao'=> [
- 15343146667,15632444443,13831488844,15028946688,18731458777,18631469655,13091353093,13313143663,17796928866,13103148171,13730345604,18611155549,17689535066,17746117181,15022762986
- ],
- 'xigua'=> [
- 15383146646,13831475226
- ]
- ]
- ];
- $list[] = [
- 'name'=> '刘金锁',
- 'customer'=> [
- 'douyin'=> [
- 18932880329,13833434921,13831443076,13582424069,13603146508,19331461999,13932494547,13833418639,18603145128,15103249006,13373580139,17732655759,13513247380,15028934111,13343381268,13383640500,18210093503,16631455333,15833261902,17303148400,13398665667,13131486316,13315893877,18230339760,15133874442,19857124090,19331434999,18395740999,13031413221,17832601282,13931429909,15903143533,13832406289,15133828147,13373147548,19932341363,18732418677,15227115631,13131433782,13932484894,18732463719,15903143825,17631422445,15831413110,15010615491,15733941601,15931405594,19331429832,15031680528
- ],
- 'toutiao'=> [
- 18831466887,13832473529,13932455667,18003140011,13633148800,18932881234,15612471220,18500876396,15512942771,13931408251
- ],
- 'guanggao'=> [],
- 'xigua'=> []
- ]
- ];
- $list[] = [
- 'name'=> '齐成林',
- 'customer'=> [
- 'douyin'=> [
- 13733249933,15731218517,15024525206,13733248973,13131465830,15832420048,13932486725,18603246062,18903143186,13283380073,15133851986,18131880898,18233880541,18031479821,15033145388,18232224899,18531472033,13323140320,17320961611,18088002911,18103148999,15028118006,13343148553,18631415169,15097811140,18831461196,13231416046,13403240927,18032817215,13932461658,15333142360,13333390559,18632409958,15512389202,13131492545,18611950798,15128597463,17810204235,15733971520,18640251095,13520535373,13832482556,18531405218,13903141871,18830406801,15028968634,17320900522,18131496397,13932405941,13803149685,15076996853,13313380975,13343387350,19322787767,19930445432,19904979678,13398672169,13613144087,18703141234,13398693323,13831499973,17320939690,13722413433,18503149612,18903144958,13303144138,13293235658,16633402526,15076922863,13603141375,13166506377,17732376356,13832427860,15831426266,18131477502,13903248587,18134048801,13603347687,18832422727,15031313266,16631409009,18395708251,15097889124,15076891946,13785395210,13303144012,15803241878,13832473088,15133808678,18631486607,17307696024,18632466192,13231421508,17603148262,13831428146,15930081510,18831449378,13503148358,13398681635,18211189830,15097825163,13931425250,13903141039,18631416029,13810531269,18103145565,15230896576,13333398639,13932409576,18131496356,15383080773,18003247704,18931421111,13831431852,18611516902,13911629668,13520702625,15231411953,18331442689,17736952100,18131429721,19133060046,13393146693,15932404665,17261109185,13831473267,15821233857,13373588608,15076378459,15031666736,15612491836,18031491494,17743606077,18731407099,18230143324,18231406832,15231485876,18903249184,13731429608,13722419711,18832408320,13303142385,13643149955,13784536966,13613148608,13623149994,17332521188,15533142199,19331485888,18003144777,13832411074,18631480608,13315885082,18631414447,18232285986,15028537507,18732456491,13932428992,13803149060,13932421509,13731405667,18395746084,13633146872,15333141658,13730345350,13131466411,13832458695,16223541475,13398696025,15510333112,15512366771,18131451835,15028971002,13383142585,18531499308,15903346180,13931415317,13833434921,15103140721,15811163192,15231441062,15327412468,15831455191,15512484542,13784534353,18703312924,15076927699,15031308016,18632453372,15031663887,13403242000,15233445370,17746107751,18816211443,15203217026,13832489928,16631430247,13831192085,15233091162,13931413456,15832895953,13363142258,18713476993,18831429804,18233585727,13832468366,15097890905,18232236864,17332351097,13722408099,18131411125,13931406732,15324069172,13932440999,13643146704,18131870740,13613145304,13313288880,15176806070,15210053885,15028544964,13803141688,15133886667,18732489965,18231408560,15383149995,13582869329,17703247772,18031497135,19912197341
- ],
- 'toutiao'=> [
- 15350728504,18103240988,15632431251,13313148850,15632458857,15512491234,15531490777,17603148512,13831438259,18713426366,13903249040,13832486253,13903146300,13503148556,19133691125,13903241666,18831405668,15028945613,13931413228,19913058222,18303148828,13343384868,13084591024,13832462661,13932481089,15028973520,13932428821,18832421588,13931418319,13091357771,13903246209,13513140019
- ],
- 'guanggao'=> [
- 15176765888,13731410222,15097876395,13932493260,19833442111,17732377333,18031400906,13313382876,13831438100,15732448886,13832407277,13333149654,13623246388,15831428345,15133860668,18903240648,17732881569,18730410915,15531486660,13831439592
- ],
- 'xigua'=> [
- 15133810791,18232282481,15097819932,13931426859
- ]
- ]
- ];
- $list[] = [
- 'name'=> '李飞飞',
- 'customer'=> [
- 'douyin'=> [
- 13932429460,18395795789,13623246880,13831466767,13832476082,13932418598,18831483803,18232620059,18134041986,13513243699,18531445226,13831406335,18801398043,13273598201,18731433334,13363140676,18903140591,13832433582,13932456662,18131878332,17732385561,15128640666,18201110356,15133866568,18131459260,13832442510,13931400100,15632437702,18232266201,18831400666,18713423785,15028557774,15010950314,15633149415,13831473821,13722408698,13398663300,18731461698,13832432848,18830424042,13293276571,13932451828,15262445578,15128615983,13503346304,15831522113,13855558806,18713400887,17725583783,13383141511,18031403668,18513583539,13831465661,13717861239,15028935730,18322189458,18015731956,13832461684,15299709720,18731479556,15932417107,15530685555,19913078703,18510136778,13831452262,17716535978,13831418009,18131885775,13722410512,13731400323,13832425152,18713462265,15233439991,13731415676,13643144487,13503148966,13603149921,13603341606,18632411035,18395779939,18631405573,19931092781,15933663806,18631487731,18201185527,17303146832,15128604811,17320966964,17332548282,13383140018,13603140301,15128558755,13603140781,15612661456,19833452501,15133866556,13103344740,19133344244,15354242217,18932866818,19913061818,13131488856,13483871682,18631473390,18131496378,13831450291,13131440161,18732453332,17703140001,13832470500,13313147588,15603149533,13293243997,13333393636,13323149579,13303144162,18131453418,15333149993,13472088482,13832415131,15732462988,13832488776,13932411288,13730142598,17303256201,13832450766,18231422545,15804299711,18612541688,13831450215,13731419827,13932445134,13503143541,16631458067,18231453111,17631421260,18730408751,18031400572,18331436609,18603144034,13303145477,15231687979,18231493639,18618267440,18932892024,13731407444,13293268075,13832412129,18731484720,18631476318,19131237653,18231469799,17332535567,13703142116,15512955510,16631424536,13503146808,13131434185,13103046618,15133886000,13932419351,15931406553,18730458080,18403242433,15031654815,13831456768,13121138598,18210833481,15910793486,18732455188,13831422227,13932487003,13831403919,13903146070,15372117452,13323141807,18327045012,18231416639,17803141618,13803147570,17316082887,15731409409,15903349009,18632404530,18632409944,15379503476,18232410324,13503148700,13832442233,18500156162,13931403053,13313381127,18500388171,13832448719,15128585555,18831458558,15306971161,18631405573,13832408971,13231469288,18831419809,17703245210,15531494486,18633594602,16631413120,17320994771,15192556141,13717817297,13831406315,17268866150,15732443234,13731413712,18832414199,13903140394,15512925869,18632443050,13831481577,18231421864
- ],
- 'toutiao'=> [
- 13903140356,17320933752,13103041359,13171600518,13931429817,19931082867,19331426154,15243388858,13903143610,13398674801,13503342036,13131491606,13932465629,17746110695,15803343948,18631440423,18632467776,13831468086,18131425522,13603343699,13932416486,17736958533,18932885068,15333141280,15512498862,15903140757,18931409568,18832449891,13303142729,18603347791,18631443788,13103249886
- ],
- 'guanggao'=> [
- 18395728000,13613141987,13303143069,13932423069,13333393346,13520558914,13785388116,18911909456,15930997658,18233871117,16603145491,19932342099,18031411608,18231400822,15531498655
- ],
- 'xigua'=> [
- 18301547881,18395744102,18715947489
- ]
- ]
- ];
- $list[] = [
- 'name'=> '李雪',
- 'customer'=> [
- 'douyin'=> [
- 13356013442,13903241045,17732899873,19131682756,13931428618,18632445456,15231473113,16631435717,15097870405,13373583913,15076901755,18232637773,17303348786,13283392987,15076363009,17303236111,13832481133,18630163855,17301090305,13932462428,18103241125,13730142857,15831430374,18832400070,13603146632,17734535379,18103241333,17732375451,18632463221,18713402626,13313149271,13373588686,13303145816,13932423187,15665411223,13283390728,18730406025,15612655698,15731443248,13803140026,15531473929,18732472921,18231415196,13903242693,15632445679,18031428288,15633148890,13731410444,18832405333,17746107185,15076987382,13191898288,15233448869,15822958185,19903143142,15131487512,17358790710,13932485958,18331421319,15901152091,13315877092,15803143828,15612674687,15512390651,13141322070,13653146459,13633240897,13333397789,18603147111,18231468211,13832403915,13831421898,13144344538,13832439999,17531422809,15028936660,13833426890,13131449024,15231439618,15128601665,13903242223,13831485165,19931068808,18715914413,13716063385,18830443456,19912192428,13261593296,13131478372,13403245149,15011374622,18503148882,13831417280,15803248444,15512496930,17631449224,17336380443,13932454146,13932471218,13903248740,15831489808,13832413140,13463673500,18531160569,15832885200,18131880601,15031319930,13653240307,18603348520,18331430822,13903241388,13831404979,13931428072,18031475907,17367473254,13831419061,17743600353,18632429034,13633240079,15834142258,13131468227,19912193126,18031423869,15933140754,18303146656,13167399113,13663340885,18931405551,18631410487,15503069034,15011469085,18830421766,13483864119,17603146155,18201691631,15303142412,13552918260,15033591120,18632420013,18832448808,13283394142,13731445110,15003145084,15831415035,15512945121,13903140713,13831408048,18732450777,19931082993,18903142900,13521103125,18903148515,13784458443,15233429992,13731444738,18832458649,18830438566,13643147866,15831491547,17732370585,13785397627,13831479700,18964086775,15097837211,18732441611,13831471733,13398669697,15128631125,13398678488,18631491979,13663344620,13315899120,18732422369,18010128151,13513144912,18231405816,15831456682,18233842295,13383145907,13231447100,13731400323,16603141689,13603140781,15176769010,18632425219,18003240756,15933667185,18732443818,18830739995,15176761816,13283360900,13363141779,13513148316,18103249666,18832486971,13313147588,15011501285,18732488511,18803246088,18832438366,15612481167,18632418565,13313381363,13522381655,15803240314,13653145167,13931419876,18732433888,13513142255,16630340824,18233861165,15176759603,13931406540,17632118556,15612489848,13784538662,16632430930,18031481447,18903140131,13931428595,15354047493,13832407000,15503047772,13903241780,13832402162,15831421333,15233418893,15632498017,13552396405,18231416218,15176788863,15128550999,17560605409,18631412223,13653345180,18931863835,13731417185,13831422027,17746109985,18631464524,16631424255,18931414497,18134040075,17631431044,13103240111,13293209550,15003249927,17769095536,17332516665,18632418860,13731428219,18131456093,17336384046,15128933458,13931428661,13803144059,15303146711,13932404993,17610725762,15128572297,13395771104,15832415932,15632431697,15133802304,18231421099,15833522104,13932411447,17732881366,18713488382,18232640858,18932896250,17332550916,13333392776,13932441592,15731441111,17603145882,19931097176,15203149897,13731400371,18233878166,18631400095,18231438885,15103146234,15176750129,15801348443,19133732525,13932411485,18730425008,17631411622,15028538174,15188757148,18631488684,13084591558,13831459340,15097805528,17732909199,19833425990,13831416245,13266916769,18631429191,19931066886,13398663027,13483883081,18713409828,17320948555,19903240044,13333148686,13231443395,13731400772
- ],
- 'toutiao'=> [
- 13603141918,18931411560,15076922188,15833247177,17703240181,18632452483,13633240689,15097803444,13393145643,13832408588,13831473556,13333149339,13603344629,13603140221,13831486810,17743601626,19931099055,13131425555,13103343334,13253176177,13603140812,13831438598,19133798787,13383648820,13932409559,13373268444,13703148199,15076892560,15097838821,18233895359,13730142566,13831491836,18303141209,15301178706,18715921598,18631424965,13831450599
- ],
- 'guanggao'=> [
- 16603148966,13784530366,13932466687,15031656067,13031428036,13191955657,18932884447,15128592709,19331400222,13472070228,15076366596,18903146788,13165526560,18831424447,13691258802,15803149808,15203242020,13091350419,17796933703,16630342081,19303143518,19134147521,13303142966,15031656066,18031412482
- ],
- 'xigua'=> [
- 13031424450,18730495058,13633145959,13463675585
- ]
- ]
- ];
- $root_id = 1035;
- $e_where[] = ['root_id', '=', $root_id];
- $e_where[] = ['name', 'in', ['刘金锁', '齐成林', '李飞飞', '李雪']];
- $e_where[] = ['uid', '>', 0];
- $e_where[] = ['state', '=', '在职'];
- $e_where[] = ['grant_id', '=', 0];
- $employee_list = Employee::with('customer')->where($e_where)->select()->toArray();
- $seldata = CustomerPortraitField::with(['select'])->where([['root_id', '=', $root_id], ['keyname', '=', 'source_id']])->find();
- $customer_source = CustomerSource::where('root_id', '=', $root_id)->select()->toArray();
- $all_phone = [];
- foreach($list as $k => $v) {
- foreach($v['customer'] as $c){
- $all_phone = array_merge($all_phone, $c);
- }
- }
- $employee_list_data = [];
- foreach ($employee_list as $k => $v) {
- $one = [];
- $one['employee_id'] = $v['id'];
- $one['name'] = $v['name'];
- $one_customer = [];
- $v_customer = [];
- if (!empty($v['customer'])) {
- foreach ($list as $kk => $vv) {
- if ($vv['name'] == $v['name']) {
- foreach ($vv['customer'] as $v_c) {
- $v_customer = array_merge($v_customer, $v_c);
- }
- }
- }
- foreach ($v['customer'] as $vv) {
- if (in_array($vv['phone'], $v_customer)) {
- $one_customer[] = $vv;
- continue;
- }
- }
- $one['customer'] = $one_customer;
- }
- $employee_list_data[] = $one;
- }
- $save_data = [];
- foreach ($list as $k => $v){
- $employee_data = [];
- foreach ($employee_list_data as $e) {
- if ($v['name'] == $e['name']) {
- $employee_data = $e;
- }
- }
- if (!empty($employee_data) && !empty($employee_data['customer'])) {
- foreach ($v['customer'] as $kk => $vv) {
- if (!empty($vv)) {
- switch ($kk){
- case 'douyin':
- $source_name = '抖音';
- break;
- case 'toutiao':
- $source_name = '今日头条';
- break;
- case 'guanggao':
- $source_name = '搜索广告';
- break;
- case 'xigua':
- $source_name = '西瓜';
- break;
- default:
- $source_name = '';
- break;
- }
- $source_id = 0;
-
- foreach ($customer_source as $kkk => $vvv) {
- if ($vvv['source'] == $source_name) {
- $source_id = $vvv['id'];
- }
- }
- if ($source_id) {
- foreach ($employee_data['customer'] as $e_d) {
- if (in_array($e_d['phone'], $vv)) {
- $one = [];
- $one['id'] = $e_d['id'];
- $one['source_id'] = $source_id;
- $ext = [['keyname'=> 'source_id', 'value'=> $source_id, 'id'=> $seldata['id']]];
- $c_logic = new CustomerLogic();
- if (!empty($e_d['ext']) && $e_d['ext'] != 'null') {
- $extdata = json_decode($e_d['ext'], true);
-
- if (isset($extdata['ext1'])) {
- $new_ext = CustomerPortraitField::where([['root_id', '=', $root_id], ['pid', '<>', 0]])->select()->toArray();
- $ext = $c_logic->old_ext_edit($e_d, $ext, $new_ext);
- } else {
- $ext = $c_logic->new_ext_edit($e_d, $ext);
- }
- }
- $one['ext'] = json_encode($ext);
- $save_data[] = $one;
- }
- }
- }
- }
- }
- }
- }
- (new Customer())->saveAll($save_data);
- Log::record(11111111)->save();
- Log::record($save_data)->save();
- Log::record(11111111)->save();
- }
- }
|