123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- // +----------------------------------------------------------------------
- // | Niucloud-admin 企业快速开发的多应用管理平台
- // +----------------------------------------------------------------------
- // | 官方网址:https://www.niucloud.com
- // +----------------------------------------------------------------------
- // | niucloud团队 版权所有 开源版本可自由商用
- // +----------------------------------------------------------------------
- // | Author: Niucloud Team
- // +----------------------------------------------------------------------
- namespace app\service\admin\diy;
- use app\dict\diy\AdvPositionDict;
- use app\model\diy\Adv;
- use core\base\BaseAdminService;
- use core\exception\AdminException;
- /**
- * 广告服务层
- */
- class AdvService extends BaseAdminService
- {
- public function __construct()
- {
- parent::__construct();
- $this->model = new Adv();
- }
- /**
- * 获取广告列表
- * @param array $where
- * @return array
- */
- public function getPage(array $where = [])
- {
- $field = 'adv_id, site_id, ap_key, adv_title, adv_url, adv_image, slide_sort, background';
- $order = 'adv_id desc';
- $search_model = $this->model->withSearch([ 'ap_key' ], $where)->field($field)->append(['ap_name'])->order($order);
- $list = $this->pageQuery($search_model);
- return $list;
- }
- /**
- * 获取广告列表
- * @param array $where
- * @param string $field
- * @return array
- */
- public function getList(array $where = [], $field = 'adv_id, site_id, ap_key, adv_title, adv_url, adv_image, slide_sort, background')
- {
- $order = 'adv_id desc';
- return $this->model->withSearch([ 'ap_key' ], $where)->field($field)->append(["ap_name"])->order($order)->select()->toArray();
- }
- /**
- * 获取广告信息
- * @param int $id
- * @return array
- */
- public function getInfo(int $id)
- {
- $field = 'adv_id, site_id, ap_key, adv_title, adv_url, adv_image, slide_sort, background';
- $info = $this->model->field($field)->where([ [ 'adv_id', '=', $id ], ['site_id', '=', $this->site_id] ])->append(["ap_name"])->findOrEmpty()->toArray();
- return $info;
- }
- /**
- * 添加广告
- * @param array $data
- * @return mixed
- */
- public function add(array $data)
- {
- $adv_position = AdvPositionDict::getAdvPosition();
- $position_list = array_column($adv_position,null,'keywords');
- if(!array_key_exists($data['ap_key'], $position_list)) throw new AdminException("DIY_ADV_POSITION_NOT_EXIST");
- $res = $this->model->create($data);
- return $res->adv_id;
- }
- /**
- * 广告编辑
- * @param int $id
- * @param array $data
- * @return bool
- */
- public function edit(int $id, array $data)
- {
- $adv_position = AdvPositionDict::getAdvPosition();
- $position_list = array_column($adv_position,null,'keywords');
- if(!array_key_exists($data['ap_key'], $position_list)) throw new AdminException("DIY_ADV_POSITION_NOT_EXIST");
- $this->model->where([ [ 'adv_id', '=', $id ]])->update($data);
- return true;
- }
- /**
- * 删除广告
- * @param int $id
- * @return bool
- */
- public function del(int $id)
- {
- $model = $this->model->where([ [ 'adv_id', '=', $id ]])->find();
- $res = $model->delete();
- return $res;
- }
- }
|