123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- // +----------------------------------------------------------------------
- // | Niucloud-admin 企业快速开发的saas管理平台
- // +----------------------------------------------------------------------
- // | 官方网址:https://www.niucloud.com
- // +----------------------------------------------------------------------
- // | niucloud团队 版权所有 开源版本可自由商用
- // +----------------------------------------------------------------------
- // | Author: Niucloud Team
- // +----------------------------------------------------------------------
- namespace app\service\admin\shop\site;
- use app\model\member\MemberLabel;
- use app\service\core\member\CoreMemberLabelService;
- use core\base\BaseAdminService;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\Response;
- /**
- * 店铺会员标签服务层
- * Class ShopService
- * @package app\service\admin\shop\site
- */
- class ShopMemberLabelService extends BaseAdminService
- {
- protected static $cache_tag_name = 'shop_member_label_cache';
- public function __construct()
- {
- parent::__construct();
- $this->model = new MemberLabel();
- }
- /**
- * 会员标签列表分页查询
- */
- public function getPage(array $where = [], string $order = 'sort desc,create_time desc')
- {
- $field = 'label_id, site_id, label_name, memo, sort, create_time, update_time';
- $search_model = $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->withSearch([ 'label_name' ], $where)->field($field)->append([ "member_num" ])->order($order);
- return $this->pageQuery($search_model);
- }
- /**
- * 获取会员标签信息
- * @param int $label_id
- * @return array
- */
- public function getInfo(int $label_id)
- {
- $field = 'label_id, site_id, label_name, memo, sort, create_time, update_time';
- return $this->model->field($field)->where([ [ 'label_id', '=', $label_id ], [ 'site_id', '=', $this->site_id ] ])->findOrEmpty()->toArray();
- }
- /**
- * 获取标签
- * @return array
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function getAll()
- {
- return ( new CoreMemberLabelService() )->getAll($this->site_id);
- }
- /**
- * 添加会员标签
- * @param array $data
- * @return mixed
- */
- public function add(array $data)
- {
- $data[ 'site_id' ] = $this->site_id;
- $res = $this->model->create($data);
- ( new CoreMemberLabelService() )->clearCache($this->site_id);
- return $res->label_id;
- }
- /**
- * 会员标签编辑
- * @param int $label_id
- * @param array $data
- * @return true
- */
- public function edit(int $label_id, array $data)
- {
- $data[ 'update_time' ] = time();
- $this->model->where([ [ 'label_id', '=', $label_id ], [ 'site_id', '=', $this->site_id ] ])->save($data);
- ( new CoreMemberLabelService() )->clearCache($this->site_id);
- return true;
- }
- /**
- * 删除会员标签
- * @param int $label_id
- * @return bool
- */
- public function del(int $label_id)
- {
- $res = $this->model->where([ [ 'label_id', '=', $label_id ], [ 'site_id', '=', $this->site_id ] ])->delete();
- ( new CoreMemberLabelService() )->clearCache($this->site_id);
- return $res;
- }
- /**
- * 通过标签id获取标签列表
- * @param array $label_ids
- * @return Response
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function getMemberLabelListByLabelIds(array $label_ids)
- {
- $site_id = $this->site_id;
- sort($label_ids);
- $cache_name = __METHOD__ . md5(implode("_", $label_ids));
- return cache_remember(
- $cache_name,
- function() use ($site_id, $label_ids) {
- return array_keys_search($this->getAll($site_id), $label_ids, 'label_id');
- },
- self::$cache_tag_name . $site_id
- );
- }
- }
|