SiteSyncLogic.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/5/10 0010
  6. * Time: 10:20
  7. */
  8. namespace App\Http\Logics\Admin;
  9. use Illuminate\Support\Facades\DB;
  10. // +"id": 95
  11. // +"code": "R2017-028"
  12. // +"name": "广州海山娱乐科技有限公司"
  13. // +"thumb": "/uploads/image/20180123/19/11bf2157ed922de5110a9279d65047af.jpg"
  14. // +"domain": "hswaterslide.com"
  15. // +"webmaster_domain": null
  16. // +"cloud_ip": ""
  17. // +"company_name": "广州海山娱乐科技有限公司"
  18. // +"company_type": "中小型企业"
  19. // +"company_addr": ""
  20. // +"area_id": 440100
  21. // +"area_text": "广东省 > 广州市"
  22. // +"province": null
  23. // +"city": null
  24. // +"trade": "其他行业"
  25. // +"linkman": ""
  26. // +"phone": ""
  27. // +"remark": ""
  28. // +"rank": 36
  29. // +"is_enabled": 0
  30. // +"reach_num": 20
  31. // +"reach_days": 620
  32. // +"status_text": "实施期"
  33. // +"google_domain": "google.com"
  34. // +"allow_googlerank": 1
  35. // +"allow_allintitle": 0
  36. // +"sign_time": 0
  37. // +"start_time": 1462550400
  38. // +"sync_time": 1539765018
  39. // +"reach_time": 1470672000
  40. // +"expire_time": 1557158400
  41. // +"create_time": 1516169486
  42. // +"number": 1
  43. // +"report_day": 0
  44. class SiteSyncLogic
  45. {
  46. public function insertGetId(array $data)
  47. {
  48. return DB::connection('rank')->table('project')->insertGetId($data + ['create_time' => time()]);
  49. }
  50. public function update($oldId, array $data)
  51. {
  52. if ($oldId) { //如果有关联的则更新
  53. DB::connection('rank')->table('project')->where(['id' => $oldId])->update($data);
  54. }
  55. }
  56. // public function updateOrInsert($attributes, $values)
  57. // {
  58. // DB::connection('rank')->table('project')->updateOrInsert($attributes, $values);
  59. // }
  60. /**
  61. *
  62. * @param $ids
  63. */
  64. public function delete($ids)
  65. {
  66. $filter = is_array($ids) ? $ids : [$ids];
  67. DB::connection('rank')->table('project')->whereIn('id', $filter)->update([
  68. 'is_enabled' => 0,
  69. 'allow_googlerank' => 0
  70. ]);
  71. }
  72. /**
  73. * 新老平台数据映射
  74. * @param array $origins
  75. * @return array
  76. */
  77. public function fieldMap(array $origins)
  78. {
  79. // $map = [
  80. // 'id' => 'id',
  81. // 'code' => 'identifier',
  82. // 'name' => 'cn_title',
  83. // 'thumb' => '',
  84. // 'domain' => 'domain',
  85. // 'webmaster_domain' => '',//
  86. // 'cloud_ip' => '',//
  87. // 'company_name' => '',
  88. // 'company_addr' => '',
  89. // 'area_id' => '',
  90. // 'area_text' => '',
  91. // 'province' => '',
  92. // 'city' => '',
  93. // 'trade' => '',
  94. // 'linkman' => '',
  95. // 'phone' => '',
  96. // 'remark' => '',
  97. // 'rank' => '',
  98. // 'is_enabled' => '',
  99. // 'reach_num' => '',
  100. // 'reach_days' => '',
  101. // 'status_text' => '',
  102. // 'google_domain' => '',
  103. // 'allow_googlerank' => '',
  104. // 'allow_allintitle' => '',
  105. // 'sign_time' => '',
  106. // 'start_time' => '',
  107. // 'sync_time' => '',
  108. // 'reach_time' => '',
  109. // 'expire_time' => '',
  110. // 'create_time' => '',
  111. // 'number' => 1,
  112. // 'report_day' => ''
  113. // ];
  114. $map = [
  115. // 'id' => 'id',
  116. 'identifier' => 'code',
  117. 'cn_title' => 'name',
  118. 'domain' => 'domain',
  119. 'report_day' => 'report_day',
  120. 'webmaster_domain' => 'webmaster_domain',
  121. 'server_ip' => 'cloud_ip',
  122. 'keyword_goal' => 'reach_num',
  123. 'online_at' => 'start_time'
  124. // 'cloud_type' => 'number'
  125. ];
  126. $result = [];
  127. foreach ($origins as $key => $item) {
  128. if (empty($map[$key]))
  129. continue;
  130. if (empty($item))
  131. continue;
  132. $result[$map[$key]] = $item;
  133. if (in_array($key, ['online_at'])) {
  134. $result[$map[$key]] = strtotime($item);
  135. }
  136. }
  137. return $result;
  138. }
  139. }