MessageController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\FrontController;
  4. use App\Models\MessageModels\Message;
  5. use App\Models\SysModels\Config;
  6. use App\Servers\Common\CommonServer;
  7. use App\Servers\Common\SmsServer;
  8. class MessageController extends FrontController
  9. {
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. }
  14. /**
  15. * 留言
  16. * @return \Illuminate\Http\JsonResponse
  17. */
  18. function saveMessage(){
  19. $name = CommonServer::creatServer()->filtrationStr('name');//留言名称
  20. $phone = CommonServer::creatServer()->filtrationStr('phone');//留言电话
  21. $content = CommonServer::creatServer()->filtrationStr('content');//留言内容
  22. if(empty($name) || empty($phone) || empty($content)){
  23. return $this->apiResponseError('请完整填写内容');
  24. }
  25. if(!CommonServer::creatServer()->verifyPhoneNumber($phone)){
  26. return $this->apiResponseError( '手机号不正确');
  27. }
  28. if (mb_strlen($name) > 20) return $this->apiResponseError( '昵称过长');
  29. if (mb_strlen($content) > 255) return $this->apiResponseError( '内容过长');
  30. $data = compact('name','phone','content');
  31. $res = Message::create($data);
  32. if($res){
  33. //发送短信通知
  34. $sms_phone = Config::where('key','sms_phone')->value('value');
  35. $sms_phone = array_filter(explode(',',$sms_phone));
  36. foreach ($sms_phone as $value){
  37. SmsServer::creatServer()->sendPayNotice($value);
  38. }
  39. return $this->apiResponseSuccess( '留言成功');
  40. }else{
  41. return $this->apiResponseError( '留言失败');
  42. }
  43. }
  44. }