xiaogang před 4 roky
rodič
revize
fc23437dc1

+ 42 - 0
app/Admin/Actions/Problem/DoReply.php

xqd
@@ -0,0 +1,42 @@
+<?php
+namespace App\admin\Actions\Problem;
+
+use App\Models\User;
+use App\Models\UserProblemModel;
+use Dcat\Admin\Contracts\LazyRenderable;
+use Dcat\Admin\Traits\LazyWidget;
+use Dcat\Admin\Widgets\Form;
+use PHPUnit\Util\Exception;
+
+class DoReply extends Form implements LazyRenderable
+{
+    use LazyWidget;
+
+
+    public function __construct($data = [], $key = null)
+    {
+        parent::__construct($data, $key);
+    }
+
+    public function handle(array $input)
+    {
+        $problem = UserProblemModel::query()->find($input['id']);
+        if(!$problem){
+            return $this->response()->error('请刷新后重试');
+        }
+        if(empty($input['reply'])){
+            return $this->response()->error('请输入回复内容');
+        }
+        $problem->status = 1;
+        $problem->reply = $input['reply'];
+        $problem->save();
+        return $this->response()->success('保存成功')->refresh();
+    }
+
+
+    public function form()
+    {
+        $this->hidden('id')->value($this->payload['id']);
+        $this->textarea('reply', '回复内容');
+    }
+}

+ 65 - 0
app/Admin/Actions/Problem/Reply.php

xqd
@@ -0,0 +1,65 @@
+<?php
+
+
+namespace App\Admin\Actions\Problem;
+
+use Dcat\Admin\Grid\RowAction;
+use Dcat\Admin\Widgets\Modal;
+
+class Reply extends RowAction
+{
+    protected $title = '回复';
+
+    protected $model;
+
+    public function __construct(string $model = null)
+    {
+        $this->model = $model;
+    }
+
+    /**
+     * 设置确认弹窗信息,如果返回空值,则不会弹出弹窗
+     *
+     * 允许返回字符串或数组类型
+     *
+     * @return array|string|void
+     */
+    public function confirm()
+    {
+
+    }
+
+    /**
+     * 处理请求
+     *
+     * @param Request $request
+     *
+     * @return \Dcat\Admin\Actions\Response
+     */
+    public function handle(Request $request)
+    {
+        return $this->response()
+            ->success('Processed successfully: '.$this->getKey())
+            ->redirect('/');
+    }
+
+    /**
+     * 设置要POST到接口的数据
+     *
+     * @return array
+     */
+    public function parameters()
+    {
+        return [];
+    }
+
+    public function render()
+    {
+        $form = DoReply::make()->payload(['id'=>$this->getKey()]);
+        return Modal::make()
+            ->lg()
+            ->title($this->title)
+            ->body($form)
+            ->button('<i class="feather icon-disc"></i> '.$this->title);
+    }
+}

+ 71 - 14
app/Admin/Controllers/UsersProblemController.php

xqd xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Admin\Controllers;
 
+use App\Admin\Actions\Problem\Reply;
 use App\Models\UserProblemModel;
 use App\Models\UsersProblem;
 use Dcat\Admin\Form;
