| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- declare (strict_types = 1);
- namespace app\model\api;
- use think\Model;
- /**
- * 用户荣誉定义表模型
- * @mixin \think\Model
- */
- class UserHonor extends Model
- {
- /**
- * 获取荣誉列表
- * @param array $post
- * @param string $field
- * @return array
- */
- public function getList($post, $field = "*")
- {
- $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
- $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
- $where = [];
- if (isset($post["status"]) && in_array((string)$post["status"], ["0", "1"])) {
- $where[] = ["status", "=", (int)$post["status"]];
- }
- if (!empty($post["name"])) {
- $where[] = ["name", "like", "%{$post["name"]}%"];
- }
- $totalCount = $this->where($where)->count();
- $data = null;
- if ($totalCount > 0) {
- $data = $this
- ->field($field)
- ->where($where)
- ->order("sort", "desc")
- ->order("id", "desc")
- ->page($post["page"], $post["pageSize"])
- ->select();
- if (!empty($data)) {
- $data = $data->toArray();
- }
- }
- $data = empty($data) ? [] : $data;
- return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
- }
- /**
- * 获取所有启用的荣誉(用于下拉选择)
- * @return array
- */
- public function getAllEnabled()
- {
- $data = $this
- ->field("id,name,icon")
- ->where("status", 1)
- ->order("sort", "desc")
- ->order("id", "desc")
- ->select();
- if (!empty($data)) {
- $data = $data->toArray();
- }
- return empty($data) ? [] : $data;
- }
- }
|