安徽博创起重服务端程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

210 lines
6.3 KiB

<?php
namespace app\admin\logic\vote;
use app\common\basics\Logic;
use app\common\model\vote\Vote;
use app\common\model\vote\VotePlayer;
use Exception;
use think\Db;
class VotePlayerLogic extends Logic
{
/**
* 获取分类
* @param $get
* @return array
*/
public static function lists($get)
{
try {
$where = [
['del', '=', 0]
];
if (!empty($get['title']) and trim($get['title'])!='')
$where[] = ['title', 'like', '%'.$get['title'].'%'];
if (!empty($get['vid']) and is_numeric($get['vid']))
$where[] = ['vote_id', '=', $get['vid']];
$model = new VotePlayer();
$lists = $model->field(true)
->where($where)
->with(['vote'])
->order('id', 'desc')
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
foreach ($lists['data'] as &$item) {
$item['vote_title'] = $item['vote']['title'] ?? '';
$item['add_time'] = $item['add_time']? date("Y-m-d H:i:s",$item['add_time']):"";
$item['status'] = $item['status'] ? '显示' : '隐藏';
}
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
} catch (Exception $e) {
return ['error'=>$e->getMessage()];
}
}
/**
* @Notes: 资料详细
* @Author:
* @param $id
* @return array
*/
public static function detail($id)
{
$model = new VotePlayer();
$detail = $model->field(true)->findOrEmpty($id)->toArray();
$detail['images_arr'] = $detail['images']? explode(",",$detail['images']):[];
return $detail;
}
/**
* @Notes: 添加帮助
* @Author:
* @param $post
* @return bool
*/
public static function add($post)
{
try {
if(isset($post['goods_image']) && count($post['goods_image'])){
$post['images'] = implode(",",$post['goods_image']);
}
VotePlayer::create([
'vote_id' => $post['vote_id']??0,
'name' => $post['name'],
'avatar' => $post['avatar'] ?? '',
'video' => $post['video'] ?? '',
'images' => $post['images'] ?? '',
'intro' => $post['intro'] ?? '',
'vote_num' => $post['vote_num'] ?? 0,
'base_visit' => $post['base_visit'] ?? 0,
'status' => $post['status'] ?? 1,
'vote_total' => 0,
'base_vote' =>$post['base_visit'] ?? 0,
'views' => 0,
'add_time' => time(),
]);
$vote_p = new VotePlayer();
$vote = new Vote();
$count = $vote_p->where('status','=',1)->where('del','=',0)->where('vote_id','=',$post['vote_id'])->sum("base_vote");
$update = [
"base_vote" => $count
];
$vote->where('id','=',$post['vote_id'])->update($update);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* @Notes: 编辑帮助
* @Author: 张无忌
* @param $post
* @return bool
*/
public static function edit($post)
{
try {
if(isset($post['goods_image']) && count($post['goods_image'])){
$post['images'] = implode(",",$post['goods_image']);
}
VotePlayer::update([
'vote_id' => $post['vote_id']??0,
'name' => $post['name'],
'avatar' => $post['avatar'] ?? '',
'video' => $post['video'] ?? '',
'images' => $post['images'] ?? '',
'intro' => $post['intro'] ?? '',
'vote_num' => $post['vote_num'] ?? 0,
'base_visit' => $post['base_visit'] ?? 0,
'base_vote' => $post['base_vote'] ?? 0,
'status' => $post['status'] ?? 1,
'update_time' => time(),
], ['id'=>$post['id']]);
$vote_p = new VotePlayer();
$vote = new Vote();
$count = $vote_p->where('status','=',1)->where('del','=',0)->where('vote_id','=',$post['vote_id'])->sum("base_vote");
$update = [
"base_vote" => $count
];
$vote->where('id','=',$post['vote_id'])->update($update);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* @Notes: 删除
* @Author:
* @param $id
* @return bool
*/
public static function del($id)
{
try {
VotePlayer::update([
'del' => 1,
'update_time' => time()
], ['id'=>$id]);
$vote_p = new VotePlayer();
$vote = new Vote();
$count = $vote_p->where('status','=',1)->where('del','=',0)->where('vote_id','=',$id)->sum("base_vote");
$update = [
"base_vote" => $count
];
$vote->where('id','=',$id)->update($update);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* @Notes: 隐藏
* @Author: 张无忌
* @param $id
* @return bool
*/
public static function status($id,$status)
{
try {
VotePlayer::update([
'status' => $status,
'update_time' => time()
], ['id'=>$id]);
$vote_p = new VotePlayer();
$vote = new Vote();
$count = $vote_p->where('status','=',1)->where('del','=',0)->where('vote_id','=',$id)->sum("base_vote");
$update = [
"base_vote" => $count
];
$vote->where('id','=',$id)->update($update);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
}