Examine.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\api\controller;
  3. use addons\epay\library\Service;
  4. use app\common\controller\Api;
  5. use app\common\model\ExamineApplyModel;
  6. use app\common\model\ExamineModel;
  7. use app\common\model\PayOrderModel;
  8. use app\common\model\UniversityEventModel;
  9. use app\common\model\Wallet;
  10. use app\utils\CurlUtil;
  11. use app\utils\Service\Tencent\TencentIm;
  12. use think\Db;
  13. /**
  14. * 老年大学 活动板块
  15. */
  16. class Examine extends Api
  17. {
  18. protected $noNeedLogin = [''];
  19. protected $noNeedRight = ['*'];
  20. // 活动列表
  21. public function list()
  22. {
  23. $user_id = $this->auth->id;
  24. $list = ExamineModel::with([
  25. 'apply' => function ($query) use ($user_id) {
  26. $query->field('id,examine_id,user_id')->where('user_id', $user_id)->where('status', 1);
  27. }
  28. ])
  29. ->field('id,name,content')
  30. ->where('status', 1)
  31. ->order('weigh desc,id desc')
  32. ->autopage()
  33. ->select();
  34. foreach ($list as $k => $v) {
  35. $list[$k]['apply'] = !empty($v['apply']) ? 1 : 0;
  36. }
  37. return $this->success('success', $list);
  38. }
  39. public function apply()
  40. {
  41. $params = $this->request->param();
  42. if (empty($params['examine_id'])) {
  43. return $this->error('参数缺失');
  44. }
  45. if (empty($params['name'])) {
  46. return $this->error('报名信息姓名不能为空');
  47. }
  48. if (empty($params['phone'])) {
  49. return $this->error('报名信息手机号不能为空');
  50. }
  51. $user_id = $this->auth->id;
  52. $info = ExamineModel::with([
  53. 'apply' => function ($query) use ($user_id) {
  54. $query->field('id,examine_id,user_id')->where('user_id', $user_id)->where('status', 1);
  55. }
  56. ])
  57. ->field('id,name,content')
  58. ->where('id', $params['examine_id'])
  59. ->where('status', 1)
  60. ->find();
  61. if (!$info) {
  62. return $this->error('套餐不存在');
  63. }
  64. if (!empty($info['apply'])) {
  65. return $this->error('您已报过名了');
  66. }
  67. $nowTime = time();
  68. // 开始报名
  69. $data = [
  70. 'user_id' => $user_id,
  71. 'examine_id' => $params['examine_id'],
  72. 'order_no' => createUniqueNo('E', $user_id),
  73. 'name' => $params['name'],
  74. 'phone' => $params['phone'],
  75. 'status' => 1,
  76. 'create_time' => $nowTime
  77. ];
  78. Db::startTrans();
  79. $apply_id = Db::name('examine_apply')->insertGetId($data);
  80. if (!$apply_id) {
  81. Db::rollback();
  82. return $this->error('订单创建失败');
  83. }
  84. Db::commit();
  85. return $this->success('报名成功');
  86. }
  87. public function applyList()
  88. {
  89. $user_id = $this->auth->id;
  90. $query = ExamineApplyModel::with([
  91. 'examine' => function ($query) {
  92. $query->field(['id','name','content']);
  93. }
  94. ])->where('user_id',$user_id)->where('status',1)->order('id','desc')->autopage()->select();
  95. $this->success('success', $query);
  96. }
  97. }