1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?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($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('报名成功');
- }
- }
|