PlanPicService.class.php
2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* 照片墙照片表Service
* @author: houyingcai
* @email: 594609175@qq.com
* @date : 2017-08-29 16:40:17
* @version $Id$
*/
namespace Common\Service;
use Common\Model\PlanPicModel;
class PlanPicService extends AbstractService
{
// 照片上传类型标识:手机端用户上传
const PIC_UPLOAD_TYPE_USER = 0;
// 照片上传类型标识:后台管理员上传
const PIC_UPLOAD_TYPE_ADMIN = 1;
// 图片名称最大长度
const PIC_NAME_MAX_LENGTH = 120;
/** @var PlanPicModel */
protected $_d;
public function __construct()
{
// 实例化照片model
$this->_d = new PlanPicModel();
parent::__construct();
}
/**
* 更新点赞量
* @author wanghuan
*
* @param int $pic_id 照片id
* @param int $type 更新类型:0=加1,1=减1
*
* @return bool
*/
public function update_likes($pic_id = 0, $type = 0)
{
return $this->_d->update_likes($pic_id, $type);
}
/**
* 获取照片墙详情接口
*
* @author 蔡建华
* @param array $params 查询条件
*
* @return array|bool
*/
public function get_pic_list($params = [])
{
if (empty($params['plan_id'])) {
E('_EMPTY_PLAN_PIC_ID');
}
// 倒序排列
$order_option = ['pic_id' => 'asc'];
$conds = ['plan_id' => $params['plan_id']];
// 列表总数
$total = $this->_d->count_by_conds($conds);
if ($total > 0) {
$fields = 'pic_name,pic_id,pic_at_id';
$list = $this->_d->list_by_conds($conds, null, $order_option, $fields);
}
$this->format_pic_list($list);
// 组装返回数
return [
'total' => intval($total),
'list' => !empty($list) ? $list : [],
];
}
/**
* 格式化图片
*
* @author 蔡建华
* @param array $list 照片列表
*/
protected function format_pic_list(&$list)
{
foreach ($list as &$val) {
$val['pic_url'] = empty($val['pic_at_id']) ? '' : imgUrlReal($val['pic_at_id']);
}
}
}