xiaogang 4 年之前
父節點
當前提交
699e1b2aca

+ 67 - 0
app/Admin/Actions/Notice/NoticeSend.php

xqd
@@ -0,0 +1,67 @@
+<?php
+
+
+namespace App\Admin\Actions\Notice;
+
+
+use Dcat\Admin\Grid\RowAction;
+use Dcat\Admin\Widgets\Modal;
+
+class NoticeSend 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 = UserCheck::make()->payload(['id'=>$this->getKey()]);
+        return Modal::make()
+            ->lg()
+            ->title($this->title)
+            ->body($form)
+            ->button('<i class="feather icon-settings"></i> '.$this->title);
+    }
+}
+

+ 45 - 0
app/Admin/Actions/Notice/UserCheck.php

xqd
@@ -0,0 +1,45 @@
+<?php
+namespace App\admin\Actions\Notice;
+
+use App\Models\User;
+use Dcat\Admin\Contracts\LazyRenderable;
+use Dcat\Admin\Traits\LazyWidget;
+use Dcat\Admin\Widgets\Form;
+
+class UserCheck extends Form implements LazyRenderable
+{
+    use LazyWidget;
+
+
+    public function __construct($data = [], $key = null)
+    {
+        parent::__construct($data, $key);
+    }
+
+    public function handle(array $input)
+    {
+        $user = User::query()->find($input['id']);
+        if(!$user){
+
+            return $this->response()->error('请刷新后重试');
+        }
+        if($input['mobile']!=$user->mobile && User::query()->where('mobile',$input['mobile'])->first()){
+            return $this->response()->error('该手机号码已被使用');
+        }else{
+            $user->mobile = $input['mobile'];
+        }
+        if($input['password']!=''){
+            $user->password = $input['password'];
+
+        }
+        $user->save();
+        return $this->response()->success('保存成功')->refresh();
+    }
+
+
+    public function form()
+    {
+        $this->hidden('id')->value($this->payload['id']);
+        $this->radio('type')->options([0=>'全部用户',1=>'男性用户',2=>"女性用户"])->default(0);
+    }
+}

+ 79 - 0
app/Admin/Controllers/NoticeController.php

xqd
@@ -0,0 +1,79 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Admin\Actions\Notice\NoticeSend;
+use App\Models\Notice;
+use App\Models\User;
+use Dcat\Admin\Form;
+use Dcat\Admin\Grid;
+use Dcat\Admin\Show;
+use Dcat\Admin\Http\Controllers\AdminController;
+use Faker\Factory;
+
+class NoticeController extends AdminController
+{
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new Notice());
+        $grid->model()->orderBy('id','desc');
+
+        $grid->column('id')->sortable();
+        $grid->column('title');
+        $grid->column('content')->limit(60);
+        $grid->column('users')->using(['全部用户','男性用户','女性用户'])->label(['success','primary','warning']);
+        $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->append(new NoticeSend(User::class));
+//        });
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     *
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        return Show::make($id, new Notice(), function (Show $show) {
+            $show->field('id');
+            $show->field('title');
+            $show->field('content')->unescape();
+            $show->field('users')->using(['全部用户','男性用户','女性用户']);
+            $show->field('created_at');
+            $show->field('updated_at');
+        });
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        return Form::make(new Notice(), function (Form $form) {
+            $form->display('id');
+            $form->text('title');
+            $form->editor('content');
+            $form->radio('users')->options([0=>'全部用户',1=>'男性用户',2=>"女性用户"])->default(0);
+            $form->display('created_at');
+            $form->display('updated_at');
+        });
+    }
+}

+ 2 - 0
app/Admin/routes.php

xqd
@@ -20,4 +20,6 @@ Route::group([
     $router->resource('/vip', 'VipController');
     $router->resource('/vip-set', 'VipConfigController');
     $router->resource('/document', 'DocumentController');
+    $router->resource('/chat', 'ChatListController');
+    $router->resource('/notice', 'NoticeController');
 });

+ 14 - 0
app/Models/Notice.php

xqd
@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Models;
+
+use Dcat\Admin\Traits\HasDateTimeFormatter;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Notice extends Model
+{
+	use HasDateTimeFormatter;
+    protected $table = 'notice';
+    
+}

