YzCommentSeeder.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/9
  6. * Time: 上午9:54
  7. */
  8. use Illuminate\Database\Seeder;
  9. use app\common\models\Member;
  10. class YzCommentSeeder extends Seeder
  11. {
  12. protected $oldTable = 'sz_yi_order_comment';
  13. protected $newTable = 'yz_comment';
  14. public function run()
  15. {
  16. return;
  17. if (!Schema::hasTable($this->oldTable)) {
  18. echo $this->oldTable." 不存在 跳过\n";
  19. return;
  20. }
  21. $newList = \Illuminate\Support\Facades\DB::table($this->newTable)->get();
  22. if ($newList->isNotEmpty()) {
  23. echo "yz_comment 已经有数据了跳过\n";
  24. return;
  25. }
  26. $list = \Illuminate\Support\Facades\DB::table($this->oldTable)->get();
  27. if ($list) {
  28. foreach ($list as $v) {
  29. $uid = Member::getUidByOpenID($v['openid']);
  30. //迁移主评论
  31. $cid = \Illuminate\Support\Facades\DB::table($this->newTable)->insertGetId([
  32. 'uniacid' => $v['uniacid'],
  33. 'order_id' => $v['orderid'],
  34. 'goods_id' => $v['goodsid'],
  35. 'uid' => $uid,
  36. 'nick_name' => $v['nickname'],
  37. 'head_img_url' => $v['headimgurl'],
  38. 'content' => $v['content'],
  39. 'level' => $v['level'],
  40. 'images' => $v['images'],
  41. 'comment_id' => 0,
  42. 'reply_id' => 0,
  43. 'reply_name' => Null,
  44. 'created_at' => $v['createtime'],
  45. 'updated_at' => NULL,
  46. 'deleted_at' => $v['deleted'] ? time() : NULL
  47. ]);
  48. //迁移管理员回复主评论
  49. if (!empty($v['reply_content'])) {
  50. \Illuminate\Support\Facades\DB::table($this->newTable)->insert([
  51. 'uniacid' => $v['uniacid'],
  52. 'order_id' => $v['orderid'],
  53. 'goods_id' => $v['goodsid'],
  54. 'uid' => 0,
  55. 'nick_name' => '',
  56. 'head_img_url' => '',
  57. 'content' => $v['reply_content'],
  58. 'level' => 0,
  59. 'images' => $v['reply_images'],
  60. 'comment_id' => $cid,
  61. 'reply_id' => $uid,
  62. 'reply_name' => $v['nickname'],
  63. 'created_at' => $v['createtime'] + 7200,
  64. 'updated_at' => NULL,
  65. 'deleted_at' => $v['deleted'] ? time() : NULL,
  66. ]);
  67. }
  68. //迁移追加评论
  69. if (!empty($v['append_content'])) {
  70. \Illuminate\Support\Facades\DB::table($this->newTable)->insert([
  71. 'uniacid' => $v['uniacid'],
  72. 'order_id' => $v['orderid'],
  73. 'goods_id' => $v['goodsid'],
  74. 'uid' => $uid,
  75. 'nick_name' => $v['nickname'],
  76. 'head_img_url' => $v['headimgurl'],
  77. 'content' => $v['append_content'],
  78. 'level' => 0,
  79. 'images' => $v['append_images'],
  80. 'comment_id' => $cid,
  81. 'reply_id' => 0,
  82. 'reply_name' => Null,
  83. 'created_at' => $v['createtime'] + 14000,
  84. 'updated_at' => NULL,
  85. 'deleted_at' => $v['deleted'] ? time() : NULL,
  86. ]);
  87. }
  88. //迁移管理员回复追加评论
  89. if (!empty($v['append_reply_content'])) {
  90. \Illuminate\Support\Facades\DB::table($this->newTable)->insert([
  91. 'uniacid' => $v['uniacid'],
  92. 'order_id' => $v['orderid'],
  93. 'goods_id' => $v['goodsid'],
  94. 'uid' => 0,
  95. 'nick_name' => '',
  96. 'head_img_url' => '',
  97. 'content' => $v['append_reply_content'],
  98. 'level' => 0,
  99. 'images' => $v['append_reply_images'],
  100. 'comment_id' => $cid,
  101. 'reply_id' => $uid,
  102. 'reply_name' => $v['nickname'],
  103. 'created_at' => $v['createtime'] + 21200,
  104. 'updated_at' => NULL,
  105. 'deleted_at' => $v['deleted'] ? time() : NULL,
  106. ]);
  107. }
  108. }
  109. }
  110. // TODO: Implement run() method.
  111. }
  112. }