QcodeProduct.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\Log;
  5. use traits\model\SoftDelete;
  6. class QcodeProduct extends Model
  7. {
  8. protected $connection = 'mongodb';
  9. protected $table = 'qcode_product';
  10. protected $deleteTime = 'delete_time';
  11. use SoftDelete;
  12. // 获取DB3连接的方法
  13. public static function db3()
  14. {
  15. return \think\Db::connect(config('database.db3'));
  16. }
  17. public function createIndex()
  18. {
  19. $this->connection->command([
  20. 'createIndexes' => $this->table,
  21. 'indexes' => [
  22. [
  23. 'key' => ['pid' => 1],
  24. 'name' => 'pid_index'
  25. ]
  26. ]
  27. ]);
  28. }
  29. protected static function init()
  30. {
  31. //把当前表加入到监听队列
  32. Redis_sAdd('watch_tables', "qcode_product");
  33. self::beforeWrite(function ($model) {
  34. if (!isset($model->create_time)){
  35. $model->create_time="";
  36. }
  37. if (!isset($model->update_time)){
  38. $model->update_time="";
  39. }
  40. if (!isset($model->delete_time)){
  41. $model->delete_time="";
  42. }
  43. $model->sync_flag=0;
  44. });
  45. // $model->sync_flag=1;
  46. }
  47. }