OaMpModel.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * OaMpModel.php UTF-8
  4. *
  5. *
  6. * @date : 2018/9/14 20:31
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HuoMp 1.0
  11. */
  12. namespace huomp\model\weixin;
  13. use huo\model\game\GameModel;
  14. use huomp\model\common\CommonModel;
  15. use huomp\model\game\GameMiniModel;
  16. class OaMpModel extends CommonModel {
  17. protected $table = 'mp_oa_mp';
  18. /**
  19. * 关联game表
  20. *
  21. * @return mixed
  22. */
  23. public function game() {
  24. return $this->hasone(GameModel::className(), 'id', 'app_id')->field(
  25. 'id,name,classify as classify_label,status as status_label,icon'
  26. );
  27. }
  28. /**
  29. * 关联game表
  30. *
  31. * @return mixed
  32. */
  33. public function gmini() {
  34. return $this->hasone(GameMiniModel::className(), 'app_id', 'app_id')->field('app_id,mini_app_id');
  35. }
  36. /**
  37. * 关联账号表
  38. *
  39. * @return mixed
  40. */
  41. public function mc() {
  42. return $this->hasone(MpConfModel::className(), 'mp_id', 'oa_id');
  43. }
  44. /**
  45. * 添加数据
  46. *
  47. * @param $data
  48. *
  49. * @return bool
  50. */
  51. public function addData($data) {
  52. if (empty($data)) {
  53. return false;
  54. }
  55. $_data = $data;
  56. $_obj = self::create($_data, true);
  57. if ($_obj) {
  58. return $_obj->id;
  59. }
  60. return false;
  61. }
  62. /**
  63. * 获取微信关联的游戏个数
  64. *
  65. * @param $oa_id
  66. *
  67. * @return float|int
  68. */
  69. public function getSumGame($oa_id) {
  70. $_map = ['oa_id' => $oa_id];
  71. return self::where($_map)->count();
  72. }
  73. /**
  74. * 删除记录
  75. *
  76. * @param $id
  77. *
  78. * @return int
  79. */
  80. public function deleteData($id) {
  81. $_map = ['id' => $id];
  82. return self::where($_map)->delete();
  83. }
  84. /**
  85. * 删除记录
  86. *
  87. * @param $app_id
  88. *
  89. * @return int
  90. */
  91. public function deleteDataByAppId($app_id) {
  92. $_map = ['app_id' => $app_id];
  93. return self::where($_map)->delete();
  94. }
  95. /**
  96. * 通过应用ID获取公众号ID
  97. *
  98. * @param int $app_id 小程序应用ID
  99. *
  100. * @return string
  101. */
  102. public function getOaByApp($app_id) {
  103. $_map['app_id'] = $app_id;
  104. $_map['is_default'] = 2;
  105. $_oa_id = $this->where($_map)->value('oa_id');
  106. if (empty($_oa_id)) {
  107. return '';
  108. }
  109. return $_oa_id;
  110. }
  111. }