QcodeGsmc.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\Log;
  5. use traits\model\SoftDelete;
  6. class QcodeGsmc extends Model
  7. {
  8. protected $connection = 'mongodb';
  9. protected $table = 'qcode_gsmc';
  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_gsmc");
  28. self::beforeWrite(function ($model) {
  29. if (!isset($model->create_time)){
  30. $model->create_time="";
  31. }
  32. if (!isset($model->update_time)){
  33. $model->update_time="";
  34. }
  35. if (!isset($model->delete_time)){
  36. $model->delete_time="";
  37. }
  38. $model->sync_flag=0;
  39. });
  40. // $model->sync_flag=1;
  41. }
  42. }