OrderController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 思维定制
  5. * Date: 2018/9/5
  6. * Time: 18:03
  7. */
  8. namespace App\Http\Controllers\Web;
  9. use App\Models\MedicalOrderModel;
  10. use Illuminate\Support\Facades\Cache;
  11. use App\Models\MedicalSmsConfModel;
  12. use Illuminate\Http\Request;
  13. class OrderController extends Controller
  14. {
  15. public function index(Request $request){
  16. $conf['nationality'] = '民族';
  17. $conf['name'] = '姓名';
  18. $conf['native_place'] = '籍贯';
  19. $conf['email'] = '邮件';
  20. $conf['work'] = '工作';
  21. $conf['mobile'] = '电话';
  22. $conf['address'] = '通讯地址';
  23. $conf['verify'] = '验证码';
  24. if($request->method() == 'POST') {
  25. $data = $request->input();
  26. $code = Cache::get($data['mobile'].'post');
  27. foreach ($data as $key=>$val){
  28. if(empty($val)&&$key!='sample_type'&&$key!='sex'){
  29. $res['state'] = 0;
  30. $res['err'] = $conf[$key].'不能为空!';
  31. return $this->api($res);
  32. }
  33. }
  34. /*if($code !== $data['verify']){
  35. $res['state'] = 0;
  36. $res['err'] = '验证码错误!';
  37. return $this->api($res);
  38. }*/
  39. $check = MedicalOrderModel::where('mobile',$data['mobile'])->first();
  40. if($check&&!empty($check->pdf)){
  41. $res['state'] = 2;
  42. $res['err'] = '您已提交';
  43. $res['redirect_url'] = url('web/Index/post').'?id='.$check->id;
  44. $res['pdf'] = $check->pdf;
  45. }elseif($check&&empty($check->pdf)){
  46. $res['state'] = 1;
  47. $res['err'] = '您已提交,请耐心等待结果';
  48. $res['redirect_url'] = url('web/Index/post').'?id='.$check->id;
  49. }else{
  50. unset($data['verify']);
  51. $query = MedicalOrderModel::create($data);
  52. if($query){
  53. $res['state'] = 1;
  54. $res['err'] = '提交成功';
  55. $res['redirect_url'] = url('web/Index/post').'?id='.$query->id;
  56. }else{
  57. $res['state'] = 0;
  58. $res['err'] ='网络错误';
  59. }
  60. }
  61. return $this->api($res);
  62. }else{
  63. return view('web.order.index');
  64. }
  65. }
  66. public function post(Request $request){
  67. if($request->method() == 'POST'){
  68. $data = $request->input();
  69. dd($data);
  70. }
  71. return view('web.order.post');
  72. }
  73. /**
  74. ***聚合数据
  75. ***DATE:2015-05-25
  76. */
  77. public function smsJuHe(Request $request)
  78. {
  79. $data = $request->input();
  80. $conf = MedicalSmsConfModel::find(1);
  81. header('content-type:text/html;charset=utf-8');
  82. $sendUrl = 'http://v.juhe.cn/sms/send'; //短信接口的URL
  83. $num = rand(1000,9999);
  84. Cache::put($data['mobile'].'post',$num,10000);
  85. $smsConf = array(
  86. 'key' => $conf->apikey, //您申请的APPKEY
  87. 'mobile' => $data['mobile'], //接受短信的用户手机号码
  88. 'tpl_id' => $conf->temp_id, //您申请的短信模板ID,根据实际情况修改
  89. 'tpl_value' =>'#code#=1234&#company#='.$conf->sign //您设置的模板变量,根据实际情况修改
  90. );
  91. $content = $this->juhecurl($sendUrl,$smsConf,1); //请求发送短信
  92. //$content=false;
  93. if($content){
  94. $result = json_decode($content,true);
  95. $error_code = $result['error_code'];
  96. if($error_code == 0){
  97. //状态为0,说明短信发送成功
  98. $res['state'] = 1;
  99. }else{
  100. //状态非0,说明失败
  101. $msg = $result['reason'];
  102. $res['err'] = "短信发送失败(".$error_code."):".$msg;
  103. $res['state'] = 0;
  104. }
  105. }else{
  106. $res['state'] = 0;
  107. $res['err'] = '发送失败';
  108. }
  109. return $this->api($res);
  110. }
  111. /**
  112. * 请求接口返回内容
  113. * @param string $url [请求的URL地址]
  114. * @param string $params [请求的参数]
  115. * @param int $ipost [是否采用POST形式]
  116. * @return string
  117. */
  118. function juhecurl($url,$params=false,$ispost=0){
  119. $httpInfo = array();
  120. $ch = curl_init();
  121. curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
  122. curl_setopt( $ch, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22' );
  123. curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 30 );
  124. curl_setopt( $ch, CURLOPT_TIMEOUT , 30);
  125. curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
  126. if( $ispost )
  127. {
  128. curl_setopt( $ch , CURLOPT_POST , true );
  129. curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
  130. curl_setopt( $ch , CURLOPT_URL , $url );
  131. }
  132. else
  133. {
  134. if($params){
  135. curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
  136. }else{
  137. curl_setopt( $ch , CURLOPT_URL , $url);
  138. }
  139. }
  140. $response = curl_exec( $ch );
  141. if ($response === FALSE) {
  142. //echo "cURL Error: " . curl_error($ch);
  143. return false;
  144. }
  145. $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
  146. $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
  147. curl_close( $ch );
  148. return $response;
  149. }
  150. }