GameRateModel.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * GameRateModel.php UTF-8
  4. * 游戏折扣模型
  5. *
  6. * @date : 2018/5/14 13:41
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\rate;
  13. use huo\model\common\CommonModel;
  14. use huolib\constant\GameConst;
  15. class GameRateModel extends CommonModel {
  16. protected $name = 'game_rate';
  17. // 开启自动写入时间戳字段
  18. protected $autoWriteTimestamp = true;
  19. /**
  20. * 添加游戏折扣数据
  21. *
  22. * @param $data
  23. *
  24. * @return bool
  25. */
  26. public function addData($data) {
  27. if (empty($data)) {
  28. return false;
  29. }
  30. if ($_obj = self::create($data, true)) {
  31. return true;
  32. } else {
  33. return false;
  34. }
  35. }
  36. /**
  37. * 更新游戏折扣数据
  38. *
  39. * @param array $data
  40. * @param string $app_id
  41. *
  42. * @return bool
  43. */
  44. public function updateData($data, $app_id) {
  45. $_map['app_id'] = $app_id;
  46. $_data = $data;
  47. $_rs = self::update($_data, $_map, true);
  48. if (false == $_rs) {
  49. return false;
  50. } else {
  51. return true;
  52. }
  53. }
  54. /**
  55. * 获取单条记录
  56. *
  57. * @param int $id
  58. *
  59. * @return array|false
  60. */
  61. public function getInfoById($id) {
  62. $_map['app_id'] = $id;
  63. $_info = $this->where($_map)->find();
  64. if (false === $_info) {
  65. return false;
  66. }
  67. if (is_object($_info)) {
  68. return $_info->toArray();
  69. } else {
  70. return $_info;
  71. }
  72. }
  73. /**
  74. * 优惠类型描述获取器
  75. *
  76. * @param $value
  77. *
  78. * @return string
  79. */
  80. public function getBenefitTypeTextAttr($value) {
  81. switch ($value) {
  82. case GameConst::RATE_BENEFIT_NO:
  83. return '无优惠';
  84. case GameConst::RATE_BENEFIT_RATE:
  85. return '折扣';
  86. case GameConst::RATE_BENEFIT_REBATE:
  87. return 'CPS';
  88. case GameConst::RATE_BENEFIT_REWARD:
  89. return 'CPA';
  90. default:
  91. return '';
  92. }
  93. }
  94. /**
  95. * 优惠类型描述获取器
  96. *
  97. * @param $value
  98. *
  99. * @return string
  100. */
  101. public function getAgentBenefitTypeTextAttr($value) {
  102. switch ($value) {
  103. case GameConst::RATE_AGENT_BENEFIT_REWARD:
  104. return 'CPA';
  105. case GameConst::RATE_AGENT_BENEFIT_REBATE:
  106. return 'CPS';
  107. default:
  108. return '';
  109. }
  110. }
  111. }