!empty($arr['agent_id']) ? $arr['agent_id'] : 0, 'merchant_id' => !empty($arr['merchant_id']) ? $arr['merchant_id'] : 0, 'store_id' => !empty($arr['store_id']) ? $arr['store_id'] : 0, 'guide_id' => !empty($arr['guide_id']) ? $arr['guide_id'] : 0, 'path' => $arr['path'], 'add_time' => isset($arr['add_time']) ? $arr['add_time'] : time(), 'storage_type' => !empty($arr['storage_type']) ? $arr['storage_type'] : 1, 'source_type' => !empty($arr['source_type']) ? $arr['source_type'] : 1, 'name' => isset($arr['name']) ? $arr['name'] : '', 'original_name' => isset($arr['original_name']) ? $arr['original_name'] : '', 'size' => isset($arr['size']) ? $arr['size'] : 0, 'from_type_id' => !empty($arr['from_type_id']) ? $arr['from_type_id'] : 0, 'user_type' => !empty($arr['user_type']) ? $arr['user_type'] : 1, 'catalog' => isset($arr['catalog']) ? $arr['catalog'] : '', 'type' => !empty($arr['type']) ? $arr['type'] : 1, 'user_id' => !empty($arr['user_id']) ? $arr['user_id'] : 0, ); // print_r($add); // if ($add['from_type_id']) { $res = $this->add($add); return $res; // } else { // return false; // } } /** * 查询 * @param $map * @return mixed */ public function getFind($map) { $res = $this->where($map)->find(); return $res; } /** * 查询某个字段 * @param string $map * @param null $field * @return mixed */ public function getOneField($map, $field) { if ($field == 'path') { $res = $this->getFieldPath($map); } else { $res = $this->where($map)->getField($field); } return $res; } /** * 获取图片 * @param $map * @return bool|string */ public function getFieldPath($map) { $img = $this->where($map)->find(); if ($img) { if ($img['storage_type'] == 1) { $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; $res = $http_type . $_SERVER['HTTP_HOST'] . $img['path']; } else { $res = $img['path']; } } else { $res = ''; } return $res; } public function getFieldInfo($map) { $img = $this->where($map)->find(); if ($img) { if ($img['storage_type'] == 1) { $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; $res['path'] = $http_type . $_SERVER['HTTP_HOST'] . $img['path']; } else { $res['path'] = $img['path']; } $res['type'] = $img['type']; } else { $res = false; } return $res; } /** * 获取图片 * @param $map * @return bool|string */ public function getImgPath($map) { $img = $this->where($map)->find(); $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; if ($img) { if ($img['storage_type'] == 1) { $res = $http_type . $_SERVER['HTTP_HOST'] . $img['path']; } else { $res = $img['path']; } } else { $res = $http_type . $_SERVER['HTTP_HOST'] . '/Public/Retail/goods/default.png'; } return $res; } /** * 获取图片 * @param $id * @return bool|string */ public function getImagePath($id) { $img = $this->where(array('id' => $id))->find(); if ($img) { if ($img['storage_type'] == 1) { $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; $res = $http_type . $_SERVER['HTTP_HOST'] . $img['path']; } else { $res = $img['path']; } } else { $res = ''; } return $res; } /** * 查询 * @param $map * @param $field * @param $order * @param $page * @param $limit * @return mixed */ public function getSelect($map, $field = '*', $order = 'id desc', $page = '', $limit = '') { if (!$field) { $field = '*'; } if (!$order) { $order = 'id asc'; } if ($page && $limit) { $res = $this->where($map)->page($page, $limit)->order($order)->field($field)->select(); } else { $res = $this->where($map)->field($field)->select(); } return $res; } /** * 获取数量 * @param $map * @return mixed */ public function getCount($map) { $res = $this->where($map)->count(); return intval($res); } public function doDelete($map) { if ($map) { $res = $this->where($map)->delete(); return $res; } else { return false; } } /** * 获取某字段 * @param $map * @param string $fields * @param $bol //true为获取多条 * @return mixed */ public function getFindField($map, $fields = 'id', $bol = false) { $res = $this->where($map)->getField($fields, $bol); return $res; } /** * 更新数据 * @param $map * @param $save * @return mixed */ public function updateData($map, $save) { $res = $this->where($map)->save($save); return $res; } /** * 获取多图 * @param $img_id 图片ID字符','串拼接 * @return array */ public function getImageArray($img_id) { $img_url = array(); $empty_img = getServerUrl() . '/Public/images/empty-image.png'; if (!empty($img_id)) { $img_id_arr = explode(',', $img_id); foreach ($img_id_arr as $key => $value) { $img = $this->getFieldPath(array('id' => $value)); $img_url[] = $img ? $img : $empty_img; } } return $img_url; } }