123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- // +----------------------------------------------------------------------
- // | Niucloud-admin 企业快速开发的多应用管理平台
- // +----------------------------------------------------------------------
- // | 官方网址:https://www.niucloud.com
- // +----------------------------------------------------------------------
- // | niucloud团队 版权所有 开源版本可自由商用
- // +----------------------------------------------------------------------
- // | Author: Niucloud Team
- // +----------------------------------------------------------------------
- namespace app\model\shop;
- use app\dict\common\ChannelDict;
- use app\dict\common\CommonDict;
- use app\dict\member\MemberDict;
- use app\dict\member\MemberLoginTypeDict;
- use app\dict\member\MemberRegisterChannelDict;
- use app\dict\member\MemberRegisterTypeDict;
- use app\dict\shop\ShopMemberIsFollowDict;
- use app\model\member\Member;
- use app\model\site\Site;
- use core\base\BaseModel;
- use think\db\Query;
- use think\model\relation\HasOne;
- /**
- * 店铺会员扩展
- * Class Shop
- * @package addon\mall\app\model\shop
- */
- class ShopMember extends BaseModel
- {
- protected $type = [
- 'first_consum_time' => 'timestamp',
- 'last_consum_time' => 'timestamp',
- ];
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'site_shop_member';
- // 设置json类型字段
- protected $json = ['shop_member_label'];
- // 设置JSON数据返回数组
- protected $jsonAssoc = true;
- public function member()
- {
- return $this->hasOne(Member::class, 'member_id', 'member_id');
- }
- public function site()
- {
- return $this->hasOne(Site::class, 'site_id', 'site_id');
- }
- /**
- * 状态字段转化
- * @param $value
- * @param $data
- * @return mixed
- */
- public function getStatusNameAttr($value, $data)
- {
- if (empty($data['status']))
- return '';
- return MemberDict::getStatus()[$data['status']] ?? '';
- }
- /**
- * 关注状态字段转化
- * @param $value
- * @param $data
- * @return mixed
- */
- public function getIsFollowNameAttr($value, $data)
- {
- if ($data['is_follow'] == '')
- return '';
- return ShopMemberIsFollowDict::getStatus()[$data['is_follow']] ?? '';
- }
- /**
- * 注册来源字段转化
- * @param $value
- * @param $data
- * @return mixed
- */
- public function getRegisterChannelNameAttr($value, $data)
- {
- if (empty($data['register_channel']))
- return '';
- return MemberRegisterChannelDict::getType()[$data['register_channel']] ?? '';
- }
- /**
- * 注册方式字段转化
- * @param $value
- * @param $data
- * @return mixed
- */
- public function getRegisterTypeNameAttr($value, $data)
- {
- if (empty($data['register_type']))
- return '';
- return MemberRegisterTypeDict::getType()[$data['register_type']] ?? '';
- }
- /**
- * 登录渠道字段转化
- * @param $value
- * @param $data
- * @return mixed
- */
- public function getLoginChannelNameAttr($value, $data)
- {
- if (empty($data['login_channel']))
- return '';
- return ChannelDict::getType()[$data['login_channel']] ?? '';
- }
- /**
- * 登录方式字段转化
- * @param $value
- * @param $data
- * @return mixed
- */
- public function getLoginTypeNameAttr($value, $data)
- {
- if (empty($data['login_type']))
- return '';
- return MemberLoginTypeDict::getType()[$data['login_type']] ?? '';
- }
- /**
- * 性别名称
- * @param $value
- * @param $data
- * @return mixed|string
- */
- public function getSexNameAttr($value, $data)
- {
- if (empty($data['sex']))
- return '';
- return CommonDict::getSexType()[$data['sex']] ?? '';
- }
- /**
- * 会员信息搜索器
- * @param $query
- * @param $value
- * @param $data
- * @return void
- */
- public function searchKeywordAttr($query, $value, $data)
- {
- if ($value) {
- $query->where('member_no|nickname|mobile', 'like', "%$value%");
- }
- }
- /**
- * 注册方式搜索
- * @param $query
- * @param $value
- * @param $data
- */
- public function searchRegisterTypeAttr($query, $value, $data)
- {
- if ($value) {
- $query->where('register_type', '=', $value);
- }
- }
- /**
- * 关注状态搜索
- * @param $query
- * @param $value
- * @param $data
- */
- public function searchIsFollowAttr($query, $value, $data)
- {
- if ($value != '') {
- $query->where('is_follow', '=', $value);
- }
- }
- /**
- * 注册来源搜索
- * @param $query
- * @param $value
- * @param $data
- */
- public function searchRegisterChannelAttr($query, $value, $data)
- {
- if ($value) {
- $query->where('register_channel', '=', $value);
- }
- }
- /**
- * 标签筛选
- * @param Query $query
- * @param $value
- * @param $data
- * @return void
- */
- public function searchShopMemberLabelAttr(Query $query, $value, $data)
- {
- if ($value) {
- $query->whereLike('shop_member_label', '%' . $value . '%');
- }
- }
- /**
- * 注册时间搜索器
- * @param Query $query
- * @param $value
- * @param $data
- */
- public function searchCreateTimeAttr(Query $query, $value, $data)
- {
- $start_time = empty($value[0]) ? 0 : strtotime($value[0]);
- $end_time = empty($value[1]) ? 0 : strtotime($value[1]);
- if ($start_time > 0 && $end_time > 0) {
- $query->whereBetweenTime('create_time', $start_time, $end_time);
- } else if ($start_time > 0 && $end_time == 0) {
- $query->where([['create_time', '>=', $start_time]]);
- } else if ($start_time == 0 && $end_time > 0) {
- $query->where([['create_time', '<=', $end_time]]);
- }
- }
- }
|