update.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /*
  3. get xml doc from db
  4. */
  5. include("../log/pref_log.php");
  6. require_once "../config.php";
  7. require_once "../public/_pdo.php";
  8. require_once "../public/function.php";
  9. require_once "../ucenter/active.php";
  10. require_once "../redis/function.php";
  11. require_once "../channal/function.php";
  12. require_once "../db/wbw_block.php";
  13. $respond['status'] = 0;
  14. $respond['message'] = "";
  15. $redis = redis_connect();
  16. $channelInfo = new Channal($redis);
  17. $_WbwBlock = new WbwBlock($redis);
  18. if (isset($_POST["data"])) {
  19. $aData = json_decode($_POST["data"]);
  20. } else {
  21. $respond['status'] = 1;
  22. $respond['message'] = "no data";
  23. echo json_encode(array(), JSON_UNESCAPED_UNICODE);
  24. exit;
  25. }
  26. if (count($aData) > 0) {
  27. add_edit_event(_WBW_EDIT_, "{$aData[0]->book}-{$aData[0]->para}-{$aData[0]->word_id}");
  28. PDO_Connect(_FILE_DB_USER_WBW_,_DB_USERNAME_,_DB_PASSWORD_);
  29. #确定block id 的写入权限
  30. $listBlockId=array();
  31. foreach ($aData as $data) {
  32. $listBlockId[$data->block_id]=0;
  33. }
  34. #查询channel 的 权限
  35. $maxPower=0;
  36. foreach ($listBlockId as $key => $value) {
  37. $listBlockId[$key] = $_WbwBlock->getPower($key);
  38. if($listBlockId[$key]>$maxPower){
  39. $maxPower = $listBlockId[$key];
  40. }
  41. }
  42. /* 开始一个事务,关闭自动提交 */
  43. $PDO->beginTransaction();
  44. $query = "UPDATE "._TABLE_USER_WBW_." SET data= ? , modify_time= ? , updated_at = now() where block_uid= ? and wid= ? ";
  45. $sth = $PDO->prepare($query);
  46. foreach ($aData as $data) {
  47. if($listBlockId[$data->block_id]>=20){
  48. $sth->execute(array($data->data, mTime(), $data->block_id, $data->word_id));
  49. }
  50. }
  51. $PDO->commit();
  52. $respond = array("status" => 0, "message" => "");
  53. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  54. /* 识别错误且回滚更改 */
  55. $PDO->rollBack();
  56. $error = PDO_ErrorInfo();
  57. $respond['status'] = 1;
  58. $respond['message'] = $error[2];
  59. } else {
  60. $respond['status'] = 0;
  61. $respond['message'] = "成功";
  62. }
  63. if($maxPower<20){
  64. $respond['status'] = 1;
  65. $respond['message'] = "没有修改权限";
  66. }
  67. if (count($aData) ==1){
  68. try {
  69. #将数据插入redis 作为自动匹配最新数据
  70. if($redis){
  71. $xmlString = "<root>" . $data->data . "</root>";
  72. $xmlWord = simplexml_load_string($xmlString);
  73. $wordsList = $xmlWord->xpath('//word');
  74. foreach ($wordsList as $word) {
  75. $pali = $word->real->__toString();
  76. $newword[]=array( "0",
  77. $pali,
  78. $word->type->__toString(),
  79. $word->gramma->__toString(),
  80. $word->parent->__toString(),
  81. $word->mean->__toString(),
  82. "",
  83. $word->org->__toString(),
  84. $word->om->__toString(),
  85. "7",
  86. "100",
  87. "my",
  88. "none"
  89. );
  90. $redis->hSet("wbwdict://new/".$_COOKIE["userid"],$pali,json_encode($newword, JSON_UNESCAPED_UNICODE));
  91. }
  92. }
  93. } catch (Throwable $e) {
  94. echo "Captured Throwable: " . $e->getMessage();
  95. }
  96. }
  97. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  98. } else {
  99. $respond['status'] = 1;
  100. $respond['message'] = "no data";
  101. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  102. }
  103. PrefLog();