AgentGameRateModel.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * AgentGameRateModel.php UTF-8
  4. * 渠道游戏
  5. *
  6. * @date : 2018/5/14 13:45
  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\CacheConst;
  15. use think\Cache;
  16. class AgentGameRateModel extends CommonModel {
  17. protected $name = 'agent_game_rate';
  18. // 开启自动写入时间戳字段
  19. protected $autoWriteTimestamp = true;
  20. protected $agent_cache_tag = CacheConst::TAG_AGENT_GAME_LIST;
  21. /**
  22. * 添加渠道游戏折扣数据
  23. *
  24. * @param $data
  25. *
  26. * @return bool
  27. */
  28. public function addData($data) {
  29. if (empty($data)) {
  30. return false;
  31. }
  32. if ($_obj = self::create($data, true)) {
  33. Cache::clear($this->agent_cache_tag);
  34. return true;
  35. } else {
  36. return false;
  37. }
  38. }
  39. /**
  40. * 更新渠道游戏折扣数据
  41. *
  42. * @param array $data
  43. * @param string $ag_id
  44. *
  45. * @return bool
  46. */
  47. public function updateData($data, $ag_id) {
  48. $_map['ag_id'] = $ag_id;
  49. $_data = $data;
  50. $_rs = self::update($_data, $_map, true);
  51. if (false == $_rs) {
  52. return false;
  53. } else {
  54. Cache::clear($this->agent_cache_tag);
  55. return true;
  56. }
  57. }
  58. /**
  59. * 通过q游戏ID 渠道ID 获取折扣信息
  60. *
  61. * @param int $app_id
  62. * @param int $agent_id
  63. *
  64. * @return array|false
  65. */
  66. public function getInfoByGameAgent($app_id, $agent_id) {
  67. $_map['app_id'] = $app_id;
  68. $_map['agent_id'] = $agent_id;
  69. $_info = $this->where($_map)->find();
  70. if (false === $_info) {
  71. return false;
  72. }
  73. if (is_object($_info)) {
  74. return $_info->toArray();
  75. } else {
  76. return $_info;
  77. }
  78. }
  79. /**
  80. * 根据渠道分成模式获取id
  81. *
  82. * @param int $agent_benefit_type 渠道分成模式
  83. *
  84. * @return array
  85. */
  86. public function getAgIdsByAgentBenefitType($agent_benefit_type) {
  87. $_map = [
  88. 'agent_benefit_type' => $agent_benefit_type
  89. ];
  90. return $this->where($_map)->column('ag_id');
  91. }
  92. }