| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123 |
- <?php
- namespace app\common\models;
- use app\backend\models\BackendModel;
- use app\backend\modules\member\models\MemberUnique;
- use app\common\events\member\BecomeAgent;
- use app\common\events\member\PluginCreateRelationEvent;
- use app\common\exceptions\AppException;
- use app\common\exceptions\MemberNotLoginException;
- use app\common\facades\Setting;
- use app\common\models\member\MemberChildren;
- use app\common\models\member\MemberDel;
- use app\common\models\member\MemberParent;
- use app\common\models\point\PointBalanceSet;
- use app\common\observers\McMemberObserver;
- use app\common\services\PluginManager;
- use app\common\modules\memberCart\MemberCartCollection;
- use app\common\services\popularize\PortType;
- use app\framework\Database\Eloquent\Collection;
- use app\frontend\modules\member\models\MemberModel;
- use app\frontend\modules\member\models\MemberWechatModel;
- use app\frontend\repositories\MemberAddressRepository;
- use Carbon\Carbon;
- use Yunshop\AggregationCps\models\AggregationCpsOrderModel;
- use Yunshop\AggregationCps\models\MemberAggregationAppModel;
- use Yunshop\AreaDividend\models\AreaDividendAgent;
- use Yunshop\Commission\models\Agents;
- use Yunshop\Gold\frontend\services\MemberCenterService;
- use Yunshop\Love\Common\Models\MemberLove;
- use Yunshop\Love\Common\Services\SetService;
- use Yunshop\MemberTags\Common\models\MemberTagsRelationModel;
- use Yunshop\Merchant\common\models\Merchant;
- use Yunshop\Micro\common\models\MicroShop;
- use Yunshop\Micro\common\services\MicroShop\GetButtonService;
- use Yunshop\StoreCashier\common\models\Store;
- use Yunshop\Supplier\admin\models\Supplier;
- use Yunshop\Supplier\common\services\VerifyButton;
- use Yunshop\TeamDividend\models\TeamDividendAgencyModel;
- use app\common\models\member\MemberInvitationCodeLog;
- use Yunshop\WechatCustomers\common\models\MemberCustomer;
- /**
- * Created by PhpStorm.
- * Author: 芸众商城 www.yunzshop.com
- * Date: 21/02/2017
- * Time: 12:58
- */
- /**
- * Class Member
- * @package app\common\models
- * @property int uid
- * @property int uniacid
- * @property string mobile
- * @property string email
- * @property string password
- * @property string salt
- * @property int groupid
- * @property float credit1
- * @property float credit2
- * @property float credit3
- * @property float credit4
- * @property float credit5
- * @property float credit6
- * @property Carbon createtime
- * @property string realname
- * @property string nickname
- * @property string avatar
- * @property string qq
- * @property int vip
- * @property int gender
- * @property int birthyear
- * @property int birthmonth
- * @property int birthday
- * @property string constellation
- * @property string zodiac
- * @property string telephone
- * @property string idcard
- * @property string studentid
- * @property string grade
- * @property string address
- * @property string zipcode
- * @property string nationality
- * @property string resideprovince
- * @property string residecity
- * @property string residedist
- * @property string graduateschool
- * @property string company
- * @property string education
- * @property string occupation
- * @property string position
- * @property string revenue
- * @property string affectivestatus
- * @property string lookingfor
- * @property string bloodtype
- * @property string height
- * @property string weight
- * @property string alipay
- * @property string msn
- * @property string taobao
- * @property string site
- * @property string bio
- * @property string interest
- * @property string pay_password
- * @property Collection memberCarts
- * @property McMappingFans hasOneFans
- * @property MemberMiniAppModel hasOneMiniApp
- * @property \app\backend\modules\member\models\MemberShopInfo yzMember
- * @property MemberDel hasOneDel
- *
- * @method static self withoutDeleted()
- * @method static self searchYzMember($search = [])
- */
- class Member extends BackendModel
- {
- static $current;
- protected $connection = 'mysql';
- public $table = 'mc_members';
- public $timestamps = false;
- protected $guarded = ['credit1', 'credit2', 'credit3', 'credit4', 'credit5'];
- protected $fillable = ['uniacid', 'mobile', 'groupid', 'createtime', 'nickname', 'avatar', 'gender', 'salt', 'password'];
- protected $attributes = ['bio' => '', 'resideprovince' => '', 'residecity' => '', 'nationality' => '', 'interest' => '', 'mobile' => '', 'email' => '', 'credit1' => 0, 'credit2' => 0, 'credit3' => 0, 'credit4' => 0, 'credit5' => 0, 'credit6' => 0, 'realname' => '', 'qq' => '', 'vip' => 0, 'birthyear' => 0, 'birthmonth' => 0, 'birthday' => 0, 'constellation' => '', 'zodiac' => '', 'telephone' => '', 'idcard' => '', 'studentid' => '', 'grade' => '', 'address' => '', 'zipcode' => '', 'residedist' => '', 'graduateschool' => '', 'company' => '', 'education' => '', 'occupation' => '', 'position' => '', 'revenue' => '', 'affectivestatus' => '', 'lookingfor' => '', 'bloodtype' => '', 'height' => '', 'weight' => '', 'alipay' => '', 'msn' => '', 'taobao' => '', 'site' => ''];
- const INVALID_OPENID = 0;
- protected $search_fields = ['uid', 'nickname', 'realname', 'mobile'];
- protected $primaryKey = 'uid';
- protected $appends = ['avatar_image', 'username'];
- protected $hidden = ['password', 'salt'];
- public function bankCard()
- {
- return $this->hasOne('app\common\models\member\BankCard', 'member_id', 'uid');
- }
- /**
- * @return \app\frontend\models\Member
- * @throws AppException
- */
- public static function current()
- {
- if (!isset(static::$current)) {
- static::$current = self::find(\YunShop::app()->getMemberId());
- if (!static::$current) {
- return new Member();
- }
- }
- return static::$current;
- }
- public static function boot()
- {
- parent::boot();
- self::observe(new McMemberObserver());
- }
- public function pointLove()
- {
- return $this->hasOne('app\common\models\finance\PointLoveSet', 'member_id', 'uid');
- }
- //关联会员删除表 yz_member_del_log
- public function hasOneDel()
- {
- return $this->hasOne('app\common\models\member\MemberDel', 'member_id', 'uid');
- }
- public function defaultAddress()
- {
- return $this->hasOne(app(MemberAddressRepository::class)->model(), 'uid', 'uid')->where('isdefault', 1);
- }
- /**
- * 主从表1:1
- *
- * @return mixed
- */
- public function yzMember()
- {
- return $this->hasOne('app\backend\modules\member\models\MemberShopInfo', 'member_id', 'uid');
- }
- /**
- * 会员-粉丝1:1关系
- *
- * @return mixed
- */
- //公众号
- public function hasOneFans()
- {
- return $this->hasOne('app\common\models\McMappingFans', 'uid', 'uid');
- }
- //小程序
- public function hasOneMiniApp()
- {
- return $this->hasOne(MemberMiniAppModel::class, 'member_id', 'uid');
- }
- //开放平台
- public function hasOneUnique()
- {
- return $this->hasOne(MemberUnique::class, 'member_id', 'uid');
- }
- //app
- public function hasOneWechat()
- {
- return $this->hasOne(\app\common\models\MemberWechatModel::class, 'member_id', 'uid');
- }
- //抖音
- public function hasOneDouyin()
- {
- return $this->hasOne(MemberDouyinModel::class, 'member_id', 'uid');
- }
- //支付宝
- public function hasOneAlipay()
- {
- return $this->hasOne(MemberAlipay::class, 'member_id', 'uid');
- }
- //会员标签
- public function hasManyTag()
- {
- return $this->hasMany(MemberTagsRelationModel::class, 'member_id', 'uid');
- }
- //企业微信客户
- public function hasOneCustomers()
- {
- return $this->hasOne(MemberCustomer::class, 'uid', 'uid');
- }
- /**
- * 会员-订单1:1关系 todo 会员和订单不是一对多关系吗?
- *
- * @return mixed
- */
- public function hasOneOrder()
- {
- return $this->hasOne('app\common\models\Order', 'uid', 'uid');
- }
- public function hasManyOrder()
- {
- return $this->hasMany('app\common\models\Order', 'uid', 'uid');
- }
- /**
- * 会员-会员优惠券1:多关系
- *
- * @return mixed
- */
- public function hasManyMemberCoupon()
- {
- return $this->hasOne(MemberCoupon::class, 'uid', 'uid');
- }
- /**
- * 公众号会员
- *
- * @return mixed
- */
- public function getMemberId($memberIds)
- {
- return self::select(['uid'])
- ->uniacid()
- ->whereIn('uid', $memberIds)->get()->map(function ($value) {
- return $value;
- })->toArray();
- }
- /**
- * 角色
- *
- * 会员-分销商
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function hasOneAgent()
- {
- return $this->hasOne(Agents::class, 'member_id', 'uid');
- }
- /**
- * 角色
- *
- * 会员-经销商
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function hasOneTeamDividend()
- {
- return $this->hasOne(TeamDividendAgencyModel::class, 'uid', 'uid');
- }
- /**
- * 角色
- *
- * 会员-区域代理
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function hasOneAreaDividend()
- {
- return $this->hasOne(AreaDividendAgent::class, 'member_id', 'uid');
- }
- /**
- * 角色
- *
- * 会员-招商员
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function hasOneMerchant()
- {
- return $this->hasOne(Merchant::class, 'member_id', 'uid');
- }
- /**
- * 角色
- *
- * 会员-招商中心
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function hasOneMerchantCenter()
- {
- return $this->hasOne(Merchant::class, 'member_id', 'uid');
- }
- /**
- * 角色
- *
- * 会员-微店店主
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function hasOneMicro()
- {
- return $this->hasOne(MicroShop::class, 'member_id', 'uid');
- }
- /**
- * 角色
- *
- * 会员-供应商
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function hasOneSupplier()
- {
- return $this->hasOne(Supplier::class, 'member_id', 'uid');
- }
- /**
- * 子会员
- *
- * 会员-子会员
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function hasOneMemberChildren()
- {
- return $this->hasOne(MemberChildren::class, 'member_id', 'uid');
- }
- public function hasOneMemberUnique()
- {
- return $this->hasOne(MemberUnique::class, 'member_id', 'uid');
- }
- public function hasOneMemberLove()
- {
- return $this->hasOne(MemberLove::class, 'member_id', 'uid');
- }
- public function scopeOfUid($query, $uid)
- {
- return $query->where('uid', $uid);
- }
- public function levelName()
- {
- return $this->yzMember->level->level_name ?? Setting::get('shop.member.level_name') ?? "普通会员";
- }
- /**
- * @param static $query
- */
- public function scopeWithoutDeleted($query)
- {
- $query->whereHas('yzMember', function ($query) {
- $query->whereNull('deleted_at');
- })->leftJoin('yz_member_del_log', 'mc_members.uid', '=', 'yz_member_del_log.member_id')->whereNull('yz_member_del_log.member_id');
- }
- /**
- * @param static $query
- * @param array $search
- */
- public function scopeSearch($query, $search)
- {
- $query->searchYzMember($search);
- if ($search['member']) $query->searchLike($search['member']);
- if ($search['member_id']) $query->where('uid', $search['member_id']);
- if ($search['min_credit2']) $query->where('credit2', '>=', $search['min_credit2']);
- if ($search['max_credit2']) $query->where('credit2', '<=', $search['max_credit2']);
- //todo 移除一下代码,规范使用,如果模糊查询 会员ID、昵称、姓名、手机号使用 $search['member']
- if ($search['realname']) $query->searchLike($search['realname']);
- }
- /**
- * todo 移除 $search['member_level'] || $search['member_group']
- *
- * @param static $query
- * @param array $search
- */
- public function scopeSearchYzMember($query, $search)
- {
- if ($search['level_id'] || $search['group_id'] || $search['member_level'] || $search['member_group']) {
- $query->whereHas('yzMember', function ($query) use ($search) {
- /**
- * @var MemberShopInfo $query
- */
- $query->search($search);
- });
- }
- }
- /**
- * 获取用户信息
- *
- * @param $member_id
- * @return mixed
- */
- public static function getUserInfos($member_id)
- {
- return self::select(['*'])
- ->uniacid()
- ->where('uid', $member_id)
- ->with([
- 'yzMember' => function ($query) {
- return $query->select(['*'])->where('is_black', 0)
- ->with([
- 'group' => function ($query1) {
- return $query1->select(['id', 'group_name']);
- },
- 'level' => function ($query2) {
- return $query2->select(['id', 'level_name']);
- },
- 'agent' => function ($query3) {
- return $query3->select(['uid', 'avatar', 'nickname']);
- }
- ]);
- },
- 'hasOneFans' => function ($query4) {
- return $query4->select(['uid', 'openid', 'follow as followed']);
- },
- 'hasOneOrder' => function ($query5) {
- return $query5->selectRaw('uid, count(uid) as total, sum(price) as sum')
- ->uniacid()
- ->where('status', 3)
- ->groupBy('uid');
- }
- ]);
- }
- /**
- * 获取该公众号下所有用户的 member ID
- *
- * @return mixed
- */
- public static function getMembersId()
- {
- return static::uniacid()
- ->select(['uid'])
- ->get();
- }
- /**
- * 通过id获取用户信息
- *
- * @param $member_id
- * @return mixed
- */
- public static function getMemberById($member_id)
- {
- return self::uniacid()
- ->where('uid', $member_id)
- ->first();
- }
- public static function getMemberByUid($member_id)
- {
- return self::uniacid()
- ->where('uid', $member_id);
- }
- /**
- * 添加评论默认名称
- * @return mixed
- */
- public static function getRandNickName()
- {
- return self::select('nickname')
- ->whereNotNull('nickname')
- ->inRandomOrder()
- ->first();
- }
- /**
- * 昵称手机号隐藏
- * @return array|mixed|string|string[]|null
- */
- public function getNicknameAttribute()
- {
- $preg = '/^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/';
- if (preg_match($preg,$this->getAttributeFromArray('nickname'))) {
- return substr_replace($this->getAttributeFromArray('nickname'),'*******',2,7);
- }
- return $this->getAttributeFromArray('nickname');
- }
- /**
- * 会员头像格式化
- * @return array|mixed|string|string[]|null
- */
- public function getAvatarAttribute()
- {
- return $this->getAttributeFromArray('avatar') ? yz_tomedia($this->getAttributeFromArray('avatar')) : yz_tomedia(\Setting::get('shop.member.headimg'));
- }
- /**
- * 判断是否有设置过头像
- * @return array|mixed|string|string[]|null
- */
- public function getHasAvatarAttribute()
- {
- return $this->getAttributeFromArray('avatar') && $this->getAttributeFromArray('nickname') ? 1 : 0;
- }
- /**
- * 添加评论默认头像
- * @return mixed
- */
- public static function getRandAvatar()
- {
- return self::select('avatar')
- ->whereNotNull('avatar')
- ->inRandomOrder()
- ->first();
- }
- public static function getOpenId($member_id)
- {
- $data = self::getUserInfos($member_id)->first();
- if ($data) {
- $info = $data->toArray();
- if (!empty($info['has_one_fans'])) {
- return $info['has_one_fans']['openid'];
- } else {
- return self::INVALID_OPENID;
- }
- }
- }
- /**
- * 触发会员成为下线事件
- *
- * @param $member_id
- */
- public static function chkAgent($member_id, $mid, $mark = '', $mark_id = '')
- {
- $model = MemberShopInfo::getMemberShopInfo($member_id);
- if (1 != $model->inviter && 2 != $model->status) {
- $relation = new MemberRelation();
- $relation->becomeChildAgent($mid, $model);
- }
- if ($mark_id && $mark) {
- event(new PluginCreateRelationEvent($mid, $model, $mark, $mark_id));
- }
- }
- /**
- * 定义字段名
- *
- * @return array
- */
- public function atributeNames()
- {
- return [
- 'mobile' => '绑定手机号',
- 'realname' => '真实姓名',
- //'avatar' => '头像',
- 'telephone' => '联系手机号',
- ];
- }
- /**
- * 字段规则
- *
- * @return array
- */
- public function rules()
- {
- $rule = [
- // 'mobile' => 'required|numeric',
- // 'realname' => 'required|between:2,10',
- //'avatar' => 'required',
- 'telephone' => 'regex:/^1\d{10}$/',
- ];
- if (\Setting::get('shop.form')['base']['name'] == 1) {
- $rule['realname'] = 'required|between:2,10';
- }
- return $rule;
- }
- /**
- * 生成分销关系链
- *
- * @param $member_id
- */
- public static function createRealtion($member_id, $upperMemberId = NULL)
- {
- $model = MemberShopInfo::getMemberShopInfo($member_id);
- $code_mid = self::getMemberIdForInviteCode();
- if (!is_null($code_mid)) {
- //邀请码关系链
- $code_model = new MemberInvitationCodeLog();
- $code_model->uniacid = \YunShop::app()->uniacid;
- $code_model->invitation_code = trim(\YunShop::request()->invite_code);
- $code_model->member_id = $member_id; //使用者id
- $code_model->mid = $code_mid; //邀请人id
- $code_model->save();
- file_put_contents(storage_path("logs/" . date('Y-m-d') . "_invitecode.log"), print_r($member_id . '-' . \YunShop::request()->invite_code . '-' . $code_mid . '-reg' . PHP_EOL, 1), FILE_APPEND);
- }
- $mid = !is_null($code_mid) ? $code_mid : self::getMid();
- $mid = !is_null($upperMemberId) ? $upperMemberId : $mid;
- \Log::debug('--------member_id---------', $member_id);
- \Log::debug('--------upper_member_id---------', $upperMemberId);
- \Log::debug('--------mid---------', self::getMid());
- \Log::debug('--------code_mid---------', $code_mid);
- event(new BecomeAgent($mid, $model));
- }
- public static function getMid()
- {
- $mid = \YunShop::request()->mid;
- return ($mid && ($mid != 'null' || $mid != 'undefined')) ? (int)$mid : 0;
- }
- /**
- * 申请插件
- *
- * @param array $data
- * @return array
- */
- public static function addPlugins(&$data = [])
- {
- $plugin_class = app('plugins');
- //供应商
- if ($plugin_class->isEnabled('supplier')) {
- $data['supplier'] = VerifyButton::button();
- } else {
- $data['supplier'] = '';
- }
- //微店
- if ($plugin_class->isEnabled('micro')) {
- $micro_set = \Setting::get('plugin.micro');
- if ($micro_set['is_open_miceo'] == 0) {
- $data['micro'] = '';
- } else {
- $data['micro'] = GetButtonService::
- verify(\YunShop::app()->getMemberId());
- }
- } else {
- $data['micro'] = '';
- }
- if ($plugin_class->isEnabled('gold')) {
- $data['gold'] = MemberCenterService::button(\YunShop::app()->getMemberId());
- } else {
- $data['gold'] = '';
- }
- //爱心值
- if ($plugin_class->isEnabled('love')) {
- $data['love'] = [
- 'status' => true,
- 'love_name' => SetService::getLoveName(),
- ];
- } else {
- $data['love'] = [
- 'status' => false,
- 'love_name' => '爱心值',
- ];
- }
- if ($plugin_class->isEnabled('froze')) {
- $data['froze'] = [
- 'status' => true,
- 'froze_name' => \Yunshop\Froze\Common\Services\SetService::getFrozeName(),
- ];
- } else {
- $data['froze'] = [
- 'status' => false,
- 'froze_name' => '冻结币',
- ];
- }
- if ($plugin_class->isEnabled('coin')) {
- $data['coin'] = [
- 'status' => true,
- 'coin_name' => \Yunshop\Coin\Common\Services\SetService::getCoinName(),
- ];
- } else {
- $data['coin'] = [
- 'status' => false,
- 'coin_name' => '华侨币',
- ];
- }
- if ($plugin_class->isEnabled('store-cashier')) {
- $store = Store::getStoreByUid(\YunShop::app()->getMemberId())->first();
- if ($store && $store->hasOneCashier->hasOneCashierGoods->is_open == 1) {
- $data['cashier'] = [
- 'button_name' => '收银台',
- 'api' => 'plugin.store-cashier.frontend.cashier.center.index'
- ];
- }
- } else {
- $data['cashier'] = '';
- }
- if ($plugin_class->isEnabled('elive')) {
- $data['elive'] = [
- 'button_name' => '生活缴费',
- 'status' => true
- ];
- } else {
- $data['elive'] = ['status' => false];
- }
- if ($plugin_class->isEnabled('sign')) {
- $data['sign'] = [
- 'status' => true,
- 'plugin_name' => trans('Yunshop\Sign::sign.plugin_name'),
- ];
- } else {
- $data['sign'] = [
- 'status' => false,
- 'plugin_name' => '签到',
- ];
- }
- //快递单插件开启
- if ($plugin_class->isEnabled('courier')) {
- $status = \Setting::get('courier.courier.radio') ? true : false;
- $data['courier'] = [
- 'button_name' => '快递',
- 'status' => $status
- ];
- } else {
- $data['courier'] = [
- 'button_name' => '快递',
- 'status' => false
- ];
- }
- //帮助中心插件开启控制
- if ($plugin_class->isEnabled('help-center')) {
- $status = \Setting::get('help-center.status') ? true : false;
- $data['help_center'] = [
- 'button_name' => '帮助中心',
- 'status' => $status
- ];
- } else {
- $data['help_center'] = [
- 'button_name' => '帮助中心',
- 'status' => false
- ];
- }
- //隐藏爱心值插件入口
- $love_show = PortType::popularizeShow(\YunShop::request()->type);
- if (isset($data['love']) && (!$love_show)) {
- $data['love']['status'] = false;
- }
- //配送站
- if (app('plugins')->isEnabled('delivery-station')) {
- $data['is_open_delivery_station'] = \Setting::get('plugin.delivery_station.is_open') ? 1 : 0;
- } else {
- $data['is_open_delivery_station'] = 0;
- }
- return $data;
- }
- /**
- * 推广提现
- * @return \Illuminate\Http\JsonResponse
- */
- public static function getIncomeCount()
- {
- $amount = Income::getIncomes()->where('member_id', \YunShop::app()->getMemberId())->sum('amount');
- if ($amount) {
- return number_format($amount, 2);
- }
- return number_format(0, 2);
- }
- /**
- * 会员3级关系链
- *
- * @param $uid
- * @param string $mid
- * @return bool
- */
- public static function setMemberRelation($uid, $mid = '')
- {
- $curr_arr = [];
- $model = MemberShopInfo::getMemberShopInfo($uid);
- if (empty($mid)) {
- $mid = 0;
- }
- //生成关系3级关系链
- $member_model = MemberModel::getMyAgentsParentInfo($mid)->first();
- if (!empty($member_model)) {
- \Log::debug('model-生成关系3级关系链');
- $member_data = $member_model->toArray();
- $relation_str = $mid;
- if (!empty($member_data['yz_member'])) {
- $count = count($member_data['yz_member'], 1);
- if ($count > 3) {
- $relation_str .= ',' . $member_data['yz_member']['parent_id'];
- }
- if ($count > 6) {
- $relation_str .= ',' . $member_data['yz_member']['has_one_pre_self']['parent_id'];
- }
- }
- } else {
- $relation_str = '0';
- }
- if ($relation_str != '0') {
- $curr_arr = explode(',', rtrim($relation_str, ','));
- $res_arr = array_unique($curr_arr);
- if (count($res_arr) != count($curr_arr)) {
- return false;
- }
- if (in_array($uid, $curr_arr)) {
- throw new AppException('修改关系链后冲突,不能填写自己的邀请码或者下级的邀请码');
- }
- }
- $model->relation = $relation_str;
- $model->save();
- return $curr_arr;
- }
- public static function getOpenIdForType($member_id, $type = null)
- {
- switch ($type) {
- case 2:
- case 55:
- $mini_app = MemberMiniAppModel::getFansById($member_id);
- return $mini_app->openid;
- break;
- case 9:
- $mini_app = MemberWechatModel::getFansById($member_id);
- return $mini_app->openid;
- break;
- case 71:
- if (!app('plugins')->isEnabled('aggregation-cps')) {
- return '';
- }
- $mini_app = AggregationCpsOrderModel::where('member_id', $member_id)->first();
- return $mini_app->openid ?: '';
- break;
- default:
- $fans = McMappingFans::getFansById($member_id);
- return $fans->openid;
- }
- }
- /**
- * 判断用户是否关注
- *
- * @return bool
- */
- public function isFollow()
- {
- return isset($this->hasOneFans) && $this->hasOneFans->follow && !empty($this->hasOneFans->openid);
- }
- public function getMemberRole($builder)
- {
- $result = $builder;
- // if (app('plugins')->isEnabled('commission')) {
- // $result = $result->with([
- // 'hasOneAgent'
- // ]);
- // }
- //
- // if (app('plugins')->isEnabled('team-dividend')) {
- // $result = $result->with([
- // 'hasOneTeamDividend'
- // ]);
- // }
- //
- // if (app('plugins')->isEnabled('area-dividend')) {
- // $result = $result->with([
- // 'hasOneAreaDividend' => function ($query) {
- // return $query->where('status', 1);
- // }
- // ]);
- // }
- //
- // if (app('plugins')->isEnabled('merchant')) {
- // $result = $result->with([
- // 'hasOneMerchant',
- // 'hasOneMerchantCenter'
- // ]);
- // }
- //
- // if (app('plugins')->isEnabled('micro')) {
- // $result = $result->with([
- // 'hasOneMicro'
- // ]);
- // }
- //
- // if (app('plugins')->isEnabled('supplier')) {
- // $result = $result->with([
- // 'hasOneSupplier' => function ($query) {
- // return $query->where('status', 1);
- // }
- // ]);
- // }
- return $result;
- }
- public static function getPid()
- {
- $pid = \YunShop::request()->pid;
- return ($pid && ($pid != 'null' || $pid != 'undefined')) ? (int)$pid : 0;
- }
- //快递单获取会员信息
- public static function getMemberInfo($uid)
- {
- return self::uniacid()->find($uid);
- }
- public static function deleted($uid)
- {
- self::uniacid()
- ->where('uid', $uid)
- ->delete();
- }
- public function getAvatarImageAttribute()
- {
- return $this->avatar ? yz_tomedia($this->avatar) : yz_tomedia(\Setting::get('shop.member.headimg'));
- }
- public function getUserNameAttribute()
- {
- if (substr($this->nickname, 0, strlen('=')) === '=') {
- $this->nickname = ' ' . $this->nickname;
- }
- return $this->nickname;
- }
- /**
- * 邀请码会员
- *
- * @return null
- */
- public function getMemberIdForInviteCode()
- {
- if ($invite_code = self::hasInviteCode()) {
- $ids = MemberShopInfo::getMemberIdForInviteCode($invite_code);
- if (!is_null($ids)) {
- return $ids[0];
- }
- }
- return null;
- }
- public static function hasInviteCode()
- {
- $required = intval(\Setting::get('shop.member.required'));
- $invite_code = \YunShop::request()->invite_code;
- $is_invite = self::chkInviteCode();
- $member = MemberShopInfo::where('invite_code', $invite_code)->count();
- if ($is_invite && $required && empty($invite_code)) {
- return null;
- }
- if ($is_invite && isset($invite_code) && !empty($invite_code) && !empty($member)) {
- return $invite_code;
- }
- return null;
- }
- /**
- * 购物车记录
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
- */
- public function memberCarts()
- {
- return $this->hasMany(MemberCart::class, 'uid', 'member_id');
- }
- /**
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
- */
- public function orderGoods()
- {
- return $this->hasMany(OrderGoods::class, 'uid', 'uid');
- }
- /**
- * @return MemberCartCollection|mixed
- */
- public function getMemberCartCollection()
- {
- if (!isset($this->memberCartCollection)) {
- $this->memberCartCollection = new MemberCartCollection($this->memberCarts->all());
- }
- return $this->memberCartCollection;
- }
- /**
- * 邀请码是否开启
- *
- * @return int
- */
- public static function chkInviteCode()
- {
- $is_invite = intval(\Setting::get('shop.member.is_invite'));
- $invite_page = intval(\Setting::get('shop.member.invite_page'));
- // //邀请页和邀请码都开启
- // if (1 == $invite_page && 1 == $is_invite) {
- // $is_invite = 0;
- // }
- return $is_invite;
- }
- public static function memberCustomer($uid)
- {
- return self::select(['avatar', 'nickname', 'realname', 'mobile', 'credit1', 'credit2'])
- ->uniacid()
- ->where('uid', $uid);
- }
- public function hasOneAggregationCpsMember()
- {
- return $this->hasOne(MemberAggregationAppModel::class, 'member_id', 'uid');
- }
- }
|