Trylesson.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 试课
  7. */
  8. class Trylesson extends Api
  9. {
  10. // 无需登录的接口,*表示全部
  11. protected $noNeedLogin = [];
  12. // 无需鉴权的接口,*表示全部
  13. protected $noNeedRight = ['*'];
  14. public function lists(){
  15. $list = Db::name('trylesson')->where('is_show',1)->order('weigh desc')->autopage()->select();
  16. $list = list_domain_image($list,['image']);
  17. $list = $this->list_lang($list,['name','content']);
  18. $this->success(1,$list);
  19. }
  20. public function info(){
  21. $id = input('id');
  22. $info = Db::name('trylesson')->where('id',$id)->find();
  23. $info = info_domain_image($info,['image']);
  24. $info = $this->info_lang($info,['name','content']);
  25. $info['map_image'] = localpath_to_netpath(config('site.index_bottom_image'));
  26. $info['public_store_address'] = config('site.public_store_address');
  27. $info['trylesson_cancel_text'] = config('site.trylesson_cancel_text');
  28. $this->success(1,$info);
  29. }
  30. public function apply(){
  31. $id = input('id',0);
  32. $info = Db::name('trylesson')->where('id',$id)->where('is_show',1)->find();
  33. if(empty($info)){
  34. $this->error('该试课已下架');
  35. }
  36. $field = ['firstname','lastname','mobile','email','height','age','weight','address','health','emergency','comefrom','is_first'];
  37. $data = request_post_hub($field);
  38. $sysdata = [
  39. 'order_no' => createUniqueNo('T',$this->auth->id),
  40. 'user_id' => $this->auth->id,
  41. 'trylesson_id' => $id,
  42. 'order_amount' => $info['price'],
  43. 'order_status' => 0,
  44. 'createtime' => time(),
  45. ];
  46. $data = array_merge($data,$sysdata);
  47. $id = Db::name('trylesson_order')->insertGetId($data);
  48. $this->success('提交成功',$id);
  49. }
  50. }