update.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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= ? , editor_id = ? , status = ?, 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. if(!isset($data->status) || empty($data->status)){
  49. $status = 7;
  50. }else{
  51. $status = (int)$data->status;
  52. }
  53. $sth->execute(array($data->data, $_COOKIE['uid'], $status , mTime(), $data->block_id, $data->word_id));
  54. }
  55. }
  56. $PDO->commit();
  57. $respond = array("status" => 0, "message" => "");
  58. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  59. /* 识别错误且回滚更改 */
  60. $PDO->rollBack();
  61. $error = PDO_ErrorInfo();
  62. $respond['status'] = 1;
  63. $respond['message'] = $error[2];
  64. } else {
  65. $respond['status'] = 0;
  66. $respond['message'] = "成功";
  67. }
  68. if($maxPower<20){
  69. $respond['status'] = 1;
  70. $respond['message'] = "没有修改权限";
  71. }
  72. if (count($aData) ==1){
  73. try {
  74. #将数据插入redis 作为自动匹配最新数据
  75. if($redis){
  76. $xmlString = "<root>" . $data->data . "</root>";
  77. $xmlWord = simplexml_load_string($xmlString);
  78. $wordsList = $xmlWord->xpath('//word');
  79. foreach ($wordsList as $word) {
  80. $pali = $word->real->__toString();
  81. $newword[]=array( "0",
  82. $pali,
  83. $word->type->__toString(),
  84. $word->gramma->__toString(),
  85. $word->parent->__toString(),
  86. $word->mean->__toString(),
  87. "",
  88. $word->org->__toString(),
  89. $word->om->__toString(),
  90. "7",
  91. "100",
  92. "my",
  93. "none"
  94. );
  95. $redis->hSet("wbwdict://new/".$_COOKIE["userid"],$pali,json_encode($newword, JSON_UNESCAPED_UNICODE));
  96. }
  97. }
  98. } catch (Throwable $e) {
  99. echo "Captured Throwable: " . $e->getMessage();
  100. }
  101. }
  102. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  103. } else {
  104. $respond['status'] = 1;
  105. $respond['message'] = "no data";
  106. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  107. }
  108. PrefLog();