|
@@ -0,0 +1,93 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use addons\epay\library\Service;
|
|
|
+use app\common\controller\Api;
|
|
|
+use app\common\model\ExamineModel;
|
|
|
+use app\common\model\PayOrderModel;
|
|
|
+use app\common\model\UniversityEventModel;
|
|
|
+use app\common\model\Wallet;
|
|
|
+use app\utils\CurlUtil;
|
|
|
+use app\utils\Service\Tencent\TencentIm;
|
|
|
+use think\Db;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 老年大学 活动板块
|
|
|
+ */
|
|
|
+class Examine extends Api
|
|
|
+{
|
|
|
+ protected $noNeedLogin = [''];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+ // 活动列表
|
|
|
+ public function list()
|
|
|
+ {
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+ $list = ExamineModel::with([
|
|
|
+ 'apply' => function ($query) use ($user_id) {
|
|
|
+ $query->field('id,examine_id,user_id')->where('user_id', $user_id)->where('status', 1);
|
|
|
+ }
|
|
|
+ ])
|
|
|
+ ->field('id,name,content')
|
|
|
+ ->where('status', 1)
|
|
|
+ ->order('weigh desc,id desc')
|
|
|
+ ->autopage()
|
|
|
+ ->select();
|
|
|
+ foreach ($list as $k => $v) {
|
|
|
+ $list[$k]['apply'] = !empty($v['apply']) ? 1 : 0;
|
|
|
+ }
|
|
|
+ return $this->success('success', $list);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function apply()
|
|
|
+ {
|
|
|
+ $params = $this->request->param();
|
|
|
+ if (empty($params['examine_id'])) {
|
|
|
+ return $this->error('参数缺失');
|
|
|
+ }
|
|
|
+ if (empty($v['name'])) {
|
|
|
+ return $this->error('报名信息姓名不能为空');
|
|
|
+ }
|
|
|
+ if (empty($v['phone'])) {
|
|
|
+ return $this->error('报名信息手机号不能为空');
|
|
|
+ }
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+ $info = ExamineModel::with([
|
|
|
+ 'apply' => function ($query) use ($user_id) {
|
|
|
+ $query->field('id,examine_id,user_id')->where('user_id', $user_id)->where('status', 1);
|
|
|
+ }
|
|
|
+ ])
|
|
|
+ ->field('id,name,content')
|
|
|
+ ->where('id', $params['examine_id'])
|
|
|
+ ->where('status', 1)
|
|
|
+ ->find();
|
|
|
+ if (!$info) {
|
|
|
+ return $this->error('套餐不存在');
|
|
|
+ }
|
|
|
+ if (!empty($info['apply'])) {
|
|
|
+ return $this->error('您已报过名了');
|
|
|
+ }
|
|
|
+ $nowTime = time();
|
|
|
+ // 开始报名
|
|
|
+ $data = [
|
|
|
+ 'user_id' => $user_id,
|
|
|
+ 'examine_id' => $params['examine_id'],
|
|
|
+ 'order_no' => createUniqueNo('E', $user_id),
|
|
|
+ 'name' => $params['name'],
|
|
|
+ 'phone' => $params['phone'],
|
|
|
+ 'status' => 1,
|
|
|
+ 'create_time' => $nowTime
|
|
|
+ ];
|
|
|
+ Db::startTrans();
|
|
|
+ $apply_id = Db::name('examine_apply')->insertGetId($data);
|
|
|
+ if (!$apply_id) {
|
|
|
+ Db::rollback();
|
|
|
+ return $this->error('订单创建失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ return $this->success('报名成功');
|
|
|
+ }
|
|
|
+
|
|
|
+}
|