JoinModel.php 2.4 KB
<?php
/**
 * Created by PhpStorm.
 * auther: sgj
 * Date: 2019/2/28
 * Time: 18:29
 */

namespace api\index\model;


use think\Model;

class JoinModel extends Model
{
        public function findData($where){
            $data=$this->where($where)->order('id','desc')->find();
            return $data;
        }

    /**
     * 查询多条
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
      public function selectData($where){
          $data=$this->where($where)->select()->toArray();
          return $data;
      }

      public function getJoinData($activity_id){
          $where['j.activity_id']=$activity_id;
          $where['j.status']=['in','1,3'];
          $where['j.delete_time']=0;
          $info=$this->alias('j')
              ->join('cmf_volunteer v','v.user_id=j.user_id')
              ->where($where)
              //->fetchSql()
              ->select()
              ->toArray();
              //->toArray();
            //dump($info);
          return $info;
      }

    /**
     * @param $userId 用户参加活动id
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
      public function getUserJoin($userId){
          $where['j.user_id']=$userId;
          $where['j.status']=['in','1,3'];
          $where['j.delete_time']=0;
          $info=$this->alias('j')
              ->field('a.*,at.type_name,pp.*,a.id as id')
              ->join('cmf_activity a','a.id=j.activity_id')
              ->join('cmf_activity_type at','a.activity_type=at.id','LEFT')
              ->join('cmf_position_province pp','a.position_id=pp.id','LEFT')
              ->where($where)
              ->order('a.start_time','desc')
              ->group('a.id')
              ->select()
              ->toArray();

          foreach ($info as $k=>$v){
               $info[$k]['start_time_text']=date('Y-m-d',$v['start_time']);
               $info[$k]['end_time_text']=date('Y-m-d',$v['end_time']);
               $info[$k]['thumbnail']=cmf_get_image_url($v['thumbnail']);
          }
         // echo  $this->getLastSql();
          return $info;
      }
}