123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- // +----------------------------------------------------------------------
- // | Niucloud-admin 企业快速开发的saas管理平台
- // +----------------------------------------------------------------------
- // | 官方网址:https://www.niucloud.com
- // +----------------------------------------------------------------------
- // | niucloud团队 版权所有 开源版本可自由商用
- // +----------------------------------------------------------------------
- // | Author: Niucloud Team
- // +----------------------------------------------------------------------
- namespace app\service\admin\shop\site;
- use app\model\shop\ShopMember;
- use core\base\BaseAdminService;
- /**
- * 店铺会员服务层
- * Class ShopService
- * @package app\service\admin\shop\site
- */
- class ShopMemberService extends BaseAdminService
- {
- public function __construct()
- {
- parent::__construct();
- $this->model = new ShopMember();
- }
- /**
- * 会员列表分页查询
- */
- public function getPage(array $where = []):array
- {
- $field = 'id, is_follow, first_consum_time, shop_member.last_consum_time, shop_member_label, member_no, mobile, nickname, username, headimg, register_channel';
- $order = 'create_time desc';
- $search_model = $this->model
- ->withJoin(['member' => ['member_no']])
- ->withSearch(['keyword', 'is_follow', 'register_channel', 'shop_member_label', 'create_time'], $where)
- ->where([['shop_member.site_id', '=', $this->site_id]])->append([ 'register_channel_name', 'is_follow_name' ])->field($field)->order($order);
- return $this->pageQuery($search_model, function ($item, $key) {
- $item = $this->makeUp($item);
- });
- }
- /**
- * 会员详情
- * @param int $member_id
- * @return array|null
- */
- public function getInfo(int $member_id)
- {
- $field = 'id, is_follow, first_consum_time, shop_member.last_consum_time, comsum_num, comsum_money, shop_member_label, member_no, mobile, nickname, username, headimg, register_channel';
- return $this->makeUp($this->model
- ->withJoin(['member' => ['member_id', 'member_no']])
- ->where([['shop_member.member_id', '=', $member_id], ['shop_member.site_id', '=', $this->site_id]])->field($field)->append(['register_channel_name'])->findOrEmpty()->toArray());
- }
- /**
- * 组合整理数据
- * @param $data
- */
- public function makeUp($data){
- //会员标签
- if(!empty($data['shop_member_label'])){
- $data['shop_member_label_array'] = (new ShopMemberLabelService())->getMemberLabelListByLabelIds($data['shop_member_label']);
- }
- return $data;
- }
- /**
- * 修改
- * @param int $member_id
- * @param string $field
- * @param $data
- * @return ShopMember
- */
- public function modify(int $member_id, string $field, $data)
- {
- $field_name = match ($field) {
- 'shop_member_label' => 'shop_member_label',
- };
- $where = [
- ['member_id', '=', $member_id],
- ];
- return $this->model->where($where)->update([$field_name => $data]);
- }
- }
|