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.
 
 
 
 
 
 
zhishifufei_php/application/admin/model/wechat/WechatNews.php

135 lines
4.6 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\admin\model\wechat;
use app\admin\model\system\SystemAdmin;
use traits\ModelTrait;
use basic\ModelBasic;
use think\Db;
/**
* 图文管理 Model
* Class WechatNews
* @package app\admin\model\wechat
*/
class WechatNews extends ModelBasic
{
use ModelTrait;
/**
* 获取配置分类
* @param array $where
* @return array
*/
public static function getAll($where = array())
{
$model = new self;
if ($where['title'] !== '') $model = $model->where('title', 'LIKE', "%$where[title]%");
if ($where['cid'] !== '') $model = $model->where("CONCAT(',',cid,',') LIKE '%,$where[cid],%'");
if ($where['cid'] == '') {
if (!$where['merchant']) $model = $model->where('mer_id', 0);
if ($where['merchant']) $model = $model->where('mer_id', 'GT', 0);
}
$model = $model->where('status', 1)->where('hide', 0);
return self::page($model, function ($item) {
$item['admin_name'] = '总后台管理员---》' . SystemAdmin::where('id', $item['admin_id'])->value('real_name');
$item['content'] = Db::name('wechatNewsContent')->where('nid', $item['id'])->value('content');
}, $where);
}
/**
* 删除图文
* @param $id
* @return bool
*/
public static function del($id)
{
return self::edit(['status' => 0], $id, 'id');
}
/**
* 获取指定字段的值
* @return array
*/
public static function getNews()
{
return self::where('status', 1)->where('hide', 0)->order('id desc')->column('id,title');
}
/**
* 给表中的字符串类型追加值
* 删除所有有当前分类的id之后重新添加
* @param $cid
* @param $id
* @return bool
*/
public static function saveBatchCid($cid, $id)
{
$res_all = self::where('cid', 'LIKE', "%$cid%")->select();//获取所有有当前分类的图文
foreach ($res_all as $k => $v) {
$cid_arr = explode(',', $v['cid']);
if (in_array($cid, $cid_arr)) {
$key = array_search($cid, $cid_arr);
array_splice($cid_arr, $key, 1);
}
if (empty($cid_arr)) {
$data['cid'] = 0;
self::edit($data, $v['id']);
} else {
$data['cid'] = implode(',', $cid_arr);
self::edit($data, $v['id']);
}
}
$res = self::where('id', 'IN', $id)->select();
foreach ($res as $k => $v) {
if (!in_array($cid, explode(',', $v['cid']))) {
if (!$v['cid']) {
$data['cid'] = $cid;
} else {
$data['cid'] = $v['cid'] . ',' . $cid;
}
self::edit($data, $v['id']);
}
}
return true;
}
public static function setContent($id, $content)
{
$count = Db::name('wechatNewsContent')->where('nid', $id)->count();
$data['nid'] = $id;
$data['content'] = $content;
if ($count) {
$res = Db::name('wechatNewsContent')->where('nid', $id)->setField('content', $content);
if ($res !== false) $res = true;
} else
$res = Db::name('wechatNewsContent')->insert($data);
return $res;
}
public static function merchantPage($where = array())
{
$model = new self;
if ($where['title'] !== '') $model = $model->where('title', 'LIKE', "%$where[title]%");
if ($where['cid'] !== '') $model = $model->where('cid', 'LIKE', "%$where[cid]%");
$model = $model
->where('status', 1)
->where('hide', 0)
->where('admin_id', $where['admin_id'])
->where('mer_id', $where['mer_id']);
return self::page($model, function ($item) {
$item['content'] = Db::name('wechatNewsContent')->where('nid', $item['id'])->value('content');
}, $where);
}
}