shawdonH 2 月之前
父节点
当前提交
6a0d27ee8e

+ 15 - 12
.env.bjcy

@@ -2,23 +2,23 @@ APP_NAME=cydsyy_produce
 APP_ENV=cydsyy
 APP_KEY=base64:cW0zUlkY/ex0w7M2bkHKaEHs3flBoe0fCb0Jvk/LPuc=
 APP_DEBUG=true
-APP_URL=http://cydsyy-api.qingerai.com/
+APP_URL=http://bjcj.com/
 
 LOG_CHANNEL=daily
 
+# DB_CONNECTION=mysql
+# DB_HOST=127.0.0.1
+# DB_PORT=3306
+# DB_DATABASE=cydsyy
+# DB_USERNAME=root
+# DB_PASSWORD=root
+
 DB_CONNECTION=mysql
-DB_HOST=127.0.0.1
+DB_HOST=116.205.137.158
 DB_PORT=3306
-DB_DATABASE=cydsyy
-DB_USERNAME=root
-DB_PASSWORD=root
-
-#DB_CONNECTION=mysql
-#DB_HOST=120.46.162.88
-#DB_PORT=3306
-#DB_DATABASE=cydsyy
-#DB_USERNAME=cydsyy
-#DB_PASSWORD=5mkBa8CxnJ562mBk
+DB_DATABASE=bj_cyzxy
+DB_USERNAME=bj_cyzxy
+DB_PASSWORD=wPEXGmibzyJySpmm
 
 BROADCAST_DRIVER=log
 CACHE_DRIVER=file
@@ -107,3 +107,6 @@ REMOTE_SSO_APPID='iog+hayCB57Kuo4lyuKWZQ=='
 REMOTE_SSO_SECRET='5wKrVVAbUlZ1nuPMPGXEar3JVnKgQEPu'
 REMOTE_SSO_URL='https://bjcy-visit-sso.qingerai.com'
 
+WG_MAP_URL='https://bjcy-psy.qingerai.com/'
+WG_MAP_APPID='vDC3mzAC7OytTDhmrkb8ww=='
+WG_MAP_SECRET='qSaz3c8qBXyNz3De290aaimu3r7kdZT9'

+ 187 - 0
app/Http/Controllers/Api/V1/FourActivityController.php

