QqConfModel.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. /**
  3. * QqConfModel.php UTF-8
  4. * QQ配置
  5. *
  6. * @date : 2018/4/26 1:17
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\conf;
  13. use huo\model\common\CommonModel;
  14. use think\db\exception\DataNotFoundException;
  15. use think\db\exception\ModelNotFoundException;
  16. use think\Exception;
  17. use think\exception\DbException;
  18. class QqConfModel extends CommonModel {
  19. protected $name = 'qq_conf';
  20. protected $autoWriteTimestamp = true;
  21. /**
  22. * 获取网页访问串
  23. *
  24. * @param $value
  25. *
  26. * @return string
  27. */
  28. public function getIdkeyAttr($value) {
  29. $_value = $value;
  30. if (!empty($_value)) {
  31. $_value = '//shang.qq.com/wpa/qunwpa?idkey='.$_value;
  32. }
  33. return $_value;
  34. }
  35. /**
  36. * 获取IOS访问串
  37. *
  38. * @param $value
  39. * @param $data
  40. *
  41. * @return string
  42. */
  43. public function getIosKeyAttr($value, $data) {
  44. $_value = $value;
  45. if (!empty($_value)) {
  46. $_value
  47. = 'mqqapi://card/show_pslcard?src_type=internal&version=1&uin='.$data['qq'].'&key='.$_value
  48. .'&card_type=group&source=external';
  49. }
  50. return $_value;
  51. }
  52. /**
  53. * 获取ANDROID访问串
  54. *
  55. * @param $value
  56. *
  57. * @return string
  58. */
  59. public function getAndKeyAttr($value) {
  60. $_value = $value;
  61. if (!empty($_value)) {
  62. $_value
  63. = 'mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D'
  64. .$_value;
  65. }
  66. return $_value;
  67. }
  68. /**
  69. * @param int $qq_id
  70. *
  71. * @param bool $is_origin 是否使用原始数据
  72. *
  73. * @return array|null
  74. */
  75. public function getInfoByQqId($qq_id, $is_origin = false) {
  76. if (empty($qq_id)) {
  77. return null;
  78. }
  79. $_map['id'] = $qq_id;
  80. try {
  81. $_field = 'type,qq,idkey,ios_key,and_key';
  82. $_qq_data = $this->field($_field)->where($_map)->find();
  83. if (is_object($_qq_data)) {
  84. if ($is_origin) {
  85. $_qq_data = $_qq_data->getData();
  86. } else {
  87. $_qq_data = $_qq_data->toArray();
  88. }
  89. }
  90. return $_qq_data;
  91. } catch (DataNotFoundException $e) {
  92. return null;
  93. } catch (ModelNotFoundException $e) {
  94. return null;
  95. } catch (DbException $e) {
  96. return null;
  97. } catch (Exception $e) {
  98. return null;
  99. }
  100. }
  101. /**
  102. * @param string $qq_ids
  103. * @param int $type
  104. *
  105. * @return array|null
  106. */
  107. public function getInfoByQqIds($qq_ids, $type) {
  108. if (empty($qq_ids)) {
  109. return null;
  110. }
  111. $_map['id'] = ['in', $qq_ids];
  112. $_map['type'] = $type;
  113. $_field = 'qq';
  114. $_qq_data = $this->field($_field)->where($_map)->column($_field);
  115. return $_qq_data;
  116. }
  117. /**
  118. * 更新QQ信息
  119. *
  120. * @param $qq_data
  121. * @param $qq_id
  122. *
  123. * @return bool
  124. */
  125. public function updateQq($qq_data, $qq_id) {
  126. $_map['id'] = $qq_id;
  127. $_data = $qq_data;
  128. $_data['update_time'] = time();
  129. $_rs = self::update($_data, $_map, true);
  130. if (false == $_rs) {
  131. return false;
  132. } else {
  133. return true;
  134. }
  135. }
  136. /**
  137. * 获取qq列表
  138. *
  139. * @param array $fields
  140. * @param array $where
  141. *
  142. * @return false|\PDOStatement|string|\think\Collection
  143. * @throws DataNotFoundException
  144. * @throws DbException
  145. * @throws ModelNotFoundException
  146. */
  147. public function getQqs($fields = [], $where = []) {
  148. $_model = [];
  149. if (!empty($fields)) {
  150. $_model = $this->field($fields);
  151. }
  152. if (!empty($where)) {
  153. $_model = $this->where($where);
  154. }
  155. return $_model->select();
  156. }
  157. /**
  158. * 添加QQ
  159. *
  160. * @param $data
  161. *
  162. * @return bool|mixed
  163. */
  164. public function addQqs($data) {
  165. if (empty($data)) {
  166. return false;
  167. }
  168. $data['create_time'] = time();
  169. if ($_obj = self::create($data, true)) {
  170. return $_obj->id;
  171. } else {
  172. return false;
  173. }
  174. }
  175. /**
  176. * 根据类型获得id name
  177. *
  178. * @param int $type
  179. *
  180. * @return array
  181. */
  182. public function getQqIdName($type = 1) {
  183. return self::where(['type' => $type, 'is_delete' => 2])->column('qq', 'id');
  184. }
  185. }