Openid.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Openid extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'openid';
  9. public static function addupdate($updata)
  10. {
  11. $weid = weid();
  12. $openid = $updata['openid'];
  13. if (empty($openid)) {
  14. $openid = getFans()['openid'];
  15. }
  16. $where['weid'] = $weid;
  17. if (!empty($updata['uid'])) {
  18. $where['uid'] = $updata['uid'];
  19. }
  20. $where['openid'] = $openid;
  21. if (!empty($updata['ptype'])) {
  22. $where['ptype'] = $updata['ptype'];
  23. }
  24. $Openidmob = self::where($where)->find();
  25. if ($Openidmob) {
  26. Openid::where(['id' => $Openidmob->id])->delete();
  27. }
  28. $adddata['weid'] = $weid;
  29. $adddata['uid'] = $updata['uid'];
  30. $adddata['ptype'] = $updata['ptype'];
  31. $adddata['openid'] = $openid;
  32. Openid::create($adddata);
  33. }
  34. public static function getMpOpenidbyuid($uid)
  35. {
  36. $data = self::where(['weid' => weid(), 'uid' => $uid, 'ptype' => 'mp'])->order('id desc')->find();
  37. if (!empty($data)) {
  38. return $data->openid;
  39. }
  40. }
  41. public static function getMpOpenidbyuuid($uuid)
  42. {
  43. if (!empty($uuid)) {
  44. if (empty($openid)) {
  45. $uid = UuidRelation::getuid($uuid);
  46. if (!empty($uid)) {
  47. $openid = self::getMpOpenidbyuid($uid);
  48. }
  49. }
  50. return $openid;
  51. }
  52. }
  53. public static function getWxappOpenidbyuid($uid)
  54. {
  55. $data = self::where(['weid' => weid(), 'uid' => $uid, 'ptype' => 'wxapp'])->order('id desc')->find();
  56. if (!empty($data)) {
  57. return $data->openid;
  58. }
  59. }
  60. public static function getuidbyopenid($openid = '')
  61. {
  62. self::getuserbyopenid($openid)['uid'];
  63. }
  64. public static function getuserbyopenid($openid = '')
  65. {
  66. if (empty($openid)) {
  67. $openid = getFans()['openid'];
  68. }
  69. $query = self::where(['weid' => weid(), 'openid' => $openid]);
  70. $query->where('uid', '>', 0);
  71. $mob = $query->order('id desc')->find();
  72. if (!empty($mob)) {
  73. if (empty($mob->ptype)) {
  74. $mob->ptype = getFans()['ptype'];
  75. $mob->save();
  76. }
  77. return $mob->toArray();
  78. }
  79. }
  80. }