Apply.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace app\common\model;
  3. use app\api\controller\Common;
  4. use think\Model;
  5. class Apply extends Model
  6. {
  7. // 表名
  8. protected $name = 'apply';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'integer';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = false;
  14. protected $deleteTime = false;
  15. // 追加属性
  16. protected $append = [
  17. ];
  18. /**
  19. * uid资料
  20. */
  21. public function uidinfo(){
  22. return $this->belongsTo('User','uid','id',[],'LEFT');
  23. }
  24. /**
  25. * 申请我的
  26. */
  27. public function applyme(){
  28. return $this->belongsTo('User','nid','id',[],"LEFT")/*->field('id,id_authentication,avatar,username,avatar')*/;
  29. }
  30. /**
  31. * 被申请信息
  32. */
  33. public function Nuser(){
  34. return $this->belongsTo('User','nid','id',[],"LEFT")->field('id,id_authentication,avatar,username,avatar,wx');
  35. }
  36. public static function n_read($arr){
  37. foreach ($arr as $v){
  38. Apply::update(['n_is_read'=>1],['id'=>$v['id']]);
  39. }
  40. }
  41. public static function u_read($arr){
  42. foreach ($arr as $v){
  43. Apply::update(['u_is_read'=>1],['id'=>$v['id']]);
  44. }
  45. }
  46. /**
  47. * 微信服务号通知
  48. */
  49. public static function wxMessage($id,$time){
  50. $user_name = User::get(['id'=>$id]);
  51. $data = [
  52. 'keyword1'=>[
  53. 'value'=>$user_name['username']
  54. ],
  55. 'keyword2'=>[
  56. 'value'=>$time
  57. ],
  58. ];
  59. (new \app\api\controller\Common())->sendWechatMessage($user_name['open_id'],'SDrPJvTOgm03PnQHibVlguD3lra3nK9pknojcMjSXq8',$data,'https://'.$_SERVER['HTTP_HOST'].'/h5/#/pages/xiaoxi/shenqing-me');
  60. }
  61. /**
  62. * 微信模板消息通知(访客到访)
  63. */
  64. public static function wxVisitorMessage($user_name,$nid,$time){
  65. $user_info = User::get(['id'=>$nid]);
  66. $data = [
  67. 'thing1'=>[
  68. 'value'=>$user_name
  69. ],
  70. 'time3'=>[
  71. 'value'=>$time
  72. ],
  73. ];
  74. (new \app\api\controller\Common())->sendWechatMessage($user_info['open_id'],'KOWDFd4MsuxROCPCLNZF5k5LHzM_-o-WoEI2NpfQYx0',$data,'http://'.$_SERVER['HTTP_HOST'].'/h5/#/pages/xiaoxi/look-me');
  75. }
  76. /**
  77. * 微信模板消息通知(喜欢我,解锁照片,解锁资料)$url_type(1:解锁照片/资料,2:喜欢)
  78. */
  79. public static function wxUnlockMessage($uid,$nid,$time,$appeal_type){
  80. $user_name = User::get(['id'=>$uid])['username'];
  81. $user_info = User::get(['id'=>$nid]);
  82. if($appeal_type == 1){ //喜欢我
  83. $appeal = '喜欢了你';
  84. }elseif ($appeal_type == 2){ //解锁照片
  85. $appeal = '解锁了你';
  86. }else{ //解锁资料
  87. $appeal = '解锁了你';
  88. }
  89. $data = [
  90. 'thing2'=>[
  91. 'value'=>$user_name
  92. ],
  93. 'time8'=>[
  94. 'value'=>$time
  95. ],
  96. 'phrase10'=>[
  97. 'value'=>$appeal
  98. ],
  99. ];
  100. $url = $appeal_type == 1?'/h5/#/pages/xiaoxi/like-me':'/h5/#/pages/xiaoxi/look-me';
  101. (new \app\api\controller\Common())->sendWechatMessage($user_info['open_id'],'VJNwruW2tQp4bG0K1gg_-HJ4vaougj6fELLED2OYcrI',$data,'http://'.$_SERVER['HTTP_HOST'].$url);
  102. }
  103. /**
  104. * 微信模板消息通知(申请通过、被拒、过期)
  105. */
  106. public static function wxApplyMessage($uid,$nid,$time,$appeal_type){
  107. $user_name = User::get(['id'=>$uid])['username'];
  108. $user_info = User::get(['id'=>$nid]);
  109. if($appeal_type == 1){ //通过
  110. $appeal = '已通过申请啦';
  111. }elseif ($appeal_type == 2){ //拒绝
  112. $appeal = '暂时不合适';
  113. }else{ //过期
  114. $appeal = '已经过期啦';
  115. }
  116. $data = [
  117. 'thing7'=>[
  118. 'value'=>$user_name
  119. ],
  120. 'time4'=>[
  121. 'value'=>$time
  122. ],
  123. 'thing3'=>[
  124. 'value'=>$appeal
  125. ],
  126. ];
  127. (new \app\api\controller\Common())->sendWechatMessage($user_info['open_id'],'bNR9STIj3_z7PwuXLNAEjGELj31DerERhXixAJqf3to',$data,'http://'.$_SERVER['HTTP_HOST'].'/h5/#/pages/xiaoxi/my-shenqing');
  128. }
  129. /**
  130. * 微信模板消息通知(申请认识)
  131. */
  132. public static function wxKnowMessage($uid,$nid,$time){
  133. $user_name = User::get(['id'=>$uid])['username'];
  134. $user_info = User::get(['id'=>$nid]);
  135. $data = [
  136. 'thing17'=>[
  137. 'value'=>$user_name
  138. ],
  139. 'time5'=>[
  140. 'value'=>$time
  141. ],
  142. 'thing9'=>[
  143. 'value'=>'想认识一下你'
  144. ],
  145. ];
  146. (new \app\api\controller\Common())->sendWechatMessage($user_info['open_id'],'rPRvrkJ7QYwGpANXf6sOU4YyrejhUh70ow7dSdCXxU8',$data,'http://'.$_SERVER['HTTP_HOST'].'/h5/#/pages/xiaoxi/look-me');
  147. }
  148. /**
  149. * 微信模板消息通知(头像,学历,工作审核通知)
  150. */
  151. public static function wxAuditMessage($uid,$type,$status){
  152. $open_id = User::get(['id'=>$uid])['open_id'];
  153. if($type == 1){ //头像
  154. $appeal = '头像';
  155. }elseif ($type == 2){ //拒绝
  156. $appeal = '学历';
  157. }else{ //过期
  158. $appeal = '工作';
  159. }
  160. $status_name = $status == 1?'审核通过':'审核驳回';
  161. $appeal .= '审核';
  162. $data = [
  163. 'thing2'=>[
  164. 'value'=>$appeal
  165. ],
  166. 'thing3'=>[
  167. 'value'=>$status_name
  168. ],
  169. ];
  170. (new \app\api\controller\Common())->sendWechatMessage($open_id,'Tfe62uA5N34evu_Z7jf-OE0NK6hJ6nFYTsZXG6yIqSY',$data,'http://'.$_SERVER['HTTP_HOST'].'/h5/#/pages/xiaoxi/system');
  171. }
  172. }