191 lines
6.1 KiB
PHP
191 lines
6.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\models;
|
|
|
|
use app\models\Activity;
|
|
use app\models\ActivityUserPrize;
|
|
use app\models\ActivityUserRate;
|
|
use app\models\Coupon;
|
|
use app\models\Model;
|
|
use app\models\Store;
|
|
use app\models\StoreUser;
|
|
use app\models\User;
|
|
use app\modules\admin\models\AdminModel;
|
|
use yii\data\Pagination;
|
|
|
|
class ActivityActionForm extends AdminModel
|
|
{
|
|
public $page;
|
|
public $limit;
|
|
|
|
public $keywords;
|
|
public $status;
|
|
public $type;
|
|
public $ids;
|
|
public $name;
|
|
public $poster_btn_name;
|
|
public $poster_btn_url;
|
|
public $content_btn_name;
|
|
public $content_btn_url;
|
|
public $poster_img_arr;
|
|
public $start_time;
|
|
public $end_time;
|
|
public $data;
|
|
public $content;
|
|
public $id;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['keywords',], 'trim'],
|
|
[['keywords','ids','name','poster_btn_name','poster_btn_url','content_btn_name','content_btn_url','start_time','end_time','data','content','poster_img_arr'], 'string'],
|
|
[['page', 'limit','status','type','id'], 'integer'],
|
|
[['page'], 'default', 'value' => 1],
|
|
[['limit'], 'default', 'value' => 20],
|
|
];
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'ids' => '选择项',
|
|
];
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
|
|
$query = Activity::find()
|
|
->where([
|
|
'is_delete' => 0
|
|
])
|
|
->andFilterWhere([
|
|
'OR',
|
|
['like','name',$this->keywords],
|
|
])->andFilterWhere([
|
|
'status' => $this->status
|
|
]);
|
|
|
|
$count = $query->count();
|
|
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
|
|
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['id' => SORT_DESC])->asArray()->all();
|
|
foreach ($list as $index => $item){
|
|
$item['created_at_cn'] = date("Y-m-d H:i",$item['created_at']);
|
|
$item['count_user'] = ActivityUserRate::find()->andWhere([
|
|
'activity_id' => $item['id'],
|
|
'is_delete' => 0,
|
|
])->count();
|
|
$item['count_user_price'] = ActivityUserPrize::find()->andWhere([
|
|
'activity_id' => $item['id'],
|
|
'is_delete' => 0,
|
|
])->groupBy('user_id')->count();
|
|
$item['count_user_price_all'] = ActivityUserPrize::find()->andWhere([
|
|
'activity_id' => $item['id'],
|
|
'is_delete' => 0,
|
|
])->count();
|
|
$item['start_date'] = date("Y-m-d H:i:s",$item['start_time']);
|
|
$item['end_date'] = date("Y-m-d H:i:s",$item['end_time']);
|
|
$res = $item;
|
|
$res['data'] = json_decode($res['data'],true);
|
|
$res['poster_img_arr'] = json_decode($res['poster_img_arr'],true)??'';
|
|
$item['res'] = $res;
|
|
$list[$index] = $item;
|
|
}
|
|
$data = [];
|
|
$data['code'] = 0;
|
|
$data['msg'] = 'ok';
|
|
$data['data'] = $list;
|
|
$data['count'] = $count;
|
|
return $data;
|
|
|
|
}
|
|
|
|
//创建数据
|
|
public function actionEdit(){
|
|
if(!empty($this->id)){
|
|
$obj = Activity::findOne([
|
|
'id' => $this->id,
|
|
]);
|
|
}
|
|
if(empty($obj)){
|
|
$obj = new Activity();
|
|
$obj->created_at = time();
|
|
$obj->is_delete = 0;
|
|
$obj->deleted_at = 0;
|
|
}
|
|
$obj->name = $this->name;
|
|
$obj->content = $this->content;
|
|
$obj->poster_img_arr = $this->poster_img_arr;
|
|
$obj->poster_btn_name = $this->poster_btn_name;
|
|
$obj->poster_btn_url = $this->poster_btn_url;
|
|
$obj->content_btn_name = $this->content_btn_name;
|
|
$obj->content_btn_url = $this->content_btn_url;
|
|
$obj->data = $this->data;
|
|
$obj->type = 1;
|
|
$obj->start_time = strtotime($this->start_time);
|
|
$obj->end_time = strtotime($this->end_time);
|
|
$obj->status = 1;
|
|
$obj->updated_at = time();
|
|
$obj->save();
|
|
return $this->apiReturnSuccess('添加成功');
|
|
}
|
|
|
|
//创建数据
|
|
public function actionDelete(){
|
|
$find = Activity::findOne([
|
|
'id' => $this->id,
|
|
]);
|
|
$find->is_delete = 1;
|
|
$find->deleted_at = time();
|
|
$find->save();
|
|
return $this->apiReturnSuccess('删除成功');
|
|
}
|
|
|
|
// 参与用户
|
|
public function actionJoinUser(){
|
|
$query = ActivityUserRate::find()
|
|
->where([
|
|
'is_delete' => 0,
|
|
'activity_id' => $this->id,
|
|
]);
|
|
|
|
$count = $query->count();
|
|
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
|
|
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['id' => SORT_DESC])->asArray()->all();
|
|
foreach ($list as $index => $item){
|
|
$item['created_at_cn'] = date("Y-m-d H:i",$item['created_at']);
|
|
$item['count_user_price_all'] = ActivityUserPrize::find()->andWhere([
|
|
'activity_id' => $item['activity_id'],
|
|
'user_id' => $item['user_id'],
|
|
'is_delete' => 0,
|
|
])->count();
|
|
$item['start_date'] = date("Y-m-d H:i:s",$item['start_time']);
|
|
$item['end_date'] = date("Y-m-d H:i:s",$item['end_time']);
|
|
$user = User::findOne([
|
|
'id' => $item['user_id'],
|
|
]);
|
|
$item['nickname'] = !empty($user->real_name)?$user->real_name:$user->nickname;
|
|
$item['mobile_phone'] = $user->mobile_phone;
|
|
$list[$index] = $item;
|
|
}
|
|
$data = [];
|
|
$data['code'] = 0;
|
|
$data['msg'] = 'ok';
|
|
$data['data'] = $list;
|
|
$data['count'] = $count;
|
|
return $data;
|
|
}
|
|
|
|
} |