SyncWord.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/11
  6. * Time: 下午3:08
  7. */
  8. namespace backend\server;
  9. use yii\base\Component;
  10. use common\models\Sensitivewords;
  11. use common\models\Syncwordrecord;
  12. use Yii;
  13. use yii\db\Exception;
  14. class SyncWord extends Component
  15. {
  16. public function LiveOpe($input)
  17. {
  18. $content = $input['content'];
  19. $info = $input['info'];
  20. $operator = $input['operator'];
  21. $model = new Sensitivewords();
  22. $wordinfo = $model->getList();
  23. $Transaction = Yii::$app->db->beginTransaction();
  24. if (!empty($wordinfo)) {
  25. $query = Sensitivewords::findOne($wordinfo['id']);
  26. $query->content = $content;
  27. $query->info = $info;
  28. $query->update_at = time();
  29. $s = $query->save();
  30. if ($s != true) return '目标站敏感四更新失败';
  31. $cordInfo = new Syncwordrecord();
  32. $cordInfo->mode = 'edit';
  33. $cordInfo->operator = $operator;
  34. $cordInfo->oos_content = $content;
  35. $cordInfo->oos_info = $info;
  36. $cordInfo->this_content = $wordinfo['content'];
  37. $cordInfo->this_info = $wordinfo['info'];
  38. $cordInfo->create_at = time();
  39. $cordInfo->update_at = time();
  40. $s = $cordInfo->save();
  41. if ($s != true) {
  42. $Transaction->rollBack();
  43. return '目标站更新纪录失败';
  44. }
  45. $Transaction->commit();
  46. } else {
  47. $query = $model;
  48. $query->content = $content;
  49. $query->info = $info;
  50. $query->create_at = time();
  51. $s = $query->save();
  52. if ($s != true) return '目标站敏感四添加失败';
  53. $cordInfo = new Syncwordrecord();
  54. $cordInfo->mode = 'add';
  55. $cordInfo->operator = $operator;
  56. $cordInfo->oos_content = $content;
  57. $cordInfo->oos_info = $info;
  58. $cordInfo->create_at = time();
  59. $cordInfo->update_at = time();
  60. $s = $cordInfo->save();
  61. if ($s != true) {
  62. $Transaction->rollBack();
  63. return '目标站添加纪录失败';
  64. }
  65. $Transaction->commit();
  66. }
  67. return true;
  68. }
  69. }