123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\api\controller;
- use addons\epay\library\Service;
- use app\common\controller\Api;
- use app\common\model\ExamineApplyModel;
- 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();
- $list = json_decode(json_encode($list),true);
- 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($params['name'])) {
- return $this->error('报名信息姓名不能为空');
- }
- if (empty($params['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('报名成功');
- }
- public function applyList()
- {
- $user_id = $this->auth->id;
- $query = ExamineApplyModel::with([
- 'examine' => function ($query) {
- $query->field(['id','name','content']);
- }
- ])->where('user_id',$user_id)->where('status',1)->order('id','desc')->autopage()->select();
- $this->success('success', $query);
- }
- }
|