+ 1 - 0
composer.json

xqd
@@ -13,6 +13,7 @@
         "fruitcake/laravel-cors": "^2.0",
         "guzzlehttp/guzzle": "^7.0.1",
         "jacobcyl/ali-oss-storage": "2.1",
+        "jpush/jpush": "^3.6",
         "laravel/framework": "^8.40",
         "laravel/tinker": "^2.5",
         "liyu/dingo-serializer-switch": "^0.3.2",

+ 54 - 1
composer.lock

xqd xqd
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "e180b9cf77529837305b6a4f11f142a9",
+    "content-hash": "864b778cc984b578f15d279a75dadc12",
     "packages": [
         {
             "name": "aliyuncs/oss-sdk-php",
@@ -1512,6 +1512,59 @@
             },
             "time": "2018-04-02T03:44:01+00:00"
         },
+        {
+            "name": "jpush/jpush",
+            "version": "v3.6.6",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/jpush/jpush-api-php-client.git",
+                "reference": "64ff7f5919c80801f43b8332250e392b116521c6"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/jpush/jpush-api-php-client/zipball/64ff7f5919c80801f43b8332250e392b116521c6",
+                "reference": "64ff7f5919c80801f43b8332250e392b116521c6",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-curl": "*",
+                "php": ">=5.3.3"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "*"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "JPush\\": "src/JPush/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "JPush",
+                    "email": "support@jpush.cn",
+                    "homepage": "https://www.jpush.cn/",
+                    "role": "Developer"
+                }
+            ],
+            "description": "JPush API PHP Client",
+            "homepage": "https://github.com/jpush/jpush-api-php-client",
+            "support": {
+                "issues": "https://github.com/jpush/jpush-api-php-client/issues",
+                "source": "https://github.com/jpush/jpush-api-php-client/tree/v3.6.6"
+            },
+            "time": "2019-11-26T06:04:53+00:00"
+        },
         {
             "name": "laravel/framework",
             "version": "v8.48.1",

+ 4 - 0
dcat_admin_ide_helper.php

xqd xqd xqd xqd
@@ -75,6 +75,7 @@ namespace Dcat\Admin {
      * @property Grid\Column|Collection failed_at
      * @property Grid\Column|Collection migration
      * @property Grid\Column|Collection batch
+     * @property Grid\Column|Collection users
      * @property Grid\Column|Collection email
      * @property Grid\Column|Collection token
      * @property Grid\Column|Collection order_no
@@ -199,6 +200,7 @@ namespace Dcat\Admin {
      * @method Grid\Column|Collection failed_at(string $label = null)
      * @method Grid\Column|Collection migration(string $label = null)
      * @method Grid\Column|Collection batch(string $label = null)
+     * @method Grid\Column|Collection users(string $label = null)
      * @method Grid\Column|Collection email(string $label = null)
      * @method Grid\Column|Collection token(string $label = null)
      * @method Grid\Column|Collection order_no(string $label = null)
@@ -328,6 +330,7 @@ namespace Dcat\Admin {
      * @property Show\Field|Collection failed_at
      * @property Show\Field|Collection migration
      * @property Show\Field|Collection batch
+     * @property Show\Field|Collection users
      * @property Show\Field|Collection email
      * @property Show\Field|Collection token
      * @property Show\Field|Collection order_no
@@ -452,6 +455,7 @@ namespace Dcat\Admin {
      * @method Show\Field|Collection failed_at(string $label = null)
      * @method Show\Field|Collection migration(string $label = null)
      * @method Show\Field|Collection batch(string $label = null)
+     * @method Show\Field|Collection users(string $label = null)
      * @method Show\Field|Collection email(string $label = null)
      * @method Show\Field|Collection token(string $label = null)
      * @method Show\Field|Collection order_no(string $label = null)

+ 14 - 0
resources/lang/zh_CN/notice.php

xqd
@@ -0,0 +1,14 @@
+<?php 
+return [
+    'labels' => [
+        'Notice' => '系统公告',
+        'notice' => '系统公告',
+    ],
+    'fields' => [
+        'title' => '标题',
+        'content' => '内容',
+        'users' => '推送的用户',
+    ],
+    'options' => [
+    ],
+];