homepagePHP/app/Common/Model/AboutUsModel.class.php

76 lines
2.1 KiB
PHP
Executable File

<?php
namespace Common\Model;
use Gy_Library\DBCont;
use Illuminate\Support\Facades\DB;
//新闻资讯
class AboutUsModel extends \Gy_Library\GyListModel {
protected $_validate = array(
array('title', 'require', '请填写标题',self::MUST_VALIDATE ,'',3),
array('content', 'require', '请填写内容详情', self::MUST_VALIDATE ,'', 3),
/*********取值范围********/
// //array('value',array(1,2,3),'值的范围不正确!',2,'in'),
array('title', '0,255', '标题过长',self::EXISTS_VALIDATE,'length', self::MODEL_BOTH),
);
protected $_auto = array(
array('create_date', 'microtime', parent::MODEL_INSERT, 'function', true),
);
public function extractNumberGetName($strs, $countarr)
{
$patterns = "/\d+/";
$str = '';
preg_match_all($patterns, $strs, $arr);
$i = 0;
foreach ($arr[0] as $key => $value) {
if ($i == 0) {
$str .= $countarr[$value];
} else {
$str .= '、' . $countarr[$value];
}
$i++;
}
return $str;
}
/*
* 提取数字并去数据库取得相应的分类名
* $strs 需要处理的字符串
* $table 数据表名
* $condition 条件字段
* $field 获取的字段
*/
public function extractNumberGetNameForCondition($strs, $table, $condition, $field)
{
if (empty($strs)) {
return '';
}
$patterns = "/\d+/"; //第一种
preg_match_all($patterns, $strs, $arr);
if (empty($arr[0])) {
return '';
}
$map[$condition] = array('in', $arr[0]);
$map['status'] = DBCont::YES_BOOL_STATUS;
$model = D($table);
$result = $model->field($field)->where($map)->select();
$str = '';
$i = 0;
foreach ($result as $key => $item) {
if ($i == 0) {
$str .= $item[$field];
} else {
$str .= '、' . $item[$field];
}
$i++;
}
return $str;
}
}