OrderController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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['msg'] = '您已提交';
  43. $res['redirect_url'] = url('web/Index/post',array('id'=>$check->id));
  44. $res['pdf'] = $check->pdf;
  45. }
  46. unset($data['verify']);
  47. $query = MedicalOrderModel::create($data);
  48. if($query){
  49. $res['state'] = 1;
  50. $res['msg'] = '提交成功';
  51. $res['redirect_url'] = url('web/Index/post',array('id'=>$query->id));
  52. }
  53. }else{
  54. return view('web.order.index');
  55. }
  56. }
  57. public function post(){
  58. return view('web.order.post');
  59. }
  60. /**
  61. ***聚合数据
  62. ***DATE:2015-05-25
  63. */
  64. public function smsJuHe(Request $request)
  65. {
  66. $data = $request->input();
  67. $conf = MedicalSmsConfModel::find(1);
  68. header('content-type:text/html;charset=utf-8');
  69. $sendUrl = 'http://v.juhe.cn/sms/send'; //短信接口的URL
  70. $num = rand(1000,9999);
  71. Cache::put($data['mobile'].'post',$num,10000);
  72. $smsConf = array(
  73. 'key' => $conf->apikey, //您申请的APPKEY
  74. 'mobile' => $data['mobile'], //接受短信的用户手机号码
  75. 'tpl_id' => $conf->temp_id, //您申请的短信模板ID,根据实际情况修改
  76. 'tpl_value' =>'#code#=1234&#company#='.$conf->sign //您设置的模板变量,根据实际情况修改
  77. );
  78. $content = $this->juhecurl($sendUrl,$smsConf,1); //请求发送短信
  79. //$content=false;
  80. if($content){
  81. $result = json_decode($content,true);
  82. $error_code = $result['error_code'];
  83. if($error_code == 0){
  84. //状态为0,说明短信发送成功
  85. $res['state'] = 1;
  86. }else{
  87. //状态非0,说明失败
  88. $msg = $result['reason'];
  89. $res['err'] = "短信发送失败(".$error_code."):".$msg;
  90. $res['state'] = 0;
  91. }
  92. }else{
  93. $res['state'] = 0;
  94. $res['err'] = '发送失败';
  95. }
  96. return $this->api($res);
  97. }
  98. /**
  99. * 请求接口返回内容
  100. * @param string $url [请求的URL地址]
  101. * @param string $params [请求的参数]
  102. * @param int $ipost [是否采用POST形式]
  103. * @return string
  104. */
  105. function juhecurl($url,$params=false,$ispost=0){
  106. $httpInfo = array();
  107. $ch = curl_init();
  108. curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
  109. 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' );
  110. curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 30 );
  111. curl_setopt( $ch, CURLOPT_TIMEOUT , 30);
  112. curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
  113. if( $ispost )
  114. {
  115. curl_setopt( $ch , CURLOPT_POST , true );
  116. curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
  117. curl_setopt( $ch , CURLOPT_URL , $url );
  118. }
  119. else
  120. {
  121. if($params){
  122. curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
  123. }else{
  124. curl_setopt( $ch , CURLOPT_URL , $url);
  125. }
  126. }
  127. $response = curl_exec( $ch );
  128. if ($response === FALSE) {
  129. //echo "cURL Error: " . curl_error($ch);
  130. return false;
  131. }
  132. $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
  133. $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
  134. curl_close( $ch );
  135. return $response;
  136. }
  137. }