QcodeClassification.php 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\Log;
  5. use traits\model\SoftDelete;
  6. class QcodeClassification extends Model
  7. {
  8. protected $connection = 'mongodb';
  9. protected $table = 'qcode_classification';
  10. protected $deleteTime = 'delete_time';
  11. use SoftDelete;
  12. public function createIndex()
  13. {
  14. $this->connection->command([
  15. 'createIndexes' => $this->table,
  16. 'indexes' => [
  17. [
  18. 'key' => ['pid' => 1],
  19. 'name' => 'pid_index'
  20. ]
  21. ]
  22. ]);
  23. }
  24. protected static function init()
  25. {
  26. //把当前表加入到监听队列
  27. Redis_sAdd('watch_tables', "qcode_classification");
  28. self::beforeWrite(function ($model) {
  29. if (!isset($model->delete_time)){
  30. $model->delete_time="";
  31. }
  32. $model->sync_flag=0;
  33. });
  34. // $model->sync_flag=1;
  35. }
  36. }