1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\FrontController;
- use App\Models\MessageModels\Message;
- use App\Models\SysModels\Config;
- use App\Servers\Common\CommonServer;
- use App\Servers\Common\SmsServer;
- class MessageController extends FrontController
- {
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * 留言
- * @return \Illuminate\Http\JsonResponse
- */
- function saveMessage(){
- $name = CommonServer::creatServer()->filtrationStr('name');//留言名称
- $phone = CommonServer::creatServer()->filtrationStr('phone');//留言电话
- $content = CommonServer::creatServer()->filtrationStr('content');//留言内容
- if(empty($name) || empty($phone) || empty($content)){
- return $this->apiResponseError('请完整填写内容');
- }
- if(!CommonServer::creatServer()->verifyPhoneNumber($phone)){
- return $this->apiResponseError( '手机号不正确');
- }
- if (mb_strlen($name) > 20) return $this->apiResponseError( '昵称过长');
- if (mb_strlen($content) > 255) return $this->apiResponseError( '内容过长');
- $data = compact('name','phone','content');
- $res = Message::create($data);
- if($res){
- //发送短信通知
- $sms_phone = Config::where('key','sms_phone')->value('value');
- $sms_phone = array_filter(explode(',',$sms_phone));
- foreach ($sms_phone as $value){
- SmsServer::creatServer()->sendPayNotice($value);
- }
- return $this->apiResponseSuccess( '留言成功');
- }else{
- return $this->apiResponseError( '留言失败');
- }
- }
- }
|