GamePriceModel.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * GamePriceModel.php UTF-8
  4. * 设置计费点
  5. *
  6. * @date : 2018/8/22 22:29
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\game;
  13. use huo\model\common\CommonModel;
  14. use huolib\constant\CacheConst;
  15. use huolib\constant\CommonConst;
  16. use think\Cache;
  17. use think\db\exception\DataNotFoundException;
  18. use think\db\exception\ModelNotFoundException;
  19. use think\Exception;
  20. use think\exception\DbException;
  21. class GamePriceModel extends CommonModel {
  22. protected $name = 'game_price';
  23. protected $tag = CacheConst::KEY_CACHE_GAME_PRICE_TAG;
  24. // 开启自动写入时间戳字段
  25. protected $autoWriteTimestamp = true;
  26. /**
  27. * 添加计费点
  28. *
  29. * @param $data
  30. *
  31. * @return bool
  32. */
  33. public function addData($data) {
  34. if (empty($data)) {
  35. return false;
  36. }
  37. $_rs = self::insertAll($data, true);
  38. return $_rs;
  39. }
  40. /**
  41. * 更新计费点
  42. *
  43. * @param $id
  44. * @param $data
  45. *
  46. * @return bool|GamePriceModel
  47. */
  48. public function updateData($id, $data) {
  49. if (empty($id)) {
  50. return false;
  51. }
  52. $_map['id'] = $id;
  53. $_rs = self::update($data, $_map, true);
  54. if ($_rs) {
  55. Cache::clear($this->tag);
  56. }
  57. return $_rs;
  58. }
  59. /**
  60. * 删除计费点
  61. *
  62. * @param $id
  63. *
  64. * @return bool|int
  65. */
  66. public function deleteData($id) {
  67. if (empty($id)) {
  68. return false;
  69. }
  70. $_map['id'] = $id;
  71. $_rs = self::where($_map)->delete();
  72. if ($_rs) {
  73. Cache::clear($this->tag);
  74. }
  75. return $_rs;
  76. }
  77. /**
  78. * 获取计费点详情
  79. *
  80. * @param $map
  81. *
  82. * @return array|bool|false|\PDOStatement|string|\think\Model
  83. */
  84. public function getGamePrice($map) {
  85. if (empty($map)) {
  86. return false;
  87. }
  88. $_key = $this->tag.'_'.md5(json_encode($map));
  89. try {
  90. $_data = self::where($map)
  91. ->cache($_key, CommonConst::CONST_DAY_SECONDS, $this->tag)
  92. ->find();
  93. if (is_object($_data)) {
  94. $_data = $_data->toArray();
  95. }
  96. return $_data;
  97. } catch (DataNotFoundException $e) {
  98. return false;
  99. } catch (ModelNotFoundException $e) {
  100. return false;
  101. } catch (DbException $e) {
  102. return false;
  103. } catch (Exception $e) {
  104. return false;
  105. }
  106. }
  107. }