Examine.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. $list = json_decode(json_encode($list),true);
  35. foreach ($list as $k => $v) {
  36. $list[$k]['apply'] = (!empty($v['apply']) ? 1 : 0);
  37. }
  38. return $this->success('success', $list);
  39. }
  40. public function apply()
  41. {
  42. $params = $this->request->param();
  43. if (empty($params['examine_id'])) {
  44. return $this->error('参数缺失');
  45. }
  46. if (empty($params['name'])) {
  47. return $this->error('报名信息姓名不能为空');
  48. }
  49. if (empty($params['phone'])) {
  50. return $this->error('报名信息手机号不能为空');
  51. }
  52. $user_id = $this->auth->id;
  53. $info = ExamineModel::with([
  54. 'apply' => function ($query) use ($user_id) {
  55. $query->field('id,examine_id,user_id')->where('user_id', $user_id)->where('status', 1);
  56. }
  57. ])
  58. ->field('id,name,content')
  59. ->where('id', $params['examine_id'])
  60. ->where('status', 1)
  61. ->find();
  62. if (!$info) {
  63. return $this->error('套餐不存在');
  64. }
  65. if (!empty($info['apply'])) {
  66. return $this->error('您已报过名了');
  67. }
  68. $nowTime = time();
  69. // 开始报名
  70. $data = [
  71. 'user_id' => $user_id,
  72. 'examine_id' => $params['examine_id'],
  73. 'order_no' => createUniqueNo('E', $user_id),
  74. 'name' => $params['name'],
  75. 'phone' => $params['phone'],
  76. 'status' => 1,
  77. 'create_time' => $nowTime
  78. ];
  79. Db::startTrans();
  80. $apply_id = Db::name('examine_apply')->insertGetId($data);
  81. if (!$apply_id) {
  82. Db::rollback();
  83. return $this->error('订单创建失败');
  84. }
  85. Db::commit();
  86. return $this->success('报名成功');
  87. }
  88. public function applyList()
  89. {
  90. $user_id = $this->auth->id;
  91. $query = ExamineApplyModel::with([
  92. 'examine' => function ($query) {
  93. $query->field(['id','name','content']);
  94. }
  95. ])->where('user_id',$user_id)->where('status',1)->order('id','desc')->autopage()->select();
  96. $this->success('success', $query);
  97. }
  98. }