WillController.class.php 4.2 KB
<?php
/**
 * Created by PhpStorm.
 * User: 29925
 * Date: 2018/4/9
 * Time: 9:33
 */

namespace Portal\Controller;

use Common\Controller\HomebaseController;

class WillController extends HomebaseController {

    protected $posts_model;

    function _initialize() {
        parent::_initialize();
        $this->posts_model = D("Portal/Posts");
        $this->will_mission_model = D("Common/WillMission");
        $this->will_events_model = D("Common/WillEvents");
        $this->will_produce_model = D("Common/WillProduce");
    }

    // 入会说明
    public function explain() {
        $post=$this->posts_model->where(array("id=10"))->find();
        $smeta = json_decode($post['smeta'], true);
        $post['thumb'] = $smeta['thumb'];
        $this->assign($post);
        $this->display();
    }

    // 任务发布列表
    public function mission_list() {
        $this->assign('list', $this->will_mission_model->getList());
        $this->display();
    }

    // 任务发布详情
    public function mission_detail() {
        $id = I("get.id",0,'intval');

        $this->assign($this->will_mission_model->getInfo($id));
        $this->display();
    }

    // 近期活动列表
    public function events_list() {
        $this->assign('list', $this->will_events_model->getList());
        $this->display();
    }

    // 近期活动详情
    public function events_detail() {
        $id = I("get.id",0,'intval');

        $this->assign($this->will_events_model->getInfo($id));
        $this->display();
    }

    // 双创项目列表
    public function produce_list() {
        $this->assign('list', $this->will_produce_model->getList());
        $this->display();
    }

    // 双创项目详情
    public function produce_detail() {
        $id = I("get.id",0,'intval');

        $this->assign($this->will_produce_model->getInfo($id));
        $this->display();
    }

    // 入会申请提交
    public function submit() {
        if(IS_AJAX) {
            $post =I('post.');
            $user_id = $post['user_id'] = 1;
//            $user_id = $post['user_id'] = sp_get_current_userid();
//            if(!$user_id) {
//                $this->ajaxReturn(array('status'=>false,'msg'=>'用户未登录'));
//            }
            $post['images'] = implode(',',I('post.images'));
            $post['ctime'] = $post['utime'] = time();
            $will_produce_apply_model = D('Common/WillProduceApply');
            if(!$will_produce_apply_model->create($post)) {
                $this->ajaxReturn(array('status'=>false,'msg'=>$will_produce_apply_model->getError()));
            }
            if(count(I('post.images'))<3 || count(I('post.images'))>5) {
                $this->ajaxReturn(array('status'=>false,'msg'=>'图片数量不符'));
            }
            $will_id = $will_produce_apply_model->add($post);
            if(!$will_id) {
                $this->ajaxReturn(array('status'=>false,'msg'=>'提交失败'));
            }
            $this->ajaxReturn(array('status'=>true,'msg'=>'提交成功','data'=>$will_id));
        } else {
            $this->error('非法操作');
        }
    }

    //上传图片
    public function personalUpload() {
        if(IS_POST){
            list($status, $info, $link, $attachmentId) = $this->uploadCommon('image', C('UPLOAD_MATERIAL_IMAGE_MAX_SIZE'), 'personal', false);
            if ($status) {
                echo json_encode(array('status' => true, 'data' => $info, 'file'=>sp_get_image_preview_url($info)));exit;
            } else {
                echo json_encode(array('status' => false, 'msg'=>$info));exit;
            }
        } else {
            $this->error('非法操作');
        }
    }

    //上传附件
    public function personalUploadAtt() {
        if(IS_POST){
            list($status, $info, $link, $attachmentId) = $this->uploadCommon('file', C('UPLOAD_MAX_SIZE'), 'file', false);
            if ($status) {
                echo json_encode(array('status' => true, 'data' => $info, 'file'=>sp_get_image_preview_url($info)));exit;
            } else {
                echo json_encode(array('status' => false, 'msg'=>$info));exit;
            }
        } else {
            $this->error('非法操作');
        }
    }
}