初始上传
This commit is contained in:
205
app/model/member/Config.php
Executable file
205
app/model/member/Config.php
Executable file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\model\system\Document;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
use app\model\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员设置
|
||||
*/
|
||||
class Config extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 注册协议
|
||||
* @param $title
|
||||
* @param $content
|
||||
* @param unknown $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function setRegisterDocument($title, $content, $site_id, $app_module = 'shop')
|
||||
{
|
||||
$document = new Document();
|
||||
$res = $document->setDocument($title, $content, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'document_key', '=', 'REGISTER_AGREEMENT' ] ]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询注册协议
|
||||
* @param $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function getRegisterDocument($site_id, $app_module = 'shop')
|
||||
{
|
||||
$document = new Document();
|
||||
$info = $document->getDocument([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'document_key', '=', 'REGISTER_AGREEMENT' ] ]);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐私协议
|
||||
* @param $title
|
||||
* @param $content
|
||||
* @param unknown $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function setPrivacyConfig($title, $content, $site_id, $app_module = 'shop')
|
||||
{
|
||||
$document = new Document();
|
||||
$res = $document->setDocument($title, $content, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'document_key', '=', 'PRIVACY_AGREEMENT' ] ]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询隐私协议
|
||||
* @param $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function getPrivacyDocument($site_id, $app_module = 'shop')
|
||||
{
|
||||
$document = new Document();
|
||||
$info = $document->getDocument([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'document_key', '=', 'PRIVACY_AGREEMENT' ] ]);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册规则
|
||||
* array $data
|
||||
*/
|
||||
public function setRegisterConfig($data, $site_id, $app_module = 'shop')
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->setConfig($data, '注册规则', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'REGISTER_CONFIG' ] ]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询注册规则
|
||||
*/
|
||||
public function getRegisterConfig($site_id, $app_module = 'shop')
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'REGISTER_CONFIG' ] ]);
|
||||
$res['data']['value'] = array_merge([
|
||||
'login' => 'username,mobile',//登录类型 账号 手机号
|
||||
'register' => 'username,mobile',//注册类型 账号 手机号
|
||||
'third_party' => 1,//允许三方平台自动注册
|
||||
'bind_mobile' => 0,//是否强制绑定手机
|
||||
'pwd_len' => 6,//密码最小长度
|
||||
'pwd_complexity' => '',//密码复杂程度
|
||||
'agreement_show' => 1,//是否显示政策协议
|
||||
'wap_bg' => '',//手机端背景图
|
||||
'wap_desc' => '',//描述
|
||||
], $res['data']['value']);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注销协议
|
||||
* @param $title
|
||||
* @param $content
|
||||
* @param unknown $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function setCancelDocument($title, $content, $site_id, $app_module = 'shop')
|
||||
{
|
||||
$document = new Document();
|
||||
$res = $document->setDocument($title, $content, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'document_key', '=', 'CANCEL_AGREEMENT' ] ]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询注销协议
|
||||
* @param $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function getCancelDocument($site_id, $app_module = 'shop')
|
||||
{
|
||||
$document = new Document();
|
||||
$info = $document->getDocument([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'document_key', '=', 'CANCEL_AGREEMENT' ] ]);
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注销规则
|
||||
* array $data
|
||||
*/
|
||||
public function setCancelConfig($data, $site_id, $app_module = 'shop')
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->setConfig($data, '注销规则', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'CANCEL_CONFIG' ] ]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询注销规则
|
||||
*/
|
||||
public function getCancelConfig($site_id, $app_module = 'shop')
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'CANCEL_CONFIG' ] ]);
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
//默认值设置
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'is_enable' => 0, //注销开关
|
||||
'is_audit' => 1, //审核开关
|
||||
];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询会员配置
|
||||
* @param $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberConfig($site_id, $app_module = 'shop')
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'MEMBER_LEVEL_CONFIG' ] ]);
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
//默认值设置
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'is_update' => 1,
|
||||
];
|
||||
} else {
|
||||
$value = $res[ 'data' ][ 'value' ];
|
||||
$value[ 'is_update' ] = $value[ 'is_update' ] ?? 1;
|
||||
$res[ 'data' ][ 'value' ] = $value;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分任务
|
||||
* @param $data
|
||||
* @param $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function setMemberConfig($data, $site_id, $app_module = 'shop')
|
||||
{
|
||||
|
||||
$config = new ConfigModel();
|
||||
$res = $config->setConfig($data, '会员等级更新配置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'MEMBER_LEVEL_CONFIG' ] ]);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
377
app/model/member/Login.php
Executable file
377
app/model/member/Login.php
Executable file
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use addon\wechat\model\Message as WechatMessage;
|
||||
use app\model\BaseModel;
|
||||
use app\model\message\Sms;
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
class Login extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function login($data)
|
||||
{
|
||||
|
||||
$info = model("member")->getInfo([
|
||||
['username|mobile|email', '=', $data['username']],
|
||||
['password', '=', data_md5($data['password'])],
|
||||
['site_id', '=', $data['site_id']],
|
||||
['is_delete', '=', 0]
|
||||
], 'member_id,username, nickname, mobile, email, status,last_login_time,can_receive_registergift');
|
||||
if (empty($info)) {
|
||||
return $this->error('', 'USERNAME_OR_PASSWORD_ERROR');
|
||||
} elseif ($info['status'] == 0) {
|
||||
return $this->error('', 'MEMBER_IS_LOCKED');
|
||||
} else {
|
||||
if ($info['can_receive_registergift'] == 1) {
|
||||
event("MemberReceiveRegisterGift", ['member_id' => $info['member_id'], 'site_id' => $data['site_id']]);
|
||||
}
|
||||
//更新登录时间
|
||||
model("member")->update([
|
||||
'login_time' => time(),
|
||||
'last_login_time' => time(),
|
||||
'can_receive_registergift' => 0,
|
||||
'login_ip' => request()->ip(),
|
||||
'login_type' => $data['app_type'] ?? '',
|
||||
'login_type_name' => $data['app_type_name'] ?? '',
|
||||
], [['member_id', '=', $info['member_id']]]);
|
||||
|
||||
//执行登录奖励
|
||||
event("MemberLogin", ['member_id' => $info['member_id'], 'site_id' => $data['site_id']], true);
|
||||
|
||||
//用户第三方信息刷新
|
||||
$this->refreshAuth($info['member_id'], $data);
|
||||
return $this->success($info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方登录
|
||||
* @param array $data 必然传输auth_tag, auth_openid
|
||||
*/
|
||||
public function authLogin($data)
|
||||
{
|
||||
//微信未使用完整服务返回数据不能做登录使用
|
||||
//未使用完整服务和使用了完整服务返回的数据是不一样的
|
||||
if(isset($data['nickName']) && isset($data['avatarUrl']) && $data['nickName'] == '微信用户' && $data['avatarUrl'] == 'https://thirdwx.qlogo.cn/mmopen/vi_32/Q3auHgzwzM6WH3T48eljAMnoGDv722DOL7nO15FgEz64psqp2xiaZJCP2v71dOqS03hKjytzRrh3ZHg09mKNtXg/132'){
|
||||
return $this->error(null, '微信授权使用完整服务');
|
||||
}
|
||||
|
||||
$info = [];
|
||||
$auth_tag = '';
|
||||
foreach ($data as $key => $value) {
|
||||
if (in_array($key, ['wx_unionid', 'wx_openid', 'weapp_openid', 'qq_openid', 'ali_openid', 'baidu_openid', 'toutiao_openid'])) {
|
||||
$auth_tag = $key;
|
||||
if (empty($value)) return $this->error('', 'PARAMETER_ERROR');
|
||||
$info = model("member")->getFirstData(
|
||||
[
|
||||
[$key, '=', $value],
|
||||
['site_id', '=', $data['site_id']],
|
||||
['is_delete', '=', 0]
|
||||
], 'member_id,username, nickname, mobile, email, status, last_login_time, can_receive_registergift'
|
||||
);
|
||||
if (!empty($info)) break;
|
||||
}
|
||||
}
|
||||
if (empty($auth_tag)) return $this->error('', 'PARAMETER_ERROR');
|
||||
|
||||
if (empty($info)) {
|
||||
// 会员不存在 第三方自动注册开启 未开启绑定手机 则进行自动注册
|
||||
$config = new Config();
|
||||
$config_info = $config->getRegisterConfig($data['site_id'], 'shop');
|
||||
if ($config_info['data']['value']['third_party'] && !$config_info['data']['value']['bind_mobile']) {
|
||||
$register = new Register();
|
||||
$register_res = $register->authRegister($data);
|
||||
if ($register_res['code'] == 0) {
|
||||
$info = model("member")->getInfo([['member_id', '=', $register_res['data']]], 'member_id,username, nickname, mobile, email, status, last_login_time,can_receive_registergift');
|
||||
$info['is_register'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($info)) {
|
||||
return $this->error('MEMBER_NOT_EXIST', 'MEMBER_NOT_EXIST');
|
||||
} elseif ($info['status'] == 0) {
|
||||
return $this->error('', 'MEMBER_IS_LOCKED');
|
||||
} else {
|
||||
if ($info['can_receive_registergift'] == 1) {
|
||||
event("MemberReceiveRegisterGift", ['member_id' => $info['member_id'], 'site_id' => $data['site_id']]);
|
||||
}
|
||||
//更新登录时间
|
||||
model("member")->update([
|
||||
'login_time' => time(),
|
||||
'last_login_time' => time(),
|
||||
'can_receive_registergift' => 0,
|
||||
'login_ip' => request()->ip(),
|
||||
'login_type' => $data['app_type'] ?? '',
|
||||
'login_type_name' => $data['app_type_name'] ?? '',
|
||||
], [['member_id', '=', $info['member_id']]]);
|
||||
|
||||
//执行登录奖励
|
||||
event("MemberLogin", ['member_id' => $info['member_id'], 'site_id' => $data['site_id']], true);
|
||||
|
||||
//用户第三方信息刷新
|
||||
if (!isset($info['is_register'])) $this->refreshAuth($info['member_id'], $data);
|
||||
|
||||
return $this->success($info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权登录仅登录
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function authOnlyLogin($data)
|
||||
{
|
||||
$info = [];
|
||||
$auth_tag = '';
|
||||
foreach ($data as $key => $value) {
|
||||
if (in_array($key, ['wx_unionid', 'wx_openid', 'weapp_openid', 'qq_openid', 'ali_openid', 'baidu_openid', 'toutiao_openid'])) {
|
||||
$auth_tag = $key;
|
||||
if (empty($value)) return $this->error('', 'PARAMETER_ERROR');
|
||||
$info = model("member")->getInfo(
|
||||
[
|
||||
[$key, '=', $value],
|
||||
['site_id', '=', $data['site_id']],
|
||||
['is_delete', '=', 0]
|
||||
], 'member_id,username, nickname, mobile, email, status, last_login_time, can_receive_registergift'
|
||||
);
|
||||
if (!empty($info)) break;
|
||||
}
|
||||
}
|
||||
if (empty($auth_tag)) return $this->error('', 'PARAMETER_ERROR');
|
||||
|
||||
if (empty($info)) {
|
||||
// 前端根据data值判断业务处理
|
||||
return $this->error('MEMBER_NOT_EXIST', 'MEMBER_NOT_EXIST');
|
||||
} elseif ($info['status'] == 0) {
|
||||
return $this->error('', 'MEMBER_IS_LOCKED');
|
||||
} else {
|
||||
//更新登录时间
|
||||
model("member")->update([
|
||||
'login_time' => time(),
|
||||
'last_login_time' => time(),
|
||||
'can_receive_registergift' => 0,
|
||||
'login_ip' => request()->ip(),
|
||||
'login_type' => $data['app_type'] ?? '',
|
||||
'login_type_name' => $data['app_type_name'] ?? '',
|
||||
], [['member_id', '=', $info['member_id']]]);
|
||||
|
||||
//执行登录奖励
|
||||
event("MemberLogin", ['member_id' => $info['member_id'], 'site_id' => $data['site_id']], true);
|
||||
//用户第三方信息刷新
|
||||
$this->refreshAuth($info['member_id'], $data);
|
||||
return $this->success($info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新第三方信息
|
||||
* @param $member_id
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
private function refreshAuth($member_id, $data)
|
||||
{
|
||||
Member::modifyLastVisitTime($member_id);
|
||||
$data = [
|
||||
'qq_openid' => $data['qq_openid'] ?? '',
|
||||
'wx_openid' => $data['wx_openid'] ?? '',
|
||||
'weapp_openid' => $data['weapp_openid'] ?? '',
|
||||
'wx_unionid' => $data['wx_unionid'] ?? '',
|
||||
'ali_openid' => $data['ali_openid'] ?? '',
|
||||
'baidu_openid' => $data['baidu_openid'] ?? '',
|
||||
'toutiao_openid' => $data['toutiao_openid'] ?? '',
|
||||
'site_id' => $data['site_id']
|
||||
];
|
||||
if (!empty($data['qq_openid'])) {
|
||||
model("member")->update(['qq_openid' => $data['qq_openid']], [['member_id', '=', $member_id], ['site_id', '=', $data['site_id']]]);
|
||||
}
|
||||
if (!empty($data['wx_openid'])) {
|
||||
model("member")->update(['wx_openid' => $data['wx_openid']], [['member_id', '=', $member_id], ['site_id', '=', $data['site_id']]]);
|
||||
}
|
||||
if (!empty($data['weapp_openid'])) {
|
||||
model("member")->update(['weapp_openid' => $data['weapp_openid']], [['member_id', '=', $member_id], ['site_id', '=', $data['site_id']]]);
|
||||
}
|
||||
if (!empty($data['wx_unionid'])) {
|
||||
model("member")->update(['wx_unionid' => $data['wx_unionid']], [['member_id', '=', $member_id], ['site_id', '=', $data['site_id']]]);
|
||||
}
|
||||
if (!empty($data['ali_openid'])) {
|
||||
model("member")->update(['ali_openid' => $data['ali_openid']], [['member_id', '=', $member_id], ['site_id', '=', $data['site_id']]]);
|
||||
}
|
||||
if (!empty($data['baidu_openid'])) {
|
||||
model("member")->update(['baidu_openid' => $data['baidu_openid']], [['member_id', '=', $member_id], ['site_id', '=', $data['site_id']]]);
|
||||
}
|
||||
if (!empty($data['toutiao_openid'])) {
|
||||
model("member")->update(['toutiao_openid' => $data['toutiao_openid']], [['member_id', '=', $member_id], ['site_id', '=', $data['site_id']]]);
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测openid是否存在
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function openidIsExits(array $data)
|
||||
{
|
||||
if (isset($data['wx_unionid']) && !empty($data['wx_unionid'])) {
|
||||
$count = model("member")->getCount([['wx_unionid', '=', $data['wx_unionid']], ['site_id', '=', $data['site_id']], ['is_delete', '=', 0]]);
|
||||
if ($count) return $this->success($count);
|
||||
}
|
||||
if (isset($data['wx_openid']) && !empty($data['wx_openid'])) {
|
||||
$count = model("member")->getCount([['wx_openid', '=', $data['wx_openid']], ['site_id', '=', $data['site_id']], ['is_delete', '=', 0]]);
|
||||
if ($count) return $this->success($count);
|
||||
}
|
||||
if (isset($data['weapp_openid']) && !empty($data['weapp_openid'])) {
|
||||
$count = model("member")->getCount([['weapp_openid', '=', $data['weapp_openid']], ['site_id', '=', $data['site_id']], ['is_delete', '=', 0]]);
|
||||
if ($count) return $this->success($count);
|
||||
}
|
||||
if (isset($data['qq_openid']) && !empty($data['qq_openid'])) {
|
||||
$count = model("member")->getCount([['qq_openid', '=', $data['qq_openid']], ['site_id', '=', $data['site_id']], ['is_delete', '=', 0]]);
|
||||
if ($count) return $this->success($count);
|
||||
}
|
||||
if (isset($data['ali_openid']) && !empty($data['ali_openid'])) {
|
||||
$count = model("member")->getCount([['ali_openid', '=', $data['ali_openid']], ['site_id', '=', $data['site_id']], ['is_delete', '=', 0]]);
|
||||
if ($count) return $this->success($count);
|
||||
}
|
||||
if (isset($data['baidu_openid']) && !empty($data['baidu_openid'])) {
|
||||
$count = model("member")->getCount([['baidu_openid', '=', $data['baidu_openid']], ['site_id', '=', $data['site_id']], ['is_delete', '=', 0]]);
|
||||
if ($count) return $this->success($count);
|
||||
}
|
||||
if (isset($data['toutiao_openid']) && !empty($data['toutiao_openid'])) {
|
||||
$count = model("member")->getCount([['toutiao_openid', '=', $data['toutiao_openid']], ['site_id', '=', $data['site_id']], ['is_delete', '=', 0]]);
|
||||
if ($count) return $this->success($count);
|
||||
}
|
||||
return $this->success(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function mobileLogin($data)
|
||||
{
|
||||
$info = model("member")->getInfo([
|
||||
['mobile', '=', $data['mobile']],
|
||||
['site_id', '=', $data['site_id']],
|
||||
['is_delete', '=', 0]
|
||||
], 'member_id,username, nickname, mobile, email, status,last_login_time, can_receive_registergift');
|
||||
if (empty($info)) {
|
||||
return $this->error('MEMBER_NOT_EXIST', 'MEMBER_NOT_EXIST');
|
||||
} elseif ($info['status'] == 0) {
|
||||
return $this->error('', 'MEMBER_IS_LOCKED');
|
||||
} else {
|
||||
if ($info['can_receive_registergift'] == 1) {
|
||||
event("MemberReceiveRegisterGift", ['member_id' => $info['member_id'], 'site_id' => $data['site_id']]);
|
||||
}
|
||||
//更新登录时间
|
||||
model("member")->update([
|
||||
'login_time' => time(),
|
||||
'last_login_time' => time(),
|
||||
'can_receive_registergift' => 0,
|
||||
'login_ip' => request()->ip(),
|
||||
'login_type' => $data['app_type'] ?? '',
|
||||
'login_type_name' => $data['app_type_name'] ?? '',
|
||||
], [['member_id', '=', $info['member_id']]]);
|
||||
|
||||
event("MemberLogin", ['member_id' => $info['member_id'], 'site_id' => $data['site_id']], true);
|
||||
|
||||
//用户第三方信息刷新
|
||||
$this->refreshAuth($info['member_id'], $data);
|
||||
return $this->success($info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录动态码
|
||||
* @param $data
|
||||
* @return array|mixed|null
|
||||
*/
|
||||
public function loginCode($data)
|
||||
{
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
$var_parse = array (
|
||||
"code" => $data["code"],
|
||||
);
|
||||
$data["sms_account"] = $data["mobile"] ?? '';//手机号
|
||||
$data["var_parse"] = $var_parse;
|
||||
$sms_result = $sms_model->sendMessage($data);
|
||||
if ($sms_result["code"] < 0)
|
||||
return $sms_result;
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录通知
|
||||
* @param $data
|
||||
* @return array|mixed|void
|
||||
*/
|
||||
public function loginSuccess($data)
|
||||
{
|
||||
$member_model = new Member();
|
||||
$member_info_result = $member_model->getMemberInfo([["member_id", "=", $data["member_id"]]], "username,mobile,email,reg_time,wx_openid,last_login_type,login_time, nickname");
|
||||
$member_info = $member_info_result["data"];
|
||||
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
|
||||
$name = $member_info["nickname"] == '' ? $member_info["mobile"] : $member_info["nickname"];
|
||||
$var_parse = array (
|
||||
"name" => replaceSpecialChar($name),//验证码
|
||||
);
|
||||
$data["sms_account"] = $member_info["mobile"] ?? '';//手机号
|
||||
$data["var_parse"] = $var_parse;
|
||||
$sms_result = $sms_model->sendMessage($data);
|
||||
// if($sms_result["code"] < 0)
|
||||
// return $sms_result;
|
||||
|
||||
|
||||
//发送模板消息
|
||||
$wechat_model = new WechatMessage();
|
||||
$data["openid"] = $member_info["wx_openid"];
|
||||
|
||||
// if(!empty($member_info["username"])){
|
||||
// $user_account = $member_info["username"];
|
||||
// }else{
|
||||
// if(!empty($member_info["mobile"])){
|
||||
// $user_account = $member_info["mobile"];
|
||||
// }else{
|
||||
// $user_account = $member_info["email"];
|
||||
// }
|
||||
// }
|
||||
|
||||
$data["template_data"] = [
|
||||
'keyword1' => !empty($member_info["nickname"]) ? $member_info["nickname"] : $member_info["mobile"],
|
||||
'keyword2' => '登录成功',
|
||||
'keyword3' => time_to_date($member_info["login_time"]),
|
||||
];
|
||||
$data["page"] = '';
|
||||
$wechat_model->sendMessage($data);
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
1128
app/model/member/Member.php
Executable file
1128
app/model/member/Member.php
Executable file
File diff suppressed because it is too large
Load Diff
612
app/model/member/MemberAccount.php
Executable file
612
app/model/member/MemberAccount.php
Executable file
@@ -0,0 +1,612 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\dict\member_account\AccountDict;
|
||||
use app\model\BaseModel;
|
||||
use app\model\message\Message;
|
||||
use app\model\message\Sms;
|
||||
use addon\wechat\model\Message as WechatMessage;
|
||||
use app\model\member\Member as MemberModel;
|
||||
use addon\weapp\model\Message as WeappMessage;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 会员账户
|
||||
*/
|
||||
class MemberAccount extends BaseModel
|
||||
{
|
||||
//账户类型
|
||||
private $account_type = [
|
||||
'balance' => '储值余额',
|
||||
'balance_money' => '现金余额',
|
||||
'point' => '积分',
|
||||
'growth' => '成长值'
|
||||
];
|
||||
|
||||
//来源类型
|
||||
public $from_type = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$event_from_type = event('MemberAccountFromType', '');
|
||||
$from_type = [];
|
||||
foreach ($event_from_type as $info) {
|
||||
|
||||
if (isset($info[ 'balance' ])) {
|
||||
$balance = array_keys($info[ 'balance' ]);
|
||||
$from_type[ 'balance' ][ $balance[ 0 ] ] = $info[ 'balance' ][ $balance[ 0 ] ];
|
||||
}
|
||||
|
||||
if (isset($info[ 'point' ])) {
|
||||
$point = array_keys($info[ 'point' ]);
|
||||
$from_type[ 'point' ][ $point[ 0 ] ] = $info[ 'point' ][ $point[ 0 ] ];
|
||||
}
|
||||
|
||||
if (isset($info[ 'growth' ])) {
|
||||
$growth = array_keys($info[ 'growth' ]);
|
||||
$from_type[ 'growth' ][ $growth[ 0 ] ] = $info[ 'growth' ][ $growth[ 0 ] ];
|
||||
}
|
||||
|
||||
if (isset($info[ 'balance_money' ])) {
|
||||
$balance_money = array_keys($info[ 'balance_money' ]);
|
||||
$from_type[ 'balance_money' ][ $balance_money[ 0 ] ] = $info[ 'balance_money' ][ $balance_money[ 0 ] ];
|
||||
}
|
||||
}
|
||||
$from_type['point']['register'] = ['type_name' => '注册', 'type_url' => ''];
|
||||
$from_type['balance']['register'] = ['type_name' => '注册', 'type_url' => ''];
|
||||
$from_type['growth']['register'] = ['type_name' => '注册', 'type_url' => ''];
|
||||
$from_type[ 'balance' ][ 'adjust' ] = [ 'type_name' => '调整', 'type_url' => '' ];
|
||||
$from_type[ 'balance_money' ][ 'adjust' ] = [ 'type_name' => '调整', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'balance' ][ 'order' ] = [ 'type_name' => '消费', 'type_url' => '' ];
|
||||
$from_type[ 'balance_money' ][ 'order' ] = [ 'type_name' => '消费', 'type_url' => '' ];
|
||||
$from_type[ 'point' ][ 'order' ] = [ 'type_name' => '消费', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'point' ][ 'adjust' ] = [ 'type_name' => '调整', 'type_url' => '' ];
|
||||
$from_type[ 'growth' ][ 'adjust' ] = [ 'type_name' => '调整', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'balance' ][ 'upgrade' ] = [ 'type_name' => '升级', 'type_url' => '' ];
|
||||
$from_type[ 'balance_money' ][ 'upgrade' ] = [ 'type_name' => '升级', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'balance' ][ 'membercode' ] = [ 'type_name' => '会员码扣款', 'type_url' => '' ];
|
||||
$from_type[ 'balance_money' ][ 'membercode' ] = [ 'type_name' => '会员码扣款', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'point' ][ 'upgrade' ] = [ 'type_name' => '升级', 'type_url' => '' ];
|
||||
$from_type[ 'growth' ][ 'upgrade' ] = [ 'type_name' => '升级', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'balance' ][ 'refund' ] = [ 'type_name' => '退还', 'type_url' => '' ];
|
||||
$from_type[ 'balance_money' ][ 'refund' ] = [ 'type_name' => '退还', 'type_url' => '' ];
|
||||
$from_type[ 'point' ][ 'refund' ] = [ 'type_name' => '退还', 'type_url' => '' ];
|
||||
$from_type[ 'point' ][ 'pointexchangerefund' ] = [ 'type_name' => '积分兑换退还', 'type_url' => '' ];
|
||||
|
||||
|
||||
|
||||
$from_type[ 'balance' ][ 'memberlevel' ] = [ 'type_name' => '开卡', 'type_url' => '' ];
|
||||
$from_type[ 'point' ][ 'memberlevel' ] = [ 'type_name' => '开卡', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'balance_money' ][ 'birthdaygift' ] = [ 'type_name' => '生日有礼', 'type_url' => '' ];
|
||||
$from_type[ 'balance' ][ 'birthdaygift' ] = [ 'type_name' => '生日有礼', 'type_url' => '' ];
|
||||
$from_type[ 'point' ][ 'birthdaygift' ] = [ 'type_name' => '生日有礼', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'balance_money' ][ 'scenefestival' ] = [ 'type_name' => '节日有礼', 'type_url' => '' ];
|
||||
$from_type[ 'balance' ][ 'scenefestival' ] = [ 'type_name' => '节日有礼', 'type_url' => '' ];
|
||||
$from_type[ 'point' ][ 'scenefestival' ] = [ 'type_name' => '节日有礼', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'balance_money' ][ 'pinfan' ] = [ 'type_name' => '拼团返利', 'type_url' => '' ];
|
||||
$from_type[ 'balance' ][ 'pinfan' ] = [ 'type_name' => '拼团返利', 'type_url' => '' ];
|
||||
$from_type[ 'point' ][ 'pinfan' ] = [ 'type_name' => '拼团返利', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'balance_money' ][ 'withdraw' ] = [ 'type_name' => '提现', 'type_url' => '' ];
|
||||
$from_type[ 'balance_money' ][ 'withdraw_fail' ] = [ 'type_name' => '提现失败', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'balance' ][ 'giftcard' ] = [ 'type_name' => '礼品卡', 'type_url' => '' ];
|
||||
$from_type[ 'balance_money' ][ 'giftcard' ] = [ 'type_name' => '礼品卡', 'type_url' => '' ];
|
||||
$from_type[ 'point' ][ 'giftcard' ] = [ 'type_name' => '礼品卡', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'balance' ][ 'hongbao' ] = [ 'type_name' => '裂变红包', 'type_url' => '' ];
|
||||
$from_type[ 'balance_money' ][ 'hongbao' ] = [ 'type_name' => '裂变红包', 'type_url' => '' ];
|
||||
|
||||
$from_type[ 'point' ][ 'point_expire' ] = [ 'type_name' => '积分到期', 'type_url' => '' ];
|
||||
$from_type[ 'point' ][ 'point_cancel' ] = [ 'type_name' => '积分取消', 'type_url' => '' ];
|
||||
$from_type[ 'point' ][ 'point_set_zero' ] = [ 'type_name' => '积分清零', 'type_url' => '' ];
|
||||
|
||||
$this->from_type = $from_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取账户类型
|
||||
*/
|
||||
public function getAccountType()
|
||||
{
|
||||
return $this->account_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取来源类型
|
||||
*/
|
||||
public function getFromType()
|
||||
{
|
||||
return $this->from_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加会员账户数据
|
||||
* @param $site_id
|
||||
* @param $member_id
|
||||
* @param $account_type
|
||||
* @param $account_data
|
||||
* @param $from_type
|
||||
* @param $relate_tag
|
||||
* @param $remark
|
||||
* @param int $related_id
|
||||
* @return array
|
||||
*/
|
||||
public function addMemberAccount($site_id, $member_id, $account_type, $account_data, $from_type, $relate_tag, $remark, $related_id = 0)
|
||||
{
|
||||
model('member_account')->startTrans();
|
||||
try {
|
||||
$msg = '';
|
||||
if ($account_type == AccountDict::balance) {
|
||||
$msg = '账户余额';
|
||||
} elseif ($account_type == AccountDict::point) {
|
||||
$msg = '账户积分';
|
||||
} elseif ($account_type == AccountDict::growth) {
|
||||
$msg = '账户成长值';
|
||||
}
|
||||
|
||||
//账户检测
|
||||
$member_account = Db::name("member")->where([
|
||||
[ 'member_id', '=', $member_id ],
|
||||
[ 'site_id', '=', $site_id ]
|
||||
])->field($account_type . ', username, mobile, nickname, email')->lock(true)->find();
|
||||
$account_new_data = round((float) $member_account[ $account_type ] + (float) $account_data, 2);
|
||||
if($account_new_data < 0){
|
||||
if(in_array($from_type,['point_cancel', 'point_expire'])){
|
||||
$account_data = -$member_account[ $account_type ];
|
||||
$remark = $this->from_type[AccountDict::point][$from_type]['type_name'].":" . $member_account[ $account_type ];
|
||||
$account_new_data = 0;
|
||||
}else{
|
||||
model('member_account')->rollback();
|
||||
return $this->error('', $msg.'不可为负数');
|
||||
}
|
||||
}
|
||||
if($account_new_data > 99999999){
|
||||
return $this->error('', $msg.'不可超出99999999');
|
||||
}
|
||||
//添加记录
|
||||
$type_info = $this->from_type[ $account_type ][ $from_type ];
|
||||
|
||||
$data = array (
|
||||
'site_id' => $site_id,
|
||||
'member_id' => $member_id,
|
||||
'account_type' => $account_type,
|
||||
'account_data' => $account_data,
|
||||
'from_type' => $from_type,
|
||||
'type_name' => $type_info[ 'type_name' ],
|
||||
'type_tag' => $relate_tag,
|
||||
'create_time' => time(),
|
||||
'username' => $member_account[ 'username' ],
|
||||
'mobile' => $member_account[ 'mobile' ],
|
||||
'email' => $member_account[ 'email' ],
|
||||
'remark' => $remark,
|
||||
'related_id' => $related_id,
|
||||
);
|
||||
|
||||
model('member_account')->add($data);
|
||||
//账户更新
|
||||
model('member')->update([
|
||||
$account_type => $account_new_data
|
||||
], [
|
||||
'member_id' => $member_id
|
||||
]);
|
||||
event('AddMemberAccount', $data);
|
||||
model('member_account')->commit();
|
||||
//发送消息通知(余额变动通知)
|
||||
|
||||
$account_type_arr = [
|
||||
'balance' => 'USER_BALANCE_CHANGE_NOTICE',
|
||||
'balance_money' => 'USER_BALANCE_CHANGE_NOTICE',
|
||||
'point' => 'USER_POINT_CHANGE_NOTICE'
|
||||
];
|
||||
if (array_key_exists($account_type, $account_type_arr)) {
|
||||
$data[ 'keywords' ] = $account_type_arr[$account_type];
|
||||
$message_model = new Message();
|
||||
$message_model->sendMessage($data);
|
||||
}
|
||||
return $this->success([ 'member_id' => $member_id, $account_type => sprintf("%.2f", $account_new_data) ]);
|
||||
} catch (\Exception $e) {
|
||||
model('member_account')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付处理会员相关账户业务(余额,可提现余额)
|
||||
* @param $order_pay_array
|
||||
* @return array|void
|
||||
*/
|
||||
public function addMemberAccountInOrderPay($order_pay_array)
|
||||
{
|
||||
$pay_info = $order_pay_array['pay_info'];
|
||||
$order_info = $order_pay_array['order_info'];
|
||||
$member_info = $order_pay_array['member_info'];
|
||||
|
||||
//订单余额账户处理
|
||||
if (( $pay_info[ 'balance' ] || $pay_info[ 'balance_money' ] ) && $order_info[ 'order_money' ]) {
|
||||
|
||||
//修改整体业务
|
||||
model('member_account')->startTrans();
|
||||
try{
|
||||
//账户变动
|
||||
$data_member_account = [
|
||||
'balance' => $member_info['balance'] - $pay_info['balance'],
|
||||
'balance_money' => $member_info['balance_money'] - $pay_info['balance_money'],
|
||||
'balance_lock' => $member_info['balance_lock'] - $pay_info['balance'],
|
||||
'balance_money_lock' => $member_info['balance_money_lock'] - $pay_info['balance_money']
|
||||
];
|
||||
model("member")->update($data_member_account, [['member_id', '=', $order_info['member_id']]]);
|
||||
|
||||
//账户记录
|
||||
$account_log = [];
|
||||
if($pay_info[ 'balance' ] > 0)
|
||||
{
|
||||
$account_log[] = [
|
||||
'site_id' => $order_info['site_id'],
|
||||
'member_id' => $member_info['member_id'],
|
||||
'account_type' => 'balance',
|
||||
'account_data' => $pay_info['balance'] * -1,
|
||||
'from_type' => 'order',
|
||||
'type_name' => $this->from_type[ 'balance' ][ 'order' ]['type_name'],
|
||||
'create_time' => time(),
|
||||
'username' => $member_info['username'],
|
||||
'mobile' => $member_info['mobile'],
|
||||
'email' => '',
|
||||
'remark' => '订单消费扣除',
|
||||
'related_id' => $order_info['order_id']
|
||||
];
|
||||
}
|
||||
if($pay_info[ 'balance_money' ] > 0)
|
||||
{
|
||||
$account_log[] = [
|
||||
'site_id' => $order_info['site_id'],
|
||||
'member_id' => $member_info['member_id'],
|
||||
'account_type' => 'balance',
|
||||
'account_data' => $pay_info['balance_money'] * -1,
|
||||
'from_type' => 'order',
|
||||
'type_name' => $this->from_type[ 'balance_money' ][ 'order' ]['type_name'],
|
||||
'create_time' => time(),
|
||||
'username' => $member_info['username'],
|
||||
'mobile' => $member_info['mobile'],
|
||||
'email' => '',
|
||||
'remark' => '订单消费扣除',
|
||||
'related_id' => $order_info['order_id']
|
||||
];
|
||||
}
|
||||
if(!empty($account_log))
|
||||
{
|
||||
model('member_account')->addList($account_log);
|
||||
|
||||
$total_balance = $pay_info[ 'balance' ] + $pay_info[ 'balance_money' ];
|
||||
if ($total_balance > 0) model('order')->update([ 'balance_money' => $total_balance, 'pay_money' => ( $order_info['pay_money'] - $total_balance ) ], [ [ 'order_id', '=', $order_info['order_id'] ] ]);
|
||||
}
|
||||
model('member_account')->commit();
|
||||
//发送消息通知(余额变动通知)
|
||||
if ($pay_info['balance_money'] + $pay_info['balance'] > 0) {
|
||||
$message_data = [
|
||||
'site_id' => $order_info['site_id'],
|
||||
'member_id' => $member_info['member_id'],
|
||||
'account_type' => 'balance',
|
||||
'account_data' => ($pay_info['balance_money'] + $pay_info['balance']) * -1,
|
||||
'from_type' => 'order',
|
||||
'type_name' => $this->from_type[ 'balance' ][ 'order' ]['type_name'],
|
||||
'create_time' => time(),
|
||||
'username' => $member_info['username'],
|
||||
'mobile' => $member_info['mobile'],
|
||||
'email' => '',
|
||||
'remark' => '订单消费扣除',
|
||||
'related_id' => $order_info['order_id'],
|
||||
'keywords' => 'USER_BALANCE_CHANGE_NOTICE',
|
||||
];
|
||||
$message_model = new Message();
|
||||
$message_model->sendMessage($message_data);
|
||||
}
|
||||
|
||||
return $this->success();
|
||||
}catch (\Exception $e)
|
||||
{
|
||||
model('member_account')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加会员账户,用于会员注册与添加
|
||||
* @param $member_data
|
||||
* @param $account_data
|
||||
*/
|
||||
public function addMemberAccountInRegister($member_data, $account_data)
|
||||
{
|
||||
$list = [];
|
||||
if($account_data['point'] > 0)
|
||||
{
|
||||
$list[] = array (
|
||||
'site_id' => $member_data['site_id'],
|
||||
'member_id' => $member_data['member_id'],
|
||||
'account_type' => 'point',
|
||||
'account_data' => $account_data['point'],
|
||||
'from_type' => 'register',
|
||||
'type_name' => '注册',
|
||||
'type_tag' => "会员注册奖励积分:".$account_data['point'],
|
||||
'create_time' => time(),
|
||||
'username' => $member_data[ 'username' ],
|
||||
'mobile' => $member_data[ 'mobile' ],
|
||||
'email' => '',
|
||||
'remark' => '会员注册奖励积分',
|
||||
'related_id' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
if($account_data['balance'] > 0)
|
||||
{
|
||||
$list[] = array (
|
||||
'site_id' => $member_data['site_id'],
|
||||
'member_id' => $member_data['member_id'],
|
||||
'account_type' => 'balance',
|
||||
'account_data' => $account_data['balance'],
|
||||
'from_type' => 'register',
|
||||
'type_name' => '注册',
|
||||
'type_tag' => "会员注册奖励余额:".$account_data['balance'],
|
||||
'create_time' => time(),
|
||||
'username' => $member_data[ 'username' ],
|
||||
'mobile' => $member_data[ 'mobile' ],
|
||||
'email' => '',
|
||||
'remark' => '会员注册奖励余额',
|
||||
'related_id' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
if($account_data['growth'] > 0)
|
||||
{
|
||||
$list[] = array (
|
||||
'site_id' => $member_data['site_id'],
|
||||
'member_id' => $member_data['member_id'],
|
||||
'account_type' => 'growth',
|
||||
'account_data' => $account_data['growth'],
|
||||
'from_type' => 'register',
|
||||
'type_name' => '注册',
|
||||
'type_tag' => "会员注册奖励成长值:".$account_data['growth'],
|
||||
'create_time' => time(),
|
||||
'username' => $member_data[ 'username' ],
|
||||
'mobile' => $member_data[ 'mobile' ],
|
||||
'email' => '',
|
||||
'remark' => '会员注册奖励成长值',
|
||||
'related_id' => 0,
|
||||
);
|
||||
}
|
||||
model("member_account")->addList($list);
|
||||
$account = [
|
||||
'point' => $account_data['point'],
|
||||
'balance' => $account_data['balance'],
|
||||
'growth' => $account_data['growth']
|
||||
];
|
||||
model("member")->update($account, [['member_id', '=', $member_data['member_id']]]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取账户分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return array|\multitype
|
||||
*/
|
||||
public function getMemberAccountPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc,id desc', $field = '*', $alias = 'a', $join = [])
|
||||
{
|
||||
$list = model('member_account')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取账户列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array|\multitype
|
||||
*/
|
||||
public function getMemberAccountList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$list = model('member_account')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取账户总额
|
||||
* @param array $where
|
||||
* @param string $field
|
||||
* @param string $alias
|
||||
* @param null $join
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberAccountSum($where = [], $field = '', $alias = 'a', $join = null)
|
||||
{
|
||||
$sum = model('member_account')->getSum($where, $field, $alias, $join);
|
||||
return $this->success($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* api接口获取用户积分信息
|
||||
* @param $member_id
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberAccountPointInApi($member_id)
|
||||
{
|
||||
//当前可用积分
|
||||
$point = model("member")->getInfo([['member_id', '=', $member_id]], 'point');
|
||||
//累计获取积分
|
||||
$point_all = model("member_account")->getSum([['member_id', '=', $member_id], ['account_type', '=', 'point'], ['account_data', '>', 0]], 'account_data');
|
||||
//累计消费积分
|
||||
$point_use = $point_all - $point['point'];
|
||||
//今日获取积分
|
||||
$start_time = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
|
||||
$point_today = model("member_account")->getSum([['member_id', '=', $member_id], ['account_data', '>', 0],['account_type', '=', 'point'], [ 'create_time', 'between', [ $start_time, time() ] ] ], 'account_data');
|
||||
return $this->success([
|
||||
'point' => $point['point'],
|
||||
'point_all' => $point_all,
|
||||
'point_use' => $point_use,
|
||||
'point_today' => $point_today
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员账户余额变动通知
|
||||
* @param $data
|
||||
*/
|
||||
public function messageAccountChangeNotice($data)
|
||||
{
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
|
||||
$member_model = new MemberModel();
|
||||
$member_info_result = $member_model->getMemberInfo([ [ "member_id", "=", $data[ "member_id" ] ] ]);
|
||||
$member_info = $member_info_result[ "data" ];
|
||||
|
||||
$remark = $data[ 'remark' ] == '' ? $data[ 'type_name' ] : $data[ 'remark' ];
|
||||
preg_match_all('/[\x{4e00}-\x{9fa5}a-zA-Z0-9]/u', $remark, $matches);
|
||||
|
||||
$username = empty($member_info[ "nickname" ]) ? $member_info[ "mobile" ] : $member_info[ "nickname" ];
|
||||
$username = !empty($username) ? $username : $member_info[ "username" ];
|
||||
$var_parse = array (
|
||||
'username' => str_replace(' ', '', $username),//会员名
|
||||
'balance' => $member_info[ 'balance' ],
|
||||
'balance_money' => $member_info[ 'balance_money' ],
|
||||
'change_money' => $data['account_data'],
|
||||
);
|
||||
$data[ "sms_account" ] = $member_info[ "mobile" ];//手机号
|
||||
$data[ "var_parse" ] = $var_parse;
|
||||
$sms_model->sendMessage($data);
|
||||
|
||||
// 【弃用,暂无模板信息,无法使用,等待后续微信支持后开发】绑定微信公众号才发送
|
||||
// if (!empty($member_info) && !empty($member_info["wx_openid"])) {
|
||||
// $money = abs($data['account_data']);
|
||||
// $wechat_model = new WechatMessage();
|
||||
// $data["openid"] = $member_info["wx_openid"];
|
||||
// $data["template_data"] = [
|
||||
// 'keyword1' => $data['type_name'],
|
||||
// 'keyword2' => $data['account_data'] > 0 ? '+¥'.$money : '-¥'.$money,
|
||||
// 'keyword3' => '¥'.($member_info['balance'] + $member_info['balance_money']),
|
||||
// 'remark' => $data['remark'],
|
||||
// ];
|
||||
// $data["page"] = "";
|
||||
// $wechat_model->sendMessage($data);
|
||||
// }
|
||||
|
||||
//发送订阅消息
|
||||
if (!empty($member_info) && !empty($member_info[ "weapp_openid" ])) {
|
||||
$weapp_model = new WeappMessage();
|
||||
$data[ "openid" ] = $member_info[ "weapp_openid" ];
|
||||
$data[ "template_data" ] = [
|
||||
'amount6' => [
|
||||
'value' => $data[ 'account_data' ]
|
||||
],
|
||||
'phrase7' => [
|
||||
'value' => $data[ 'type_name' ]
|
||||
],
|
||||
'time8' => [
|
||||
'value' => time_to_date(time())
|
||||
]
|
||||
];
|
||||
$data[ "page" ] = "";
|
||||
$weapp_model->sendMessage($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员账户月份数据
|
||||
* @param $condition
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getMemberAccountMonthData($condition)
|
||||
{
|
||||
$list = Db::name('member_account')
|
||||
->where($condition)
|
||||
->field("DATE_FORMAT(FROM_UNIXTIME(create_time), '%Y-%m') as month")
|
||||
->order('id desc')
|
||||
->group('month')
|
||||
->select()
|
||||
->toArray();
|
||||
$data = array_column($list, 'month');
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 会员积分变动通知
|
||||
*/
|
||||
public function messagePointChangeNotice($data)
|
||||
{
|
||||
|
||||
//return $this->success();
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
|
||||
$member_model = new MemberModel();
|
||||
$member_info_result = $member_model->getMemberInfo([ [ "member_id", "=", $data[ "member_id" ] ] ]);
|
||||
$member_info = $member_info_result[ "data" ];
|
||||
|
||||
$remark = $data[ 'remark' ] == '' ? $data[ 'type_name' ] : $data[ 'remark' ];
|
||||
preg_match_all('/[\x{4e00}-\x{9fa5}a-zA-Z0-9]/u', $remark, $matches);
|
||||
|
||||
$username = empty($member_info[ "nickname" ]) ? $member_info[ "mobile" ] : $member_info[ "nickname" ];
|
||||
$username = !empty($username) ? $username : $member_info[ "username" ];
|
||||
$var_parse = array (
|
||||
'username' => str_replace(' ', '', $username),//会员名
|
||||
'point' => $member_info[ 'point' ],
|
||||
'change_point' => $data['account_data'],
|
||||
);
|
||||
$data[ "sms_account" ] = $member_info[ "mobile" ];//手机号
|
||||
$data[ "var_parse" ] = $var_parse;
|
||||
|
||||
//短信通知
|
||||
$sms_model->sendMessage($data);
|
||||
|
||||
//公众号消息模版
|
||||
if (!empty($member_info) && !empty($member_info["wx_openid"])) {
|
||||
$money = abs($data['account_data']);
|
||||
$wechat_model = new WechatMessage();
|
||||
$data["openid"] = $member_info["wx_openid"];
|
||||
$data["template_data"] = [
|
||||
'keyword1' => $data['type_name'],
|
||||
'keyword2' => $data['account_data'] > 0 ? '+'.$money : '-'.$money,
|
||||
'keyword3' => $member_info['point'],
|
||||
'remark' => $data['remark'],
|
||||
];
|
||||
$data["page"] = "";
|
||||
$wechat_model->sendMessage($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
172
app/model/member/MemberAddress.php
Executable file
172
app/model/member/MemberAddress.php
Executable file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use think\facade\Cache;
|
||||
use app\model\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员地址
|
||||
*/
|
||||
class MemberAddress extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 添加会员地址
|
||||
* @param array $data
|
||||
*/
|
||||
public function addMemberAddress($data)
|
||||
{
|
||||
if (!empty($data[ 'longitude' ]) && !empty($data[ 'latitude' ])) {
|
||||
$data[ 'type' ] = 2;
|
||||
} else {
|
||||
$data[ 'type' ] = 1;
|
||||
}
|
||||
if ($data[ 'is_default' ] == 1) {
|
||||
model('member_address')->update([ 'is_default' => 0 ], [ [ 'member_id', '=', $data[ 'member_id' ] ], [ 'type', '=', $data[ 'type' ] ] ]);
|
||||
}
|
||||
$res = model('member_address')->add($data);
|
||||
$count = model('member_address')->getCount([ 'member_id' => $data[ 'member_id' ] ]);
|
||||
if ($count == 1) {
|
||||
model('member_address')->update([ 'is_default' => 1 ], [ [ 'member_id', '=', $data[ 'member_id' ] ], [ 'id', '=', $res ], [ 'type', '=', $data[ 'type' ] ] ]);
|
||||
// 设置会员地址
|
||||
model('member')->update([
|
||||
'province_id' => $data[ 'province_id' ],
|
||||
'city_id' => $data[ 'city_id' ],
|
||||
'district_id' => $data[ 'district_id' ],
|
||||
'community_id' => $data[ 'community_id' ],
|
||||
'address' => $data[ 'address' ],
|
||||
'full_address' => $data[ 'full_address' ],
|
||||
'longitude' => $data[ 'longitude' ],
|
||||
'latitude' => $data[ 'latitude' ],
|
||||
], [ [ 'member_id', '=', $data[ 'member_id' ] ] ]);
|
||||
}
|
||||
Cache::tag("member_address_" . $data[ 'member_id' ])->clear();
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会员地址
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function editMemberAddress($data)
|
||||
{
|
||||
$info = model('member_address')->getInfo([ 'id' => $data[ 'id' ], 'member_id' => $data[ 'member_id' ] ], 'type');
|
||||
$type = $info[ 'type' ] ?? 1;
|
||||
if (!empty($data[ 'longitude' ]) && !empty($data[ 'latitude' ])) {
|
||||
$data[ 'type' ] = 2;
|
||||
} else {
|
||||
$data[ 'type' ] = 1;
|
||||
if ($type == 2) {
|
||||
//定位地址不能修改为,非定位地址
|
||||
return $this->error([], '');
|
||||
}
|
||||
}
|
||||
if ($data[ 'is_default' ] == 1) {
|
||||
model('member_address')->update([ 'is_default' => 0 ], [ [ 'member_id', '=', $data[ 'member_id' ] ], [ 'type', '=', $data[ 'type' ] ] ]);
|
||||
}
|
||||
$res = model('member_address')->update($data, [ 'id' => $data[ 'id' ], 'member_id' => $data[ 'member_id' ] ]);
|
||||
Cache::tag("member_address_" . $data[ 'member_id' ])->clear();
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除收获地址
|
||||
* @param array $condition
|
||||
*/
|
||||
public function deleteMemberAddress($condition)
|
||||
{
|
||||
$check_condition = array_column($condition, 2, 0);
|
||||
$member_id = $check_condition['member_id'] ?? 0;
|
||||
if (empty($member_id)) {
|
||||
return $this->error("", "缺少必填参数会员id");
|
||||
}
|
||||
$res = model('member_address')->delete($condition);
|
||||
Cache::tag("member_address_" . $member_id)->clear();
|
||||
if ($res === false) {
|
||||
return $this->error('', 'RESULT_ERROR');
|
||||
}
|
||||
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认收货地址
|
||||
* @param $id
|
||||
* @param $member_id
|
||||
* @return \multitype
|
||||
*/
|
||||
public function setMemberDefaultAddress($id, $member_id)
|
||||
{
|
||||
model('member_address')->startTrans();
|
||||
try {
|
||||
$info = model('member_address')->getInfo([ 'id' => $id, 'member_id' => $member_id ], 'type');
|
||||
model('member_address')->update([ 'is_default' => 0 ], [ [ 'member_id', '=', $member_id ], [ 'type', '=', $info[ 'type' ] ] ]);
|
||||
$res = model('member_address')->update([ 'is_default' => 1 ], [ 'member_id' => $member_id, 'id' => $id ]);
|
||||
model('member_address')->commit();
|
||||
Cache::tag("member_address_" . $member_id)->clear();
|
||||
return $this->success($res);
|
||||
} catch (\Exception $e) {
|
||||
model('member_address')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情收获地址
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberAddressInfo($condition, $field = '*')
|
||||
{
|
||||
$res = model('member_address')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取收获地址列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param string $limit
|
||||
* @return multitype:string mixed
|
||||
*/
|
||||
public function getMemberAddressList($condition = [], $field = '*', $order = 'is_default desc', $limit = null)
|
||||
{
|
||||
$list = model('member_address')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取收获地址分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return \multitype
|
||||
*/
|
||||
public function getMemberAddressPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'is_default desc,id desc', $field = 'id, member_id, name, mobile, telephone, address, full_address, is_default, type')
|
||||
{
|
||||
$list = model('member_address')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
//获取默认地址
|
||||
public function getMemberDefault($member_id)
|
||||
{
|
||||
return model('member_address')->getInfo(['member_id'=>$member_id,'is_default'=>1,'type'=>1], 'id');
|
||||
}
|
||||
}
|
||||
165
app/model/member/MemberAuth.php
Executable file
165
app/model/member/MemberAuth.php
Executable file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\model\BaseModel;
|
||||
|
||||
/**
|
||||
* 实名认证
|
||||
*/
|
||||
class MemberAuth extends BaseModel
|
||||
{
|
||||
|
||||
//申请状态
|
||||
private $status = [
|
||||
1 => '审核通过',
|
||||
0 => '待审核',
|
||||
-1 => '审核失败',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取实名认证分页列表
|
||||
*
|
||||
* @param array $condition
|
||||
* @param number $page
|
||||
* @param string $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
*/
|
||||
public function getMemberAuthPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
|
||||
{
|
||||
$list = model('member_auth')->pageList($condition, $field, $order, $page, $page_size, '', '', '');
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实名认证列表
|
||||
*
|
||||
* @param array $where
|
||||
* @param bool $field
|
||||
* @param string $order
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @param string $group
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberAuthList($where = [], $field = true, $order = '', $alias = 'a', $join = [], $group = '', $limit = null)
|
||||
{
|
||||
$res = model('member_auth')->getList($where, $field, $order, $alias, $join, $group, $limit);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实名认证信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return unknown
|
||||
*/
|
||||
public function getMemberAuthInfo($condition = [], $field = '*')
|
||||
{
|
||||
$member_info = model('member_auth')->getInfo($condition, $field);
|
||||
return $this->success($member_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加实名认证
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function add($data)
|
||||
{
|
||||
|
||||
$member_id = $data['member_id'] ?? '';
|
||||
if ($member_id === '') {
|
||||
return $this->error('', 'REQUEST_SITE_ID');
|
||||
}
|
||||
|
||||
$data["create_time"] = time();
|
||||
$result = model("member_auth")->add($data);
|
||||
if ($result === false) {
|
||||
return $this->error('', 'UNKNOW_ERROR');
|
||||
}
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑实名认证
|
||||
* @param $data
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function edit($data, $condition)
|
||||
{
|
||||
$check_condition = array_column($condition, 2, 0);
|
||||
$member_id = $check_condition['member_id'] ?? '';
|
||||
$auth_id = $check_condition['auth_id'] ?? '';
|
||||
if ($member_id === '') {
|
||||
return $this->error('', '会员ID不能为空');
|
||||
}
|
||||
if ($auth_id === '') {
|
||||
return $this->error('', '实名认证ID不能为空');
|
||||
}
|
||||
$res = model("member_auth")->update($data, $condition);
|
||||
if ($res === false) {
|
||||
return $this->error('', 'UNKNOW_ERROR');
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 实名认证 审核通过 后台审核
|
||||
* @param unknown $auth_id
|
||||
*/
|
||||
public function authPass($auth_id)
|
||||
{
|
||||
// 开启事务
|
||||
model('member_auth')->startTrans();
|
||||
try {
|
||||
//获取实名认证 信息
|
||||
$member_auth_info = model('member_auth')->getInfo([['auth_id', '=', $auth_id]]);
|
||||
//获取会员id
|
||||
$member_id = $member_auth_info['member_id'];
|
||||
|
||||
// 会员用户实名修改
|
||||
model('member')->update(['is_auth' => 1], [['member_id', '=', $member_id]]);
|
||||
// 会员实名认证通过修改
|
||||
$res = model('member_auth')->update(['status' => 1, 'audit_time' => time()], [['auth_id', '=', $auth_id]]);
|
||||
// 事务提交
|
||||
model('member_auth')->commit();
|
||||
return $this->success($res);
|
||||
} catch (\Exception $e) {
|
||||
// 事务回滚
|
||||
model('member_auth')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核拒绝
|
||||
* @param unknown $auth_id
|
||||
* @param unknown $reason
|
||||
*/
|
||||
public function authReject($auth_id, $reason)
|
||||
{
|
||||
$res = model('member_auth')->update(['status' => -1, 'remark' => $reason], [['auth_id', '=', $auth_id]]);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实名审核状态
|
||||
*/
|
||||
public function getAuthStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
}
|
||||
194
app/model/member/MemberBankAccount.php
Executable file
194
app/model/member/MemberBankAccount.php
Executable file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 会员提现账号
|
||||
*/
|
||||
class MemberBankAccount extends BaseModel
|
||||
{
|
||||
private $withdraw_type = [
|
||||
'alipay' => '支付宝',
|
||||
'bank' => '银行卡',
|
||||
'wechatpay' => '微信'
|
||||
];
|
||||
|
||||
public function getWithdrawType()
|
||||
{
|
||||
return $this->withdraw_type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加会员提现账号
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addMemberBankAccount($data)
|
||||
{
|
||||
//获取提现设置
|
||||
$config_model = new Withdraw();
|
||||
$config_result = $config_model->getConfig(1, 'shop');
|
||||
$config = $config_result['data']['value'];
|
||||
if (!empty($config)) {
|
||||
|
||||
//提现方式为微信的时候 判断用户是否已关注公众号
|
||||
if ($data['withdraw_type'] == 'wechatpay') {
|
||||
//获取会员信息
|
||||
$member_info = model('member')->getInfo([['member_id', '=', $data['member_id']]], 'wx_openid,weapp_openid');
|
||||
if (empty($member_info['wx_openid']) && empty($member_info['weapp_openid'])) {
|
||||
return $this->error('', '请先绑定微信');
|
||||
}
|
||||
}
|
||||
|
||||
model('member_bank_account')->startTrans();
|
||||
try {
|
||||
|
||||
if ($data['is_default'] == 1) {
|
||||
model('member_bank_account')->update(['is_default' => 0], ['member_id' => $data['member_id']]);
|
||||
}
|
||||
$data['create_time'] = time();
|
||||
$id = model('member_bank_account')->add($data);
|
||||
$count = model('member_bank_account')->getCount(['member_id' => $data['member_id']]);
|
||||
if ($count == 1)
|
||||
model('member_bank_account')->update(['is_default' => 1], ['member_id' => $data['member_id'], 'id' => $id]);
|
||||
|
||||
Cache::tag("member_bank_account_" . $data['member_id'])->clear();
|
||||
|
||||
model('member_bank_account')->commit();
|
||||
return $this->success($id);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
model('member_bank_account')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->error('', '平台未开启会员提现');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会员提现账号
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function editMemberBankAccount($data)
|
||||
{
|
||||
//获取提现设置
|
||||
$config_model = new Withdraw();
|
||||
$config_result = $config_model->getConfig(1, 'shop');
|
||||
$config = $config_result['data']['value'];
|
||||
|
||||
if (!empty($config)) {
|
||||
|
||||
//提现方式为微信的时候 判断用户是否已关注公众号
|
||||
if ($data['withdraw_type'] == 'wechatpay') {
|
||||
//获取会员信息
|
||||
$member_info = model('member')->getInfo([['member_id', '=', $data['member_id']]], 'wx_openid,weapp_openid');
|
||||
if (empty($member_info['wx_openid']) && empty($member_info['weapp_openid'])) {
|
||||
return $this->error('', '请先绑定微信');
|
||||
}
|
||||
}
|
||||
|
||||
model('member_bank_account')->startTrans();
|
||||
try {
|
||||
|
||||
if ($data['is_default'] == 1) {
|
||||
model('member_bank_account')->update(['is_default' => 0], ['member_id' => $data['member_id']]);
|
||||
}
|
||||
$data['modify_time'] = time();
|
||||
$res = model('member_bank_account')->update($data, ['id' => $data['id']]);
|
||||
Cache::tag("member_bank_account_" . $data['member_id'])->clear();
|
||||
|
||||
model('member_bank_account')->commit();
|
||||
return $this->success($res);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
model('member_bank_account')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->error('', '平台未开启会员提现');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除会员提现账号
|
||||
* @param array $condition
|
||||
*/
|
||||
public function deleteMemberBankAccount($condition)
|
||||
{
|
||||
$check_condition = array_column($condition, 2, 0);
|
||||
$res = model('member_bank_account')->delete($condition);
|
||||
Cache::tag("member_bank_account_" . $check_condition['member_id'])->clear();
|
||||
if ($res === false) {
|
||||
return $this->error('', 'RESULT_ERROR');
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认会员提现账号
|
||||
* @param $id
|
||||
* @param $member_id
|
||||
* @return \multitype
|
||||
*/
|
||||
public function modifyDefaultAccount($id, $member_id)
|
||||
{
|
||||
model('member_bank_account')->startTrans();
|
||||
try {
|
||||
model('member_bank_account')->update(['is_default' => 0], ['member_id' => $member_id]);
|
||||
$res = model('member_bank_account')->update(['is_default' => 1], ['member_id' => $member_id, 'id' => $id]);
|
||||
model('member_bank_account')->commit();
|
||||
Cache::tag("member_bank_account_" . $member_id)->clear();
|
||||
return $this->success($res);
|
||||
} catch (\Exception $e) {
|
||||
model('member_bank_account')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员提现账号信息
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberBankAccountInfo($condition, $field = '*')
|
||||
{
|
||||
$res = model('member_bank_account')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员提现账号分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return array|\multitype
|
||||
*/
|
||||
public function getMemberBankAccountPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*')
|
||||
{
|
||||
$list = model('member_bank_account')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
}
|
||||
421
app/model/member/MemberCluster.php
Executable file
421
app/model/member/MemberCluster.php
Executable file
@@ -0,0 +1,421 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use addon\coupon\model\Coupon;
|
||||
use app\model\system\Cron;
|
||||
|
||||
/**
|
||||
* 会员群体
|
||||
*/
|
||||
class MemberCluster extends BaseModel
|
||||
{
|
||||
public $basic = [
|
||||
'member_level' => '会员等级',
|
||||
'member_label' => '会员标签',
|
||||
'sex' => '性别',
|
||||
'birthday' => '生日',
|
||||
'reg_time' => '注册时间',
|
||||
'point' => '当前积分',
|
||||
'balance' => '当前余额',
|
||||
'growth' => '当前成长值',
|
||||
'sign_days_series' => '连续签到次数',
|
||||
'mobile' => '会员手机',
|
||||
];
|
||||
|
||||
public $consume = [
|
||||
'order_money' => '付款金额',
|
||||
'order_complete_money' => '消费金额',
|
||||
'order_num' => '付款次数',
|
||||
'order_complete_num' => '消费次数',
|
||||
'recharge_total' => '累计充值',
|
||||
'recharge_time' => '充值次数',
|
||||
];
|
||||
|
||||
public $promotion = [
|
||||
'coupon_num' => '优惠券数',
|
||||
];
|
||||
|
||||
/**
|
||||
* 查询规则
|
||||
*/
|
||||
public $rule = [
|
||||
'member_level' => [ 'field' => "member_level", 'query_method' => "FIND_IN_SET", "table" => "member" ],
|
||||
'member_label' => [ 'field' => "member_label", 'query_method' => "FIND_IN_SET", "table" => "member" ],
|
||||
'sex' => [ 'field' => "sex", 'query_method' => "in", "table" => "member" ],
|
||||
'birthday' => [ 'field' => "birthday", 'query_method' => "between time", "table" => "member" ],
|
||||
'reg_time' => [ 'field' => "reg_time", 'query_method' => "between time", "table" => "member" ],
|
||||
'point' => [ 'field' => "point", 'query_method' => "between", "table" => "member" ],
|
||||
'balance' => [ 'field' => "balance", 'query_method' => "between", "table" => "member" ],
|
||||
'growth' => [ 'field' => "growth", 'query_method' => "between", "table" => "member" ],
|
||||
'sign_days_series' => [ 'field' => "sign_days_series", 'query_method' => "between", "table" => "member" ],
|
||||
'mobile' => [ 'field' => "mobile", 'query_method' => "like", "table" => "member" ],
|
||||
'order_money' => [ 'field' => "order_money", 'query_method' => "between", "table" => "member" ],
|
||||
'order_complete_money' => [ 'field' => "order_complete_money", 'query_method' => "between", "table" => "member" ],
|
||||
'order_num' => [ 'field' => "order_num", 'query_method' => "between", "table" => "member" ],
|
||||
'order_complete_num' => [ 'field' => "order_complete_num", 'query_method' => "between", "table" => "member" ],
|
||||
'recharge_total' => [ 'field' => "recharge_total", 'query_method' => "between", "table" => "member_recharge_order" ],
|
||||
'recharge_time' => [ 'field' => "recharge_time", 'query_method' => "between", "table" => "member_recharge_order" ],
|
||||
'coupon_num' => [ 'field' => "coupon_num", 'query_method' => "between", "table" => "promotion_coupon" ]
|
||||
];
|
||||
|
||||
/**
|
||||
* 添加会员群体
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addMemberCluster($data)
|
||||
{
|
||||
//重新计算符合会员群体的会员
|
||||
$calculate_data = $this->calculate($data);
|
||||
|
||||
$data[ 'member_num' ] = $calculate_data[ 'data' ][ 'member_num' ];
|
||||
$data[ 'member_ids' ] = $calculate_data[ 'data' ][ 'member_ids' ];
|
||||
|
||||
$res = model('member_cluster')->add($data);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑会员群体
|
||||
* @param $data
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function editMemberCluster($data, $condition)
|
||||
{
|
||||
//重新计算符合会员群体的会员
|
||||
$calculate_data = $this->calculate($data);
|
||||
|
||||
$data[ 'member_num' ] = $calculate_data[ 'data' ][ 'member_num' ];
|
||||
$data[ 'member_ids' ] = $calculate_data[ 'data' ][ 'member_ids' ];
|
||||
|
||||
$res = model('member_cluster')->update($data, $condition);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除会员群体
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function deleteMemberCluster($condition)
|
||||
{
|
||||
$res = model('member_cluster')->delete($condition);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员群体信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberClusterInfo($condition = [], $field = '*')
|
||||
{
|
||||
$info = model('member_cluster')->getInfo($condition, $field);
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员群体详情
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberClusterDetail($condition = [], $field = '*')
|
||||
{
|
||||
$info = model('member_cluster')->getInfo($condition, $field);
|
||||
$info[ 'rule_arr' ] = json_decode($info[ 'rule_json' ], true);
|
||||
|
||||
//获取标签
|
||||
$member_label_content = $info[ 'rule_arr' ][ 'basic' ][ 'member_label' ][ 'content' ];
|
||||
$info[ 'rule_arr' ][ 'basic' ][ 'member_label' ][ 'content_name' ] = '';
|
||||
if (!empty($member_label_content)) {
|
||||
$member_label_list = model('member_label')->getColumn([ [ "label_id", "in", $member_label_content ] ], 'label_name');
|
||||
$info[ 'rule_arr' ][ 'basic' ][ 'member_label' ][ 'content_name' ] = implode(",", $member_label_list);
|
||||
}
|
||||
//获取等级
|
||||
$member_level_content = $info[ 'rule_arr' ][ 'basic' ][ 'member_level' ][ 'content' ];
|
||||
$info[ 'rule_arr' ][ 'basic' ][ 'member_level' ][ 'content_name' ] = '';
|
||||
if (!empty($member_level_content)) {
|
||||
$member_level_list = model('member_level')->getColumn([ [ "level_id", "in", $member_level_content ] ], 'level_name');
|
||||
$info[ 'rule_arr' ][ 'basic' ][ 'member_level' ][ 'content_name' ] = implode(",", $member_level_list);
|
||||
}
|
||||
|
||||
//获取性别
|
||||
$member_sex_content = $info[ 'rule_arr' ][ 'basic' ][ 'sex' ][ 'content' ];
|
||||
$info[ 'rule_arr' ][ 'basic' ][ 'sex' ][ 'content_arr' ] = [];
|
||||
if (!empty($member_sex_content)) {
|
||||
$info[ 'rule_arr' ][ 'basic' ][ 'sex' ][ 'content_arr' ] = explode(",", $member_sex_content);
|
||||
}
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员群体列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberClusterList($condition = [], $field = '*', $order = 'cluster_id asc', $limit = null)
|
||||
{
|
||||
$list = model('member_cluster')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员群体分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberClusterPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'cluster_id asc', $field = '*')
|
||||
{
|
||||
$list = model('member_cluster')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算人数
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function calculate($data)
|
||||
{
|
||||
//根据规则获得条件
|
||||
$condition = $this->handleRule($data[ 'rule_json' ]);
|
||||
|
||||
$condition[] = [ "site_id", '=', $data[ 'site_id' ] ];
|
||||
//只查询正常用户
|
||||
$condition[] = [ 'is_delete', '=', 0 ];
|
||||
|
||||
$member_arr = model('member')->getColumn($condition, 'member_id');
|
||||
$member_ids = implode(',', $member_arr);
|
||||
$member_num = model('member')->getCount($condition);
|
||||
|
||||
return $this->success([ "member_num" => $member_num, "member_ids" => $member_ids ]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理规则条件
|
||||
* @param $rule_json
|
||||
* @return array
|
||||
*/
|
||||
public function handleRule($rule_json)
|
||||
{
|
||||
$rule_arr = json_decode($rule_json, true);
|
||||
|
||||
$all_field = array_merge($this->basic, $this->consume, $this->promotion);
|
||||
|
||||
$condition = [];
|
||||
foreach ($rule_arr as $key => $value) {
|
||||
//获取键
|
||||
$keys = array_keys($value);
|
||||
foreach ($keys as $key) {
|
||||
|
||||
if (array_key_exists($key, $all_field)) {
|
||||
$values = $value[ $key ];
|
||||
$query_method = $this->rule[ $key ][ 'query_method' ];
|
||||
$start = $values['start'] ?? '';
|
||||
$end = $values['end'] ?? '';
|
||||
$content = $values['content'] ?? '';
|
||||
$include = $values[ 'include' ] == 2 ? "not " : "";
|
||||
$is_show = $values[ 'is_show' ];
|
||||
if ($is_show == 1) {
|
||||
switch ( $query_method ) {
|
||||
case "between":
|
||||
$condition[] = [ $key, $include . 'between', [ $start, $end ] ];
|
||||
break;
|
||||
case "between time":
|
||||
if ($values[ 'include' ] == 1) {
|
||||
//注册时间
|
||||
if ($start != '' && $end != '') {
|
||||
$condition[] = [ $key, 'between', [ strtotime($start), strtotime($end) ] ];
|
||||
} else if ($start != '' && $end == '') {
|
||||
$condition[] = [ $key, '>=', strtotime($start) ];
|
||||
} else if ($start == '' && $end != '') {
|
||||
$condition[] = [ $key, '<=', strtotime($end) ];
|
||||
}
|
||||
} else if ($values[ 'include' ] == 2) {
|
||||
//注册时间
|
||||
if ($start != '' && $end != '') {
|
||||
$condition[] = [ $key, $include . 'between', [ strtotime($start), strtotime($end) ] ];
|
||||
} else if ($start != '' && $end == '') {
|
||||
$condition[] = [ $key, '<', strtotime($start) ];
|
||||
} else if ($start == '' && $end != '') {
|
||||
$condition[] = [ $key, '>', strtotime($end) ];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "in":
|
||||
$condition[] = [ $key, $include . 'in', $content ];
|
||||
break;
|
||||
case "like":
|
||||
$condition[] = [ $key, $include . 'like', "%" . $content . "%" ];
|
||||
break;
|
||||
case "FIND_IN_SET":
|
||||
//使用like搜索 暂不使用find_in_set 不可用包含不包含
|
||||
// $content_arr = explode(",",$content);
|
||||
// $temp_sql = '';
|
||||
// foreach ($content_arr as $content_value){
|
||||
// if(empty($temp_sql)){
|
||||
// $temp_sql .= "FIND_IN_SET({$content_value}, member_label)";
|
||||
// }else{
|
||||
// $temp_sql .= " or FIND_IN_SET({$content_value}, member_label)";
|
||||
// }
|
||||
// }
|
||||
// $condition[] = [ "", 'exp', Db::raw($temp_sql) ];
|
||||
$content_arr = explode(",", $content);
|
||||
if ($values[ 'include' ] == 1) {
|
||||
$find_in_set = "or";
|
||||
$find_in_set_method = "like";
|
||||
} else if ($values[ 'include' ] == 2) {
|
||||
$find_in_set = "and";
|
||||
$find_in_set_method = "not like";
|
||||
}
|
||||
$temp_arr = [];
|
||||
foreach ($content_arr as $content_value) {
|
||||
$content_condition = [ $content_value, '%' . $content_value . ',%', '%' . $content_value, '%,' . $content_value . ',%' ];
|
||||
$temp_arr = array_merge($content_condition, $temp_arr);
|
||||
}
|
||||
$condition[] = [ $key, $find_in_set_method, $temp_arr, $find_in_set ];
|
||||
break;
|
||||
case 4://其他表数据
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $condition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自动定时刷新数据
|
||||
* @return array
|
||||
*/
|
||||
public function refreshMemberCluster()
|
||||
{
|
||||
$list = model('member_cluster')->getList([], 'rule_json,site_id,cluster_id');
|
||||
//循环刷新事件
|
||||
foreach ($list as $value) {
|
||||
$calculate_data = $this->calculate($value)[ 'data' ];
|
||||
model("member_cluster")->update([ "member_num" => $calculate_data[ 'member_num' ], "member_ids" => $calculate_data[ 'member_ids' ], "update_time" => time() ], [ "cluster_id" => $value[ 'cluster_id' ] ]);
|
||||
}
|
||||
|
||||
return $this->success();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发放积分
|
||||
* @param $point
|
||||
* @param $cluster_id
|
||||
* @param $remark
|
||||
* @return array
|
||||
*/
|
||||
public function sendPoint($point, $cluster_id, $remark)
|
||||
{
|
||||
$member_cluster_info = model("member_cluster")->getInfo([ "cluster_id" => $cluster_id ], "member_ids");
|
||||
|
||||
$member_list = model("member")->getList([ [ "member_id", "in", $member_cluster_info[ "member_ids" ] ] ], 'site_id,member_id');
|
||||
$member_account_model = new MemberAccount();
|
||||
model('member_account')->startTrans();
|
||||
try {
|
||||
foreach ($member_list as $value) {
|
||||
$member_account_model->addMemberAccount($value[ 'site_id' ], $value[ 'member_id' ], 'point', $point, 'adjust', '会员群体发放积分' . $point, $remark);
|
||||
}
|
||||
model('member_account')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
model('member_account')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发放余额
|
||||
* @param $balance
|
||||
* @param $cluster_id
|
||||
* @param $remark
|
||||
* @return array
|
||||
*/
|
||||
public function sendBalance($balance, $cluster_id, $remark)
|
||||
{
|
||||
$member_cluster_info = model("member_cluster")->getInfo([ "cluster_id" => $cluster_id ], "member_ids");
|
||||
|
||||
$member_list = model("member")->getList([ [ "member_id", "in", $member_cluster_info[ "member_ids" ] ] ], 'site_id,member_id');
|
||||
$member_account_model = new MemberAccount();
|
||||
model('member_account')->startTrans();
|
||||
try {
|
||||
foreach ($member_list as $value) {
|
||||
$member_account_model->addMemberAccount($value[ 'site_id' ], $value[ 'member_id' ], 'balance', $balance, 'adjust', '会员群体发放红包' . $balance, $remark);
|
||||
}
|
||||
model('member_account')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
model('member_account')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发放优惠券
|
||||
* @param $coupon
|
||||
* @param $cluster_id
|
||||
* @return array
|
||||
*/
|
||||
public function sendCoupon($coupon, $cluster_id)
|
||||
{
|
||||
$member_cluster_info = model("member_cluster")->getInfo([ "cluster_id" => $cluster_id ], "member_ids");
|
||||
|
||||
$member_list = model("member")->getList([ [ "member_id", "in", $member_cluster_info[ "member_ids" ] ] ], 'site_id,member_id');
|
||||
model('promotion_coupon')->startTrans();
|
||||
try {
|
||||
$coupon_model = new Coupon();
|
||||
foreach ($member_list as $value) {
|
||||
$coupon_model->giveCoupon($coupon, $value[ 'site_id' ], $value[ 'member_id' ], Coupon::GET_TYPE_MERCHANT_GIVE);
|
||||
}
|
||||
model('promotion_coupon')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('promotion_coupon')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺初始化的时候添加定时任务
|
||||
*/
|
||||
public function addMemberClusterCronRefresh()
|
||||
{
|
||||
//添加会员群体刷新时间
|
||||
$cron_model = new Cron();
|
||||
$execute_time = time() + 60;
|
||||
$res = $cron_model->addCron(2, 1, "会员群体定时刷新", "CronMemberClusterRefresh", $execute_time, 0);
|
||||
return $this->success($res);
|
||||
}
|
||||
}
|
||||
121
app/model/member/MemberLabel.php
Executable file
121
app/model/member/MemberLabel.php
Executable file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use think\facade\Cache;
|
||||
use app\model\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员标签
|
||||
*/
|
||||
class MemberLabel extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 添加会员标签
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function addMemberLabel($data)
|
||||
{
|
||||
|
||||
$res = model('member_label')->add($data);
|
||||
Cache::tag("member_label")->clear();
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会员标签
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $condition
|
||||
*/
|
||||
public function editMemberLabel($data, $condition)
|
||||
{
|
||||
|
||||
$res = model('member_label')->update($data, $condition);
|
||||
Cache::tag("member_label")->clear();
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除会员标签
|
||||
* @param array $condition
|
||||
*/
|
||||
public function deleteMemberLabel($condition)
|
||||
{
|
||||
$res = model('member_label')->delete($condition);
|
||||
Cache::tag("member_label")->clear();
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改标签排序
|
||||
* @param int $sort
|
||||
* @param int $label_id
|
||||
*/
|
||||
public function modifyMemberLabelSort($sort, $label_id)
|
||||
{
|
||||
//判断标签下有没有会员
|
||||
if(!empty($label_ids)){
|
||||
$label_id_array = explode(',',$label_ids);
|
||||
foreach($label_id_array as $val){
|
||||
$label_is_has_member = model('member')->getList([['member_label','like','%'.$val.'%'],['is_delete','=','0']],'member_id');
|
||||
if(!empty($label_is_has_member))return $this->error('','标签下有会员不能删除!');
|
||||
}
|
||||
}
|
||||
$res = model('member_label')->update(['sort' => $sort], [['label_id', '=', $label_id]]);
|
||||
Cache::tag("member_label")->clear();
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员标签信息
|
||||
*
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
*/
|
||||
public function getMemberLabelInfo($condition = [], $field = '*')
|
||||
{
|
||||
$info = model('member_label')->getInfo($condition, $field);
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员标签列表
|
||||
*
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param string $limit
|
||||
*/
|
||||
public function getMemberLabelList($condition = [], $field = '*', $order = 'sort asc, label_id asc', $limit = null)
|
||||
{
|
||||
$list = model('member_label')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员标签分页列表
|
||||
*
|
||||
* @param array $condition
|
||||
* @param number $page
|
||||
* @param string $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
*/
|
||||
public function getMemberLabelPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'sort asc, level_id asc', $field = '*')
|
||||
{
|
||||
$list = model('member_label')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
}
|
||||
357
app/model/member/MemberLevel.php
Executable file
357
app/model/member/MemberLevel.php
Executable file
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
|
||||
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use addon\coupon\model\Coupon;
|
||||
use app\model\system\Cron;
|
||||
use app\model\BaseModel;
|
||||
use addon\coupon\model\CouponType;
|
||||
|
||||
/**
|
||||
* 会员等级
|
||||
*/
|
||||
class MemberLevel extends BaseModel
|
||||
{
|
||||
public $level_change_type = [
|
||||
'upgrade' => '自动升级',
|
||||
'buy' => '付费购卡',
|
||||
'adjust' => '商家调整',
|
||||
'expire' => '到期降级'
|
||||
];
|
||||
|
||||
public $level_time = [
|
||||
'week' => '一周',
|
||||
'month' => '一月',
|
||||
'quarter' => '一季',
|
||||
'year' => '一年',
|
||||
];
|
||||
|
||||
/**
|
||||
* 添加会员等级
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addMemberLevel($data)
|
||||
{
|
||||
$res = model('member_level')->add($data);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会员等级(不允许批量处理)
|
||||
* @param $data
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function editMemberLevel($data, $condition)
|
||||
{
|
||||
$res = model('member_level')->update($data, $condition);
|
||||
$check_condition = array_column($condition, 2, 0);
|
||||
$level_id = $check_condition['level_id'] ?? 0;
|
||||
if (!empty($level_id) && isset($data['level_name'])) {
|
||||
model('member')->update(['member_level_name' => $data['level_name']], [['member_level', '=', $level_id]]);
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新会员等级
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function startlevel($site_id)
|
||||
{
|
||||
$list = model('member_level')->getList([['level_type', '=', 0], ['site_id', '=', $site_id]], 'level_id, level_name, growth', 'growth asc');
|
||||
|
||||
foreach ($list as $key => $val) {
|
||||
$where = [
|
||||
['growth', '>=', $val['growth']],
|
||||
['is_delete', '=', 0],
|
||||
['member_level_type', '=', 0],
|
||||
['is_member', '=', 1]
|
||||
];
|
||||
if (!empty($list[$key + 1])) $where[] = ['growth', '<', $list[$key + 1]['growth']];
|
||||
model("member")->update(['member_level' => $val['level_id'], 'member_level_name' => $val['level_name']], $where);
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新会员等级排序
|
||||
* @param $site_id
|
||||
*/
|
||||
private function refreshSort($site_id)
|
||||
{
|
||||
$list = model('member_level')->getList([['site_id', '=', $site_id]], 'level_id, growth', 'growth asc');
|
||||
foreach ($list as $k => $v) {
|
||||
model('member_level')->update(['sort' => $k], [['level_id', '=', $v['level_id']]]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新会员等级
|
||||
* @param $site_id
|
||||
*/
|
||||
private function refreshLevel($site_id)
|
||||
{
|
||||
model('member_level')->update(['is_default' => 0], [['is_default', '=', 1], ['site_id', '=', $site_id]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除会员等级
|
||||
* @param $level_id
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function deleteMemberLevel($level_id, $site_id)
|
||||
{
|
||||
$count = model('member')->getCount([['member_level', '=', $level_id], ['is_delete', '=', 0]]);
|
||||
if ($count > 0) return $this->error('', '有会员正持有该等级不可删除');
|
||||
$condition = [
|
||||
['level_id', '=', $level_id],
|
||||
['site_id', '=', $site_id],
|
||||
];
|
||||
$res = model('member_level')->delete($condition);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条等级
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @return array
|
||||
*/
|
||||
public function getFirstMemberLevel($condition, $field = '*', $order = "")
|
||||
{
|
||||
$data = model('member_level')->getFirstData($condition, $field, $order);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员等级信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberLevelInfo($condition = [], $field = '*')
|
||||
{
|
||||
$info = model('member_level')->getInfo($condition, $field);
|
||||
if ($info) {
|
||||
//获取优惠券信息
|
||||
if (isset($info['send_coupon']) && !empty($info['send_coupon'])) {
|
||||
//优惠券字段
|
||||
$coupon_field = 'coupon_type_id,type,coupon_name,image,money,discount,validity_type,fixed_term,status,is_limit,at_least,count,lead_count,end_time';
|
||||
|
||||
$model = new CouponType();
|
||||
$coupon = $model->getCouponTypeList([['coupon_type_id', 'in', $info['send_coupon']]], $coupon_field);
|
||||
$info['coupon_list'] = $coupon;
|
||||
}
|
||||
}
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员等级列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberLevelList($condition = [], $field = '*', $order = 'sort asc, level_id asc', $limit = null)
|
||||
{
|
||||
|
||||
$list = model('member_level')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过会员等级查询会员数量
|
||||
*/
|
||||
public function getMemberCountGroupByLevel()
|
||||
{
|
||||
$list = model('member')->getList([], "count(*) as count, member_level", '', '', '', 'member_level');
|
||||
if (!empty($list)) {
|
||||
$key = array_column($list, 'member_level');
|
||||
$member_level_array = array_combine($key, $list);
|
||||
return $member_level_array;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员等级分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberLevelPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'sort asc, level_id asc', $field = '*')
|
||||
{
|
||||
|
||||
$list = model('member_level')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加会员卡变更记录
|
||||
* @param int $member_id 变更会员
|
||||
* @param $site_id
|
||||
* @param int $after_level 变更之后的会员卡
|
||||
* @param $expire_time
|
||||
* @param $change_type
|
||||
* @param int $action_uid 操作人
|
||||
* @param int $action_type 操作人类型
|
||||
* @param string $action_name 操作人昵称
|
||||
* @param string $action_desc
|
||||
* @return array
|
||||
*/
|
||||
public function addMemberLevelChangeRecord($member_id, $site_id, $after_level, $expire_time, $change_type, $action_uid, $action_type, $action_name, $action_desc = '')
|
||||
{
|
||||
model('member_level_records')->startTrans();
|
||||
|
||||
try {
|
||||
$member_info = model('member')->getInfo([['member_id', '=', $member_id]], 'member_level,member_level_name,member_level_type,level_expire_time,is_member');
|
||||
$member_level = model('member_level')->getInfo([['level_id', '=', $member_info['member_level']]], 'growth, level_type');
|
||||
$level_info = model('member_level')->getInfo([['level_id', '=', $after_level], ['site_id', '=', $site_id]], 'level_id,level_name,level_type,growth');
|
||||
if ($member_info['member_level'] == $level_info['level_id']) {
|
||||
model('member_level_records')->rollback();
|
||||
return $this->success('', '会员卡未发生变更');
|
||||
}
|
||||
|
||||
$prev_record = model('member_level_records')->getFirstData([['member_id', '=', $member_id]], 'id', 'change_time desc');
|
||||
// 添加变更记录
|
||||
$data = [
|
||||
'member_id' => $member_id,
|
||||
'site_id' => $site_id,
|
||||
'before_level_id' => $member_info['member_level'],
|
||||
'before_level_name' => $member_info['member_level_name'],
|
||||
'before_level_type' => $member_info['member_level_type'],
|
||||
'before_expire_time' => $member_info['level_expire_time'],
|
||||
'after_level_id' => $level_info['level_id'],
|
||||
'after_level_name' => $level_info['level_name'],
|
||||
'after_level_type' => $level_info['level_type'],
|
||||
'prev_id' => $prev_record['id'] ?? 0,
|
||||
'change_time' => time(),
|
||||
'action_uid' => $action_uid,
|
||||
'action_type' => $action_type,
|
||||
'action_name' => $action_name,
|
||||
'action_desc' => $action_desc,
|
||||
'change_type' => $change_type,
|
||||
'change_type_name' => $this->level_change_type[$change_type]
|
||||
];
|
||||
model('member_level_records')->add($data);
|
||||
|
||||
// 变更会员等级
|
||||
$edit_member_data = [
|
||||
'member_level' => $level_info['level_id'],
|
||||
'member_level_name' => $level_info['level_name'],
|
||||
'member_level_type' => $level_info['level_type'],
|
||||
'level_expire_time' => $level_info['level_type'] == 0 ? 0 : $expire_time
|
||||
];
|
||||
|
||||
if (!$member_info['is_member']) {
|
||||
$edit_member_data['is_member'] = 1;
|
||||
$edit_member_data['member_time'] = time();
|
||||
}
|
||||
model('member')->update($edit_member_data, [['member_id', '=', $member_id]]);
|
||||
$cron = new Cron();
|
||||
$cron->deleteCron([['event', '=', 'MemberLevelAutoExpire'], ['relate_id', '=', $member_id]]);
|
||||
if ($level_info['level_type']) {
|
||||
$cron->addCron(1, 0, "会员卡自动过期", "MemberLevelAutoExpire", $expire_time, $member_id);
|
||||
}
|
||||
model('member_level_records')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('member_level_records')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员会员卡变更记录
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $list_rows
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @param null $group
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberLevelRecordPageList($condition = [], $page = 1, $list_rows = PAGE_LIST_ROWS, $field = '*', $order = 'change_time desc', $alias = 'a', $join = [], $group = null)
|
||||
{
|
||||
$list = model('member_level_records')->pageList($condition, $field, $order, $page, $list_rows, $alias, $join, $group);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员卡过期
|
||||
* @param $member_id
|
||||
*/
|
||||
public function memberLevelExpire($member_id)
|
||||
{
|
||||
$member_info = model('member')->getInfo([['member_id', '=', $member_id]], 'member_id,site_id,nickname,member_level,level_expire_time,growth');
|
||||
if (!empty($member_info) && !empty($member_info['level_expire_time']) && $member_info['level_expire_time'] < time()) {
|
||||
$alias = 'mlr';
|
||||
$join = [
|
||||
['member_level ml', 'ml.level_id = mlr.before_level_id', 'inner']
|
||||
];
|
||||
// 如果会员还存在未过期的付费会员卡
|
||||
$level_info = model('member_level_records')->getFirstDataView([['before_expire_time', '>', time()], ['member_id', '=', $member_id]], 'mlr.*', 'change_time desc', $alias, $join);
|
||||
|
||||
if (!empty($level_info)) {
|
||||
$this->addMemberLevelChangeRecord($member_id, $member_info['site_id'], $level_info['before_level_id'], $level_info['before_expire_time'], 'expire', $member_id, 'member', $member_info['nickname']);
|
||||
} else {
|
||||
// 如果之前免费卡还存在
|
||||
$level_info = model('member_level_records')->getFirstDataView([['before_level_type', '=', 0], ['member_id', '=', $member_id]], 'mlr.*', 'change_time desc', $alias, $join);
|
||||
if (!empty($level_info)) {
|
||||
$this->addMemberLevelChangeRecord($member_id, $member_info['site_id'], $level_info['before_level_id'], $level_info['before_expire_time'], 'expire', $member_id, 'member', $member_info['nickname']);
|
||||
event("AddMemberAccount", ['account_type' => 'growth', 'member_id' => $member_id, 'site_id' => $member_info['site_id']]);
|
||||
} else {
|
||||
// 如果之前的免费卡不存在
|
||||
$level_info = model('member_level')->getFirstData([['site_id', '=', $member_info['site_id']], ['level_type', '=', 0], ['growth', '<=', $member_info['growth']]], '*', 'growth desc');
|
||||
|
||||
if (!empty($level_info)) {
|
||||
$this->addMemberLevelChangeRecord($member_id, $member_info['site_id'], $level_info['level_id'], 0, 'expire', $member_id, 'member', $member_info['nickname']);
|
||||
$member_account = new MemberAccount();
|
||||
//赠送红包
|
||||
if ($level_info['send_balance'] > 0) {
|
||||
$member_account->addMemberAccount($member_info['site_id'], $member_info['member_id'], 'balance', $level_info['send_balance'], 'upgrade', '会员升级得红包' . $level_info['send_balance'], '会员等级升级奖励');
|
||||
}
|
||||
//赠送积分
|
||||
if ($level_info['send_point'] > 0) {
|
||||
$member_account->addMemberAccount($member_info['site_id'], $member_info['member_id'], 'point', $level_info['send_point'], 'upgrade', '会员升级得积分' . $level_info['send_point'], '会员等级升级奖励');
|
||||
}
|
||||
//给用户发放优惠券
|
||||
if (!empty($level_info['send_coupon'])) {
|
||||
$coupon_array = explode(',', $level_info['send_coupon']);
|
||||
$coupon_model = new Coupon();
|
||||
$coupon_array = array_map(function ($value) {
|
||||
return ['coupon_type_id' => $value, 'num' => 1];
|
||||
}, $coupon_array);
|
||||
$coupon_model->giveCoupon($coupon_array, $member_info['site_id'], $member_info['member_id'], Coupon::GET_TYPE_ACTIVITY_GIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
137
app/model/member/MemberSignin.php
Executable file
137
app/model/member/MemberSignin.php
Executable file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use Carbon\Carbon;
|
||||
use think\db\exception\DbException;
|
||||
|
||||
/**
|
||||
* 会员签到
|
||||
*/
|
||||
class MemberSignin extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 获取签到奖励规则
|
||||
*/
|
||||
public function getAward($site_id)
|
||||
{
|
||||
$award = event('MemberSigninAward', [ 'site_id' => $site_id ], true);
|
||||
return $this->success($award);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否已经签到
|
||||
* @param $member_id
|
||||
* @return array
|
||||
*/
|
||||
public function isSign($member_id)
|
||||
{
|
||||
$member_info = model("member")->getInfo([ [ 'member_id', '=', $member_id ] ], 'sign_time');
|
||||
if ($member_info[ 'sign_time' ] != 0) {
|
||||
$compare_time = Carbon::today()->timestamp;
|
||||
if ($member_info[ 'sign_time' ] < $compare_time) {
|
||||
$is_sign = 0;
|
||||
} else {
|
||||
$is_sign = 1;
|
||||
}
|
||||
|
||||
//纠正连签天数
|
||||
$compare_yesterday = Carbon::yesterday()->timestamp;
|
||||
if ($compare_yesterday > $member_info[ 'sign_time' ]) {
|
||||
model("member")->update([ 'sign_days_series' => 0, 'sign_time' => 0 ], [ [ 'member_id', '=', $member_id ] ]);
|
||||
}
|
||||
|
||||
} else {
|
||||
$is_sign = 0;
|
||||
}
|
||||
return $this->success($is_sign);
|
||||
}
|
||||
|
||||
/**
|
||||
* 签到
|
||||
* @param $member_id
|
||||
* @param $site_id
|
||||
* @return array|\multitype
|
||||
* @throws DbException
|
||||
*/
|
||||
public function signin($member_id, $site_id)
|
||||
{
|
||||
$member_info = model("member")->getInfo([ [ 'member_id', '=', $member_id ] ], 'sign_time,sign_days_series');
|
||||
if ($member_info[ 'sign_time' ] != 0) {
|
||||
$compare_time = Carbon::today()->timestamp;
|
||||
if ($member_info[ 'sign_time' ] < $compare_time) {
|
||||
$is_sign = 0;
|
||||
} else {
|
||||
$is_sign = 1;
|
||||
}
|
||||
} else {
|
||||
$is_sign = 0;
|
||||
}
|
||||
if ($is_sign == 1) {
|
||||
return $this->error('', "SIGNED_IN");
|
||||
} else {
|
||||
$data_log = [
|
||||
'member_id' => $member_id,
|
||||
'action' => 'membersignin',
|
||||
'action_name' => '会员签到',
|
||||
'create_time' => time(),
|
||||
'remark' => '会员签到'
|
||||
];
|
||||
model("member_log")->add($data_log);
|
||||
|
||||
//连续签到
|
||||
$compare_yesterday = Carbon::yesterday()->timestamp;
|
||||
if ($compare_yesterday < $member_info[ 'sign_time' ]) {
|
||||
model("member")->setInc([ [ 'member_id', '=', $member_id ] ], 'sign_days_series');
|
||||
model("member")->update([ 'sign_time' => time() ], [ [ 'member_id', '=', $member_id ] ]);
|
||||
} else {
|
||||
model("member")->update([ 'sign_days_series' => 1, 'sign_time' => time() ], [ [ 'member_id', '=', $member_id ] ]);
|
||||
}
|
||||
|
||||
//执行签到奖励
|
||||
$res = event("MemberSignin", [ 'member_id' => $member_id, 'site_id' => $site_id ], true);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取签到记录
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberSigninList($condition = [], $field = '*', $order = 'create_time asc')
|
||||
{
|
||||
$list = model('member_log')->getList($condition, $field, $order);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取连续签到天数
|
||||
* @param $member_id
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberSignDaysSeries($member_id)
|
||||
{
|
||||
$member_info = model("member")->getInfo([ [ 'member_id', '=', $member_id ] ], 'sign_time,sign_days_series');
|
||||
$sign_days_series = 0;
|
||||
if(!empty($member_info)){
|
||||
$compare_yesterday = Carbon::yesterday()->timestamp;
|
||||
if ($compare_yesterday < $member_info[ 'sign_time' ]) {
|
||||
$sign_days_series = $member_info['sign_days_series'];
|
||||
}
|
||||
}
|
||||
return $this->success($sign_days_series);
|
||||
}
|
||||
}
|
||||
383
app/model/member/Register.php
Executable file
383
app/model/member/Register.php
Executable file
@@ -0,0 +1,383 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use addon\coupon\model\CouponType;
|
||||
use addon\wechat\model\Message as WechatMessage;
|
||||
use app\model\BaseModel;
|
||||
use app\model\message\Sms;
|
||||
use addon\coupon\model\Coupon;
|
||||
use app\model\system\Stat;
|
||||
use think\facade\Queue;
|
||||
|
||||
/**
|
||||
* 注册
|
||||
* Class Register
|
||||
* @package app\model\member
|
||||
*/
|
||||
class Register extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 用户名密码注册(必传username, password),之前检测重复性,判断用户名是否为手机,邮箱
|
||||
* @param $data
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function usernameRegister($data)
|
||||
{
|
||||
$examine_username_exit = $this->usernameExist($data['username'], $data['site_id']);
|
||||
if ($examine_username_exit) return $this->error('', '用户名已存在');
|
||||
|
||||
$nickname = $data['username']; // 默认昵称为用户名
|
||||
if (isset($data['nickname']) && !empty($data['nickname'])) {
|
||||
$nickname = preg_replace_callback('/./u', function(array $match) {
|
||||
return strlen($match[0]) >= 4 ? '' : $match[0];
|
||||
}, $data['nickname']);
|
||||
}
|
||||
$data['nickname'] = $nickname;
|
||||
return $this->memberRegister($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号密码注册(必传mobile, password),之前检测重复性
|
||||
* @param $data
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function mobileRegister($data)
|
||||
{
|
||||
$examine_mobile_exit = $this->mobileExist($data['mobile'], $data['site_id']);
|
||||
if ($examine_mobile_exit) return $this->error('', '手机号已存在');
|
||||
$data['username'] = $data['username'] ?? $this->createRandUsername($data['site_id']);
|
||||
$nickname = substr($data['mobile'], 0, 3).'****'.substr($data['mobile'], 7);
|
||||
if (isset($data['nickname']) && !empty($data['nickname'])) {
|
||||
$nickname = preg_replace_callback('/./u', function(array $match) {
|
||||
return strlen($match[0]) >= 4 ? '' : $match[0];
|
||||
}, $data['nickname']);
|
||||
}
|
||||
$data['nickname'] = $nickname;
|
||||
return $this->memberRegister($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方注册
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function authRegister($data)
|
||||
{
|
||||
$data['username'] = $this->createRandUsername($data['site_id']);
|
||||
$nickname = $data['username'];
|
||||
if (isset($data['nickName']) && !empty($data['nickName'])) {
|
||||
$nickname = preg_replace_callback('/./u', function(array $match) {
|
||||
return strlen($match[0]) >= 4 ? '' : $match[0];
|
||||
}, $data['nickName']);
|
||||
}
|
||||
$data['nickname'] = $nickname;
|
||||
return $this->memberRegister($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员注册方法
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
private function memberRegister($data)
|
||||
{
|
||||
//会员注册相关奖励
|
||||
$award_array = [
|
||||
'point' => 0,
|
||||
'balance' => 0,
|
||||
'growth' => 0,
|
||||
'coupon' => 0,
|
||||
'coupon_list' => [],
|
||||
'coupon_list_config'=>[]
|
||||
];
|
||||
$reg_award_array = event("MemberRegisterAward", ['site_id' => $data['site_id']]);
|
||||
if (!empty($reg_award_array)) {
|
||||
foreach ($reg_award_array as $k => $v) {
|
||||
$award_array['point'] += $v['point'] ?? 0;
|
||||
$award_array['balance'] += $v['balance'] ?? 0;
|
||||
$award_array['growth'] += $v['growth'] ?? 0;
|
||||
$coupon_list = $v['coupon_list'] ?? [];
|
||||
if (!empty($coupon_list)) {
|
||||
$award_array['coupon_list'] = empty($award_array['coupon_list']) ? $coupon_list : array_merge($award_array['coupon_list'], $v['coupon_list']);
|
||||
$award_array['coupon_list_config'] = array_column($v['coupon_new'] ?? [],'num','id');
|
||||
}
|
||||
}
|
||||
}
|
||||
//查询会员等级相关(根据会员获取的成长值)
|
||||
$member_level = new MemberLevel();
|
||||
$member_level_info = $member_level->getFirstMemberLevel([['site_id', '=', $data['site_id']], ['level_type', '=', 0], ['growth', '<=', $award_array['growth']]], '*', 'growth desc')['data'];
|
||||
//查询会员等级相关奖励
|
||||
$data_reg = [
|
||||
'site_id' => $data['site_id'],
|
||||
'source_member' => $data['source_member'] ?? 0,
|
||||
'username' => $data['username'],
|
||||
'nickname' => $data['nickname'],
|
||||
'mobile' => $data['mobile'] ?? '',
|
||||
'password' => isset($data['password']) && !empty($data['password']) ? data_md5($data['password']) : '',
|
||||
'qq_openid' => $data['qq_openid'] ?? '',
|
||||
'wx_openid' => $data['wx_openid'] ?? '',
|
||||
'weapp_openid' => $data['weapp_openid'] ?? '',
|
||||
'wx_unionid' => $data['wx_unionid'] ?? '',
|
||||
'ali_openid' => $data['ali_openid'] ?? '',
|
||||
'baidu_openid' => $data['baidu_openid'] ?? '',
|
||||
'toutiao_openid' => $data['toutiao_openid'] ?? '',
|
||||
'headimg' => $data['avatarUrl'] ?? '',
|
||||
'member_level' => !empty($member_level_info) ? $member_level_info['level_id'] : 0,
|
||||
'member_level_name' => !empty($member_level_info) ? $member_level_info['level_name'] : '',
|
||||
'is_member' => !empty($member_level_info) ? 1 : 0,
|
||||
'member_time' => !empty($member_level_info) ? time() : 0,
|
||||
'reg_time' => time(),
|
||||
'login_time' => time(),
|
||||
'last_login_time' => time(),
|
||||
'is_edit_username' => 1,
|
||||
'last_visit_time' => time(),
|
||||
'login_type' => $data['app_type'] ?? '',
|
||||
'login_type_name' => $data['app_type_name'] ?? '',
|
||||
];
|
||||
$member_id = model("member")->add($data_reg);
|
||||
|
||||
if ($member_id) {
|
||||
if (!empty($member_level_info)) {
|
||||
$award_array['point'] += $member_level_info['send_point'];
|
||||
$award_array['balance'] += $member_level_info['send_balance'];
|
||||
//获取优惠券信息
|
||||
if (!empty($member_level_info['send_coupon'])) {
|
||||
//优惠券字段
|
||||
$coupon_field = '*';
|
||||
|
||||
$model = new CouponType();
|
||||
$coupon = $model->getCouponTypeList([['coupon_type_id', 'in', $member_level_info['send_coupon']]], $coupon_field);
|
||||
$member_level_info['coupon_list'] = $coupon['data'];
|
||||
}
|
||||
|
||||
$coupon_list = $member_level_info['coupon_list'] ?? [];
|
||||
if (!empty($coupon_list)) {
|
||||
$award_array['coupon_list'] = empty($award_array['coupon_list']) ? $coupon_list : array_merge($award_array['coupon_list'], $v['coupon_list']);
|
||||
}
|
||||
|
||||
}
|
||||
//会员注册奖励积分,优惠券,红包
|
||||
$data_reg['member_id'] = $member_id;
|
||||
$member_account_model = new MemberAccount();
|
||||
$member_account_model->addMemberAccountInRegister($data_reg, $award_array);
|
||||
//给用户发放优惠券
|
||||
if (!empty($award_array['coupon_list'])) {
|
||||
$coupon_model = new Coupon();
|
||||
$coupon_data = [];
|
||||
foreach($award_array['coupon_list'] as $val){
|
||||
$coupon_data[] = ['coupon_type_id' => $val['coupon_type_id'], 'num' => $award_array['coupon_list_config'][$val['coupon_type_id']] ?? 1];
|
||||
}
|
||||
$coupon_model->giveCoupon($coupon_data, $data['site_id'], $member_id, Coupon::GET_TYPE_ACTIVITY_GIVE);
|
||||
}
|
||||
//会员注册成功后续事件
|
||||
Queue::push('app\job\MemberRegisterAfter', $data_reg);
|
||||
|
||||
}
|
||||
|
||||
return $this->success($member_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员注册成功后续事件
|
||||
* @param $data_reg
|
||||
*/
|
||||
public function memberRegisterAfter($data_reg)
|
||||
{
|
||||
event("MemberRegister", ['member_id' => $data_reg['member_id'], 'site_id' => $data_reg['site_id']]);
|
||||
//添加统计
|
||||
$stat = new Stat();
|
||||
$stat->switchStat(['type' => 'add_member', 'data' => ['member_count' => 1, 'site_id' => $data_reg['site_id']]]);
|
||||
$this->pullHeadimg($data_reg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机用户名
|
||||
* @param $site_id
|
||||
* @return string
|
||||
*/
|
||||
private function createRandUsername($site_id)
|
||||
{
|
||||
$usernamer = 'u_' . random_keys(10);
|
||||
$count = model('member')->getCount([['username', '=', $usernamer], ['site_id', '=', $site_id]]);
|
||||
if ($count) {
|
||||
$usernamer = $this->createRandUsername($site_id);
|
||||
return $usernamer;
|
||||
} else {
|
||||
return $usernamer;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置用户微信openid
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function wxopenidBind($data)
|
||||
{
|
||||
$res = model("member")->update(['wx_openid' => $data['wx_openid']], [['member_id', '=', $data['member_id']], ['site_id', '=', $data['site_id']], ['is_delete', '=', 0]]);
|
||||
if ($res) {
|
||||
return $this->success($res);
|
||||
} else {
|
||||
return $this->error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户存在性(用户名)
|
||||
* @param $username
|
||||
* @param $site_id
|
||||
* @return int
|
||||
*/
|
||||
public function usernameExist($username, $site_id)
|
||||
{
|
||||
$member_info = model("member")->getInfo([
|
||||
['username|mobile', '=', $username],
|
||||
['site_id', '=', $site_id],
|
||||
['is_delete', '=', 0]
|
||||
], 'member_id');
|
||||
if (!empty($member_info)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户存在性(用户名) 存在返回1
|
||||
* @param $mobile
|
||||
* @param $site_id
|
||||
* @return int
|
||||
*/
|
||||
public function mobileExist($mobile, $site_id)
|
||||
{
|
||||
$member_info = model("member")->getInfo([
|
||||
['mobile', '=', $mobile],
|
||||
['site_id', '=', $site_id],
|
||||
['is_delete', '=', 0]], 'member_id');
|
||||
if (!empty($member_info)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户存在性(wx_openid) 存在返回1 新增2021.06.18
|
||||
* @param $mobile
|
||||
* @param $site_id
|
||||
* @return int
|
||||
*/
|
||||
public function openidExist($mobile, $site_id)
|
||||
{
|
||||
$member_info = model("member")->getInfo([
|
||||
['mobile', '=', $mobile],
|
||||
['site_id', '=', $site_id],
|
||||
['is_delete', '=', 0]
|
||||
], 'wx_openid');
|
||||
if (!empty($member_info['wx_openid'])) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户ID 新增2021.06.18
|
||||
* @param $mobile
|
||||
* @param $site_id
|
||||
* @return int
|
||||
*/
|
||||
public function getMemberId($mobile, $site_id)
|
||||
{
|
||||
$member_info = model("member")->getInfo([
|
||||
['mobile', '=', $mobile],
|
||||
['site_id', '=', $site_id],
|
||||
['is_delete', '=', 0]
|
||||
], 'member_id');
|
||||
if (!empty($member_info)) {
|
||||
return $member_info['member_id'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册发送验证码
|
||||
* @param $data
|
||||
* @return array|mixed|void
|
||||
*/
|
||||
public function registerCode($data)
|
||||
{
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
$var_parse = array (
|
||||
"code" => $data["code"],//验证码
|
||||
);
|
||||
$data["sms_account"] = $data["mobile"] ?? '';//手机号
|
||||
$data["var_parse"] = $var_parse;
|
||||
$sms_result = $sms_model->sendMessage($data);
|
||||
if ($sms_result["code"] < 0)
|
||||
return $sms_result;
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册成功通知
|
||||
* @param $data
|
||||
* @return array|mixed|void
|
||||
*/
|
||||
public function registerSuccess($data)
|
||||
{
|
||||
|
||||
$member_model = new Member();
|
||||
$member_info_result = $member_model->getMemberInfo([["member_id", "=", $data["member_id"]]], "username,mobile,email,reg_time,wx_openid,last_login_type,nickname");
|
||||
$member_info = $member_info_result["data"];
|
||||
$name = $member_info["nickname"] == '' ? $member_info["mobile"] : $member_info["nickname"];
|
||||
//发送短信
|
||||
$var_parse = [
|
||||
"shopname" => replaceSpecialChar($data['site_info']['site_name']), //商城名称
|
||||
"username" => replaceSpecialChar($name), //会员名称
|
||||
];
|
||||
$data["sms_account"] = $member_info["mobile"] ?? '';//手机号
|
||||
$data["var_parse"] = $var_parse;
|
||||
$sms_model = new Sms();
|
||||
$sms_result = $sms_model->sendMessage($data);
|
||||
// if ($sms_result["code"] < 0) return $sms_result;
|
||||
|
||||
//发送模板消息
|
||||
$wechat_model = new WechatMessage();
|
||||
$data["openid"] = $member_info["wx_openid"];
|
||||
|
||||
$data["template_data"] = [
|
||||
'keyword1' => $member_info["nickname"],
|
||||
'keyword2' => time_to_date($member_info["reg_time"]),
|
||||
];
|
||||
$data["page"] = '';
|
||||
$wechat_model->sendMessage($data);
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取用户头像
|
||||
* @param unknown $info
|
||||
*/
|
||||
private function pullHeadimg($data)
|
||||
{
|
||||
if (!empty($data['headimg']) && is_url($data['headimg'])) {
|
||||
$url = __ROOT__ . '/api/member/pullheadimg?member_id=' . $data['member_id'];
|
||||
http($url, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
774
app/model/member/Withdraw.php
Executable file
774
app/model/member/Withdraw.php
Executable file
@@ -0,0 +1,774 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use app\model\message\Message;
|
||||
use app\model\message\Sms;
|
||||
use app\model\shop\ShopAcceptMessage;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
use app\model\system\Pay;
|
||||
use app\model\system\PayTransfer;
|
||||
use app\model\system\Stat;
|
||||
use think\facade\Cache;
|
||||
use addon\memberwithdraw\model\Withdraw as MemberWithdraw;
|
||||
use addon\wechat\model\Message as WechatMessage;
|
||||
use addon\weapp\model\Message as WeappMessage;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 会员提现
|
||||
*/
|
||||
class Withdraw extends BaseModel
|
||||
{
|
||||
const STATUS_WAIT_AUDIT = 0;//待审核
|
||||
const STATUS_WAIT_TRANSFER = 1;//待转账
|
||||
const STATUS_SUCCESS = 2;//已转账
|
||||
const STATUS_IN_PROCESS = 3;//转账中
|
||||
const STATUS_FAIL = -2;//转账失败
|
||||
const STATUS_REFUSE = -1;//已拒绝
|
||||
|
||||
public $status = array (
|
||||
self::STATUS_WAIT_AUDIT => '待审核',
|
||||
self::STATUS_WAIT_TRANSFER => '待转账',
|
||||
self::STATUS_SUCCESS => '已转账',
|
||||
self::STATUS_IN_PROCESS => '转账中',
|
||||
self::STATUS_FAIL => '转账失败',
|
||||
self::STATUS_REFUSE => '已拒绝',
|
||||
);
|
||||
|
||||
/**************************************************************************** 会员提现设置 *************************************************************/
|
||||
/**
|
||||
* 会员提现设置
|
||||
* @param $data
|
||||
* @param $is_use
|
||||
* @param int $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function setConfig($data, $is_use, $site_id = 0, $app_module = 'shop')
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->setConfig($data, '会员提现设置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'MEMBER_WITHDRAW_CONFIG' ] ]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员提现设置
|
||||
* @param int $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function getConfig($site_id = 0, $app_module = 'shop')
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'MEMBER_WITHDRAW_CONFIG' ] ]);
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'is_auto_audit' => 0,
|
||||
'rate' => 0,
|
||||
'transfer_type' => '',
|
||||
'is_auto_transfer' => 0,
|
||||
'min' => 0,
|
||||
'max' => 0,
|
||||
];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
/**************************************************************************** 会员提现设置 *************************************************************/
|
||||
/**
|
||||
* 申请提现
|
||||
* @param $data
|
||||
* @param int $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function apply($data, $site_id = 0, $app_module = 'shop')
|
||||
{
|
||||
|
||||
$config_result = $this->getConfig($site_id, $app_module);
|
||||
$config = $config_result[ "data" ][ 'value' ];
|
||||
if ($config_result[ "data" ][ "is_use" ] == 0)
|
||||
return $this->error([], "提现未开启");
|
||||
|
||||
$withdraw_no = $this->createWithdrawNo();
|
||||
$apply_money = round($data[ "apply_money" ], 2);
|
||||
if ($apply_money < $config[ "min" ])
|
||||
return $this->error([], "申请提现金额不能小于最低提现额度" . $config[ "min" ]);
|
||||
if ($apply_money > $config[ 'max' ]) return $this->error([], "申请提现金额不能大于最高提现额度" . $config[ "max" ]);
|
||||
$member_id = $data[ "member_id" ];
|
||||
$member_model = new Member();
|
||||
$member_info_result = $member_model->getMemberInfo([ [ "member_id", "=", $member_id ] ], "balance_money,headimg,wx_openid,username,mobile,weapp_openid,nickname");
|
||||
$member_info = $member_info_result[ "data" ];
|
||||
if (empty($member_info))
|
||||
return $this->error([], "MEMBER_NOT_EXIST");
|
||||
|
||||
$balance_money = $member_info[ "balance_money" ];
|
||||
if ($apply_money > $balance_money)
|
||||
return $this->error([], "申请提现金额不能大于会员可提现金额");
|
||||
$transfer_type = $data[ "transfer_type" ];
|
||||
$transfer_type_list = $this->getTransferType($site_id, $app_module);
|
||||
$transfer_type_name = $transfer_type_list[ $transfer_type ] ?? '';
|
||||
if (empty($transfer_type_name))
|
||||
return $this->error([], "不支持的提现方式");
|
||||
|
||||
model('member_withdraw')->startTrans();
|
||||
try {
|
||||
$rate = $config[ "rate" ];
|
||||
$bank_name = "";
|
||||
$account_number = "";
|
||||
$applet_type = 0;
|
||||
switch ( $transfer_type ) {
|
||||
case "bank":
|
||||
$bank_name = $data[ "bank_name" ];
|
||||
$account_number = $data[ "account_number" ];
|
||||
|
||||
break;
|
||||
case "alipay":
|
||||
$bank_name = '';
|
||||
$account_number = $data[ "account_number" ];
|
||||
break;
|
||||
case "wechatpay":
|
||||
$bank_name = '';
|
||||
if (empty($member_info[ "wx_openid" ]) && empty($member_info[ "weapp_openid" ])) {
|
||||
return $this->error('', '请绑定微信或更换提现账户');
|
||||
}
|
||||
if ($data['app_type'] != 'weapp') {
|
||||
$account_number = $member_info[ "wx_openid" ];
|
||||
$applet_type = 0; // 公众号
|
||||
} else {
|
||||
$account_number = $member_info[ "weapp_openid" ];
|
||||
$applet_type = 1; // 小程序
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$service_money = round($apply_money * $rate / 100, 2);//手续费
|
||||
$money = $apply_money - $service_money;
|
||||
$data = array (
|
||||
"site_id" => $site_id,
|
||||
"withdraw_no" => $withdraw_no,
|
||||
"member_name" => $member_info[ "username" ] == '' ? $member_info[ "mobile" ] : $member_info[ "username" ],
|
||||
"member_id" => $data[ "member_id" ],
|
||||
"transfer_type" => $data[ "transfer_type" ],
|
||||
"transfer_type_name" => $transfer_type_name,
|
||||
"apply_money" => $apply_money,
|
||||
"service_money" => $service_money,
|
||||
"rate" => $rate,
|
||||
"money" => $money,
|
||||
"apply_time" => time(),
|
||||
"status" => self::STATUS_WAIT_AUDIT,
|
||||
"status_name" => $this->status[self::STATUS_WAIT_AUDIT],
|
||||
"member_headimg" => $member_info[ "headimg" ],
|
||||
"realname" => $data[ "realname" ],
|
||||
"bank_name" => $bank_name,
|
||||
"account_number" => $account_number,
|
||||
"mobile" => $data[ "mobile" ],
|
||||
"applet_type" => $applet_type
|
||||
);
|
||||
|
||||
//减少现金余额
|
||||
$member_account = new MemberAccount();
|
||||
$account_res = $member_account->addMemberAccount($site_id, $member_id, 'balance_money', -$apply_money, 'withdraw', '会员提现', '会员提现扣除');
|
||||
if ($account_res[ 'code' ] < 0) {
|
||||
model('member_withdraw')->rollback();
|
||||
return $account_res;
|
||||
}
|
||||
|
||||
//增加提现中余额
|
||||
model("member")->setInc([ [ "member_id", "=", $member_id ] ], "balance_withdraw_apply", $apply_money);
|
||||
|
||||
$result = model("member_withdraw")->add($data);
|
||||
|
||||
//添加转账记录
|
||||
$pay_transfer_model = new PayTransfer();
|
||||
$info = model('member_withdraw')->getInfo([['id', '=', $result]]);
|
||||
$pay_transfer_model->add([
|
||||
"real_name" => $info[ "realname" ],
|
||||
"amount" => $info[ "money" ],
|
||||
"desc" => "会员提现" . $info[ "memo" ],
|
||||
"transfer_type" => $info[ "transfer_type" ],
|
||||
"account_number" => $info[ "account_number" ],
|
||||
"site_id" => $info[ "site_id" ],
|
||||
"is_weapp" => $info[ "applet_type" ],
|
||||
"member_id" => $info[ 'member_id' ],
|
||||
'from_type' => 'member_withdraw',
|
||||
"relate_tag" => $info['id'],
|
||||
]);
|
||||
|
||||
//是否启用自动通过审核(必须是微信)
|
||||
if ($config[ "is_auto_audit" ] == 0) {
|
||||
$this->agree([ [ "id", "=", $result ], [ 'site_id', '=', $site_id ] ]);
|
||||
}
|
||||
|
||||
model('member_withdraw')->commit();
|
||||
|
||||
//申请提现发送消息
|
||||
$data[ 'keywords' ] = 'USER_WITHDRAWAL_APPLY';
|
||||
$data[ 'member_name' ] = $member_info[ 'nickname' ];
|
||||
$message_model = new Message();
|
||||
$message_model->sendMessage($data);
|
||||
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('member_withdraw')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同意提现申请
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function agree($condition)
|
||||
{
|
||||
$check_condition = array_column($condition, 2, 0);
|
||||
$site_id = $check_condition[ 'site_id' ];
|
||||
$app_module = $check_condition[ 'app_module' ] ?? 'shop';
|
||||
if (empty($site_id)) {
|
||||
return $this->error(-1, '参数错误');
|
||||
}
|
||||
$info = model("member_withdraw")->getInfo($condition);
|
||||
if (empty($info))
|
||||
return $this->error();
|
||||
|
||||
$config_result = $this->getConfig($site_id, $app_module);
|
||||
$config = $config_result[ "data" ];
|
||||
|
||||
model('member_withdraw')->startTrans();
|
||||
try {
|
||||
$data = array (
|
||||
"status" => self::STATUS_WAIT_TRANSFER,
|
||||
"status_name" => $this->status[self::STATUS_WAIT_TRANSFER],
|
||||
"audit_time" => time(),
|
||||
);
|
||||
$result = model("member_withdraw")->update($data, $condition);
|
||||
|
||||
//是否启用自动转账(必须是微信或支付宝)
|
||||
if ($config[ "value" ][ "is_auto_transfer" ] == 1) {
|
||||
$member_withdraw_model = new MemberWithdraw();
|
||||
$member_withdraw_model->transfer($info[ "id" ]);
|
||||
/*if ($transfer_res['code'] == 0) {
|
||||
//提现成功发送消息
|
||||
$info['keywords'] = 'USER_WITHDRAWAL_SUCCESS';
|
||||
$message_model = new Message();
|
||||
$res = $message_model->sendMessage($info);
|
||||
}*/
|
||||
}
|
||||
model('member_withdraw')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('member_withdraw')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拒绝提现申请
|
||||
* @param $condition
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function refuse($condition, $param)
|
||||
{
|
||||
$info = model("member_withdraw")->getInfo($condition, "status,site_id,transfer_type,member_id,apply_money");
|
||||
if (empty($info)){
|
||||
return $this->error(null, '提现信息有误');
|
||||
}
|
||||
if (!in_array($info['status'], [self::STATUS_WAIT_AUDIT, self::STATUS_WAIT_TRANSFER])){
|
||||
return $this->error(null, '提现状态有误');
|
||||
}
|
||||
|
||||
model('member_withdraw')->startTrans();
|
||||
try {
|
||||
$data = array (
|
||||
"status" => self::STATUS_REFUSE,
|
||||
"status_name" => $this->status[self::STATUS_REFUSE],
|
||||
"refuse_reason" => $param[ "refuse_reason" ],
|
||||
"audit_time" => time(),
|
||||
);
|
||||
$result = model("member_withdraw")->update($data, $condition);
|
||||
|
||||
//增加现金余额
|
||||
$member_account = new MemberAccount();
|
||||
$account_res = $member_account->addMemberAccount($info[ 'site_id' ], $info[ 'member_id' ], 'balance_money', $info[ "apply_money" ], 'withdraw', '会员提现申请未通过', '提现申请未通过返还');
|
||||
if ($account_res[ 'code' ] != 0) {
|
||||
model('member_withdraw')->rollback();
|
||||
return $account_res;
|
||||
}
|
||||
//减少提现中余额
|
||||
model("member")->setDec([ [ "member_id", "=", $info[ "member_id" ] ] ], "balance_withdraw_apply", $info[ "apply_money" ]);
|
||||
|
||||
model('member_withdraw')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('member_withdraw')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现转账完成
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
public function transferFinish($param = [])
|
||||
{
|
||||
$condition = [
|
||||
[ 'id', '=', $param[ 'id' ] ],
|
||||
[ 'site_id', '=', $param[ 'site_id' ] ],
|
||||
[ 'status', 'in', [self::STATUS_WAIT_TRANSFER, self::STATUS_IN_PROCESS] ],
|
||||
];
|
||||
$info = model("member_withdraw")->getInfo($condition);
|
||||
if (empty($info)) return $this->error();
|
||||
|
||||
$payment_time = time();
|
||||
model('member_withdraw')->startTrans();
|
||||
try {
|
||||
$data = [
|
||||
'status' => self::STATUS_SUCCESS,
|
||||
'status_name' => $this->status[self::STATUS_SUCCESS],
|
||||
'payment_time' => $payment_time,
|
||||
'certificate' => $param[ 'certificate' ] ?? '',
|
||||
'certificate_remark' => $param[ 'certificate_remark' ] ?? ''
|
||||
];
|
||||
$result = model("member_withdraw")->update($data, $condition);
|
||||
|
||||
//增加已提现余额
|
||||
model("member")->setInc([ [ "member_id", "=", $info[ "member_id" ] ] ], "balance_withdraw", $info[ "apply_money" ]);
|
||||
//减少提现中余额
|
||||
model("member")->setDec([ [ "member_id", "=", $info[ "member_id" ] ] ], "balance_withdraw_apply", $info[ "apply_money" ]);
|
||||
|
||||
model('member_withdraw')->commit();
|
||||
|
||||
$member_info = model("member")->getInfo([ [ "member_id", "=", $info[ "member_id" ] ] ], 'nickname');
|
||||
|
||||
//提现成功发送消息
|
||||
$info[ 'keywords' ] = 'USER_WITHDRAWAL_SUCCESS';
|
||||
$info[ 'payment_time' ] = $payment_time;
|
||||
$info[ 'member_name' ] = $member_info[ 'nickname' ];
|
||||
$message_model = new Message();
|
||||
$message_model->sendMessage($info);
|
||||
|
||||
$stat_model = new Stat();
|
||||
$stat_model->switchStat([ 'type' => 'member_withdraw', 'data' => [ 'site_id' => $info[ 'site_id' ], 'id' => $info[ 'id' ] ] ]);
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('member_withdraw')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账失败
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function transferFail($param)
|
||||
{
|
||||
$id = $param['id'];
|
||||
$site_id = $param['site_id'];
|
||||
$fail_reason = $param['fail_reason'];
|
||||
|
||||
$condition = [
|
||||
[ 'id', '=', $id ],
|
||||
[ 'site_id', '=', $site_id ],
|
||||
[ 'status', 'in', [self::STATUS_WAIT_TRANSFER, self::STATUS_IN_PROCESS] ],
|
||||
];
|
||||
$info = model("member_withdraw")->getInfo($condition);
|
||||
if (empty($info)) return $this->error(null, '提现信息有误');
|
||||
|
||||
model('member_withdraw')->startTrans();
|
||||
try {
|
||||
$data = [
|
||||
'status' => self::STATUS_FAIL,
|
||||
'status_name' => $this->status[self::STATUS_FAIL],
|
||||
'fail_reason' => $fail_reason,
|
||||
];
|
||||
model("member_withdraw")->update($data, $condition);
|
||||
|
||||
//减少提现中余额
|
||||
model("member")->setDec([ [ "member_id", "=", $info[ "member_id" ] ] ], "balance_withdraw_apply", $info[ "apply_money" ]);
|
||||
|
||||
//减少现金余额
|
||||
$member_account = new MemberAccount();
|
||||
$account_res = $member_account->addMemberAccount($site_id, $info[ "member_id" ], 'balance_money', $info[ "apply_money" ], 'withdraw_fail', $id, '会员提现失败退回');
|
||||
if ($account_res[ 'code' ] < 0) {
|
||||
model('member_withdraw')->rollback();
|
||||
return $account_res;
|
||||
}
|
||||
|
||||
model('member_withdraw')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('member_withdraw')->rollback();
|
||||
return $this->error(['file' => $e->getFile(), 'line' => $e->getLine(), 'message' => $e->getMessage()], $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账中
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function transferInProcess($param)
|
||||
{
|
||||
$id = $param['id'];
|
||||
$site_id = $param['site_id'];
|
||||
|
||||
$condition = [
|
||||
[ 'id', '=', $id ],
|
||||
[ 'site_id', '=', $site_id ],
|
||||
[ 'status', '=', self::STATUS_WAIT_TRANSFER ]
|
||||
];
|
||||
$info = model("member_withdraw")->getInfo($condition);
|
||||
if (empty($info)) return $this->error(null, '提现信息有误');
|
||||
|
||||
model("member_withdraw")->update([
|
||||
'status' => self::STATUS_IN_PROCESS,
|
||||
'status_name' => $this->status[self::STATUS_IN_PROCESS],
|
||||
], [['id', '=', $id]]);
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberWithdrawInfo($condition, $field = "*")
|
||||
{
|
||||
$info = model('member_withdraw')->getInfo($condition, $field);
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现详情
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberWithdrawDetail($condition)
|
||||
{
|
||||
$info = model('member_withdraw')->getInfo($condition, "*");
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现单数
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberWithdrawCount($condition)
|
||||
{
|
||||
$count = model('member_withdraw')->getCount($condition, "id");
|
||||
return $this->success($count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现总和
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberWithdrawSum($condition, $field = 'apply_money')
|
||||
{
|
||||
$count = model('member_withdraw')->getSum($condition, $field);
|
||||
return $this->success($count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员提现分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @param string $alias
|
||||
* @param string $join
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberWithdrawPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*',$alias='',$join='')
|
||||
{
|
||||
$list = model('member_withdraw')->pageList($condition, $field, $order, $page, $page_size, $alias, $join, '');
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员提现列表
|
||||
* @param array $where
|
||||
* @param bool $field
|
||||
* @param string $order
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @param string $group
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberWithdrawList($where = [], $field = true, $order = '', $alias = 'a', $join = [], $group = '', $limit = null)
|
||||
{
|
||||
$res = model('member_withdraw')->getList($where, $field, $order, $alias, $join, $group, $limit);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现流水号
|
||||
*/
|
||||
private function createWithdrawNo()
|
||||
{
|
||||
$cache = Cache::get("member_withdraw_no" . time());
|
||||
if (empty($cache)) {
|
||||
Cache::set("niutk" . time(), 1000);
|
||||
$cache = Cache::get("member_withdraw_no" . time());
|
||||
} else {
|
||||
$cache = $cache + 1;
|
||||
Cache::set("member_withdraw_no" . time(), $cache);
|
||||
}
|
||||
$no = date('Ymdhis', time()) . rand(1000, 9999) . $cache;
|
||||
return $no;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账方式
|
||||
* @param int $site_id
|
||||
* @param string $app_module
|
||||
* @return array
|
||||
*/
|
||||
public function getTransferType($site_id = 0, $app_module = 'shop')
|
||||
{
|
||||
$pay_model = new Pay();
|
||||
$transfer_type_list = $pay_model->getTransferType($site_id);
|
||||
$config_result = $this->getConfig($site_id, $app_module);
|
||||
$config = $config_result[ "data" ][ 'value' ];
|
||||
$data = [];
|
||||
$support_type = explode(",", $config[ "transfer_type" ]);
|
||||
foreach ($transfer_type_list as $k => $v) {
|
||||
if (in_array($k, $support_type)) {
|
||||
$data[ $k ] = $v;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员提现成功通知
|
||||
* @param $data
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function messageUserWithdrawalSuccess($data)
|
||||
{
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
|
||||
$var_parse = array (
|
||||
'username' => $data[ "member_name" ],//会员名
|
||||
'money' => $data[ 'apply_money' ]
|
||||
);
|
||||
|
||||
$data[ "sms_account" ] = $data[ "mobile" ];//手机号
|
||||
$data[ "var_parse" ] = $var_parse;
|
||||
$sms_model->sendMessage($data);
|
||||
|
||||
$member_model = new Member();
|
||||
$member_info_result = $member_model->getMemberInfo([ [ "member_id", "=", $data[ "member_id" ] ] ]);
|
||||
$member_info = $member_info_result[ "data" ];
|
||||
|
||||
//绑定微信公众号才发送
|
||||
if (!empty($member_info) && !empty($member_info[ "wx_openid" ])) {
|
||||
$wechat_model = new WechatMessage();
|
||||
$data[ "openid" ] = $member_info[ "wx_openid" ];
|
||||
$data[ "template_data" ] = [
|
||||
'amount1' => $data[ 'apply_money' ], // 提现金额
|
||||
'time3' => time_to_date($data[ 'payment_time' ]), // 提现日期
|
||||
];
|
||||
$data[ "page" ] = "";
|
||||
$wechat_model->sendMessage($data);
|
||||
}
|
||||
|
||||
//发送订阅消息
|
||||
if (!empty($member_info) && !empty($member_info[ "weapp_openid" ])) {
|
||||
$weapp_model = new WeappMessage();
|
||||
$data[ "openid" ] = $member_info[ "weapp_openid" ];
|
||||
$data[ "template_data" ] = [
|
||||
'amount6' => [
|
||||
'value' => $data[ 'apply_money' ]
|
||||
],
|
||||
'date3' => [
|
||||
'value' => time_to_date(time())
|
||||
]
|
||||
];
|
||||
$data[ "page" ] = "";
|
||||
$weapp_model->sendMessage($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员提现失败通知
|
||||
* @param $data
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function messageUserWithdrawalError($data)
|
||||
{
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
|
||||
$var_parse = array (
|
||||
'username' => $data[ "member_name" ],//会员名
|
||||
'money' => $data[ 'apply_money' ]
|
||||
);
|
||||
|
||||
$data[ "sms_account" ] = $data[ "mobile" ];//手机号
|
||||
$data[ "var_parse" ] = $var_parse;
|
||||
$sms_model->sendMessage($data);
|
||||
|
||||
$member_model = new Member();
|
||||
$member_info_result = $member_model->getMemberInfo([ [ "member_id", "=", $data[ "member_id" ] ] ]);
|
||||
$member_info = $member_info_result[ "data" ];
|
||||
|
||||
//绑定微信公众号才发送
|
||||
if (!empty($member_info) && !empty($member_info[ "wx_openid" ])) {
|
||||
$wechat_model = new WechatMessage();
|
||||
$data[ "openid" ] = $member_info[ "wx_openid" ];
|
||||
$data[ "template_data" ] = [
|
||||
'keyword1' => time_to_date($data[ 'create_time' ]),
|
||||
'keyword2' => '审核失败',
|
||||
'keyword3' => '会员申请提现',
|
||||
'keyword4' => $data[ 'apply_money' ],
|
||||
];
|
||||
$data[ "page" ] = "";
|
||||
$wechat_model->sendMessage($data);
|
||||
}
|
||||
|
||||
//发送订阅消息
|
||||
if (!empty($member_info) && !empty($member_info[ "weapp_openid" ])) {
|
||||
$weapp_model = new WeappMessage();
|
||||
$data[ "openid" ] = $member_info[ "weapp_openid" ];
|
||||
$data[ "template_data" ] = [
|
||||
'amount3' => [
|
||||
'value' => $data[ 'apply_money' ]
|
||||
],
|
||||
'phrase4' => [
|
||||
'value' => '审核失败'
|
||||
],
|
||||
'date2' => [
|
||||
'value' => time_to_date(time())
|
||||
]
|
||||
];
|
||||
$data[ "page" ] = "";
|
||||
$weapp_model->sendMessage($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员申请提现通知,卖家通知
|
||||
* @param $data
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function messageUserWithdrawalApply($data)
|
||||
{
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
|
||||
$var_parse = array (
|
||||
"username" => replaceSpecialChar($data[ "member_name" ]),//会员名
|
||||
"money" => $data[ "apply_money" ],//退款申请金额
|
||||
);
|
||||
// $site_id = $data['site_id'];
|
||||
// $shop_info = model("shop")->getInfo([["site_id", "=", $site_id]], "mobile,email");
|
||||
// $message_data["sms_account"] = $shop_info["mobile"];//手机号
|
||||
$data[ "var_parse" ] = $var_parse;
|
||||
|
||||
$shop_accept_message_model = new ShopAcceptMessage();
|
||||
$list = $shop_accept_message_model->getShopAcceptMessageList()[ 'data' ];
|
||||
if (!empty($list)) {
|
||||
foreach ($list as $v) {
|
||||
$message_data = $data;
|
||||
$message_data[ "sms_account" ] = $v[ "mobile" ];//手机号
|
||||
$sms_model->sendMessage($message_data);
|
||||
|
||||
if ($v[ 'wx_openid' ] != "") {
|
||||
|
||||
$wechat_model = new WechatMessage();
|
||||
$data[ "openid" ] = $v[ 'wx_openid' ];
|
||||
$data[ "template_data" ] = [
|
||||
'thing3' => replaceSpecialChar($data[ "member_name" ]), // 客户名称
|
||||
'amount6' => $data[ "apply_money" ], // 提现金额
|
||||
'time8' => time_to_date($data[ 'apply_time' ]) // 提现时间
|
||||
];
|
||||
|
||||
$data[ "page" ] = "";
|
||||
$wechat_model->sendMessage($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function exportWithdraw($condition, $order)
|
||||
{
|
||||
try {
|
||||
$file_name = date('Y年m月d日-余额提现', time()) . '.csv';
|
||||
// $file_name = date('YmdHis').'.csv';//csv文件名
|
||||
//通过分批次执行数据导出(防止内存超出配置设置的)
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '256M');
|
||||
//设置header头
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/vnd.ms-excel');
|
||||
header('Content-Disposition: attachment; filename="' . $file_name . '"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
//打开php数据输入缓冲区
|
||||
$fp = fopen('php://output', 'a');
|
||||
// fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF)); // 添加 BOM
|
||||
$heade = [ '会员账号', '提现方式', '申请提现金额', '提现手续费', '实际转账金额', '提现状态', '申请时间', '银行名称', '收款账号', '真实姓名', '手机号' ];
|
||||
//将数据编码转换成GBK格式
|
||||
mb_convert_variables('GBK', 'UTF-8', $heade);
|
||||
//将数据格式化为CSV格式并写入到output流中
|
||||
fputcsv($fp, $heade);
|
||||
//写入第一行表头
|
||||
Db::name('member_withdraw')->where($condition)->order($order)->chunk(500, function($item_list) use ($fp) {
|
||||
//写入导出信息
|
||||
foreach ($item_list as $k => $item_v) {
|
||||
$temp_data = [
|
||||
$item_v[ 'member_name' ] . "\t",
|
||||
$item_v[ 'transfer_type_name' ] . "\t",
|
||||
(float) $item_v[ 'apply_money' ] . "\t",
|
||||
(float) $item_v[ 'service_money' ] . "\t",
|
||||
(float) $item_v[ 'money' ] . "\t",
|
||||
$item_v[ 'status_name' ] . "\t",
|
||||
time_to_date($item_v[ 'apply_time' ]) . "\t",
|
||||
$item_v[ 'bank_name' ] . "\t",
|
||||
$item_v[ 'account_number' ] . "\t",
|
||||
$item_v[ 'realname' ] . "\t",
|
||||
$item_v[ 'mobile' ] . "\t",
|
||||
];
|
||||
mb_convert_variables('GBK', 'UTF-8', $temp_data);
|
||||
fputcsv($fp, $temp_data);
|
||||
//将已经存储到csv中的变量数据销毁,释放内存
|
||||
unset($item_v);
|
||||
}
|
||||
unset($item_list);
|
||||
});
|
||||
|
||||
//关闭句柄
|
||||
fclose($fp);
|
||||
die;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->error([], $e->getMessage() . $e->getFile() . $e->getLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user