DistAdminDistributor.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. namespace App\Admin\Repositories;
  3. use App\Models\DistAdminDistributor as Model;
  4. use App\Models\DistProductCategory;
  5. use App\Models\DistProduct;
  6. use App\Models\SitePagesTag;
  7. use App\Models\SitePages;
  8. use App\Models\SitePagesTagRelationship;
  9. use Carbon\Carbon;
  10. use Dcat\Admin\Repositories\EloquentRepository;
  11. class DistAdminDistributor extends EloquentRepository
  12. {
  13. /**
  14. * Model.
  15. *
  16. * @var string
  17. */
  18. protected $eloquentClass = Model::class;
  19. /*
  20. * 清缓存
  21. */
  22. public static function clearCache($distId,$timeOut = 2)
  23. {
  24. //使用二级域名清缓存
  25. $domain = self::getDomain($distId,1);
  26. $url = $domain . '/?__clear_cache=1';
  27. curlGet($url,$timeOut);
  28. }
  29. /*
  30. * 得到指定分销商的域名
  31. * type 0:当前域名 1:二级域名 2:自定义域名
  32. */
  33. public static function getDomain($distId,$type=0)
  34. {
  35. $model = new Model();
  36. return $model->getDomain($distId,$type);
  37. }
  38. /*
  39. * 获取一个标签
  40. */
  41. public static function getOneById($id)
  42. {
  43. return Model::where('id', $id)->first();
  44. }
  45. /*
  46. * 始始化分销商
  47. */
  48. public static function initDist($appearanceId,$distId)
  49. {
  50. //初始化数据,现在用默认,以后有可能不同主题不同
  51. self::default($distId);
  52. }
  53. //默认
  54. public static function default($distId)
  55. {
  56. //生成默认产品分类
  57. $distProductCategory = new DistProductCategory();
  58. $categoryRow = $distProductCategory->create([
  59. 'parent_id' => 0,
  60. 'name' => 'Default Category',
  61. 'order' => 0,
  62. 'enabled' => 1,
  63. 'dist_id'=>$distId,
  64. 'seo_title' => 'Default Category',
  65. 'slug' => 'default-category',
  66. ]);
  67. //生成默认产品
  68. $distProduct = new DistProduct();
  69. $productRow = $distProduct->create([
  70. 'category_id' => $categoryRow->id,
  71. 'title' => 'Default Product',
  72. 'sku' => 'sku001',
  73. 'order' => 1,
  74. 'enabled' => 1,
  75. 'dist_id'=>$distId,
  76. 'content' => 'Default Content',
  77. 'slug' => 'default-product',
  78. 'seo_title' => 'Default Product',
  79. 'issuance_date' => Carbon::now(),
  80. 'created_at'=>Carbon::now(),
  81. 'updated_at'=>Carbon::now(),
  82. ]);
  83. $productRow->order = $productRow->id;
  84. $productRow->save();
  85. //生成默认tab
  86. $sitePagesTag = new SitePagesTag();
  87. $tagRow = $sitePagesTag->create([
  88. 'name' => 'News',
  89. 'dist_id'=>$distId,
  90. 'slug' => 'news',
  91. 'seo_title' => 'News',
  92. 'created_at'=>Carbon::now(),
  93. 'updated_at'=>Carbon::now(),
  94. ]);
  95. //生成默认页面
  96. $sitePages = new SitePages();
  97. $pageRow = $sitePages->create([
  98. 'title' => 'Default Page',
  99. 'status' => 1,
  100. 'author' => 'admin',
  101. 'dist_id'=>$distId,
  102. 'content' => 'Default Content',
  103. 'slug' => 'default-page',
  104. 'seo_title' => 'Default Page',
  105. 'post_date' => Carbon::now(),
  106. 'created_at'=>Carbon::now(),
  107. 'updated_at'=>Carbon::now(),
  108. ]);
  109. //生成绑定关系
  110. $sitePagesTagRelationship = new SitePagesTagRelationship();
  111. $sitePagesTagRelationship->create([
  112. 'tag_id' => $tagRow->id,
  113. 'pages_id' => $pageRow->id,
  114. ]);
  115. //生成about-us
  116. $aboutUs = $sitePages->create([
  117. 'title' => 'About Us',
  118. 'status' => 1,
  119. 'author' => 'admin',
  120. 'dist_id'=>$distId,
  121. 'content' => 'Default Content',
  122. 'slug' => 'about-us',
  123. 'seo_title' => 'About Us',
  124. 'post_date' => Carbon::now(),
  125. 'created_at'=>Carbon::now(),
  126. 'updated_at'=>Carbon::now(),
  127. ]);
  128. //生成privacy
  129. $privacy = $sitePages->create([
  130. 'title' => 'Privacy',
  131. 'status' => 1,
  132. 'author' => 'admin',
  133. 'dist_id'=>$distId,
  134. 'content' => 'Default Content',
  135. 'slug' => 'privacy',
  136. 'seo_title' => 'Privacy',
  137. 'post_date' => Carbon::now(),
  138. 'created_at'=>Carbon::now(),
  139. 'updated_at'=>Carbon::now(),
  140. ]);
  141. //生成sales
  142. $sales = $sitePages->create([
  143. 'title' => 'Sales',
  144. 'status' => 1,
  145. 'author' => 'admin',
  146. 'dist_id'=>$distId,
  147. 'content' => 'Default Content',
  148. 'slug' => 'sales',
  149. 'seo_title' => 'Sales',
  150. 'post_date' => Carbon::now(),
  151. 'created_at'=>Carbon::now(),
  152. 'updated_at'=>Carbon::now(),
  153. ]);
  154. //生成service
  155. $service = $sitePages->create([
  156. 'title' => 'Services',
  157. 'status' => 1,
  158. 'author' => 'admin',
  159. 'dist_id'=>$distId,
  160. 'content' => 'Default Content',
  161. 'slug' => 'services',
  162. 'seo_title' => 'Services',
  163. 'post_date' => Carbon::now(),
  164. 'created_at'=>Carbon::now(),
  165. 'updated_at'=>Carbon::now(),
  166. ]);
  167. //生成faqs
  168. $faqs = $sitePages->create([
  169. 'title' => 'FAQs',
  170. 'status' => 1,
  171. 'author' => 'admin',
  172. 'dist_id'=>$distId,
  173. 'content' => 'Default Content',
  174. 'slug' => 'faqs',
  175. 'seo_title' => 'FAQs',
  176. 'post_date' => Carbon::now(),
  177. 'created_at'=>Carbon::now(),
  178. 'updated_at'=>Carbon::now(),
  179. ]);
  180. //生成菜单
  181. $siteMenu = new SiteMenu();
  182. $menuConfig = [
  183. 'collections_type' => '',
  184. 'product_category' => '',
  185. 'pages_tag' => '',
  186. 'product' => '',
  187. 'pages' => '',
  188. 'url' => '',
  189. 'unique_page' => '',
  190. ];
  191. /*
  192. * ==========================================
  193. * 顶部菜单
  194. * ==========================================
  195. */
  196. //----------------主页------------------
  197. $data = [];
  198. $newMenuConfig = $menuConfig;
  199. $menuType = 0; //主页
  200. $data[1] = [
  201. 'parentId' => 0,
  202. 'title' => 'Home',
  203. 'distId'=>$distId,
  204. 'uri' => $siteMenu->generateUri($menuType,$menuConfig,$distId),
  205. 'menuType' => $menuType,
  206. 'menuConfig' => $newMenuConfig,
  207. 'menuLocation' => 0,
  208. ];
  209. //----------------Products------------------
  210. $menuType = 0; //主页
  211. $newMenuConfig = $menuConfig;
  212. $data[2] = [
  213. 'parentId' => 0,
  214. 'title' => 'Products',
  215. 'distId'=>$distId,
  216. 'uri' => $siteMenu->generateUri($menuType,$menuConfig,$distId),
  217. 'menuType' => $menuType,
  218. 'menuConfig' => $newMenuConfig,
  219. 'menuLocation' => 0,
  220. ];
  221. //----------------Products Category------------------
  222. $newMenuConfig = $menuConfig;
  223. $newMenuConfig['collections_type'] = 0;
  224. $newMenuConfig['product_category'] = $categoryRow->id;
  225. $menuType = 1;//collections
  226. $data[3] = [
  227. 'parentId' => 2,
  228. 'title' => 'Default Category',
  229. 'distId'=>$distId,
  230. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  231. 'menuType' => $menuType,
  232. 'menuConfig' => $newMenuConfig,
  233. 'menuLocation' => 0,
  234. ];
  235. //----------------news------------------
  236. $newMenuConfig = $menuConfig;
  237. $newMenuConfig['collections_type'] = 1;
  238. $newMenuConfig['pages_tag'] = $tagRow->id;
  239. $menuType = 1;//collections
  240. $data[4] = [
  241. 'parentId' => 0,
  242. 'title' => 'News',
  243. 'distId'=>$distId,
  244. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  245. 'menuType' => $menuType,
  246. 'menuConfig' => $newMenuConfig,
  247. 'menuLocation' => 0,
  248. ];
  249. //----------------About Us------------------
  250. $newMenuConfig = $menuConfig;
  251. $newMenuConfig['pages'] = $aboutUs->id;
  252. $menuType = 3;//pages
  253. $data[5] = [
  254. 'parentId' => 0,
  255. 'title' => 'About Us',
  256. 'distId'=>$distId,
  257. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  258. 'menuType' => $menuType,
  259. 'menuConfig' => $newMenuConfig,
  260. 'menuLocation' => 0,
  261. ];
  262. //----------------Contact------------------
  263. $newMenuConfig = $menuConfig;
  264. $newMenuConfig['unique_page'] = 'contact';
  265. $menuType = 4;//pages
  266. $data[6] = [
  267. 'parentId' => 0,
  268. 'title' => 'Contact',
  269. 'distId'=>$distId,
  270. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  271. 'menuType' => $menuType,
  272. 'menuConfig' => $newMenuConfig,
  273. 'menuLocation' => 0,
  274. ];
  275. $siteMenu->createMenuBatch($data);
  276. /*
  277. * ==========================================
  278. * 底部菜单
  279. * ==========================================
  280. */
  281. //----------------SUPPORT------------------
  282. $data = [];
  283. $newMenuConfig = $menuConfig;
  284. $menuType = 0; //主页
  285. $data[1] = [
  286. 'parentId' => 0,
  287. 'title' => 'SUPPORT',
  288. 'distId'=>$distId,
  289. 'uri' => $siteMenu->generateUri($menuType,$menuConfig,$distId),
  290. 'menuType' => $menuType,
  291. 'menuConfig' => $newMenuConfig,
  292. 'menuLocation' => 1,
  293. ];
  294. //----------------FAQ------------------
  295. $newMenuConfig = $menuConfig;
  296. $newMenuConfig['pages'] = $faqs->id;
  297. $menuType = 3;//pages
  298. $data[2] = [
  299. 'parentId' => 1,
  300. 'title' => 'FAQ',
  301. 'distId'=>$distId,
  302. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  303. 'menuType' => $menuType,
  304. 'menuConfig' => $newMenuConfig,
  305. 'menuLocation' => 1,
  306. ];
  307. //----------------Sales------------------
  308. $newMenuConfig = $menuConfig;
  309. $newMenuConfig['pages'] = $sales->id;
  310. $menuType = 3;//pages
  311. $data[3] = [
  312. 'parentId' => 1,
  313. 'title' => 'Sales',
  314. 'distId'=>$distId,
  315. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  316. 'menuType' => $menuType,
  317. 'menuConfig' => $newMenuConfig,
  318. 'menuLocation' => 1,
  319. ];
  320. //----------------COMPANY------------------
  321. $newMenuConfig = $menuConfig;
  322. $menuType = 0; //主页
  323. $data[4] = [
  324. 'parentId' => 0,
  325. 'title' => 'COMPANY',
  326. 'distId'=>$distId,
  327. 'uri' => $siteMenu->generateUri($menuType,$menuConfig,$distId),
  328. 'menuType' => $menuType,
  329. 'menuConfig' => $newMenuConfig,
  330. 'menuLocation' => 1,
  331. ];
  332. //----------------Home------------------
  333. $newMenuConfig = $menuConfig;
  334. $menuType = 0; //主页
  335. $data[5] = [
  336. 'parentId' => 4,
  337. 'title' => 'Home',
  338. 'distId'=>$distId,
  339. 'uri' => $siteMenu->generateUri($menuType,$menuConfig,$distId),
  340. 'menuType' => $menuType,
  341. 'menuConfig' => $newMenuConfig,
  342. 'menuLocation' => 1,
  343. ];
  344. //----------------About Us------------------
  345. $newMenuConfig = $menuConfig;
  346. $newMenuConfig['pages'] = $aboutUs->id;
  347. $menuType = 3;//pages
  348. $data[6] = [
  349. 'parentId' => 4,
  350. 'title' => 'About Us',
  351. 'distId'=>$distId,
  352. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  353. 'menuType' => $menuType,
  354. 'menuConfig' => $newMenuConfig,
  355. 'menuLocation' => 1,
  356. ];
  357. //----------------Services------------------
  358. $newMenuConfig = $menuConfig;
  359. $newMenuConfig['pages'] = $service->id;
  360. $menuType = 3;//pages
  361. $data[7] = [
  362. 'parentId' => 4,
  363. 'title' => 'Services',
  364. 'distId'=>$distId,
  365. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  366. 'menuType' => $menuType,
  367. 'menuConfig' => $newMenuConfig,
  368. 'menuLocation' => 1,
  369. ];
  370. //----------------News------------------
  371. $newMenuConfig = $menuConfig;
  372. $newMenuConfig['collections_type'] = 1;
  373. $newMenuConfig['pages_tag'] = $tagRow->id;
  374. $menuType = 1;//collections
  375. $data[8] = [
  376. 'parentId' => 4,
  377. 'title' => 'News',
  378. 'distId'=>$distId,
  379. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  380. 'menuType' => $menuType,
  381. 'menuConfig' => $newMenuConfig,
  382. 'menuLocation' => 1,
  383. ];
  384. //----------------Contact------------------
  385. $newMenuConfig = $menuConfig;
  386. $newMenuConfig['unique_page'] = 'contact';
  387. $menuType = 4;//pages
  388. $data[9] = [
  389. 'parentId' => 4,
  390. 'title' => 'Contact',
  391. 'distId'=>$distId,
  392. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  393. 'menuType' => $menuType,
  394. 'menuConfig' => $newMenuConfig,
  395. 'menuLocation' => 1,
  396. ];
  397. $siteMenu->createMenuBatch($data);
  398. }
  399. }