Examine.php 2.7 KB

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