@@ -18,20 +19,46 @@ class UsersProblemController extends AdminController
      */
     protected function grid()
     {
-        return Grid::make(new UserProblemModel(), function (Grid $grid) {
-            $grid->column('id')->sortable();
-            $grid->column('user_id');
-            $grid->column('content');
-            $grid->column('img_url');
-            $grid->column('status');
-            $grid->column('created_at');
-            $grid->column('updated_at')->sortable();
+        $grid = new Grid(new UserProblemModel());
+        $grid->model()->orderBy('id','desc');
 
-            $grid->filter(function (Grid\Filter $filter) {
-                $filter->equal('id');
+        $grid->column('id')->sortable();
+        $grid->column('user_id');
+        $grid->column('content')->limit(50);
+        $grid->column('img_url')->display(function ($v){
+            if(isset($v)){
+                $v = json_decode($v,true);
+                $str = '';
+                if(count($v)>0){
+                    foreach ($v as $item){
+                        $str.='<img data-action="preview-img" src="'.$item.'" style="max-width:50px;max-height:200px;cursor:pointer" class="img img-thumbnail">';
+                    }
+                }
+                return $str;
+            }else{
+                return "";
+            }
+        });
+        $grid->column('status')->using(['待处理','已处理'])->label(['warning','success']);
+        $grid->column('reply','回复内容');
+        $grid->column('created_at');
+        $grid->column('updated_at')->sortable();
 
-            });
+        $grid->filter(function (Grid\Filter $filter) {
+            $filter->equal('id');
+
+        });
+        //操作管理
+        $grid->actions(function (Grid\Displayers\Actions $actions) {
+            $actions->disableEdit();
+            $actions->disableDelete();
+            if ($actions->row->status == 0) {
+                $actions->append(new Reply(UserProblemModel::class));
+            }
         });
+
+        $grid->disableCreateButton();
+        return $grid;
     }
 
     /**
@@ -46,9 +73,39 @@ class UsersProblemController extends AdminController
         return Show::make($id, new UserProblemModel(), function (Show $show) {
             $show->field('id');
             $show->field('user_id');
-            $show->field('content');
-            $show->field('img_url');
-            $show->field('status');
+            $show->field('content')->unescape();
+            $show->html(function ($res){
+                $str = "";
+                if($res['img_url']){
+                    $res = json_decode($res['img_url'],true);
+                    if(count($res)>0){
+
+                        foreach ($res as $k=>$v){
+                            $str.='<img data-action="preview-img" src="'.$v.'" style="max-width:100px;max-height:100px;cursor:pointer" class="img img-thumbnail">';
+                        }
+                    }else{
+                        $str = "无";
+                    }
+                }else{
+                    $str = "无";
+                }
+                $html = '<div class="show-field form-group row">
+                    <div class="col-sm-2 control-label">
+                        <span>图片</span>
+                    </div>
+
+                    <div class="col-sm-8">
+                        <div class="box box-solid box-default no-margin box-show">
+                            <div class="box-body">
+                                      '.$str.'
+                            </div>
+                        </div>
+                    </div>
+                </div>';
+                return $html;
+            });
+            $show->field('status')->using(['待处理','已处理']);
+            $show->field('reply','回复内容');
             $show->field('created_at');
             $show->field('updated_at');
         });

+ 1 - 1
app/Models/UserProblemModel.php

xqd
@@ -10,5 +10,5 @@ class UserProblemModel extends Model
 {
 	use HasDateTimeFormatter;
     protected $table = 'users_problem';
-    protected $fillable = ['user_id', 'content','img_url','status'];
+    protected $fillable = ['user_id', 'content','img_url','status','reply'];
 }

+ 7 - 0
app/Services/DynamicService.php

xqd
@@ -71,6 +71,13 @@ class DynamicService
      * 动态列表
      */
     public function dynamic_list($where){
+        $user = auth('api')->user();
+        if($user){
+            $lat = $user->latitude;
+            $lng = $user->longitude;
+        }else{
+
+        }
         $dynamic = DynamicModel::query();
         $dynamic = $dynamic->with(["user"=>function($query){
                 $query->select('id','sex','is_vip','tencent_im_user_id');

+ 86 - 0
app/Services/JPushService.php

xqd
@@ -182,4 +182,90 @@ class JPushService
 
         return false;
     }
+
+
+    /**
+     * jgOpensslPrivateDecrypt($encrypted)     (加密) 手机号码解密获取手机号
+     * @param   $encrypted        string       (加密) 手机号码
+     * @param
+     *
+     * @return              string         手机号|false
+     *  err:错误信息
+     *
+     */
+    public function jgOpensslPrivateDecrypt($encrypted){
+        $prefix = '-----BEGIN RSA PRIVATE KEY-----';
+        $suffix = '-----END RSA PRIVATE KEY-----';
+        $result = '';
+
+        $prikey = JG_YJDL_PRIVATE_RSA;
+
+        $key = $prefix . "\n" . $prikey . "\n" . $suffix;//拼接换行符
+        $r = openssl_private_decrypt(base64_decode($encrypted), $result, openssl_pkey_get_private($key));
+        if($r){
+            return $result;
+        }else{
+            return false;
+        }
+
+    }
+
+    /**
+     * jgLoginTokenVerify($token)         提交loginToken,验证后返回手机号码(加密)
+     * @param   $token        string       认证SDK获取到的loginToken
+     * @param   $exId         开发者自定义的id,非必填
+     *
+     * @return              array         手机号
+     *  err:错误信息
+     *
+     */
+    public function jgLoginTokenVerify($token,$exId)
+    {
+        $host    = JG_YJDL_POST_URL;
+        $method  = "POST";
+        $appcode = VERIFY_APPCODE;
+        $headers = array();
+        array_push($headers, "Authorization: Basic " .base64_encode(JG_APPKEY.':'.JG_MASTERSECRET));
+        //根据API的要求,定义相对应的Content-Type
+        array_push($headers, "Content-Type".":"."application/json");
+
+        $data = json_encode(["loginToken"=>$token,"exId"=>$exId]);
+
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
+        curl_setopt($curl, CURLOPT_URL, $host);
+        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($curl, CURLOPT_FAILONERROR, false);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+        //设定返回信息中是否包含响应信息头,启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头
+        //如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false
+        curl_setopt($curl, CURLOPT_HEADER, false);
+
+        $ret = curl_exec($curl);
+        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+
+        // file_put_contents(PATH_USER_JG_LOGIN_LOG.date('Y-m-d').'.log', date('Y-m-d H:i:s').$ret.PHP_EOL,FILE_APPEND);//写入文件 常量需要自己在定义
+
+        $ret  = json_decode($ret,true);
+
+
+
+        if ($ret['code'] == 8000) {
+            if($ret['exID']!=$exId){
+                $ret['err'] = 'exID 返回与发送不一致';
+            }
+
+        } else {
+            $ret['err'] = $ret['code'].':'.$ret['content'];
+        }
+
+
+        return $ret;
+
+
+       // $ret = jgLoginTokenVerify($token,$exId);
+       // $res = jgOpensslPrivateDecrypt($ret['phone']);
+    }
+
 }