Task.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * 任务和成就配置相关
  4. */
  5. defined('IN_WEB') or die( 'Include Error!');
  6. include_once dirname(__FILE__) . "/Base.php";
  7. class Task extends Base
  8. {
  9. private $_config; //配置文件
  10. private $_table;
  11. private $_cjtable;//成就配置文件
  12. public function __construct()
  13. {
  14. $this->_config = include PATH_CFG.'config.task.php';
  15. $this->_table = otable::taskConfig();
  16. $this->_cjtable = otable::achievementConfig();
  17. }
  18. /**
  19. * 获取配置文件
  20. */
  21. public function getConfig()
  22. {
  23. $sql = " SELECT * FROM {$this->_table} ORDER BY sort DESC";
  24. $info = oo::commonOprDb('common')->getAll($sql, 1);
  25. return json_encode($info);
  26. }
  27. /**
  28. * 获取成就配置文件
  29. */
  30. public function getCjConfig()
  31. {
  32. $sql = " SELECT * FROM {$this->_cjtable} ";
  33. $info = oo::commonOprDb('common')->getAll($sql, 1);
  34. return json_encode($info);
  35. }
  36. /**
  37. * 获取单个记录
  38. */
  39. public function getOne($param)
  40. {
  41. $tid = oo::functions()->uint($param['tid']);
  42. $sql = " SELECT * FROM {$this->_table} WHERE id = {$tid} LIMIT 1 ";
  43. $info = oo::commonOprDb('common')->getOne($sql, MYSQLI_ASSOC);
  44. return json_encode($info);
  45. }
  46. /**
  47. * 获取单个记录
  48. */
  49. public function getOnecj($param)
  50. {
  51. $tid = oo::functions()->uint($param['tid']);
  52. $sql = " SELECT * FROM {$this->_cjtable} WHERE id = {$tid} LIMIT 1 ";
  53. $info = oo::commonOprDb('common')->getOne($sql, MYSQLI_ASSOC);
  54. return json_encode($info);
  55. }
  56. /**
  57. * 编辑
  58. */
  59. public function editTask($param)
  60. {
  61. $tid = oo::functions()->uint($param['tid']);
  62. $tc_zh_name = oo::functions()->escape($param['tc_zh_name']);
  63. $tc_name = oo::functions()->escape($param['tc_name']);
  64. $tc_sort = oo::functions()->uint($param['tc_sort']);
  65. $tc_goto = oo::functions()->uint($param['tc_goto']);
  66. $rewardNum = json_decode($param['rewardNum'], 1);
  67. $rewardMoney = json_decode($param['rewardMoney'], 1);
  68. $i = 1;
  69. $tc_subtask = array();
  70. foreach ($rewardNum as $key => $nums) {
  71. $tc_subtask[$i] = array('num' => $nums, 'reward' => array('money' => $rewardMoney[$key]));
  72. $i++;
  73. }
  74. $tc_subtask = json_encode($tc_subtask);
  75. $sql = " UPDATE {$this->_table} SET zh_name = '{$tc_zh_name}', name = '{$tc_name}', sort = {$tc_sort}, goto = {$tc_goto}, subtask = '{$tc_subtask}' WHERE id = {$tid} LIMIT 1 ";
  76. oo::commonOprDb('common')->query($sql);
  77. $ret = oo::commonOprDb('common')->affectedRows();
  78. if ($ret) {
  79. //删除缓存
  80. $key = okeys::taskConfig();
  81. oo::commonOprRedis('common')->delete($key);
  82. }
  83. return json_encode(array('num' => $ret));
  84. }
  85. /**
  86. * 编辑
  87. */
  88. public function editCj($param)
  89. {
  90. $tid = oo::functions()->uint($param['tid']);
  91. $zh_name = oo::functions()->escape($param['zh_name']);
  92. $name = oo::functions()->escape($param['name']);
  93. $sort = oo::functions()->uint($param['sort']);
  94. $rewardNum = json_decode($param['rewardNum'], 1);
  95. $rewardMoney = json_decode($param['rewardMoney'], 1);
  96. $i = 1;
  97. $tc_subtask = array();
  98. foreach ($rewardNum as $key => $nums) {
  99. $tc_subtask[$i] = array($nums, $rewardMoney[$key]);
  100. $i++;
  101. }
  102. $tc_subtask = json_encode($tc_subtask);
  103. $sql = " UPDATE {$this->_cjtable} SET zh_name = '{$zh_name}', name = '{$name}', sort = {$sort}, subtask = '{$tc_subtask}' WHERE id = {$tid} LIMIT 1 ";
  104. oo::commonOprDb('common')->query($sql);
  105. $ret = oo::commonOprDb('common')->affectedRows();
  106. if ($ret) {
  107. $key = okeys::achievementConfig();
  108. oo::commonOprRedis('common')->delete($key);
  109. }
  110. return json_encode(array('num' => $ret));
  111. }
  112. }
  113. ?>