123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- namespace app\api\controller;
- use addons\epay\library\Service;
- use app\common\controller\Api;
- use app\common\model\PayOrderModel;
- use app\common\model\UniversityEventApplyModel;
- use app\common\model\UniversityEventModel;
- use app\common\model\Wallet;
- use app\utils\CurlUtil;
- use app\utils\Service\Tencent\TencentIm;
- use think\Db;
- 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', $info['start_apply_time']);
- $info['end_apply_time'] = date('Y-m-d', $info['end_apply_time']);
- $info['start_time'] = date('Y-m-d', $info['start_time']);
- $info['apply'] = !empty($info['apply']) ? 1 : 0;
- return $this->success('success', $info);
- }
- public function apply()
- {
- $params = $this->request->param();
- if (empty($params['event_id'])) {
- return $this->error('参数缺失');
- }
- if (empty($params['apply_list'])) {
- return $this->error('请提交报名信息');
- }
- foreach ($params['apply_list'] as $k => $v) {
- if (empty($v['name'])) {
- return $this->error('报名信息姓名不能为空');
- }
- if (empty($v['phone'])) {
- return $this->error('报名信息手机号不能为空');
- }
- if (empty($v['sex'])) {
- return $this->error('报名信息性别不能为空');
- }
- if (empty($v['age'])) {
- 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();
- if (!$info) {
- return $this->error('活动不存在');
- }
- if (!empty($info['apply'])) {
- return $this->error('您已报过名了');
- }
- $nowTime = time();
- if ($info['start_apply_time'] > $nowTime) {
- return $this->error('报名未开始');
- }
- if ($info['end_apply_time'] < $nowTime) {
- return $this->error('报名已结束');
- }
-
- $num = count($params['apply_list']);
- $data = [
- 'user_id' => $user_id,
- 'event_id' => $params['event_id'],
- 'order_no' => createUniqueNo('E', $user_id),
- 'pay_amount' => bcmul($info['price'], $num, 2),
- 'status' => 1,
- 'create_time' => $nowTime
- ];
- Db::startTrans();
- $apply_id = Db::name('university_event_apply')->insertGetId($data);
- if (!$apply_id) {
- Db::rollback();
- return $this->error('订单创建失败');
- }
- $apply_info = [];
- foreach ($params['apply_list'] as $k => $v) {
- $apply_info[] = [
- 'user_id' => $user_id,
- 'event_id' => $params['event_id'],
- 'order_id' => $apply_id,
- 'order_no' => $data['order_no'],
- 'name' => $v['name'],
- 'phone' => $v['phone'],
- 'sex' => $v['sex'],
- 'age' => $v['age'],
- ];
- }
- if (!Db::name('university_event_apply_info')->insertAll($apply_info)) {
- Db::rollback();
- return $this->error('订单创建失败');
- }
- Db::commit();
- return $this->success('报名成功');
- }
- public function applyList()
- {
- $user_id = $this->auth->id;
- $query = UniversityEventApplyModel::with([
- 'events' => function ($query) {
- $query->field(['id','name','image']);
- }
- ])->where('user_id',$user_id)->where('status',1)->order('id','desc')->autopage()->select();
- $this->success('success', $query);
- }
- }
|