@@ -0,0 +1,187 @@
+<?php
+
+namespace App\Http\Controllers\Api\V1;
+
+use App\Http\Controllers\Controller;
+use App\Models\FourActivity;
+use Encore\Admin\Facades\Admin;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Redis;
+
+
+class FourActivityController extends Controller
+{
+    public function loginOrRegister (Request $request) 
+    {
+        $signData = $request->all();
+
+        $user = Admin::user();
+        $checkUserData = $user;
+        try {
+            DB::beginTransaction();
+            $plaintext = "";
+            $defaultPassword = "";
+            if (!empty($checkUserData)){
+                $plaintext = "{$checkUserData->username}@123456";
+                $defaultPassword = bcrypt($plaintext);
+            }
+            if (empty($checkUserData)){
+                
+                $userAvatar = config('admin.default_avatar');
+                $userModelClass = config('admin.database.users_model');
+                $userModel = new $userModelClass();
+                $name = $signData["username"] ?? "";//名称
+                $userName="mp_".$signData["username"] ?? "";//登录账号
+                $plaintext = "{$userName}@123456";
+                $defaultPassword = bcrypt($plaintext);
+                $checkUserData = $userModel->create(array(
+                    "username"=>$userName,
+                    "password"=>$defaultPassword,
+                    "name"=>$name,
+                    "avatar"=>null,
+                ));
+                if (empty($checkUserData)){
+                    throw new \RuntimeException("新增用户信息失败");
+                }
+                DB::table($userModel::query()->getModel()->getTable())->where(
+                    array("id"=>$checkUserData->id)
+                )->update(array(
+                    "third_openid"=>$signData["open_id"]
+                ));
+                DB::commit();
+                Admin::guard()->login(
+                    $checkUserData
+                );
+                $key = "RemoteSso:".$_SERVER['HTTP_HOST'].":".$checkUserData->id;
+                Redis::SET($key, true);
+            }
+            return [
+                'code'=>200,
+                'data'=>[
+                    'user' => $checkUserData,
+                    'doc' => [
+                        'service_document' => 'https://cydsyy-api.qingerai.com/vendor/excel/附件:2024年朝阳区精神卫生特色服务项目申报书.doc',
+                        'task_document' => 'https://cydsyy-api.qingerai.com/vendor/excel/附件2特色项目任务书.doc',
+                        'report_document' => 'https://cydsyy-api.qingerai.com/vendor/excel/附件3:朝阳区特色项目结题报告书.doc',
+                        'receipt_document' => 'https://cydsyy-api.qingerai.com/vendor/excel/回执单.xlsx'
+                    ],
+                    'config' => [
+                        'type_map' => FourActivity::TYPE_MAP,
+                        'activities_type_map' => FourActivity::ACTIVITIES_TYPE_MAP,
+                        'audience_crowd_map' => FourActivity::AUDIENCE_CROWD_MAP,
+                        'mode_map' => FourActivity::MODE_MAP,
+                        
+                    ]
+                ],
+                'msg' => 'success'
+                
+            ];
+        }catch (\Exception $exception){
+            echo $exception->getMessage();
+            DB::rollBack();
+            return ["code" => 400, 'data' => "", "msg" => $exception->getMessage()];
+        }
+    
+    }
+   
+    public function report(Request $request)
+    {
+        $type = $request->input('type');
+        if(!$type){
+            return [
+                'code'=>400,
+                'msg'=>'type参数不能为空'
+            ];
+        }
+        $validate = new \App\Validate\FourActivityValidate();
+        $validateResult = $validate->scene($type)->check($request->all());
+        if(!$validateResult) {
+            return [
+                'code'=>400,
+                'msg'=>$validate->getError()
+            ];
+        }
+        $data = $request->all();
+        $data['creator'] = Admin::user()->id;
+        $model = new FourActivity();
+        if($model->fill($data)->save()){
+            return [
+                'code'=>200,
+                'data'=>$model,
+                'msg'=>'success'
+            ];
+        }else{
+            return [
+                'code'=>400,
+                'data'=>"",
+                'msg'=>'error'
+            ];
+        }
+    }
+
+      /**
+     * 单个文件上传
+     * @param Request $request
+     * @return \Illuminate\Http\JsonResponse
+     */
+    public function upload(Request $request)
+    {
+        $path = $this->_simpleUpload('file', 'activity', $request);
+        $currentData = current($path);
+        $data = array(
+            "path"=>$currentData["path"],
+            "url"=>url($currentData["path"]),
+            "name"=>$currentData["name"]
+        );
+        return ['code' => 200, 'data' =>$data, 'msg' => 'success'];
+    }
+
+    /**
+     * 多个文件上传
+     * @param Request $request
+     * @return \Illuminate\Http\JsonResponse
+     */
+    public function uploadMultiple(Request $request)
+    {
+        $paths = $this->_simpleUpload('file', 'avatar', $request);
+        $result = array();
+        foreach ($paths as $val){
+            $result[] = array(
+                'path' => $val["path"],
+                'url' => url($val["path"]),
+                'name'=>$val["name"]
+            );
+        }
+        return ['code' => 200, 'data' =>$result, 'msg' => 'success'];
+    }
+    /**
+     * 上传文件
+     * @param string $name 上传文件名称
+     * @param string $cate 上传文件类型
+     * @param Request $request 请求数据
+     * @return array
+     */
+    private function _simpleUpload ($name, $cate = 'ccommon', Request $request)
+    {
+        $path = '/uploads/'.$cate.'/'.date('Y-m-d');
+        $result = array();
+        $file = $request->file($name);
+        if (is_array($file)){
+            foreach ($file as $val){
+                $result[] = array(
+                    "path"=>$val->store($path),
+                    "name"=>$val->getFilename()
+                );
+            }
+        }else{
+            $result[] = array(
+                "path"=>$file->store($path),
+                "name"=>$file->getFilename()
+            );
+        }
+        return $result;
+    }
+
+
+}

+ 6 - 3
app/Http/Controllers/Api/V1/Mentality/DrillController.php

@@ -106,17 +106,20 @@ class DrillController extends BaseController
      */
     public function playSubject(int $id)
     {
+        $object_id = MentalityDrillsSubject::query()->find($id)->mentality_drills_id;
+
         $record = [
             'uid'       => $this->auth(),
             'column'    => BrowseRecord::COLUMN_4,
-            'object_id' => $id,
-            'repeat'    => 'uid:'.$this->auth().' column:'.BrowseRecord::COLUMN_4.' object_id:'.$id
+            'subject_id' => $id,
+            'object_id' => $object_id,
+            'repeat'    => 'uid:'.$this->auth().' column:'.BrowseRecord::COLUMN_4.' object_id:'.$object_id
         ];
         //加入浏览记录
         try {
             BrowseRecordFacade::create($record);
         } catch (\Exception $e) {
-
+            echo $e->getMessage();exit;
         }
        return response()->horesp(1000, MentalityDrillsSubject::query()->find($id), "成功");
     }

+ 23 - 0
app/Http/Controllers/Api/V1/Specialist/IndexController.php

