V20190227Command.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. namespace App\Console\Commands\Upgrade;
  3. use App\Models\Deed\FriendsModel;
  4. use App\Models\Gteam\RoomMemberModel;
  5. use App\Models\Gteam\RoomModel;
  6. use App\Services\Deed\FriendService;
  7. use Illuminate\Console\Command;
  8. use Illuminate\Support\Facades\DB;
  9. class V20190227Command extends Command
  10. {
  11. protected $signature = "upgrade:v20190227";
  12. protected $description = "版本升级脚本|2019-02-27号更新版本升级\n
  13. 更新内容:\n
  14. 1. 72小时匹配历史同步到好友列表\n
  15. 2. 晚安匹配历史同步到好友列表\n
  16. 3. 开黑匹配历史同步到好友列表\n
  17. 4. 邀请历史到好友\n";
  18. public function handle()
  19. {
  20. $this->gteam2friend();
  21. $this->goodnight2friend();
  22. $this->hour2friend();
  23. $this->invite2friend();
  24. }
  25. // 开黑到好友
  26. public function gteam2friend()
  27. {
  28. dump("开黑到好友:开始启动");
  29. $start = 13925;
  30. $descroom = DB::table('kdgx_gteam_room')->where('id', '>=', $start)->orderBy('id', 'desc')->first();
  31. for ($i = $start; $i <= $descroom->id; $i++) {
  32. try {
  33. $room = RoomModel::findOrFail($i);
  34. $members = RoomMemberModel::where('room_id', $room->id)->get();
  35. if ($descroom->type == "wz_wx" || $descroom->type == "wz_qq") {
  36. $friend_type = 5;
  37. } else {
  38. $friend_type = 4;
  39. }
  40. $friend1 = FriendsModel::firstOrCreate([
  41. 'uid' => $members[0]->uid,
  42. 'friend_uid' => $members[1]->uid
  43. ], [
  44. 'created_at' => $room->created_at->timestamp,
  45. 'uid' => $members[0]->uid,
  46. 'friend_uid' => $members[1]->uid,
  47. 'last_at' => $room->created_at->timestamp,
  48. 'friend_type' => $friend_type,
  49. 'friend_type_data' => $i
  50. ]);
  51. if ($friend1->last_at < $room->created_at->timestamp) {
  52. $friend1->last_at = $room->created_at->timestamp;
  53. $friend1->friend_type = $friend_type;
  54. $friend1->friend_type_data = $i;
  55. $friend1->save();
  56. }
  57. $friend2 = FriendsModel::firstOrCreate([
  58. 'uid' => $members[1]->uid,
  59. 'friend_uid' => $members[0]->uid
  60. ], [
  61. 'created_at' => $room->created_at->timestamp,
  62. 'uid' => $members[1]->uid,
  63. 'friend_uid' => $members[0]->uid,
  64. 'last_at' => $room->created_at->timestamp,
  65. 'friend_type' => $friend_type,
  66. 'friend_type_data' => $i
  67. ]);
  68. if ($friend2->last_at < $room->created_at->timestamp) {
  69. $friend2->last_at = $room->created_at->timestamp;
  70. $friend2->friend_type = $friend_type;
  71. $friend2->friend_type_data = $i;
  72. $friend2->save();
  73. }
  74. } catch (\Exception $exception) {
  75. }
  76. }
  77. dump("开黑到好友:结束,目前进度:{$descroom->id}");
  78. }
  79. // 晚安匹配到好友
  80. public function goodnight2friend()
  81. {
  82. dump("晚安匹配到好友:开始启动");
  83. $start = 3881;
  84. $descroom = DB::table('kdgx_goodnight_rooms')->where('id', '>=', $start)->orderBy('id', 'desc')->first();
  85. for ($i = $start; $i <= $descroom->id; $i++) {
  86. try {
  87. $room = \App\Models\Goodnight\RoomModel::findOrFail($i);
  88. $members = \App\Models\Goodnight\RoomMemberModel::where('room_id', $room->id)->get();
  89. $friend1 = FriendsModel::firstOrCreate([
  90. 'uid' => $members[0]->uid,
  91. 'friend_uid' => $members[1]->uid
  92. ], [
  93. 'created_at' => $room->created_at->timestamp,
  94. 'uid' => $members[0]->uid,
  95. 'friend_uid' => $members[1]->uid,
  96. 'last_at' => $room->created_at->timestamp,
  97. 'friend_type' => 3,
  98. 'friend_type_data' => $i
  99. ]);
  100. if ($friend1->last_at < $room->created_at->timestamp) {
  101. $friend1->last_at = $room->created_at->timestamp;
  102. $friend1->friend_type = 3;
  103. $friend1->friend_type_data = $i;
  104. $friend1->save();
  105. }
  106. $friend2 = FriendsModel::firstOrCreate([
  107. 'uid' => $members[1]->uid,
  108. 'friend_uid' => $members[0]->uid
  109. ], [
  110. 'created_at' => $room->created_at->timestamp,
  111. 'uid' => $members[1]->uid,
  112. 'friend_uid' => $members[0]->uid,
  113. 'last_at' => $room->created_at->timestamp,
  114. 'friend_type' => 3,
  115. 'friend_type_data' => $i
  116. ]);
  117. if ($friend2->last_at < $room->created_at->timestamp) {
  118. $friend2->last_at = $room->created_at->timestamp;
  119. $friend2->friend_type = 3;
  120. $friend2->friend_type_data = $i;
  121. $friend2->save();
  122. }
  123. } catch (\Exception $exception) {
  124. }
  125. }
  126. dump("晚安匹配到好友:结束,目前进度:{$descroom->id}");
  127. }
  128. // 72小时活动到好友
  129. public function hour2friend()
  130. {
  131. dump("72小时活动到好友:开始启动");
  132. $start = 256576;
  133. $descroom = \App\Models\Fpdx\RoomModel::where('room_id', '>=', $start)->where('type', 1)->orderBy(
  134. 'room_id',
  135. 'desc'
  136. )->first();
  137. for ($i = $start; $i <= $descroom->room_id; $i++) {
  138. try {
  139. $room = \App\Models\Fpdx\RoomModel::where([['type', 1], ['room_id', $i]])->first();
  140. $members = $room->member;
  141. $friend1 = FriendsModel::firstOrCreate([
  142. 'uid' => $members[0],
  143. 'friend_uid' => $members[1]
  144. ], [
  145. 'created_at' => $room->create_time,
  146. 'uid' => $members[0],
  147. 'friend_uid' => $members[1],
  148. 'last_at' => $room->create_time,
  149. 'friend_type' => 2,
  150. 'friend_type_data' => $i
  151. ]);
  152. if ($friend1->last_at < $room->create_time) {
  153. $friend1->last_at = $room->create_time;
  154. $friend1->friend_type = 2;
  155. $friend1->friend_type_data = $i;
  156. $friend1->save();
  157. }
  158. $friend2 = FriendsModel::firstOrCreate([
  159. 'uid' => $members[1],
  160. 'friend_uid' => $members[0]
  161. ], [
  162. 'created_at' => $room->create_time,
  163. 'uid' => $members[1],
  164. 'friend_uid' => $members[0],
  165. 'last_at' => $room->create_time,
  166. 'friend_type' => 2,
  167. 'friend_type_data' => $i
  168. ]);
  169. if ($friend2->last_at < $room->create_time) {
  170. $friend2->last_at = $room->create_time;
  171. $friend2->friend_type = 2;
  172. $friend2->friend_type_data = $i;
  173. $friend2->save();
  174. }
  175. } catch (\Exception $exception) {
  176. }
  177. }
  178. dump("72小时活动到好友:结束,目前进度:{$descroom->room_id}");
  179. }
  180. // 邀请到好友
  181. public function invite2friend()
  182. {
  183. dump("邀请到好友:开始启动");
  184. $start = 220284;
  185. $datas = DB::table('kdgx_fpdx_invitation_card')->where('id', '>', $start)->where('state', 1)->get();
  186. $fs = new FriendService();
  187. foreach ($datas as $data) {
  188. $friend1 = FriendsModel::firstOrCreate([
  189. 'uid' => $data->uid,
  190. 'friend_uid' => $data->invite_uid
  191. ], [
  192. 'created_at' => $data->created_at,
  193. 'uid' => $data->uid,
  194. 'friend_uid' => $data->invite_uid,
  195. 'last_at' => $data->created_at,
  196. 'friend_type' => 1,
  197. 'friend_type_data' => $data->id
  198. ]);
  199. if ($friend1->last_at < $data->created_at) {
  200. $friend1->last_at = $data->created_at;
  201. $friend1->friend_type = 1;
  202. $friend1->friend_type_data = $data->id;
  203. $friend1->save();
  204. }
  205. $friend2 = FriendsModel::firstOrCreate([
  206. 'uid' => $data->invite_uid,
  207. 'friend_uid' => $data->uid
  208. ], [
  209. 'created_at' => $data->created_at,
  210. 'uid' => $data->invite_uid,
  211. 'friend_uid' => $data->uid,
  212. 'last_at' => $data->created_at,
  213. 'friend_type' => 6,
  214. 'friend_type_data' => $data->id
  215. ]);
  216. if ($friend2->last_at < $data->created_at) {
  217. $friend2->last_at = $data->created_at;
  218. $friend2->friend_type = 6;
  219. $friend2->friend_type_data = $data->id;
  220. $friend2->save();
  221. }
  222. }
  223. dump("邀请到好友:结束,目前进度:{$data->id}");
  224. }
  225. }