DistAdminDistributor.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. 'slug' => 'default-category',
  65. ]);
  66. //生成默认产品
  67. $distProduct = new DistProduct();
  68. $productRow = $distProduct->create([
  69. 'category_id' => $categoryRow->id,
  70. 'title' => 'Default Product',
  71. 'sku' => 'sku001',
  72. 'order' => 1,
  73. 'enabled' => 1,
  74. 'dist_id'=>$distId,
  75. 'content' => 'Default Content',
  76. 'slug' => 'default-product',
  77. 'seo_title' => 'Default Product',
  78. 'issuance_date' => Carbon::now(),
  79. 'created_at'=>Carbon::now(),
  80. 'updated_at'=>Carbon::now(),
  81. ]);
  82. $productRow->order = $productRow->id;
  83. $productRow->save();
  84. //生成默认tab
  85. $sitePagesTag = new SitePagesTag();
  86. $tagRow = $sitePagesTag->create([
  87. 'name' => 'News',
  88. 'dist_id'=>$distId,
  89. 'slug' => 'news',
  90. 'seo_title' => 'News',
  91. 'created_at'=>Carbon::now(),
  92. 'updated_at'=>Carbon::now(),
  93. ]);
  94. //生成默认页面
  95. $sitePages = new SitePages();
  96. $pageRow = $sitePages->create([
  97. 'title' => 'Default Page',
  98. 'status' => 1,
  99. 'author' => 'admin',
  100. 'dist_id'=>$distId,
  101. 'content' => 'Default Content',
  102. 'slug' => 'default-page',
  103. 'seo_title' => 'Default Page',
  104. 'post_date' => Carbon::now(),
  105. 'created_at'=>Carbon::now(),
  106. 'updated_at'=>Carbon::now(),
  107. ]);
  108. //生成绑定关系
  109. $sitePagesTagRelationship = new SitePagesTagRelationship();
  110. $sitePagesTagRelationship->create([
  111. 'tag_id' => $tagRow->id,
  112. 'pages_id' => $pageRow->id,
  113. ]);
  114. //生成about-us
  115. $aboutUs = $sitePages->create([
  116. 'title' => 'About Us',
  117. 'status' => 1,
  118. 'author' => 'admin',
  119. 'dist_id'=>$distId,
  120. 'content' => 'Default Content',
  121. 'slug' => 'about-us',
  122. 'seo_title' => 'About Us',
  123. 'post_date' => Carbon::now(),
  124. 'created_at'=>Carbon::now(),
  125. 'updated_at'=>Carbon::now(),
  126. ]);
  127. //生成privacy
  128. $privacy = $sitePages->create([
  129. 'title' => 'Privacy',
  130. 'status' => 1,
  131. 'author' => 'admin',
  132. 'dist_id'=>$distId,
  133. 'content' => 'Default Content',
  134. 'slug' => 'privacy',
  135. 'seo_title' => 'Privacy',
  136. 'post_date' => Carbon::now(),
  137. 'created_at'=>Carbon::now(),
  138. 'updated_at'=>Carbon::now(),
  139. ]);
  140. //生成sales
  141. $sales = $sitePages->create([
  142. 'title' => 'Sales',
  143. 'status' => 1,
  144. 'author' => 'admin',
  145. 'dist_id'=>$distId,
  146. 'content' => 'Default Content',
  147. 'slug' => 'sales',
  148. 'seo_title' => 'Sales',
  149. 'post_date' => Carbon::now(),
  150. 'created_at'=>Carbon::now(),
  151. 'updated_at'=>Carbon::now(),
  152. ]);
  153. //生成service
  154. $service = $sitePages->create([
  155. 'title' => 'Services',
  156. 'status' => 1,
  157. 'author' => 'admin',
  158. 'dist_id'=>$distId,
  159. 'content' => 'Default Content',
  160. 'slug' => 'services',
  161. 'seo_title' => 'Services',
  162. 'post_date' => Carbon::now(),
  163. 'created_at'=>Carbon::now(),
  164. 'updated_at'=>Carbon::now(),
  165. ]);
  166. //生成faqs
  167. $faqs = $sitePages->create([
  168. 'title' => 'FAQs',
  169. 'status' => 1,
  170. 'author' => 'admin',
  171. 'dist_id'=>$distId,
  172. 'content' => 'Default Content',
  173. 'slug' => 'faqs',
  174. 'seo_title' => 'FAQs',
  175. 'post_date' => Carbon::now(),
  176. 'created_at'=>Carbon::now(),
  177. 'updated_at'=>Carbon::now(),
  178. ]);
  179. //生成菜单
  180. $siteMenu = new SiteMenu();
  181. $menuConfig = [
  182. 'collections_type' => '',
  183. 'product_category' => '',
  184. 'pages_tag' => '',
  185. 'product' => '',
  186. 'pages' => '',
  187. 'url' => '',
  188. 'unique_page' => '',
  189. ];
  190. /*
  191. * ==========================================
  192. * 顶部菜单
  193. * ==========================================
  194. */
  195. //----------------主页------------------
  196. $data = [];
  197. $newMenuConfig = $menuConfig;
  198. $menuType = 0; //主页
  199. $data[1] = [
  200. 'parentId' => 0,
  201. 'title' => 'Home',
  202. 'distId'=>$distId,
  203. 'uri' => $siteMenu->generateUri($menuType,$menuConfig,$distId),
  204. 'menuType' => $menuType,
  205. 'menuConfig' => $newMenuConfig,
  206. 'menuLocation' => 0,
  207. ];
  208. //----------------Products------------------
  209. $menuType = 0; //主页
  210. $newMenuConfig = $menuConfig;
  211. $data[2] = [
  212. 'parentId' => 0,
  213. 'title' => 'Products',
  214. 'distId'=>$distId,
  215. 'uri' => $siteMenu->generateUri($menuType,$menuConfig,$distId),
  216. 'menuType' => $menuType,
  217. 'menuConfig' => $newMenuConfig,
  218. 'menuLocation' => 0,
  219. ];
  220. //----------------Products Category------------------
  221. $newMenuConfig = $menuConfig;
  222. $newMenuConfig['collections_type'] = 0;
  223. $newMenuConfig['product_category'] = $categoryRow->id;
  224. $menuType = 1;//collections
  225. $data[3] = [
  226. 'parentId' => 2,
  227. 'title' => 'Default Category',
  228. 'distId'=>$distId,
  229. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  230. 'menuType' => $menuType,
  231. 'menuConfig' => $newMenuConfig,
  232. 'menuLocation' => 0,
  233. ];
  234. //----------------news------------------
  235. $newMenuConfig = $menuConfig;
  236. $newMenuConfig['collections_type'] = 1;
  237. $newMenuConfig['pages_tag'] = $tagRow->id;
  238. $menuType = 1;//collections
  239. $data[4] = [
  240. 'parentId' => 0,
  241. 'title' => 'News',
  242. 'distId'=>$distId,
  243. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  244. 'menuType' => $menuType,
  245. 'menuConfig' => $newMenuConfig,
  246. 'menuLocation' => 0,
  247. ];
  248. //----------------About Us------------------
  249. $newMenuConfig = $menuConfig;
  250. $newMenuConfig['pages'] = $aboutUs->id;
  251. $menuType = 3;//pages
  252. $data[5] = [
  253. 'parentId' => 0,
  254. 'title' => 'About Us',
  255. 'distId'=>$distId,
  256. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  257. 'menuType' => $menuType,
  258. 'menuConfig' => $newMenuConfig,
  259. 'menuLocation' => 0,
  260. ];
  261. //----------------Contact------------------
  262. $newMenuConfig = $menuConfig;
  263. $newMenuConfig['unique_page'] = 'contact';
  264. $menuType = 4;//pages
  265. $data[6] = [
  266. 'parentId' => 0,
  267. 'title' => 'Contact',
  268. 'distId'=>$distId,
  269. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  270. 'menuType' => $menuType,
  271. 'menuConfig' => $newMenuConfig,
  272. 'menuLocation' => 0,
  273. ];
  274. $siteMenu->createMenuBatch($data);
  275. /*
  276. * ==========================================
  277. * 底部菜单
  278. * ==========================================
  279. */
  280. //----------------SUPPORT------------------
  281. $data = [];
  282. $newMenuConfig = $menuConfig;
  283. $menuType = 0; //主页
  284. $data[1] = [
  285. 'parentId' => 0,
  286. 'title' => 'SUPPORT',
  287. 'distId'=>$distId,
  288. 'uri' => $siteMenu->generateUri($menuType,$menuConfig,$distId),
  289. 'menuType' => $menuType,
  290. 'menuConfig' => $newMenuConfig,
  291. 'menuLocation' => 1,
  292. ];
  293. //----------------FAQ------------------
  294. $newMenuConfig = $menuConfig;
  295. $newMenuConfig['pages'] = $faqs->id;
  296. $menuType = 3;//pages
  297. $data[2] = [
  298. 'parentId' => 1,
  299. 'title' => 'FAQ',
  300. 'distId'=>$distId,
  301. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  302. 'menuType' => $menuType,
  303. 'menuConfig' => $newMenuConfig,
  304. 'menuLocation' => 1,
  305. ];
  306. //----------------Sales------------------
  307. $newMenuConfig = $menuConfig;
  308. $newMenuConfig['pages'] = $sales->id;
  309. $menuType = 3;//pages
  310. $data[3] = [
  311. 'parentId' => 1,
  312. 'title' => 'Sales',
  313. 'distId'=>$distId,
  314. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  315. 'menuType' => $menuType,
  316. 'menuConfig' => $newMenuConfig,
  317. 'menuLocation' => 1,
  318. ];
  319. //----------------COMPANY------------------
  320. $newMenuConfig = $menuConfig;
  321. $menuType = 0; //主页
  322. $data[4] = [
  323. 'parentId' => 0,
  324. 'title' => 'COMPANY',
  325. 'distId'=>$distId,
  326. 'uri' => $siteMenu->generateUri($menuType,$menuConfig,$distId),
  327. 'menuType' => $menuType,
  328. 'menuConfig' => $newMenuConfig,
  329. 'menuLocation' => 1,
  330. ];
  331. //----------------Home------------------
  332. $newMenuConfig = $menuConfig;
  333. $menuType = 0; //主页
  334. $data[5] = [
  335. 'parentId' => 4,
  336. 'title' => 'Home',
  337. 'distId'=>$distId,
  338. 'uri' => $siteMenu->generateUri($menuType,$menuConfig,$distId),
  339. 'menuType' => $menuType,
  340. 'menuConfig' => $newMenuConfig,
  341. 'menuLocation' => 1,
  342. ];
  343. //----------------About Us------------------
  344. $newMenuConfig = $menuConfig;
  345. $newMenuConfig['pages'] = $aboutUs->id;
  346. $menuType = 3;//pages
  347. $data[6] = [
  348. 'parentId' => 4,
  349. 'title' => 'About Us',
  350. 'distId'=>$distId,
  351. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  352. 'menuType' => $menuType,
  353. 'menuConfig' => $newMenuConfig,
  354. 'menuLocation' => 1,
  355. ];
  356. //----------------Services------------------
  357. $newMenuConfig = $menuConfig;
  358. $newMenuConfig['pages'] = $service->id;
  359. $menuType = 3;//pages
  360. $data[7] = [
  361. 'parentId' => 4,
  362. 'title' => 'Services',
  363. 'distId'=>$distId,
  364. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  365. 'menuType' => $menuType,
  366. 'menuConfig' => $newMenuConfig,
  367. 'menuLocation' => 1,
  368. ];
  369. //----------------News------------------
  370. $newMenuConfig = $menuConfig;
  371. $newMenuConfig['collections_type'] = 1;
  372. $newMenuConfig['pages_tag'] = $tagRow->id;
  373. $menuType = 1;//collections
  374. $data[8] = [
  375. 'parentId' => 4,
  376. 'title' => 'News',
  377. 'distId'=>$distId,
  378. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  379. 'menuType' => $menuType,
  380. 'menuConfig' => $newMenuConfig,
  381. 'menuLocation' => 1,
  382. ];
  383. //----------------Contact------------------
  384. $newMenuConfig = $menuConfig;
  385. $newMenuConfig['unique_page'] = 'contact';
  386. $menuType = 4;//pages
  387. $data[9] = [
  388. 'parentId' => 4,
  389. 'title' => 'Contact',
  390. 'distId'=>$distId,
  391. 'uri' => $siteMenu->generateUri($menuType,$newMenuConfig,$distId),
  392. 'menuType' => $menuType,
  393. 'menuConfig' => $newMenuConfig,
  394. 'menuLocation' => 1,
  395. ];
  396. $siteMenu->createMenuBatch($data);
  397. }
  398. }