@@ -28,6 +28,29 @@ class IndexController extends Controller
         return SpecialistCloumnFacade::getList($conditions, $fields, $sort, $page, $limit);
     }
 
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function getChapterList()
+    {
+        $conditions = [
+            'pid'       => request('pid', SpecialistCloumn::PID_0),
+            'is_show'   => SpecialistCloumn::IS_SHOW_1,
+        ];
+        $fields     = ['*'];
+        $sort       = '`rank` desc,`id` asc';
+        $page       = request('page', 1);
+        $limit      = request('limit', 20);
+        $limit  = 100;
+        return SpecialistCloumnFacade::getChapterList($conditions, $fields, $sort, $page, $limit);
+    }
+    
+    public function category()
+    {
+        
+    }
     /**
      * Store a newly created resource in storage.
      *

+ 14 - 3
app/Http/Controllers/Api/V1/Specialist/SpecialistInfoController.php

@@ -9,6 +9,7 @@ use App\Facades\SpecialistInfoFacade;
 use App\Models\SpecialistInfo;
 use App\Models\BrowseRecord;
 use App\Facades\BrowseRecordFacade;
+use Qiniu\Http\Request as HttpRequest;
 
 class SpecialistInfoController extends BaseController
 {
@@ -26,13 +27,23 @@ class SpecialistInfoController extends BaseController
 
         $conditions = [
             'first_id'  => request('first_id'),
-            'second_id' => request('second_id') == 0 ? null : request('second_id'),
+            // 'second_id' => request('second_id') == 0 ? null : request('second_id'),
             'tag_id'    => request('tag_id'),
             'comment_tag' => $commentTag,
-            'name'=>request("name","")
+            'name'=>request("search",""),
+            'type' => 3
         ];
         $fields     = ['*'];
-        $sort       = '`rank` desc, `id` desc';
+        $sortable = request('sort', 0);
+        if($sortable == 1){
+            $sort = '`created_at` desc, `id` desc';
+
+        } elseif($sortable == 2){
+            $sort = '`number_of_studies` desc, `id` desc';
+        }else{
+            $sort = '`rank` desc, `id` desc';
+
+        }
         $page       = request('page', 1);
         $limit      = request('limit', 20);
         return SpecialistInfoFacade::getList($conditions, $fields, $sort, $page, $limit);

+ 1 - 0
app/Http/Kernel.php

@@ -65,5 +65,6 @@ class Kernel extends HttpKernel
         
         'apiSign'=>\App\Http\Middleware\ApiSign::class,
         'token'=>\App\Http\Middleware\CheckToken::class,
+        'psy_user'=>\App\Http\Middleware\PsyUserVerify::class,
     ];
 }

+ 280 - 0
app/Http/Middleware/PsyUserVerify.php

@@ -0,0 +1,280 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+use Encore\Admin\Facades\Admin;
+use Illuminate\Log\Logger;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+use Illuminate\Support\Facades\Validator;
+use Monolog\Handler\RotatingFileHandler;
+
+//社心站点用户验证
+
+class PsyUserVerify
+{
+    const USER_DATA_URL = "/api.php";
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \Closure  $next
+     * @return mixed
+     */
+    public function handle($request, Closure $next)
+    {
+        $validator = Validator::make($request->all(), [
+            'appid' => 'required',
+            'open_id' => 'required',
+            'op' => 'required',
+            'task' => 'required',
+        ], [
+            'appid.required' => 'appid参数不能为空',
+            'open_id.required' => 'open_id参数不能为空',
+            'op.required' => 'op参数不能为空',
+            'task.required' => 'task参数不能为空',
+        ]);
+
+        if ($validator->fails()) {
+            $msg = $validator->errors()->first();
+            return response()->json([
+                'code'=>400,
+                'msg'=>$msg
+            ]);
+        }
+
+        $sign = $request->input("sign");
+        $signData = $request->only(array("appid","open_id","op", "task","version"));
+        $paramsData = $request->except(array("appid","op", "task","version","sign"));
+        $config = config("console.wg_map");
+        if ($config["appid"] != $signData["appid"]){
+            throw new \Exception("appid非法参数:{$signData["appid"]}");
+        }
+        
+        if (Admin::guard()->check() && Admin::user()->third_openid == $signData["open_id"]){
+            return next($request);
+        }
+        $nowSign=$this->getSign(
+            $paramsData,
+            $signData["op"],
+            $signData["task"],
+            $signData["version"]
+        );
+        if ($nowSign != $sign){
+            throw new \Exception("签名验证不能通过:sign:{$sign}、nowSign:{$nowSign}");
+        }
+
+        $userModelClass = config('admin.database.users_model');
+        $userModel = new $userModelClass();
+        $checkUserData = $userModel::query()
+            ->where(
+                array(
+                    "third_openid"=>$signData["open_id"]
+                )
+            )
+            ->orderBy("id","desc")->first();
+
+
+        if($checkUserData) {
+            Admin::guard()->login(
+                $checkUserData
+            ); 
+        }
+
+        return $next($request);
+    }
+
+    public function getUserData(string $openId)
+    {
+        if (empty($openId)){
+            throw new \Exception("openId不能为空");
+        }
+        $config = config("console.remote_sso");
+        $url = $config["url"].self::USER_DATA_URL;//http://www.baidu.com/api.php
+        $query = array(
+            "op"=>"user",
+            "task"=>"userData",
+            "version"=>"1.0.0",
+            "appid"=>$config["appid"]
+        );
+        $sendData = array(
+            "open_id"=>$openId
+        );
+        $postData = $sendData;
+        $query["sign"] = $this->getSign($postData,$query["op"],$query["task"],$query["version"]);
+//        $client = new Client();
+        $url = $url."?".http_build_query($query);
+        $resultStr = $this->curlPost($url,$postData);
+//        $response = $client->request('post', $url, [
+//            'query' => $query,
+//            "headers"=>array(
+//                "Content-type"=>"application/json"
+//            ),
+//            "form_params"=>$postData
+//        ]);
+//        $resultStr = $response->getBody()->getContents();
+        return $this->getResult($resultStr);
+    }
+    public function getUserMenuWebsiteData(string $openId)
+    {$config = config("console.remote_sso");
+        $url = $config["url"].self::USER_DATA_URL;//http://www.baidu.com/api.php
+        $query = array(
+            "op"=>"menu",
+            "task"=>"getMenu",
+            "version"=>"1.0.0",
+            "appid"=>$config["appid"]
+        );
+        $sendData = array(
+            "open_id"=>$openId
+        );
+        $query["sign"] = $this->getSign($sendData,$query["op"],$query["task"],$query["version"]);
+//        $client = new Client();
+//        $response = $client->request('post', $url, [
+//            'query' => $query,
+//            "headers"=>array(
+//                "Content-type"=>"application/json"
+//            ),
+//            "form_params"=>$sendData
+//        ]);
+//        $resultStr = $response->getBody()->getContents();
+        $url = $url."?".http_build_query($query);
+        $resultStr = $this->curlPost($url,$sendData);
+        return $this->getResult($resultStr);
+    }
+
+
+    public function getSign(array $sendData, string $op = "user", string $task = "login", string $version = "1.0.0")
+    {
+        $config = config("console.wg_map");
+        $appid = $config["appid"];
+        $secret = $config["secret"];
+        ksort($sendData);
+        $str = "";
+        foreach($sendData as $key =>$value){
+            $str.= stripslashes($value);
+        }
+        $sign = md5($appid. $op . $task . $version . $str. $secret);
+        return $sign;
+    }
+    /**
+     * 得到结果数据
+     * @param string $resultStr
+     * @return mixed
+     * @throws \Exception
+     */
+    private function getResult(string $resultStr){
+        $result = json_decode($resultStr,true);
+        if (json_last_error() !== JSON_ERROR_NONE) {
+            $this->log("数据格式响应错误",$resultStr);
+            throw new \Exception("数据格式响应错误".$resultStr);
+        }
+        if (empty($result["status"])){
+            $content = $result["message"] ?? $resultStr;
+            $this->log("结果信息发生错误",$content);
+            throw new \Exception("结果信息发生错误".$content);
+        }
+        if (!isset($result["data"])){
+            $content = $resultStr;
+            $this->log("结果信息格式发送错误",$content);
+            throw new \Exception("结果信息格式发送错误".$content);
+        }
+        return $result["data"];
+    }
+
+    /**
+     * @param string $msg 消息提示
+     * @param array|string|object $content 结果内容
+     * @return void
+     */
+    private function log(string $msg,$content)
+    {
+        $sqlFile = 'logs/remoteSso/info.log';
+        (new Logger('remoteSso'))->pushHandler(new RotatingFileHandler(storage_path($sqlFile)))->info($msg,[$content]);
+    }
+    private function curlPost($url, $data=null, $file=null)
+    {
+        $ch = curl_init($url);
+        curl_setopt($ch, CURLOPT_TIMEOUT, 60); //设置超时
+
+//        if(!empty($file)){
+//            foreach ($file as $k=>$v){
+//                if(is_array($v)){
+//                    //多个文件
+//                    foreach ($v as $key=>$val){
+//                        $data[$k.'['.$key.']'] = new CURLFile($val);
+//                    }
+//                }else{
+//                    //一维
+//                    $data[$k] = new CURLFile($v);
+//                }
+//            }
+//        }
+
+        if (0 === strpos(strtolower($url), "https")) {
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //对认证证书来源的检查
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //从证书中检查SSL加密算法是否存在
+        }
+        curl_setopt($ch, CURLOPT_POST, true);
+
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+//         curl_setopt($ch, CURLOPT_HTTPHEADER);
+        $rtn = curl_exec($ch);//CURLOPT_RETURNTRANSFER 不设置  curl_exec返回TRUE 设置  curl_exec返回json(此处) 失败都返回FALSE
+        curl_close($ch);
+        return $rtn;
+    }
+    /**
+     * json 形式传参
+     * @param unknown $url
+     * @param unknown $data
+     */
+    private function curlPostJson($url, $data = null)
+    {
+        $headers = array(
+            "Content-type: application/json;charset='utf-8'",
+            "Accept: application/json",
+            "Cache-Control: no-cache",
+            "Pragma: no-cache",
+        );
+        $ch = curl_init($url);
+        curl_setopt($ch, CURLOPT_TIMEOUT, 60); //设置超时
+
+        if (0 === strpos(strtolower($url), "https")) {
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //对认证证书来源的检查
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //从证书中检查SSL加密算法是否存在
+        }
+        curl_setopt($ch, CURLOPT_POST, true);
+
+        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
+
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($ch, CURLOPT_HEADER, 1);//打印响应header
+        $rtn = curl_exec($ch);//CURLOPT_RETURNTRANSFER 不设置  curl_exec返回TRUE 设置  curl_exec返回json(此处) 失败都返回FALSE
+
+        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+
+        // 根据头大小去获取头信息内容
+        $header = substr($rtn, 0, $header_size);
+
+        $data = substr($rtn, $header_size);
+
+        $is_gzipped = false;
+
+        if (preg_match("/Content-Encoding: gzip/", $header)) {
+            $is_gzipped = true;
+        }
+
+        if($is_gzipped){
+            $data = gzdecode($data);
+        }
+
+        curl_close($ch);
+
+        return $data;
+    }
+}

