panda 5 months ago
parent
commit
1e8bec3e46

+ 93 - 0
application/api/controller/Examine.php

@@ -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('报名成功');
+    }
+
+}

+ 21 - 0
application/common/model/ExamineApplyModel.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace app\common\model;
+
+use think\Db;
+use think\Model;
+
+/**
+ * 群组
+ */
+class ExamineApplyModel extends Model
+{
+    // 表名
+    protected $name = 'examine_apply';
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+}

+ 40 - 0
application/common/model/ExamineModel.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace app\common\model;
+
+use think\Db;
+use think\Model;
+
+/**
+ * 群组
+ */
+class ExamineModel extends Model
+{
+    // 表名
+    protected $name = 'examine';
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    public function getImageAttr($value, $data)
+    {
+        return cdnurl($value);
+    }
+
+    public function getImagesAttr($value, $data)
+    {
+        $value = explode(',',$value);
+        foreach ($value as &$v){
+            $v = cdnurl($v);
+        }
+        return $value;
+    }
+
+    public function apply()
+    {
+        return $this->hasOne(ExamineApplyModel::class, 'examine_id', 'id');
+    }
+}