Follow.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\api\model\service;
  3. use think\Model;
  4. class Follow extends Model
  5. {
  6. // 表名
  7. protected $name = 'service_follow';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. public static function getCount($where)
  14. {
  15. return self::where($where)->count();
  16. }
  17. /**
  18. * 更新状态
  19. * @param $data
  20. * @param $info
  21. * @return true
  22. */
  23. public static function updateFollow($data,$info)
  24. {
  25. if($info)
  26. {
  27. self::where(['id'=>$info['id']])->update(['state'=>$data['state'],'updatetime'=>time()]);
  28. }else{
  29. $data['createtime'] = time();
  30. $data['updatetime'] = time();
  31. self::create($data);
  32. }
  33. return true;
  34. }
  35. public static function getState($params)
  36. {
  37. $params['state'] = 1;
  38. return self::where($params)->value('state');
  39. }
  40. public static function getList($params)
  41. {
  42. $list = self::where(['user_id'=>$params['user_id'],'type'=>$params['type'],'state'=>1])->field('id,type,follow_id')->order('updatetime desc')->page($params['page'])->limit(10)->select();
  43. foreach ($list as $key=>$value)
  44. {
  45. switch ($value['type'])
  46. {
  47. case 0:
  48. $followInfo = Skill::getSkillInfo(['id'=>$value['follow_id'],'lng'=>$params['lng'],'lat'=>$params['lat']]);
  49. break;
  50. case 1:
  51. $followInfo = Goods::where(['id'=>$value['follow_id'],'status'=>'normal'])->field('id,name,image,price,tag_name,response_hour,salenums')->find();
  52. break;
  53. case 2:
  54. $followInfo = Shop::getShopInfo(['id'=>$value['follow_id'],'lng'=>$params['lng'],'lat'=>$params['lat']]);
  55. break;
  56. }
  57. if(!$followInfo)
  58. {
  59. unset($list[$key]);
  60. }else{
  61. $list[$key] = $followInfo;
  62. }
  63. }
  64. return array_values($list);
  65. }
  66. }