1. 程式人生 > >獲取分類演算法

獲取分類演算法

/**
* 獲取所有下級分類(包含本身)
*/
public function getAllLowerCategory($pid = 0){
$category = ProductCategory::select('pc_id')->where('pc_parent_id',$pid)->get()->toArray();
if(!in_array($pid,self::$lower_category)){
//新增自身
self::$lower_category[] = $pid;
}
if(!empty($category)){
foreach($category as $k => $v){
self::$lower_category[] = $v['pc_id'];
$this->getAllLowerCategory($v['pc_id']);
}
}
return self::$lower_category;
}

資料結構如下:
[0,"22c87a8ed3ede665da618fec107f6c07",
"3b37669405b484cd026d68c984044d0f","604bab2a4774d2c9cc55db134151456f",

"45e71495dc1cd9dae87b3a44c693c908","604bab2a4774d2c9cc55db134151456f",
"6144bb9fae96e8682ca03c97f8fad31c",
"bf86e8a6246984a5e657e8bce0048c71",
"90a870a8cbd839709b0af3895b216b03","137e6461f817652f575f132e8f09381b",
"6d1142811b15e6de3c02ff9e2d7be8b5","9e101897c571d192afc58b5bbf11f4a6",
"99aba3e50a6fe51ac8872e9ad73a8c33","188af378256c7eea89d7879b314cc976",
"a1a06bc0385167c625dcb9d0c3696ab1","c100b0c8c3ad8b6d85cab9ca9a92b23f",
"f21996a943a99fe5bcfa118b42d3b23c","1f355f076d6f56626d3e609c7829a819",
"3c9e6ca5f7580bdcac6106ab3456c255","8a11fd37be83345c3e10f9b0797976bb",
"ffe6224f29a4d9e6ea99721564b2470b","f82fcab994c4e949eaf50ccf8ab73f89",
"5383ab80f28c38c078174ac253500997","6e521a5f0b5bfbe4f513d8ea1ecaadd7",
"d0c9aad9bce99d427845ded7bd8e0736","d12cb564d7d303a07223b930ec8dfc62",
"f46a39ac9f9f1a4490d61ed457bfc6df","f64d7ecb82be7e7198d2947cf63ed397",
"2b328a46f4b7e8bb223a921a17b1ddef","19b6053266d49800882e410c601f3fe0",
"377794aa1796548da143ef4031ee30c4","4a4faf2f68ec5e8f63e28ac7e8d5ac97",
"706ddb096fd906cc9bad5cf30aee1b76","afd2e721e8e06a5e1730ff41fa7255d6",
"d81ae7c7375647ceff7eb8240a89602e","53985846e049376bc1ba38a1cd23d986",
"284ccc08cb4ef6324eb5368f040fe0ed","7d763a3aaa80ecdcc9848d462f150bd7",
"86e12d62c19e736022e224e90c2edad5","b7b18d8066d3618c4d9273762885f7df",
"3abec3ec16c161e56e1d940318c5311d","8f5f5fb63d6fa4310b8f650ac4d8f6d6",
"b521e08adcae4fb68988a492a4f4de44","dabad5c83fbc1bb5374ed79215b8916b",
"f3df1caf4aee298923de1dba4b0bce1a","c6ba4fd48ccd1ebab672aa3f9e6eeded",
"3ab18a1d2eecd2203554005ac3872203","7be13ead31ec9a3f50b27046daac9d82",
"c32848b9aead0fbf12c1e426d9f357ee","e9b36ff16bce870137432c1102d513ae",
"f2470f338728bfff89b41602fad308f5","485d0b5770efd69ac77110563df1aac5","66e2dd8ef82dc7509206d575c4ddd1ac","70a38cd828ecdfb6224ce89dc82f83dc","9e5733c50e58559a946dde53db3af952","e4af2e48583cca2277e3408e209ca824","fa5faaa57c48d9d91eb10f0bfc16f288","a5b3db8022f930e1a1691b623f354412","4fbef52537946aaf54b3df30187c228a","604ed86f0a136be6a20c5cbd66487a39","fa7a6938f53d0e3a1c34a86615451462","cd6c94fe9aca806ddad96645282e21d4","079eb6d23b6e862f176b72dacc8e8896","a4a8dc17238ec0f8f42faa1d00b3e38b","e003c085887773ba5c8b030dca79ee86","4c450cee2de69abd0e0367e35df4606d","7dbea8a9a31d329946ecaebe704509a0","32091da4c26dcfa3ccb4f8d9a15c6056","78f002e3e5c5f9c883f1afda22743688","c4d2fd14fea9a2b7e1ac3c7a56f41f82","fd0096835872d42eaf2ddf78b2301ba9","99e5cc2272a5598a4906d31235e772d6","0d512c2ca6e3ae883230184ca7966706","5ae66b6a0b2f349644ace188571fb92f","70adb8ff771e2a0862b99b8c61cef4d0","926fd80cff00f7421f8baa3fff50066e","b1b9c6c77cf9ee68e4f18f0c52a52290","ef4d3d4809c06b4baa5e2c2a14e17931","f7fe0d758c947a08559171fe0715faa9","c17a41670914393970f48171180b9da1","0a157844be37457d073041c1f9861d89","2cf7926121b60dcd7837099728a86f9c","3fe4d69f2b4c3fef326dc130293b7c6c","4387fb830595d193ec2ba57d80a53e0f","ae9e1d9f851dfe3a6668e8a009f7f875","be6a3fa00ffa0fbe6a7854b8d123d9c9","cf10364ac01014898a53b43df1683b39","0727dc3ccbbd5bac6430f47124d9e401","3a5118c4ba342594c6260be6161b9ab9","597edd68d70861904b45f89861dd6361","b59876987a427c792009e1af538bdd56","5d00cd9eb79e7ce7671793f25e6958a2","2f7b535100348d44858958bb0860ec6e","3ba3f9d7e442fbaab2d187237cc3f8da","ba1925719dadaad0af693e10a71556d4","c9f4493ea05648a7058b877dd9d0efa1","5e0cd54b3391e7117231978b879dbe86","4b43a9fee3b5232ded47c918fffe4b87","5ad948d71113d8018f015146c488b38d","6a0dbfb1bfe85dc94dbfa95a072295dc","91206b7a7e5007b63dd47c897ed41de2","99fab70202d019c264eb16402295cd8b","fbf4e2bc992c3bf697fcaf2dd7c85d71","c005233b877b26147efe0db4b6e554c8","54cbd1f1b82c5d320381179c233fb2d3","b0b6df67cbc4e139bd3a9e4a5ae4fe04","bc3c2b3f9911134f5bbbc57fd2fb9835","fe2da8fbca2677bde9223808c769333e","6429c5d1c78c4f7d9a4bd195ac354d34","2970ae30b8eb8808a96f9b959b455e02","4ba04a65e1f7c8fbcc069408eec95986","e73bea12fb87d47ed58d3d4c8efa4e8c","fe7cc181892beee037afff6b5f2e1c11","5e1df24ea51f879c87168358a445d548","15a5d5dcc8e6a5156a69e16faafe2b89","5981bfc02112f60b25491f0109a1384d","ae0ce2966218c351bb4acf728d3157ad","d9eb6c34256d4054868cde0f182883c7","701d747cbf140b84e277cc7ff62039e9","060efb89e5427539854d5849f2a22910","3d794fffed07b4569d751e1cf2664786","be44990ea876fb788eaf200d6ec6b665","ca4cd876e1437f4df88688853a0d8253","f96bbfb7654635d6be1a2340a758f3d5","7eea94d51456824ccfae34ce7ff731a5","1b80487cc0b76d5369726ade24bd1325","897da08dbc909aa79d4dccde03597bec","b7ea15003b40832a02257393c128e609","fa5b0ed1999f7873a19e1bb25b03ba02","0bb23533cce9d9963ad13d0c3e89061f","1f9762f2312154fc0adc2e042de63344","9502135ecb123f5c361c3148b362386e","a81e8e08ef6a18dea2ddc8368b345a67","6ce9afb200c603439bd742825a331f0f","49efde3966cf38e84a2af273284387a0","0eca7d79154eaa8743ee0a359a0f28d1","2a2d11c38491a0aa8cfabf0143dfc723","62bfda44591b64ef766f28d8347d1f13","6fde2f9c25932aa2e0d1e1f54d164f51","782a2f14baaa37fc0700965f39321a12","d37c9a98749886bc66808e70bb019ee0","9ca4f4c8995877f5d3f181c6af7c9693","627f20a2a59a5432924d57b452948b9d","730351b995416371fb9454d2e0039aa3","8bf639c09bb75fb1a4209290ac1ae9ac","bd31ac292b8fce123fa902c6336d084d","d2fab36dac83fb06029f8b021091340d","ddce2bb0cb37ecbb7d75951f009cf02a","7bcd933f9251b6e09a163ed9c3bfe259","caa6309cd38fc0d0ff27fb323373b05a","50e4e445bfaa31a444a37b6f9990d002","e299087231920e76d1b3ffaeaeea387b","f5265d684ab275dbbd614dd4e535941d","3dbbd9f9183090c8c138e4e6b1fd6517","4d7b676e239f5a11f1c347861c073a20","cb06a2158df4ecb67d8d05aef356b883","839a55570468063872c8bddeb68042f4","07c6ca2f45d3fde3e17d1117b36937fb","640651c0f1fd86a39fe6c03fb3f782bc","90131b480604efffa603fb93524ac82e","4ea34867471306b594ebca13ea68dea7","1cca6e18b1163f95459efd9c96c2838d","70a12a13e139bc750170baead0c54b6b","9a6b74cefc2b9f13d4240457f65034f1","b7d70800883ccb0390468f21bfc11796","c85cf12314da4e995b8806b2c22a8ff8","979c7dd7a77068be492bfeb3c5f8609e","0772889b5358f93d1d48d46680255b7e","124f545d65e52cbec4caac9bba42e0a9","32f1c388e7e1e8dabc438b7880b6f72a","6f3c7557faceb3ffb39ac66c87fa07ff","81fc4563e60d35362e96d23141c84af7","85cc6cb67759d10d4e1276d3bebb3615","ba29b340c64eb8cc829fe5bf738118ee","f8055f7580fbe1fefdf60b6024d00b0f","4c449789b880bd62cb3421a66a88212a","0b81824023462f00ed68c1c5855891b5","17a8215547110dacecefdfaa3ceb65ed","4176a8b9f03c6b40201fdf5e6fc4d2c8","66bca4696c9facac768d43748fdd0638","9da5bffb3207576680da8db528812fce","b3dc3fe53a68d491371ba34b06e67075","d9cb0017249c3f4d9f3b3cfaaa1a7fb5","b8e3ccb7ecd418d6ad0a138403becc98","3ea51bcec5e6be56cfbc1e4ab0ebde55","54050c4dac5d2e353742499ce7e91328","67fa4e92bd932c770a1fb4247ff4b75d","6bbf88c5da2792c8f158476279646edd","ff31d05b45da669771905d17e7545ee4","09fa3eebeb8e8eb0bbc266ed6777ce4e","874155d5776e7d605a0280aaf2f2fb87","e0725807469484fd1229a5d10cc05fc7","ec510b9ea4302e2b8e5176194e3c6e1f","f4b95e5dad35179606e562fe6b0da0c2","9bd3cf689ffc40ffdc73a0f03a5ee0d1","6adc621e1a9c409670e9ff1226ea34ec","1d6b44300fb55efca82d97f98354300a","33682402bb0061fc1c63766f66f5b411","501e47baa6adc55855ad8451f484c9f6","c03b72549c08ce9551c3be89e0e7fb0e","727cfb08ab51b84dbf06a030bbfb0a67","05678a95693190016e2dc2defd58ba70","0677f135b10b7f27f60187fb5cc8c662","7503e598cd08226de35e891759eaac25","9a12fa7bee30e50f40973037837b21be","a42ede15f825b031c92702506e2a4ba0","5c3b8cf6095601d3c6c0edde460f5757","274a76bfe69a5cdbf2900885c6c54092","43e22878b51f7f8f8e5c7744480cacae","904228916d4cb79bf65923c090cd4fac","a9aaa378408c8bf6f9b6160e93c5c921","afe870a29d31935922074ea98f1fe063","c839a33216baae665df6f65642797a36","d56723f45d8665c192cdd6881280a259","5c810a871063f749b36a67ce9c4abe18","06a2b5a006017ad98f44cbad9c49dc19","39f699f0f8482d15d32dea66f9fa1e0d","60826aa6289f0c51fec0ddf6555d515e","910b45bc0d039d2f7370c6d23fa3c0b2","dac65f1eb95359259484bcd21e1efb92","f454d1e70e2afece8798af7fa80feeec","fb37ac8cb2122649dc46d419a92f179c","c02251e2658c58badfb77c5b308e965b","0c104441b5b0adc55d11ff2c99c128b3","1e2664a10bd651d8bb8117ef1d6b489a","22883b2cc76811e8491a052bd219dd48","272eb441407347b23b63ba900053a21d","8cfe10b4b738bef608c91a5ed71e720a","8dbac2c726cdfaf50098658c5820137f","a75ca54e259de84627c65bc5b222c407","b402eabc336ed5abca64ba00b650e280","c1d6877b25eaf46ef341bc65e86173f6","d43b2a5db3c47fbaad17ffb868da59ea","de199fda6011fa052be772fb3b8201da","cfd4e9c64f9ff3bf7c092bcb8ace6651","0a6e5fe5e9000b2212101982d9e1cecd","23050fa2016c8ddc0e0fd1e8e01794ed","275336de121b4aa09bb5acebd1dc53c6","2bb9d3e3d422d4ca421ef8e95582d207","553685259c12bd5ba03d6b3f9108374c","5d4e7525fe46bacf5b93478be318e02f","6b13e7dcbec98c6ff956367b1263da18","838340f33f69ddd680cda56ce37bb93b","c14d33399b28207c70eb766618e39d3b","cd852ec338fa28dd001d317c6f3d1ade","ede60da5cb95bfb94534e46362538f52","a600f02c273ae6f1a0fa0237e6b91810","408a9028df3c294489e5f281ddcd1c08","33388f0ce735c18c2a610f9e71a918d7","548f0b424f67025dfcc6fcab7be7c6a4","7d782fd9545a854c68ae5ffae2dc4122","8663cf83dcb28a098f208620e0a58801","436e0801b868919cc5e4077f8a9200f4","2ca7eeefc416c722262459824ed80969","b336b0be1053ca2ee48ce3d8e230b129","d842a367506fe9144aa39cf1694d41e1","4a1741224641e037590cd61c73ce7b7e","b55bcf3394bb5fa83a22568aae00e77f","c9bf6f392038e0ccb974b210444b62ac","53ff7fea96cafcc0b818a1c9a8299780","050c827c25c6a824e496174533670b0c","7972a8049f4db703b618878af62722eb","c5292de60c582edb41fe386ab3713775","5c2ca8770b40b168f0745f428e66ad69","24a61b1a7455b5348d004c1290253594","7591375660993851c1c42bb21fb89dbf","bef2dd97c9a0f9eebb0cdc244f565976","c3dba2ea18f53715886bc715238410e6","fc2cb31133299c5fc594a0d21bff728a","a928f2a82b201b6caae929c56d9c3547","011d68fec9e0af2d0c70305fc68f85f0","02ff48ff3e757d81833cbb785625a6d9","1300c39057e40442a867da3ef47f02fc","2d39e1a1b9785b22366679c22f5d2605","8a678d04fd926eb8a4b74639f6c0d4bb","2d0f682e11ce1cdcbab906a8b7ea34d6","08f5c96f253c8ecd33b0ad0b0cd13af5","b28e5bea8b54f0a644541b435225e4c2","ca2f5ec84d87ad4ffcc2ae3413fad7f3","f4606b10456ab3ee67dd71a44e3100b1","3b064b67d49ab468fa50fda928cbe83f","6ed692954b718cf57b40acce100be007","9be7ef37fa21a2cd5e812e3ae3069d18","a80249037ad60aed50ab93e56ea99d59","cfa6476b463af3c8b7fa2be7a42a066d","f61a230d68d90a60df233254b0f3a1f7","8dc94fc6a675b6c8c30bbed0402601ed","0acf37c1b325f4c44110e431ac58f708","2fc9c29b247878d8b938e402bea253fc","4d008a8837ddb7c44eac2154e016ae57","5bafc0d87ecdda1ee0e273aa09a585da","c004af4d5e392f447d07ee6a123db35d","51f883775f428fa9e3fa0bb6b3568e78","a8987a443b5f2dd74d84c9e6c7c40406","c3270932fd5b87587eec869850d19a9f","d3ef9e883e732b81315491a100d384f8","0df7353c204de1fa45d6722882141788","32bd6be464756a8ff8304359a571fc4f","66d3dd83add96112ba76371108526989","ce5bfddbeff25a5cbc9bffd9b516656b","e95c4a5d683e8c93bf18f277c39e17e5","aceff632c52103992838fb4633390254","0679c83be783c2e4a9793a6842c2cbfe","5a2f4f872696f16378c5adba7416295a","97c59380b7c6e4f9d180595d6c5d6ad8","9c5ac057702182e66cd6175ff19debc2","c1590a7712da1bf54e8d6afaa3be095e","cfe0fd2aeecc3eb9d692a04cd1374861","dbb37ff4059bc28cabe057f658c2dc18","dc25227503aa2cdcb15c4a65232fde64","898a97949a608cd79b382849b0b2f6cb","ac2af4cb9e98de9ee53b2e8f8970ee9d","fa50e007aa4a640dc8fa14ee6c4f7380","95b879d1fc9ce6cf06cc72ae820a351a","062563254ba84d5e00075c83ffe37dad","36d50e53db5d265e5fe834700f31df81","3bc89a42be03b551673a16b071d82209","4b0f36dea6199c45bbe0abc6072218a6","ea6b95bf05482f092ec5f3c2c3adb372","b1a8fd3017015846271514ba6ad6bc8f","0fc887fc2c8ea4c17e94969abb5fdf68","5ebf3ff9b10fbacd25dd8444d11aaa59","6c071af622add2694da94ec8c5496575","b0e0a59c64db1932cf2c12c19183e4fc","e657e86ccd74d41f93ff959af1b953d8","e7d35717e8505b9269c21f7446ff0217","0479a192635f98254d19e15c3fe82031","0b951ac047fb19499365f7689e76665a","2567f696d2fa374b164db6666b07f56e","2eb69cf27f2d89a36d86b4e2c98cf2b8","fc451ee5a04de0f32637f7c467e7b6d3","9718f6e0fe9c30a9854627a99d52c2db","247e250ee528f9e2bc27386f290b5616","2e8fa44d234ff2e3e179cc6cb5257a7c","3d1938b66236bd8060a59c26e3e967aa","604f32d1382d794f0811d73618f614f8","86269de925a340888c3d8968b914ec2d","e831967bfb86d6de361417a1a0080e1c","91f4a5252ea395fcdbac9d55356afc59","26d620be759cd12a829a4f00e7848d5f","399825093b96dc456a130ce00639d391","929705a13f053b2add5f6e112b15a0cf","95637d28e4eb7a04e33605145f6362fd","c3595c582bcbbc6b9140b36e9cf4f63f","e4d9fd90546aea0b07ecbfee35c66a77","d23e2b9be415bc4c72ec0c8de5d438d6","3e957fd4f68227ca59026c03d416c3b3","60ec08907e67862ebdb17ab525e85e36","979acf872a6e02b1041d89a25e196478","b801bd1c8a1713df0dc0335c7d21cb90","edeef9ef3788696f530c27bb03317c7b","e68256ac2708b791113bbb8bfa5bada3","38cb94f2fb1b3f7e1c51ae4e99243b47","762b05b56582bcc74cc71b9b76d48456","7e56cf4402a698fd944f0f0cb0c7ee17","85cb25664852c6a3b4d7ea8c8d786c50","fae9b75a997c00b47d64748d5eb20b03","606d741a9fd12e7d1fafdd8212758a4e","00e1668b14a903ba01dcec0887e80247","3130731d28315bca24eb0374130b25cd","3f16762e56f0b431546281bae3876c69","6fb8d815b92c63a93b298dfc02a6c4c2","7c2cc134e0d85fcac6fc40479f1231ac","c6669f3892682b10d80811bcffb18306","fc2def157b2352e59812846a325a0c08","8fb5a5d115cec394fbb4a2ba982ff5ed","451d37184325260c4ac131c5082d3e2b","59acbd410436aaea2025fa508e3068fb","f3f81c1b487886034fcd58d03eca5f19","4906f61a3b79c55bd2b0e9c9279ecdb5","707e4446a473747177af3ccbcbb36061","ae349d5a83da19baab5968f95e38ca17","b0dea76fcfb267f1974e770b90bc0fc5","bf74a746a348112c3adf5973668aae06","ebe01cc222dc11c4369171d6bd2ac3a1","f9d5e455cdf163f7dc98b6a8f697294c","fa94857db9df892b02d390eeab6900fb","40fc1a44b31e8e89d2095adb4e08330e","583444754c8aa9e7cfe6dd5016e5acc0","6b12047955089a43bfd7d5e1264a2e0c","715e3c78aaa7c9a47da4a8136f7c576f","7ae19f118feec972656723b335cec21b","cc1d85c04d9c92a3f48cda652fad5148","fd282f3f5f60ffbdf756f623fb6caf2d","01ed9641d2cb60df6cac078642f2213b","2b395f5c9cb8e1aa7699a4c1f26788ea","b3b0108656637e7cfbbda15db8bf825b","d5da6bfcf443e021e6511a57ad37dcae","1f5ed97deb6b49615e8b0cde4f9277c3","4ff219874ba6cca83b5e64881d475635","668c88922e74862c2e9a4bca803c39ce","76aeb8ec2643714f71e7958e10026644","ae061795ae41af372bf0f7b31031ab1b","e2e29489495883de7f96fd4d7e858573","61845855297402e0bd31e9455124354a","670f26a2a16d430ac5127f324007bb86","f14c5cc9f904958dbfc3513a58acf974","aa0afe4239d6e583e6795e57e42cd7b3","6bb09e940b0f99c180120d9ebbdb7d54","d875909ead451aa5f8507d8c6e849640","dfa16ffffdb63882506a176a6d70b082","dbb3b3cac18002d388b8a728b92b01ee","1de5dd6c3192078d7e7573fd2f3307d1","56188c160f3c6d77705e4884b069aa39","e0c13e18a0aa153650730e9bc154b271"]