Samien 1 rok pred
rodič
commit
f7b485fbe5

+ 2 - 18
addons/LsActivity/api/modules/v1/controllers/ActivityController.php

@@ -43,7 +43,7 @@ class ActivityController extends OnAuthController
         return new ActiveDataProvider([
             'query' => $this->modelClass::find()
                 ->where(['status' => StatusEnum::ENABLED])
-                ->select(['id', 'title', 'cover', 'author', 'content', 'description', 'view'])
+                ->select(['id', 'title', 'cover', 'author', 'content', 'description','created_at',  'view'])
                 ->orderBy('sort asc, id desc')
                 ->asArray(),
             'pagination' => [
@@ -66,7 +66,7 @@ class ActivityController extends OnAuthController
 
         $data = $this->modelClass::find()
             ->select(['id', 'title', 'description', 'cover', 'author','created_at', 'view'])
-            // ->where(['status' => StatusEnum::ENABLED])
+            ->where(['status' => StatusEnum::ENABLED])
             ->andFilterWhere(['like', 'title', $keyword]);
         $pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
         $models = $data->offset($pages->offset)
@@ -99,21 +99,5 @@ class ActivityController extends OnAuthController
     //     ]);
     // }
 
-    /**
-     * @param $id
-     * @return \yii\db\ActiveRecord
-     * @throws NotFoundHttpException
-     */
-    protected function findModel($id)
-    {
-        /* @var $model \yii\db\ActiveRecord */
-        if (empty($id) || !($model = $this->modelClass::find()->where([
-                'id' => $id,
-                'status' => StatusEnum::ENABLED,
-            ])->one())) {
-            throw new NotFoundHttpException('请求的数据不存在');
-        }
 
-        return $model;
-    }
 }

+ 262 - 0
addons/LsActivity/api/modules/v1/controllers/SignController.php

@@ -0,0 +1,262 @@
+<?php
+
+namespace addons\LsActivity\api\modules\v1\controllers;
+
+use Yii;
+use yii\data\ActiveDataProvider;
+use yii\data\Pagination;
+use yii\web\NotFoundHttpException;
+use common\enums\StatusEnum;
+use addons\LsActivity\common\models\Sign;
+use api\controllers\OnAuthController;
+use common\helpers\ResultHelper;
+use common\helpers\ArrayHelper;
+
+/**
+ * 文章接口
+ *
+ * Class ArticleController
+ * @package addons\TinyBlog\api\modules\v1\controllers
+ * @author jianyan74 <751393839@qq.com>
+ */
+class SignController extends OnAuthController
+{
+    /**
+     * @var Sign
+     */
+    public $modelClass = Sign::class;
+
+    /**
+     * 不用进行登录验证的方法
+     * 例如: ['index', 'update', 'create', 'view', 'delete']
+     * 默认全部需要验证
+     *
+     * @var array
+     */
+    protected $authOptional = ['index', 'view', 'list','update','create'];
+
+    /**
+     * 首页
+     *
+     * @return ActiveDataProvider
+     */
+    public function actionIndex()
+    {
+        return new ActiveDataProvider([
+            'query' => $this->modelClass::find()
+                ->where(['status' => StatusEnum::ENABLED])
+                ->select(['*'])
+                ->orderBy('id desc')
+                ->asArray(),
+            'pagination' => [
+                'pageSize' => $this->pageSize,
+                'validatePage' => false,// 超出分页不返回data
+            ],
+        ]);
+    }
+
+    /**
+     * 自定义装修可用
+     *
+     * 修改数据格式返回
+     *
+     * @return array|mixed
+     */
+    public function actionList()
+    {
+        $keyword = Yii::$app->request->get('keyword');
+
+        $data = $this->modelClass::find()
+            ->select(['*'])
+            ->where(['status' => StatusEnum::ENABLED]);
+            // ->andFilterWhere(['like', 'title', $keyword]);
+        $pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
+        $models = $data->offset($pages->offset)
+            ->orderBy('id desc')
+            ->limit($pages->limit)
+            ->asArray()
+            ->all();
+
+        return [
+            'list' => $models,
+            'pages' => [
+                'totalCount' => $pages->totalCount,
+                'pageSize' => $pages->pageSize,
+            ]
+        ];
+    }
+
+    /**
+     * 查看
+     *
+     * @return ActiveDataProvider
+     */
+    // public function actionView($id)
+    // {
+
+    //     $uid = Yii::$app->request->get('uid');
+    //     $aid = Yii::$app->request->get('aid');
+
+    //     $data = $this->modelClass::find()
+    //         ->select(['*'])
+    //         ->where(['uid' => $uid, 'aid' => $aid])->one();
+    //     return $data;
+    // }
+
+    /**
+     * @param $id
+     * @return \yii\db\ActiveRecord
+     * @throws NotFoundHttpException
+     */
+    protected function findModel($id)
+    {
+        /* @var $model \yii\db\ActiveRecord */
+        if (empty($id) || !($model = $this->modelClass::find()->where([
+                'id' => $id,
+                'status' => StatusEnum::ENABLED,
+            ])->one())) {
+            throw new NotFoundHttpException('请求的数据不存在');
+        }
+
+        return $model;
+    }
+
+        /**
+     * 编辑/创建
+     *
+     * @return mixed
+     */
+    public function actionEdit()
+    {
+        $id = Yii::$app->request->get('id', null);
+        $model = $this->findModel($id);
+        $model->status= StatusEnum::ENABLED;
+        // $model->updated_at = time();
+        if ($model->load(Yii::$app->request->post()))
+        {
+            return $model->save()
+                ? $this->message('保存成功', $this->redirect(['index']))
+                    : $this->message('保存失败', $this->redirect(['index']), 'error');
+        }
+
+        return $this->render($this->action->id, [
+           'model' => $model,
+        ]);
+    }
+
+     /**
+     * 更新
+     *
+     * @param $id
+     * @return bool|mixed
+     * @throws NotFoundHttpException
+     */
+    public function actionUpdate($id)
+    {
+        // $model = new LoginForm();
+        $id = Yii::$app->request->get('id', null);
+        $uid = Yii::$app->request->get('uid');
+        $aid = Yii::$app->request->get('aid');
+        $model = $this->findModel($id);
+
+        // $model->attributes = Yii::$app->request->post();
+        $model->status= StatusEnum::ENABLED;
+
+        // $data = Yii::$app->request->post();
+        // $data = ArrayHelper::filter($data, [
+        //     'uid',
+        //     'aid',
+        // ]);
+
+        // $model = $this->findModel($id);
+        $model->uid = $uid;
+        $model->aid = $aid;
+        // $model->attributes = $data;
+        if (!$model->save()) {
+            return ResultHelper::json(422, $this->getError($model));
+        }
+
+        return 'ok';
+    }
+    
+    /**
+     * 创建
+     *
+     * @return mixed|\yii\db\ActiveRecord
+     */
+    public function actionCreate()
+    {
+        $params = Yii::$app->request->post('params');
+
+        $aid = $params["aid"];
+        $uid = $params["uid"];
+        // $model = $this->modelClass::find()->where([
+        //     'aid' => $aid,
+        //     'uid' => $uid,
+        //     'status' => StatusEnum::ENABLED,
+        // ])->one();
+        if ($model = $this->modelClass::find()->where([
+            'aid' => $aid,
+            'uid' => $uid,
+            // 'status' => StatusEnum::ENABLED,
+        ])->one()) {
+            if($model->status !== StatusEnum::ENABLED){
+                $model->status = '1';
+                if (!$model->save()) {
+                    return ResultHelper::json(422, $this->getError($model));
+                }
+            }else
+            {
+                return ResultHelper::json(422, '已经报名!');
+
+            }
+        }
+        
+        $model = new $this->modelClass();
+        // $params["status"] = StatusEnum::ENABLED;
+        $model->attributes = $params;
+
+        if (!$model->save()) {
+            return ResultHelper::json(422, $this->getError($model));
+        }
+
+        return "OK";
+    }
+    
+    /**
+     * 获取报名情况
+     *
+     * @return mixed|\yii\db\ActiveRecord
+     */
+    public function actionGetSignStatus()
+    {
+        $uid = Yii::$app->request->get('uid');
+        $aid = Yii::$app->request->get('aid');
+
+        if (!($model = $this->modelClass::find()
+          ->select(['*'])
+          ->where(['uid' => $uid, 'aid' => $aid])->one()))
+        {
+            //throw new NotFoundHttpException('请求的数据不存在');
+            return "OK";
+
+        }
+        
+
+        return $model;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function verbs()
+    {
+        return [
+            'index' => ['GET', 'POST', 'HEAD', 'OPTIONS'],
+            'view' => ['GET', 'HEAD', 'OPTIONS'],
+            'create' => ['POST', 'OPTIONS'],
+            'update' => ['PUT', 'PATCH', 'OPTIONS' , 'POST'],
+            'delete' => ['DELETE', 'OPTIONS'],
+        ];
+    }
+}

+ 3 - 1
addons/LsActivity/backend/controllers/ActivityController.php

@@ -7,7 +7,7 @@ use addons\LsActivity\common\models\Activity;
 use common\traits\Curd;
 use common\models\base\SearchModel;
 use common\controllers\AddonsController;
-
+use common\enums\StatusEnum;
 /**
 * Activity
 *
@@ -61,6 +61,8 @@ class ActivityController extends BaseController
     {
         $id = Yii::$app->request->get('id', null);
         $model = $this->findModel($id);
+        $model->status= StatusEnum::ENABLED;
+        // $model->updated_at = time();
         if ($model->load(Yii::$app->request->post()))
         {
             return $model->save()

+ 16 - 0
addons/LsActivity/backend/views/Activity/edit.php

@@ -2,6 +2,7 @@
 
 use common\helpers\Html;
 use yii\widgets\ActiveForm;
+use kartik\datetime\DateTimePicker;
 
 /* @var $this yii\web\View */
 /* @var $model addons\LsActivity\common\models\Activity */
@@ -41,6 +42,21 @@ $this->params['breadcrumbs'][] = $this->title;
                     <?= $form->field($model, 'seo_content')->textInput(['maxlength' => true]) ?>
                     <?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>
                     <?= $form->field($model, 'seo_key')->textInput(['maxlength' => true]) ?>
+                    <?= $form->field($model, 'view')->textInput(['maxlength' => true]) ?>
+                    <?= $form->field($model, 'check_max')->textInput(['maxlength' => true]) ?>
+                    <?= $form->field($model, 'author')->textInput(['maxlength' => true]) ?>
+                    <?= $form->field($model, 'created_at')->widget(DateTimePicker::class, [
+                            'language' => 'zh-CN',
+                            'options' => [
+                                'value' => $model->isNewRecord ? date('Y-m-d H:i:s') : date('Y-m-d H:i:s', $model->created_at),
+                            ],
+                            'pluginOptions' => [
+                                'format' => 'yyyy-mm-dd hh:ii',
+                                'todayHighlight' => true,//今日高亮
+                                'autoclose' => true,//选择后自动关闭
+                                'todayBtn' => true,//今日按钮显示
+                            ]
+                        ]);?>
                     <?= $form->field($model, 'content')->widget(\common\widgets\ueditor\UEditor::class, []) ?>
                 </div>
                 <div class="form-group">

+ 15 - 0
addons/LsActivity/common/models/Activity.php

@@ -1,6 +1,7 @@
 <?php
 
 namespace addons\LsActivity\common\models;
+use common\helpers\StringHelper;
 
 use Yii;
 
@@ -72,4 +73,18 @@ class Activity extends \yii\db\ActiveRecord
             'updated_at' => '更新时间',
         ];
     }
+
+    /**
+     * @param bool $insert
+     * @return bool
+     */
+    public function beforeSave($insert)
+    {
+        // 推荐位
+        // $this->position = $this->getPosition();
+        $this->created_at = StringHelper::dateToInt($this->created_at);
+        $this->updated_at = time();
+
+        return parent::beforeSave($insert);
+    }
 }

+ 50 - 0
addons/LsActivity/common/models/Sign.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace addons\LsActivity\common\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "rf_addon_activity_sign".
+ *
+ * @property int $id
+ * @property int|null $uid 用户ID
+ * @property int|null $aid 活动ID
+ * @property int|null $created_at 报名时间
+ * @property string|null $status 状态
+ */
+class Sign extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'rf_addon_activity_sign';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['uid', 'aid', 'created_at'], 'integer'],
+            [['status'], 'string', 'max' => 255],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'uid' => '用户ID',
+            'aid' => '活动ID',
+            'created_at' => '报名时间',
+            'status' => '状态',
+        ];
+    }
+}

粤ICP备19079148号