Forráskód Böngészése

老年大学活动板块数据接口

panda 5 hónapja
szülő
commit
5640d430c4

+ 46 - 0
application/api/controller/UniversityEvent.php

@@ -3,7 +3,9 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
+use app\common\model\UniversityEventModel;
 use app\utils\Service\Tencent\TencentIm;
+use think\Db;
 
 /**
  * 老年大学 活动板块
@@ -13,9 +15,53 @@ class UniversityEvent extends Api
     protected $noNeedLogin = [''];
     protected $noNeedRight = ['*'];
 
+    // 活动列表
     public function list()
     {
+        $user_id = $this->auth->id;
+        $list = UniversityEventModel::with([
+            'apply' => function ($query) use ($user_id) {
+                $query->field('id,event_id,user_id')->where('user_id', $user_id)->where('status', 1);
+            }
+        ])
+            ->field('id,name,price,image,start_apply_time,end_apply_time,start_time,address')
+            ->where('status', 1)
+            ->order('id desc')
+            ->autopage()
+            ->select();
+        foreach ($list as $k => $v) {
+            $list[$k]['start_apply_time'] = date('Y-m-d H:i', $v['start_apply_time']);
+            $list[$k]['end_apply_time'] = date('Y-m-d H:i', $v['end_apply_time']);
+            $list[$k]['start_time'] = date('Y-m-d H:i', $v['start_time']);
+            $list[$k]['apply'] = !empty($v['apply']) ? 1 : 0;
+        }
+        return $this->success('success',$list);
+    }
+
+    // 活动详情
+    public function info()
+    {
+        $params = $this->request->param();
+        if (empty($params['event_id'])){
+            return $this->error('参数缺失');
+        }
+        $user_id = $this->auth->id;
 
+        $info = UniversityEventModel::with([
+            'apply' => function ($query) use ($user_id) {
+                $query->field('id,event_id,user_id')->where('user_id', $user_id)->where('status', 1);
+            }
+        ])
+            ->field('id,name,price,image,images,start_apply_time,end_apply_time,start_time,address,content')
+            ->where('id', $params['event_id'])
+            ->where('status', 1)
+            ->order('id desc')
+            ->find();
+        $info['start_apply_time'] = date('Y-m-d H:i', $info['start_apply_time']);
+        $info['end_apply_time'] = date('Y-m-d H:i', $info['end_apply_time']);
+        $info['start_time'] = date('Y-m-d H:i', $info['start_time']);
+        $info['apply'] = !empty($info['apply']) ? 1 : 0;
+        return $this->success('success',$info);
     }
 
 

+ 27 - 0
application/common/model/UniversityEventApplyModel.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\common\model;
+
+use think\Db;
+use think\Model;
+
+/**
+ * 群组
+ */
+class UniversityEventApplyModel extends Model
+{
+    // 表名
+    protected $name = 'university_event_apply';
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+
+    public function user()
+    {
+        return $this->hasOne(UserModel::class, 'id', 'user_id');
+    }
+}

+ 40 - 0
application/common/model/UniversityEventModel.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace app\common\model;
+
+use think\Db;
+use think\Model;
+
+/**
+ * 群组
+ */
+class UniversityEventModel extends Model
+{
+    // 表名
+    protected $name = 'university_event';
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    public function getImageAttr($value, $data)
+    {
+        return cdnurl($value);
+    }
+
+    public function getImagesAttr($value, $data)
+    {
+        $value = explode(',',$value);
+        foreach ($value as &$v){
+            $v = cdnurl($v);
+        }
+        return $value;
+    }
+
+    public function apply()
+    {
+        return $this->hasOne(UniversityEventApplyModel::class, 'event_id', 'id');
+    }
+}

+ 97 - 0
application/common/model/UserModel.php

@@ -0,0 +1,97 @@
+<?php
+
+namespace app\common\model;
+
+use app\utils\CurlUtil;
+use think\Db;
+use think\Model;
+
+/**
+ * 动态评论
+ */
+class UserModel extends Model
+{
+    // 表名
+    protected $name = 'user';
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    /**
+     * 获取头像
+     * @param string $value
+     * @param array  $data
+     * @return string
+     */
+    public function getAvatarAttr($value, $data)
+    {
+        if (!$value) {
+            //如果不需要启用首字母头像,请使用
+            $value = CurlUtil::getHttp('/assets/img/avatar.png');
+//            $value = letter_avatar($data['nickname']);
+        }else{
+            $value = cdnurl($value);
+        }
+        return $value;
+    }
+
+    public static function getInfoById($id)
+    {
+        $info = self::where('id', $id)->find();
+        unset(
+            $info['username'],
+            $info['password'],
+            $info['salt'],
+            $info['successions'],
+            $info['maxsuccessions'],
+            $info['prevtime'],
+            $info['loginip'],
+            $info['loginfailure'],
+            $info['joinip'],
+            $info['jointime'],
+            $info['updatetime'],
+        );
+        return $info;
+    }
+
+    public static function getInfoByUserNo($user_no)
+    {
+        $info = self::where('user_no', $user_no)->find();
+        unset(
+            $info['username'],
+            $info['password'],
+            $info['salt'],
+            $info['successions'],
+            $info['maxsuccessions'],
+            $info['prevtime'],
+            $info['loginip'],
+            $info['loginfailure'],
+            $info['joinip'],
+            $info['jointime'],
+            $info['updatetime'],
+        );
+        return $info;
+    }
+
+    public static function getInfoByChatId($chat_id)
+    {
+        $info = self::where('chat_id', $chat_id)->find();
+        unset(
+            $info['username'],
+            $info['password'],
+            $info['salt'],
+            $info['successions'],
+            $info['maxsuccessions'],
+            $info['prevtime'],
+            $info['loginip'],
+            $info['loginfailure'],
+            $info['joinip'],
+            $info['jointime'],
+            $info['updatetime'],
+        );
+        return $info;
+    }
+}