安徽博创起重服务端程序
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.
 
 
 
 
 

220 lines
6.9 KiB

<?php
namespace app\admin\logic\vote;
use app\common\basics\Logic;
use app\common\model\content\ResourceCategory;
use app\common\model\vote\Vote;
use Exception;
class VoteLogic 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['cid']) and is_numeric($get['cid']))
$where[] = ['cid', '=', $get['cid']];
$model = new Vote();
$lists = $model->field(true)
->where($where)
->with(['category'])
->order('add_time', 'desc')
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
foreach ($lists['data'] as &$item) {
$item['category'] = $item['category']['name'] ?? '未知';
$item['start_time'] = $item['start_time']? date("Y-m-d H:i:s",$item['start_time']):"";
$item['end_time'] = $item['end_time']? date("Y-m-d H:i:s",$item['end_time']):"";
$item['add_time'] = $item['add_time']? date("Y-m-d H:i:s",$item['add_time']):"";
$item['is_rank'] = $item['is_rank'] ? '显示' : '隐藏';
$item['is_redo'] = $item['is_redo']==0 ? '当天不可重复' : ($item['is_redo']==1?"全部不重复":"可重复");
$item['vote_str'] = ($item['vote_type']==0 ? '每天' : '总共').$item['vote_num']."";
$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 Vote();
$detail = $model->field(true)->findOrEmpty($id)->toArray();
$detail['start_time'] = $detail['start_time']? date("Y-m-d H:i:s",$detail['start_time']):"";
$detail['end_time'] = $detail['end_time']? date("Y-m-d H:i:s",$detail['end_time']):"";
$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']);
}
Vote::create([
'cid' => $post['cid'],
'title' => $post['title'],
'image' => $post['image'] ?? '',
'video' => $post['video'] ?? '',
'images' => $post['images'] ?? '',
'notice' => $post['notice'] ?? '',
'content' => $post['content'] ?? '',
'start_time' => $post['start_time'] ? strtotime($post['start_time']) : 0,
'end_time' => $post['end_time'] ? strtotime($post['end_time']) : 0,
'is_rank' => $post['is_rank'] ?? 1,
'is_redo' => $post['is_redo'] ?? 0,
'province_id' => $post['province_id'] ?? 0,
'vote_type' => $post['vote_type'] ?? 0,
'vote_num' => $post['vote_num'] ?? 0,
'base_visit' => $post['base_visit'] ?? 0,
'status' => $post['status'] ?? 1,
'vote_total' => 0,
'views' => 0,
'add_time' => time(),
]);
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']);
}
Vote::update([
'cid' => $post['cid'],
'title' => $post['title'],
'image' => $post['image'] ?? '',
'video' => $post['video'] ?? '',
'images' => $post['images'] ?? '',
'notice' => $post['notice'] ?? '',
'content' => $post['content'] ?? '',
'start_time' => $post['start_time'] ? strtotime($post['start_time']) : 0,
'end_time' => $post['end_time'] ? strtotime($post['end_time']) : 0,
'is_rank' => $post['is_rank'] ?? 1,
'is_redo' => $post['is_redo'] ?? 0,
'province_id' => $post['province_id'] ?? 0,
'vote_type' => $post['vote_type'] ?? 0,
'vote_num' => $post['vote_num'] ?? 0,
'base_visit' => $post['base_visit'] ?? 0,
'status' => $post['status'] ?? 1,
'update_time' => time(),
], ['id'=>$post['id']]);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* @Notes: 删除
* @Author:
* @param $id
* @return bool
*/
public static function del($id)
{
try {
Vote::update([
'del' => 1,
'update_time' => time()
], ['id'=>$id]);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* @Notes: 隐藏
* @Author: 张无忌
* @param $id
* @return bool
*/
public static function status($id,$status)
{
try {
Vote::update([
'status' => $status,
'update_time' => time()
], ['id'=>$id]);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* @Notes: 获取分类
* @Author: 张无忌
* @return array
*/
public static function getVotes()
{
try {
$model = new Vote();
return $model->field(true)
->where(['del'=>0, 'status'=>1])
->order('id', 'desc')
->select()
->toArray();
} catch (\Exception $e) {
return [];
}
}
}