2020_08_12_172252_create_yz_protocol_table.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. use Illuminate\Support\Facades\Schema;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Database\Migrations\Migration;
  5. class CreateYzProtocolTable extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. *
  10. * @return void
  11. */
  12. public function up()
  13. {
  14. if (!Schema::hasTable('yz_protocol')) {
  15. Schema::create('yz_protocol', function (Blueprint $table) {
  16. $table->increments('id');
  17. $table->integer('uniacid')->comment('公众号');
  18. $table->boolean('status')->default(0)->comment('0关闭1开启');
  19. $table->longText('content')->nullable()->comment('内容');
  20. $table->integer('created_at')->nullable();
  21. $table->integer('updated_at')->nullable();
  22. });
  23. \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . app('db')->getTablePrefix()
  24. . "yz_protocol comment '会员--会员注册协议表'");//表注释
  25. }
  26. $member_protocol = \app\common\models\Setting::where(['key' => 'protocol', 'group' => 'shop'])->select('uniacid', 'value')->get()->toArray();
  27. foreach ($member_protocol as $k => $value){
  28. $data[$k]['status'] = unserialize($value['value'])['protocol'] ?: 0;
  29. $data[$k]['content'] = unserialize($value['value'])['content'] ?: '';
  30. $data[$k]['uniacid'] = $value['uniacid'];
  31. $data[$k]['created_at'] = time();
  32. $data[$k]['updated_at'] = time();
  33. }
  34. if(!empty($data)){
  35. \Illuminate\Support\Facades\DB::table('yz_protocol')->insert($data);
  36. }
  37. }
  38. /**
  39. * Reverse the migrations.
  40. *
  41. * @return void
  42. */
  43. public function down()
  44. {
  45. //
  46. }
  47. }