MerchantFollow.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\merchant;
  12. use app\wap\model\special\Lecturer;
  13. use traits\ModelTrait;
  14. use basic\ModelBasic;
  15. class MerchantFollow extends ModelBasic
  16. {
  17. use ModelTrait;
  18. /**用户关注 取消 讲师关注
  19. * @param $uid
  20. * @param $mer_id
  21. * @param $is_follow 0 =取消关注 1= 关注
  22. */
  23. public static function user_merchant_follow($uid, $mer_id, $is_follow = 0)
  24. {
  25. $data['is_follow'] = $is_follow;
  26. if (self::be(['uid' => $uid, 'mer_id' => $mer_id])) {
  27. if ($is_follow == 1) {
  28. $data['follow_time'] = time();
  29. } else {
  30. $data['unfollow_time'] = time();
  31. }
  32. return self::where(['uid' => $uid, 'mer_id' => $mer_id])->update($data);
  33. } else {
  34. $data['uid'] = $uid;
  35. $data['mer_id'] = $mer_id;
  36. $data['follow_time'] = time();
  37. return self::set($data);
  38. }
  39. }
  40. /**讲师关注列表
  41. * @param $uid
  42. * @param int $page
  43. * @param int $limit
  44. * @return array
  45. */
  46. public static function get_user_merchant_follow_list($uid, $page = 1, $limit = 20)
  47. {
  48. $data = self::alias('f')->where(['f.uid' => $uid, 'f.is_follow' => 1,'l.is_show' => 1, 'l.is_del' => 0])
  49. ->join('Lecturer l', 'f.mer_id=l.mer_id')
  50. ->where('l.mer_id','>',0)->page((int)$page, (int)$limit)
  51. ->order('f.follow_time desc')->field('f.uid,f.mer_id,f.is_follow,l.id,l.mer_id,l.is_show,l.is_del,l.lecturer_name,l.lecturer_head,l.label,l.introduction,l.study,l.curriculum')
  52. ->select();
  53. $data = count($data) > 0 ? $data->toArray() : [];
  54. return $data;
  55. }
  56. /**是否关注
  57. * @param $uid
  58. * @param $mer_id
  59. */
  60. public static function isFollow($uid, $mer_id)
  61. {
  62. $follow=self::where(['uid'=>$uid,'mer_id'=>$mer_id,'is_follow'=>1])->find();
  63. if($follow) return true;
  64. else return false;
  65. }
  66. }