UserLike.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 模型
  6. */
  7. class UserLike extends Model
  8. {
  9. // 开启自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. /**
  14. * 获取喜欢列表
  15. */
  16. public function getUserList($user_id,$pageStart=1,$pageNum=10) {
  17. $where = [];
  18. $where["a.fans_id"] = $user_id;
  19. $list = $this->alias("a")
  20. ->field("a.id,a.user_id,a.fans_id,u.nickname,u.avatar,u.age,u.constellation,u.wechat,hobby_ids,profession,u.copy_mobile,u.mobile")
  21. ->join("hx_user u","u.id = a.user_id","left")
  22. ->where($where)
  23. ->limit($pageStart,$pageNum)
  24. ->select();
  25. if($list) {
  26. $public_key = "-----BEGIN PUBLIC KEY-----" .PHP_EOL.
  27. wordwrap(config('public_key'), 64, PHP_EOL, true) .
  28. PHP_EOL."-----END PUBLIC KEY-----";
  29. foreach($list as $k => &$v) {
  30. if ($v['wechat']) {
  31. $wechat = "";
  32. openssl_public_encrypt($v['wechat'], $wechat, $public_key);
  33. $v['wechat'] = base64_encode($wechat);
  34. } else {
  35. $v['wechat'] = '';
  36. }
  37. $mobile = "";
  38. // openssl_private_encrypt($data['mobile'], $mobile, $private_key); // 使用私钥加密数据
  39. openssl_public_encrypt($v['mobile'], $mobile, $public_key);
  40. $v['mobile'] = base64_encode($mobile);
  41. if($v['hobby_ids']) {
  42. $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
  43. } else {
  44. $list[$k]['hobby_ids'] = [];
  45. }
  46. }
  47. }
  48. return $list;
  49. }
  50. /**
  51. * 获取喜欢列表
  52. */
  53. public function getFansList($user_id,$pageStart=1,$pageNum=10) {
  54. $where = [];
  55. $where["a.user_id"] = $user_id;
  56. $list = $this->alias("a")
  57. ->field("a.id,a.fans_id as user_id,u.nickname,u.avatar,u.age,u.constellation,u.wechat,hobby_ids,profession,u.copy_mobile,u.mobile")
  58. ->join("hx_user u","u.id = a.fans_id","left")
  59. ->where($where)
  60. ->limit($pageStart,$pageNum)
  61. ->select();
  62. if($list) {
  63. $public_key = "-----BEGIN PUBLIC KEY-----" .PHP_EOL.
  64. wordwrap(config('public_key'), 64, PHP_EOL, true) .
  65. PHP_EOL."-----END PUBLIC KEY-----";
  66. foreach($list as $k => &$v) {
  67. if ($v['wechat']) {
  68. $wechat = "";
  69. openssl_public_encrypt($v['wechat'], $wechat, $public_key);
  70. $v['wechat'] = base64_encode($wechat);
  71. } else {
  72. $v['wechat'] = '';
  73. }
  74. $mobile = "";
  75. // openssl_private_encrypt($data['mobile'], $mobile, $private_key); // 使用私钥加密数据
  76. openssl_public_encrypt($v['mobile'], $mobile, $public_key);
  77. $v['mobile'] = base64_encode($mobile);
  78. if($v['hobby_ids']) {
  79. $list[$k]['hobby_ids'] = \app\common\model\Hobby::getHobbyNames($v['hobby_ids']);
  80. } else {
  81. $list[$k]['hobby_ids'] = [];
  82. }
  83. }
  84. }
  85. return $list;
  86. }
  87. }