+ 21 - 0
app/Models/FourActivity.php

@@ -8,6 +8,27 @@ use Illuminate\Database\Eloquent\Model;
 class FourActivity extends SoftBaseModel
 {
     public static  $mode = 'admin';
+
+    protected $fillable = [
+        'title',
+            'activities_type',
+            'active_time','place',
+            'audience_crowd',
+            'anchor',
+            'educational_materials',
+            'publicity_board',
+            'member_num',
+            'planned_number',
+            'actual_number',
+            'filling_people',
+            'filling_time',
+            'mode',
+            'declaration_form',
+            'task_book',
+            'final_report',
+            'return_receipt',
+            'ext'
+    ];
     //四进类型[1:进社区,2:进企业,3:进学校,4:进特殊群体]
     const ACTIVITIES_TYPE_COMMUNITY = 1;
     const ACTIVITIES_TYPE_ENTERPRISE = 2;

+ 4 - 4
app/Repositories/Eloquent/BrowseRecordFacadeRepository.php

@@ -21,10 +21,10 @@ class BrowseRecordFacadeRepository extends BaseRepository implements CollectInte
                 }
                 if (isset($conditions['column'])){
                     if ($conditions['column']==2){
-                        $query->where('column', 3);
-                        $query->whereRaw("
-                           object_id in ( select id from specialist_infos where second_id in (12,13) )
-");
+                        $query->where('column', 2);
+//                         $query->whereRaw("
+//                            object_id in ( select id from specialist_infos where second_id in (12,13) )
+// ");
                     }elseif ($conditions['column']==3){
                         $query->where('column', 3);
                         $query->whereRaw("

+ 1 - 1
app/Repositories/Eloquent/MentalityDrillCategoryFacadeRepository.php

@@ -15,7 +15,7 @@ class MentalityDrillCategoryFacadeRepository extends BaseRepository implements M
 {
     public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
     {
-        $result = MentalityDrillCategory::where(function(Builder $query) use($conditions){
+        $result = MentalityDrillCategory::where(function( $query) use($conditions){
             if (isset($conditions['id'])){
                 $query->where('id', $conditions['id']);
             }

+ 3 - 0
app/Repositories/Eloquent/MentalityDrillFacadeRepository.php

@@ -1,6 +1,7 @@
 <?php
 namespace app\Repositories\Eloquent;
 
+use App\Models\BrowseRecord;
 use App\Models\SpecialistInfoLeaveMessage;
 use App\Models\SpecialistInfosAssociation;
 use App\Repositories\Eloquent\BaseRepository;
@@ -68,6 +69,8 @@ class MentalityDrillFacadeRepository extends BaseRepository implements Mentality
                     "association_type"=>SpecialistInfosAssociation::ASSOCIATION_TYPE_LOVE,
                     "operation_type"=>SpecialistInfosAssociation::OPERATION_TYPE_WORKOUT
                 ))->count();
+            $history = BrowseRecord::where('object_id', $result['id'])->where('column', BrowseRecord::COLUMN_4)->orderBy('id','desc')->first();
+            $result['current_subject_id'] =  $history?$history->subject_id: 0;
         }
         return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
     }

+ 127 - 0
app/Repositories/Eloquent/RemoteSsoFacadeRepository.php

@@ -32,6 +32,133 @@ class RemoteSsoFacadeRepository extends BaseRepository implements RemoteSsoInter
      * @return mixed
      * @throws \Exception
      */
+    public function verifyVisitApi(Request $request,Response $response)
+    {
+        $sign = $request->get("sign");
+        $signData = $request->only(array("task","appid","open_id","version","go_url"));
+        $config = config("console.remote_sso");
+        if ($config["appid"] != $signData["appid"]){
+            throw new \Exception("appid非法参数:{$signData["appid"]}");
+        }
+        if (Admin::guard()->check() && Admin::user()->third_openid == $signData["open_id"]){
+            return $this->redirect($this->url,"登录成功");
+        }
+
+        $nowSign=$this->getSign(
+            array("open_id"=>$signData["open_id"]),
+            "core",
+            $signData["task"],
+            $signData["version"]
+        );
+        if ($nowSign != $sign){
+            throw new \Exception("签名验证不能通过:sign:{$sign}、nowSign:{$nowSign}");
+        }
+        $userModelClass = config('admin.database.users_model');
+        $userModel = new $userModelClass();
+        $checkUserData = $userModel::query()
+            ->where(
+                array(
+                    "third_openid"=>$signData["open_id"]
+                )
+            )
+            ->orderBy("id","desc")->first();
+        try {
+            DB::beginTransaction();
+            $plaintext = "";
+            $defaultPassword = "";
+            if (!empty($checkUserData)){
+                $plaintext = "{$checkUserData->username}@123456";
+                $defaultPassword = bcrypt($plaintext);
+            }
+            if (empty($checkUserData)){
+                //开始菜单授权
+                $permissionModelClass = config('admin.database.permissions_model');
+                $roleModelClass = config('admin.database.roles_model');
+                $userAvatar = config('admin.default_avatar');
+                $name = "";//名称
+                $userName="";//登录账号
+                $userData = $this->getUserData($signData["open_id"]);//下面需要获取用户账号、昵称、头像
+                if (isset($userData["user"])){
+                    if (isset($userData["user"]["name"])){
+                        $name = $userData["user"]["name"];
+                    }
+                    $name = empty($name)?$userData["user"]["username"]:$name;
+                    $userName = $userData["user"]["username"];
+                }
+                $plaintext = "{$userName}@123456";
+                $defaultPassword = bcrypt($plaintext);
+                $checkUserData = $userModel->create(array(
+                    "username"=>$userName,
+                    "password"=>$defaultPassword,
+                    "name"=>$name,
+                    "avatar"=>null,
+                ));
+                if (empty($checkUserData)){
+                    throw new \RuntimeException("新增用户信息失败");
+                }
+                DB::table($userModel::query()->getModel()->getTable())->where(
+                    array("id"=>$checkUserData->id)
+                )->update(array(
+                    "third_openid"=>$signData["open_id"]
+                ));
+                $roleSlugName = array("RemoteSso");//角色名称 slug
+                $permissionsSlugName = array("RemoteSso");//权限名称 slug
+                $permissionModel = new $permissionModelClass();
+                $roleModel = new $roleModelClass();
+                foreach ($roleSlugName as $val){
+                    $roleData = $roleModel::query()
+                        ->where(
+                            array(
+                                "slug"=>$val
+                            )
+                        )
+                        ->orderBy("id","desc")->first();
+                    if (!empty($roleData)){
+                        DB::table("admin_role_users")->insert(
+                            array(
+                                "role_id"=>$roleData->id,
+                                "user_id"=>$checkUserData->id,
+                                "created_at"=>date("Y-m-d H:i:s")
+                            )
+                        );
+                    }
+                }
+                foreach ($permissionsSlugName as $val){
+                    $permissionData = $permissionModel::query()
+                        ->where(
+                            array(
+                                "slug"=>$val
+                            )
+                        )
+                        ->orderBy("id","desc")->first();
+                    if (!empty($permissionData)){
+                        DB::table("admin_user_permissions")->insert(
+                            array(
+                                "permission_id"=>$permissionData->id,
+                                "user_id"=>$checkUserData->id,
+                                "created_at"=>date("Y-m-d H:i:s")
+                            )
+                        );
+                    }
+                }
+            }
+//            if ($defaultPassword != $checkUserData->password){
+//                $checkUserData->update(array("password"=>$defaultPassword));
+//            }
+            DB::commit();
+            Admin::guard()->login(
+                $checkUserData
+            );
+            $key = "RemoteSso:".$_SERVER['HTTP_HOST'].":".$checkUserData->id;
+            Redis::SET($key, true);
+            return $this->redirect($this->url,"登录成功");
+        }catch (\Exception $exception){
+            Log::error("远程授权登录出错",[$exception->getMessage(),$exception->getTrace()]);
+            DB::rollBack();
+            return "登录失败";
+        }
+    }
+
     public function verifyVisitUrl(Request $request,Response $response)
     {
         $sign = $request->get("sign");

+ 34 - 0
app/Repositories/Eloquent/SpecialistCloumnFacadeRepository.php

@@ -4,6 +4,8 @@ namespace app\Repositories\Eloquent;
 use App\Repositories\Eloquent\BaseRepository;
 use App\Models\SpecialistCloumn;
 use App\Repositories\Contracts\SpecialistCloumnInterface;
+use Illuminate\Support\Facades\DB;
+
 
 /**
  *
@@ -71,5 +73,37 @@ class SpecialistCloumnFacadeRepository extends BaseRepository implements Special
         })->delete();
         return $result ? $this->response($result) : $this->error()->fail();
     }
+    
+     public function getChapterList(array $conditions, array $fields, string $sort, int $page, int $limit)
+    {
+        $result = SpecialistCloumn::with(['tags'])->where(function($query) use($conditions){
+            if (isset($conditions['pid'])){
+//                $query->where('pid', $conditions['pid']);
+            }
+            if (isset($conditions['is_show'])){
+                $query->where('is_show', $conditions['is_show']);
+            }
+            $query->where('pid', 0);
+        })->orderByRaw($sort)->paginate($limit, $fields,"",$page);
+
+//         $result->each(function($item) use ($conditions){
+//             $sort       = 's.rank desc, s.id asc';
+//             $item->infoList = DB::table("specialist_infos as s")->selectRaw("s.*,!ISNULL(b.id) as  isStudy")
+//                 ->leftJoin("browse_records as b",function($join) use ($conditions){
+//                     $join->on('s.id','=','b.object_id')
+//                         ->where('b.column','=',3);
+//                 })->where("s.deleted_at","=",null)
+// //                ->where("s.release","=",1)
+//                 ->where("s.second_id","=",$item->id)
+//                 ->orderByRaw($sort)
+//                 ->get();
+
+//             $item->infoListcount = count($item->infoList);
+//         });
+
+
+
+        return $this->response($result);
+    }
 }
 

+ 148 - 0
app/Validate/BaseValidate.php

@@ -0,0 +1,148 @@
+<?php
+namespace App\Validate;
+
+use Illuminate\Support\Facades\Validator;
+/**
+ * 扩展验证器
+ */
+class BaseValidate {
+
+    /**
+     * 当前验证规则
+     * @var array
+     */
+    protected $rule = [];
+
+    /**
+     * 验证提示信息
+     * @var array
+     */
+    protected $message = [];
+
+    /**
+     * 验证场景定义
+     * @var array
+     */
+    protected $scene = [];
+
+    /**
+     * 设置当前验证场景
+     * @var array
+     */
+    protected $currentScene = null;
+
+    /**
+     * 验证失败错误信息
+     * @var array
+     */
+    protected $error = [];
+
+    /**
+     * 场景需要验证的规则
+     * @var array
+     */
+    protected $only = [];
+
+
+    /**
+     * 设置验证场景
+     * @access public
+     * @param  string  $name  场景名
+     * @return $this
+     */
+    public function scene($name)
+    {
+        // 设置当前场景
+        $this->currentScene = $name;
+
+        return $this;
+    }
+
+    /**
+     * 数据验证
+     * @access public
+     * @param  array     $data  数据
+     * @param  mixed     $rules  验证规则
+     * @param  array    $message 自定义验证信息
+     * @param  string    $scene 验证场景
+     * @return bool
+     */
+    public function check($data, $rules = [], $message = [],$scene = '')
+    {
+        $this->error =[];
+        if (empty($rules)) {
+            //读取验证规则
+            $rules = $this->rule;
+        }
+        if (empty($message)) {
+            $message = $this->message;
+        }
+
+        //读取场景
+        if (!$this->getScene($scene)) {
+            return false;
+        }
+
+        //如果场景需要验证的规则不为空
+        if (!empty($this->only)) {
+            $new_rules = [];
+            foreach ($this->only as $key => $value) {
+                if (array_key_exists($value,$rules)) {
+                    $new_rules[$value] = $rules[$value];
+                }    
+            }
+            $rules = $new_rules;
+        }
+        // var_dump($rules);die;
+        $validator = Validator::make($data,$rules,$message);
+        //验证失败
+        if ($validator->fails()) {
+            $this->error = $validator->errors()->first();
+            return false;
+        }
+
+        return !empty($this->error) ? false : true;
+    }
+
+    /**
+     * 获取数据验证的场景
+     * @access protected
+     * @param  string $scene  验证场景
+     * @return void
+     */
+    protected function getScene($scene = '')
+    {
+        if (empty($scene)) {
+            // 读取指定场景
+            $scene = $this->currentScene;
+        }
+        $this->only = [];
+
+        if (empty($scene)) {
+            return true;
+        }
+
+        if (!isset($this->scene[$scene])) {
+            //指定场景未找到写入error
+            $this->error = "scene:".$scene.'is not found';
+            return false;
+        }
+        // 如果设置了验证适用场景
+        $scene = $this->scene[$scene];
+        if (is_string($scene)) {
+            $scene = explode(',', $scene);
+        }
+        //将场景需要验证的字段填充入only
+        $this->only = $scene;
+        return true;
+    }
+
+    // 获取错误信息
+    public function getError()
+    {
+        return $this->error;
+    }
+
+
+
+}

+ 100 - 0
app/Validate/FourActivityValidate.php

@@ -0,0 +1,100 @@
+<?php
+namespace App\Validate;
+
+use App\Models\FourActivity;
+use App\Validate\BaseValidate;
+/**
+ * 文章验证器
+ */
+class FourActivityValidate extends BaseValidate {
+    //验证规则
+    protected $rule =[
+        'activities_type'=>'required',
+        'active_time' => 'required',
+        'place' => 'required',
+        'audience_crowd' => 'required',
+        'title' => 'required',
+        'anchor' => 'required',
+        'educational_materials' => 'required',
+        'publicity_board' => 'required',
+        'member_num' => 'required',
+        'planned_number' => 'required',
+        'actual_number' => 'required',
+        'filling_people' => 'required',
+        'filling_time' => 'required',
+        'mode' => 'required',
+        'declaration_form' => 'required',
+        'task_book' => 'required',
+        'final_report' => 'required',
+        'return_receipt' => 'required',
+        'ext' => 'required',
+
+    ];
+    //自定义验证信息
+    protected $message = [
+        'title.required'=>'标题不能为空',
+        'activities_type.required'=>'四进类型不能为空',
+        'active_time.required'=>'活动时间不能为空',
+        'place.required'=>'活动地点不能为空',
+        'audience_crowd.required'=>'受众人群不能为空',
+        'anchor.required'=>'讲者/主持不能为空',
+        'educational_materials.required'=>'发放宣教材料不能为空',
+        'publicity_board.required'=>'宣传栏不能为空',
+        'member_num.required'=>'受宣人次数不能为空',
+        'planned_number.required'=>'计划人数不能为空',
+        'actual_number.required'=>'实到人数不能为空',
+        'filling_people.required'=>'填表人不能为空',
+        'filling_time.required'=>'填表时间不能为空',
+        'mode.required'=>'方式不能为空',
+        'declaration_form.required'=>'申报书不能为空',
+        'task_book.required'=>'任务书不能为空',
+        'final_report.required'=>'结题报告书不能为空',
+        'return_receipt.required'=>'回执单不能为空',
+    ];
+
+    //自定义场景
+    protected $scene = [
+        FourActivity::TYPE_SCIENCE_POPULARIZATION_BASE =>[
+        'title',
+        'activities_type',
+        'active_time','place',
+        'audience_crowd',
+        'anchor',
+        'educational_materials',
+        'publicity_board',
+        'member_num',
+        'planned_number',
+        'actual_number',
+        'filling_people',
+        'filling_time',
+        'mode',
+        ],
+        FourActivity::TYPE_PROMOTION_ACTIVITIES => [
+            'title',
+            'activities_type',
+            'active_time','place',
+            'audience_crowd',
+            'anchor',
+            'educational_materials',
+            'publicity_board',
+            'member_num',
+            'planned_number',
+            'actual_number',
+            'filling_people',
+            'filling_time',
+            'mode',
+            ],
+        FourActivity::TYPE_FEATURED_SERVICES => [
+            'title',
+            'declaration_form',
+            'task_book',
+            'final_report',
+            'ext'
+        ],
+        FourActivity::TYPE_FEATURED_REPORT_RECEIPT => [
+            'title',
+            'return_receipt',
+            'ext'
+        ],
+    ];
+}

+ 6 - 0
config/console.php

@@ -58,6 +58,12 @@ return [
         'url'       => env('REMOTE_SSO_URL'),
         'appid'     => env('REMOTE_SSO_APPID'),
         'secret'    => env('REMOTE_SSO_SECRET'),
+    ],
+     //远程授权访问
+     'wg_map'  => [
+        'url'       => env('WG_MAP_URL'),
+        'appid'     => env('WG_MAP_APPID'),
+        'secret'    => env('WG_MAP_SECRET'),
     ],
     'redis_key' => [
         'api_auth' => 'api:sign:',

+ 1 - 0
config/filesystems.php

@@ -90,6 +90,7 @@ return [
 
     'links' => [
         public_path('storage') => storage_path('app/public'),
+        public_path('uploads') => storage_path('app/uploads'),
     ],
 
 ];

+ 1 - 4
public/nginx.htaccess

@@ -1,4 +1 @@
-location / {  
- try_files $uri $uri/ /index.php?$query_string;  
-}
-
+try_files $uri $uri/ /index.php?$query_string;

+ 6 - 1
routes/api.php

@@ -171,6 +171,7 @@ Route::group(['namespace' => 'Api'], function(){
             Route::group(['namespace' => 'Specialist', 'prefix' => 'specialist'], function(){
                 //首页 一级栏目列表 二级栏目列表 栏目详情
                 Route::resource('index', 'IndexController');
+                Route::get('category', 'IndexController@category');
 //                    Route::resource('getChapterList', 'IndexController');
                 Route::get('getChapterList', 'IndexController@getChapterList')->name('getChapterList');
                 Route::group(['middleware'=>['token']], function(){
@@ -240,7 +241,11 @@ Route::group(['namespace' => 'Api'], function(){
                 Route::resource('browse_record', 'BrowseRecordController');
             });
         });
-
+        Route::group(['prefix' => 'workstation'], function(){
+            Route::post('login', 'FourActivityController@loginOrRegister')->middleware('psy_user');
+            Route::post('report', 'FourActivityController@report')->middleware('psy_user');
+            Route::post('upload', 'FourActivityController@upload');
+        });
 
     });
 });