123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- // +----------------------------------------------------------------------
- // | 文件说明:幻灯片
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Author: wuwu <15093565100@163.com>
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Date: 2017-5-25
- // +----------------------------------------------------------------------
- namespace api\activity\controller;
- use api\activity\model\ActivityJoinModel;
- use api\activity\model\ActivityModel;
- use api\activity\model\ActivitySiteJoinModel;
- use api\applet\model\UserModel;
- use cmf\controller\RestBaseController;
- class ActivityController extends RestBaseController
- {
- /**
- * 列表
- */
- public function index()
- {
- $param = $this->request->param();
- $page = empty($param['page']) ? 1 : $param['page'];
- $size = empty($param['size']) ? 10 : $param['size'];
- //搜索条件
- $where = [['status', '=', 2]];
- if (!empty($param['keyword'])) {
- $where[] = ['title', 'like', "%{$param['keyword']}%"];
- }
- if (!empty($param['user_id'])) {
- $where[] = ['user_id', '=', $param['user_id']];
- }
- $list = ActivityModel::where($where)->order('create_time desc')->page($page, $size)->select();
- //数据处理
- if (!$list->isEmpty()) {
- foreach ($list as $v) {
- $v['main_image'] = cmf_get_image_preview_url($v['main_image']);
- $v['status_text'] = ActivityModel::statusText($v);
- $v['start_time'] = date('Y-m-d H:i', $v['start_time']);
- $v['end_time'] = date('Y-m-d H:i', $v['end_time']);
- }
- }
- $this->success('成功', $list);
- }
- /**
- * 详情
- */
- public function detail()
- {
- $id = $this->request->post('id');
- $info = ActivityModel::get($id, ['review']);
- $info['main_image'] = cmf_get_image_preview_url($info['main_image']);
- $info['status_text'] = ActivityModel::statusText($info);
- $info['start_time'] = date('Y-m-d H:i', $info['start_time']);
- $info['end_time'] = date('Y-m-d H:i', $info['end_time']);
- $info['create_time'] = date('Y-m-d H:i', $info['create_time']);
- if (!empty($info['options'])) {
- $options = [];
- foreach ($info['options'] as $v) {
- $options[] = [
- 'url' => cmf_get_file_download_url($v['url']),
- 'name' => $v['name'],
- ];
- }
- $info['options'] = $options;
- }
- $this->success('成功', $info);
- }
- /**
- * 报名列表
- */
- public function joinList()
- {
- $param = $this->request->param();
- $page = empty($param['page']) ? 1 : $param['page'];
- $size = empty($param['size']) ? 10 : $param['size'];
- $user_id = $this->getUserId();
- $activityIds = ActivityJoinModel::where('user_id', '=', $user_id)
- ->order('create_time desc')
- ->page($page, $size)
- ->column('activity_id');
- $list = ActivityModel::where('id', 'in', $activityIds)->order('create_time desc')->select();
- //数据处理
- if (!$list->isEmpty()) {
- foreach ($list as $v) {
- $v['main_image'] = cmf_get_image_preview_url($v['main_image']);
- $v['status_text'] = ActivityModel::statusText($v);
- $v['start_time'] = date('Y-m-d H:i', $v['start_time']);
- $v['end_time'] = date('Y-m-d H:i', $v['end_time']);
- }
- }
- $this->success('成功', $list);
- }
- /**
- * 报名
- */
- public function join()
- {
- $activity_id = $this->request->param('id');
- $user_id = $this->getUserId();
- $user = UserModel::get($user_id);
- if (empty($user['user_name']) || empty($user['mobile'])) {
- $this->success('', ['code' => 1001, 'msg' => '请完善信息']);
- }
- $check = ActivityJoinModel::where('user_id', '=', $user_id)->where('activity_id', '=', $activity_id)->find();
- if (empty($check)) {
- //活动报名
- ActivityJoinModel::create([
- 'user_id' => $user_id,
- 'activity_id' => $activity_id,
- 'create_time' => time(),
- ]);
- $site_id = ActivityModel::where('id', $activity_id)->value('user_id');
- //站点报名记录
- $site_check = ActivitySiteJoinModel::where('user_id', '=', $user_id)->where('site_id', '=', $site_id)->find();
- if (empty($site_check)) {
- ActivitySiteJoinModel::create([
- 'user_id' => $user_id,
- 'site_id' => $site_id,
- 'create_time' => time(),
- ]);
- }
- $this->success('报名成功', ['msg' => '报名成功']);
- } else {
- $this->success('请勿重复报名', ['msg' => '请勿重复报名']);
- }
- }
- /**
- * 签到
- */
- public function signin()
- {
- $activity_id = $this->request->param('activity_id');
- $code = $this->request->param('code');
- //查找记录
- $activity = ActivityModel::get(['id' => $activity_id, 'signin_code' => $code]);
- if (empty($activity)) {
- $this->error('二维码有误!请重新确认');
- }
- //签到
- $user_id = $this->getUserId();
- $join = ActivityJoinModel::get(['user_id' => $user_id, 'activity_id' => $activity_id]);
- if (empty($join)) {
- $this->error('请先报名该活动!');
- }
- if ($join['status'] == 1) {
- $this->error('请勿重复签到!');
- }
- //增加积分
- if ($activity->score > 0) {
- $model = new \app\user\model\UserModel();
- $res = $model->changeScore($activity->score, "活动签到:{$activity->title}");
- if ($res['code'] == 0) {
- $this->error($res['msg']);
- }
- }
- //更改签到状态
- $join->status = 1;
- $join->save();
- $this->success('签到成功', ['msg' => '签到成功']);
- }
- }
|