chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材 添加系统版本配置文件(.version)和常量定义文件(.constant) 更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件 添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
156
app/services/user/member/MemberCardBatchServices.php
Normal file
156
app/services/user/member/MemberCardBatchServices.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\user\member;
|
||||
|
||||
|
||||
use app\dao\user\member\MemberCardBatchDao;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* Class MemberCardBatchServices
|
||||
* @package app\services\user\member
|
||||
* @mixin MemberCardBatchDao
|
||||
*/
|
||||
class MemberCardBatchServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var MemberCardBatchDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected MemberCardBatchDao $dao;
|
||||
|
||||
/**
|
||||
* 获取会员卡批次列表
|
||||
* @param array $where
|
||||
*/
|
||||
public function getList(array $where = [])
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getList($where, $page, $limit);
|
||||
|
||||
if ($list) {
|
||||
foreach ($list as &$v) {
|
||||
$v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
|
||||
//$v['qrcode'] = json_decode($v['qrcode'], true);
|
||||
}
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function save(int $id, array $data)
|
||||
{
|
||||
if (!$data['title']) throw new AdminException("请填写批次名称");
|
||||
if (!$data['total_num']) throw new AdminException("请填写要生成卡的数量");
|
||||
if (!is_numeric($data['total_num']) || $data['total_num'] < 0) throw new AdminException("卡片数量只能为正整数");
|
||||
if ($data['total_num'] > 6000) throw new AdminException("单次制卡数量最高不得超过6000张");
|
||||
if (!$data['use_day'] || !is_numeric($data['use_day'])) throw new AdminException("请填写免费使用天数");
|
||||
if ($data['use_day'] < 0) throw new AdminException("免费使用天数只能为正整数");
|
||||
/**
|
||||
* 具体时间段试用,业务需要打开即可
|
||||
*/
|
||||
/* $use_start_time = strtotime($data['use_start_time']);
|
||||
$use_end_time = strtotime($data['use_end_time']);
|
||||
if (!$use_start_time) {
|
||||
$use_start_time = strtotime(date('Y-m-d 00:00:00', strtotime('+1 day')));
|
||||
}else{
|
||||
$use_start_time = strtotime($data['use_start_time']);
|
||||
}
|
||||
if (!$use_end_time) {
|
||||
$use_end_time = strtotime(date('Y-m-d 23:59:59', strtotime('+1 day')));
|
||||
}else{
|
||||
$use_end_time = strtotime($data['use_end_time']);
|
||||
}
|
||||
if ($use_end_time < time()) throw new AdminException("体验结束时间不能小于当天");
|
||||
if ($use_end_time < $use_start_time) throw new AdminException("体验结束时间不能小于体验开始时间");
|
||||
$data['use_start_time'] = $use_start_time;
|
||||
$data['use_end_time'] = $use_end_time;*/
|
||||
$data['use_day'] = abs(ceil($data['use_day']));
|
||||
$data['total_num'] = abs(ceil($data['total_num']));
|
||||
$data['add_time'] = time();
|
||||
$this->transaction(function () use ($id, $data) {
|
||||
if ($id) {
|
||||
unset($data['total_num']);
|
||||
$data['update_time'] = time();
|
||||
return $this->dao->update($id, $data);
|
||||
} else {
|
||||
/** @var MemberCardServices $memberCardService */
|
||||
$memberCardService = app()->make(MemberCardServices::class);
|
||||
$res = $this->dao->save($data);
|
||||
$add_card['card_batch_id'] = $res->id;
|
||||
$add_card['total_num'] = $data['total_num'];
|
||||
return $memberCardService->addCard($add_card);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表操作
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function setValue(int $id, array $data)
|
||||
{
|
||||
if (!is_numeric($id) || !$id) throw new AdminException("参数缺失");
|
||||
if (!isset($data['field']) || !isset($data['value']) || !$data['field']) throw new AdminException("参数错误");
|
||||
$res = true;
|
||||
if ($data['field'] == 'status') {
|
||||
/** @var MemberCardServices $memberCardService */
|
||||
$memberCardService = app()->make(MemberCardServices::class);
|
||||
$res = $memberCardService->update(['card_batch_id' => $id], ['status' => $data['value']]);
|
||||
}
|
||||
if ($res) {
|
||||
$this->dao->update($id, [$data['field'] => $data['value']]);
|
||||
} else {
|
||||
throw new AdminException("操作错误");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取单条卡批次资源
|
||||
* @param array $uid
|
||||
* @param string $field
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getOne(int $bid, $field = '*')
|
||||
{
|
||||
if (is_string($field)) $field = explode(',', $field);
|
||||
return $this->dao->get($bid, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批次卡数量统计
|
||||
* @param int $id
|
||||
* @param string $field
|
||||
* @param int $inc
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function useCardSetInc(int $id, string $field, int $inc = 1)
|
||||
{
|
||||
return $this->dao->bcInc($id, $field, $inc);
|
||||
}
|
||||
|
||||
}
|
||||
453
app/services/user/member/MemberCardServices.php
Normal file
453
app/services/user/member/MemberCardServices.php
Normal file
@@ -0,0 +1,453 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\user\member;
|
||||
|
||||
|
||||
use app\dao\user\member\MemberCardDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\order\OtherOrderServices;
|
||||
use app\services\order\StoreOrderCreateServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\SystemConfigService;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
use app\services\user\UserServices;
|
||||
|
||||
/**
|
||||
* Class MemberCardServices
|
||||
* @package app\services\user\member
|
||||
* @mixin MemberCardDao
|
||||
*/
|
||||
class MemberCardServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array|string[]
|
||||
*/
|
||||
public static array $_memberTypePrefix = ['month', 'quarter', 'year', 'ever', 'free'];
|
||||
|
||||
/**
|
||||
* @var MemberCardDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected MemberCardDao $dao;
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/9/18
|
||||
*/
|
||||
public function getSearchList(array $where = [])
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$where['batch_card_id'] = $where['card_batch_id'];
|
||||
if ($where['is_use'] != "") {
|
||||
if ($where['is_use'] == 0) {
|
||||
$where['use_time'] = 0;
|
||||
} else {
|
||||
$where['use_time'] = 1;
|
||||
}
|
||||
}
|
||||
unset($where['is_use']);
|
||||
$list = $this->dao->getSearchList($where, $page, $limit);
|
||||
if ($list) {
|
||||
/** @var UserServices $userService */
|
||||
$userService = app()->make(UserServices::class);
|
||||
$userInfos = $userService->getColumn([['uid', 'in', array_unique(array_column($list, 'use_uid'))]], 'uid,real_name,nickname,phone', 'uid');
|
||||
foreach ($list as $k => $v) {
|
||||
$list[$k]['username'] = $list[$k]['phone'] = '';
|
||||
$user_info = $userInfos[$v['use_uid']] ?? [];
|
||||
if ($v['use_uid'] && $user_info) {
|
||||
$list[$k]['username'] = $user_info['real_name'] ? $user_info['real_name'] : $user_info['nickname'];
|
||||
$list[$k]['phone'] = $user_info ? $user_info['phone'] : "";
|
||||
}
|
||||
$list[$k]['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
|
||||
$list[$k]['use_time'] = $v['use_time'] != 0 ? date('Y-m-d H:i:s', $v['use_time']) : "未使用";
|
||||
}
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成免费会员卡
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function addCard(array $data)
|
||||
{
|
||||
if (!isset($data['card_batch_id']) || !$data['card_batch_id'] || $data['card_batch_id'] == 0 || !isset($data['total_num']) || !$data['total_num'] || $data['total_num'] == 0) {
|
||||
throw new AdminException("非法参数");
|
||||
}
|
||||
try {
|
||||
if (!isset($data['total_num'])) throw new AdminException("数据缺失");
|
||||
$num = $data['total_num'];
|
||||
unset($data['total_num']);
|
||||
for ($i = 0; $i < $num; $i++) {
|
||||
$data['card_number'] = $this->makeRandomNumber("CR", $data['card_batch_id']);
|
||||
$data['card_password'] = $this->makeRandomNumber();
|
||||
$data['status'] = 1;
|
||||
$data['add_time'] = time();
|
||||
$res[] = $data;
|
||||
}
|
||||
//数据切片批量插入,提高性能。
|
||||
$chunk_inster_card = array_chunk($res, 100, true);
|
||||
foreach ($chunk_inster_card as $v) {
|
||||
$this->dao->saveAll($v);
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $exception) {
|
||||
throw new AdminException("生成卡失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取制卡卡号随机数
|
||||
* @param false $prefix
|
||||
* @param false $random
|
||||
* @return string
|
||||
*/
|
||||
public function makeRandomNumber($prefix = false, $random = false)
|
||||
{
|
||||
if (!$prefix) {
|
||||
$prefix = "";
|
||||
}
|
||||
if (!$random || !is_numeric($random)) {
|
||||
mt_srand();
|
||||
$one_random = mt_rand(11111, 99999);
|
||||
} else {
|
||||
$one_random = sprintf("%05d", $random);
|
||||
}
|
||||
$date_random = date('ymd', time());
|
||||
$random_tmp = strlen($one_random);
|
||||
mt_srand();
|
||||
$two_randow = str_pad(mt_rand(1, 99999), $random_tmp, '0', STR_PAD_LEFT);
|
||||
if (!$random) {
|
||||
return $two_randow;
|
||||
} else {
|
||||
return $prefix . $one_random . $date_random . $two_randow;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取会员卡
|
||||
* @param array $data
|
||||
* @param int $uid
|
||||
*/
|
||||
public function drawMemberCard(array $data, int $uid)
|
||||
{
|
||||
if (!$uid || !$data) throw new ValidateException('参数缺失!');
|
||||
$isOpenMember = $this->isOpenMemberCardCache();
|
||||
if (!$isOpenMember) throw new ValidateException('会员功能暂未开启!');
|
||||
if (!isset($data['member_card_code']) || !$data['member_card_code']) throw new ValidateException('请输入会员卡号!');
|
||||
if (!isset($data['member_card_code']) || !$data['member_card_pwd']) throw new ValidateException('请输入领取卡密!');
|
||||
$card_info = $this->dao->getOneByWhere(['card_number' => trim($data['member_card_code'])]);
|
||||
if (!$card_info) throw new ValidateException('会员卡不存在!');
|
||||
/** @var MemberCardBatchServices $memberBatchServices */
|
||||
$memberBatchServices = app()->make(MemberCardBatchServices::class);
|
||||
$batch_info = $memberBatchServices->getOne($card_info['card_batch_id']);
|
||||
if (!$batch_info) throw new ValidateException('会员卡未激活,暂无法使用.');
|
||||
if ($batch_info->status != 1) throw new ValidateException('会员卡未激活,暂无法使用..');
|
||||
if ($card_info['status'] == 0) throw new ValidateException('会员卡暂未激活');
|
||||
if ($card_info['card_password'] != trim($data['member_card_pwd'])) throw new ValidateException('会员卡密码有误!');
|
||||
if ($card_info['use_uid'] && $card_info['use_time']) throw new ValidateException('会员卡已使用!');
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$user_info = $userServices->getUserInfo($uid);
|
||||
if (!$user_info) throw new ValidateException('用户不存在,请重新登录');
|
||||
if ($user_info->is_money_level > 0 && $user_info->is_ever_level == 1) throw new ValidateException('您已是永久会员,无需再领取,可以将此卡转送亲朋好友,一起享受优惠');
|
||||
|
||||
/**
|
||||
* 批次卡具体使用期限,业务需要打开即可,勿删。
|
||||
*/
|
||||
//if ($batch_info->use_start_time > time()) throw new ValidateException('卡片未在合法有效期内,暂无法使用');
|
||||
//if ($batch_info->use_end_time < time()) throw new ValidateException('卡片已经失效,无法使用');
|
||||
if ($card_info->status != 1) throw new ValidateException('会员卡未激活,暂无法使用...');
|
||||
$this->transaction(function () use ($card_info, $user_info, $batch_info, $memberBatchServices, $userServices, $data) {
|
||||
$res1 = $this->dao->update($card_info->id, ['use_uid' => $user_info->uid, 'use_time' => time(), 'update_time' => time()], 'id');
|
||||
if ($res1) {
|
||||
$res2 = $memberBatchServices->useCardSetInc($batch_info->id, 'use_num', 1);
|
||||
if ($user_info->overdue_time > time()) {
|
||||
$overdue_time = bcadd(bcmul($batch_info->use_day, 86400, 0), $user_info->overdue_time, 0);
|
||||
} else {
|
||||
$overdue_time = bcadd(bcmul($batch_info->use_day, 86400, 0), time(), 0);
|
||||
}
|
||||
$channel_type = $data['from'];
|
||||
/** @var OtherOrderServices $OtherOrderServices */
|
||||
$OtherOrderServices = app()->make(OtherOrderServices::class);
|
||||
$storeOrderCreateService = app()->make(StoreOrderCreateServices::class);
|
||||
$record_data['uid'] = $user_info->uid;
|
||||
$record_data['member_code'] = $card_info->card_number;
|
||||
$record_data['use_day'] = $batch_info->use_day;
|
||||
$record_data['overdue_time'] = $overdue_time;
|
||||
$record_data['order_id'] = $storeOrderCreateService->getNewOrderId();
|
||||
$record_data['channel_type'] = $channel_type;
|
||||
$record_data['member_type'] = "free";
|
||||
$record_data['vip_day'] = $batch_info->use_day;
|
||||
$record_data['type'] = 2;
|
||||
$record_data['paid'] = 1;
|
||||
$record_data['pay_time'] = time();
|
||||
$res3 = $OtherOrderServices->addOtherOrderData($record_data);
|
||||
//if ($res3) $res4 = $userServices->update($user_info->uid, ['level' => 1, 'overdue_time' => $overdue_time, 'is_permanent' => 0], 'uid');
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$res4 = $userServices->setMemberOverdueTime($batch_info->use_day, $user_info->uid, 2, $record_data['member_type']);
|
||||
$res5 = $res1 && $res2 && $res3 && $res4;
|
||||
return $res5;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/** 验证是否存在此类型会员卡
|
||||
* @param string $member_type
|
||||
* @return bool
|
||||
*/
|
||||
public function checkmemberType(string $member_type)
|
||||
{
|
||||
$member_type_arr = $this->getMemberTypeInfo();
|
||||
if (!array_key_exists($member_type, $member_type_arr)) throw new ValidateException('暂无此类型会员卡');
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 获取会员权益和说明配置
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberRightsInfo()
|
||||
{
|
||||
/** @var MemberRightServices $memberRightService */
|
||||
$memberRightService = app()->make(MemberRightServices::class);
|
||||
$memberRight = $memberRightService->getSearchList(['status' => 1], ['id', 'right_type', 'title', 'show_title', 'image', 'explain','content', 'number']);
|
||||
if ($memberRight['list']) {
|
||||
foreach ($memberRight['list'] as $k => &$v) {
|
||||
$v['title'] = $v['show_title'];
|
||||
$v['pic'] = $v['image'];
|
||||
unset($v['show_title'], $v['image']);
|
||||
}
|
||||
}
|
||||
return ['member_right' => $memberRight['list']];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员卡配置
|
||||
* @return array
|
||||
*/
|
||||
public function getMemberTypeInfo()
|
||||
{
|
||||
/** @var SystemConfigService $systemConfigService */
|
||||
$systemConfigService = app()->make(SystemConfigService::class);
|
||||
$data = [];
|
||||
foreach (self::$_memberTypePrefix as $v) {
|
||||
$data[$v] = $systemConfigService::more([$v . '_title', $v . '_vip_day', $v . '_pre_price', $v . '_price']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员卡数据处理
|
||||
* @param int $uid
|
||||
* @param bool $is_free
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function DoMemberType(int $uid = 0, bool $is_free = true)
|
||||
{
|
||||
$data = array();
|
||||
/** @var MemberShipServices $memberShipService */
|
||||
$memberShipService = app()->make(MemberShipServices::class);
|
||||
if ($is_free) {
|
||||
$where = [['is_del', '=', 0]];
|
||||
} else {
|
||||
$where = [['is_del', '=', 0], ['type', '<>', 'free']];
|
||||
}
|
||||
$list = $memberShipService->getApiList($where);
|
||||
foreach ($list as $v) {
|
||||
$data[] = [
|
||||
'id' => $v['id'],
|
||||
'title' => $v['title'],
|
||||
'type' => $v['type'],
|
||||
'vip_day' => $v['vip_day'],
|
||||
'pre_price' => $v['pre_price'],
|
||||
'is_label' => $v['is_label'],
|
||||
'price' => $v['price'],
|
||||
'overdue_time' => $memberShipService->getOverdueTime($uid, (int)$v['id'], [], $v, true)
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员类型数据
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getMemberTypeValue(int $uid = 0)
|
||||
{
|
||||
$member_type = $this->DoMemberType($uid);
|
||||
if (!$member_type) return false;
|
||||
foreach ($member_type as $k => $v) {
|
||||
$new_member_data[$v['id']] = $v;
|
||||
}
|
||||
return $new_member_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出会员卡
|
||||
* @param $where
|
||||
* @return array|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getExportData($where, int $limit = 0)
|
||||
{
|
||||
if ($limit) {
|
||||
[$page] = $this->getPageValue();
|
||||
} else {
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
}
|
||||
$data = $this->dao->getSearchList($where, $page, $limit);
|
||||
if ($data) {
|
||||
/** @var UserServices $userService */
|
||||
$userService = app()->make(UserServices::class);
|
||||
$userInfos = $userService->getColumn([['uid', 'in', array_unique(array_column($data, 'use_uid'))]], 'uid,real_name,nickname,phone', 'uid');
|
||||
foreach ($data as $k => $v) {
|
||||
$data[$k]['use_time'] = $v['use_time'] != 0 ? date('Y-m-d H:i:s', $v['use_time']) : "";
|
||||
$data[$k]['user_name'] = '';
|
||||
$data[$k]['user_phone'] = '';
|
||||
$userInfo = $userInfos[$v['use_uid']] ?? [];
|
||||
if ($v['use_uid'] && $userInfo) {
|
||||
$data[$k]['user_name'] = $userInfo['real_name'] ? $userInfo['real_name'] : $userInfo['nickname'];
|
||||
$data[$k]['user_phone'] = $userInfo['phone'];
|
||||
}
|
||||
}
|
||||
}
|
||||
/** @var MemberCardBatchServices $batchService */
|
||||
$batchService = app()->make(MemberCardBatchServices::class);
|
||||
$batchInfo = $batchService->getOne($where['batch_card_id']);
|
||||
$dataArray['title'] = $batchInfo ? $batchInfo['title'] : "";
|
||||
$dataArray['data'] = $data;
|
||||
return $dataArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员记录
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function getSearchRecordList(array $where)
|
||||
{
|
||||
/** @var OtherOrderServices $otherOrderSevice */
|
||||
$otherOrderSevice = app()->make(OtherOrderServices::class);
|
||||
return $otherOrderSevice->getMemberRecord($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 看是会员权益时候开启|并返回数据
|
||||
* @param string $rightType
|
||||
* @param bool $get_number
|
||||
* @param int $member_status
|
||||
* @return bool|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function isOpenMemberCard(string $rightType = '', bool $get_number = true, $member_status = -1)
|
||||
{
|
||||
if ($member_status == -1) {
|
||||
$isOpen = sys_config('member_card_status', 1);
|
||||
} else {
|
||||
$isOpen = $member_status;
|
||||
}
|
||||
//如果传入权益类别,查看是否具有某权益
|
||||
if (!$rightType) {
|
||||
if ($isOpen) return true;
|
||||
return false;
|
||||
} else {
|
||||
if ($isOpen) {
|
||||
/** @var MemberRightServices $memberRightService */
|
||||
$memberRightService = app()->make(MemberRightServices::class);
|
||||
$memberRight = $memberRightService->getOne(['right_type' => $rightType], 'status,number');
|
||||
if ($memberRight && $memberRight['status']) {
|
||||
if ($get_number) {
|
||||
$number = $memberRight['number'];
|
||||
if (!$number) return false;
|
||||
return $number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 看是会员权益时候开启|并返回数据
|
||||
* @param string $rightType
|
||||
* @param bool $get_number
|
||||
* @param int $member_status
|
||||
* @param int $expire
|
||||
* @return bool|mixed|null
|
||||
* @throws \throwable
|
||||
*/
|
||||
public function isOpenMemberCardCache(string $rightType = '', bool $get_number = true, $member_status = -1, int $expire = 30)
|
||||
{
|
||||
if ($member_status == -1) {
|
||||
$isOpen = sys_config('member_card_status', 1);
|
||||
} else {
|
||||
$isOpen = $member_status;
|
||||
}
|
||||
//如果传入权益类别,查看是否具有某权益
|
||||
if (!$rightType) {
|
||||
if ($isOpen) return true;
|
||||
return false;
|
||||
} else {
|
||||
if ($isOpen) {
|
||||
/** @var MemberRightServices $memberRightService */
|
||||
$memberRightService = app()->make(MemberRightServices::class);
|
||||
$memberRight = $memberRightService->getMemberRightCache($rightType);
|
||||
if ($memberRight && $memberRight['status']) {
|
||||
if ($get_number) {
|
||||
$number = $memberRight['number'];
|
||||
if (!$number) return false;
|
||||
return $number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会员卡状态
|
||||
* @param $id
|
||||
* @param $status
|
||||
* @return bool
|
||||
*/
|
||||
public function setStatus($id, $status)
|
||||
{
|
||||
$res = $this->dao->update($id, ['status' => $status]);
|
||||
if ($res) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
174
app/services/user/member/MemberRightServices.php
Normal file
174
app/services/user/member/MemberRightServices.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\user\member;
|
||||
|
||||
use app\dao\user\member\MemberRightDao;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* Class MemberRightServices
|
||||
* @package app\services\user\member
|
||||
* @mixin MemberRightDao
|
||||
*/
|
||||
class MemberRightServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var MemberRightDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected MemberRightDao $dao;
|
||||
|
||||
/**
|
||||
* 获取会员权益
|
||||
* @param array $where
|
||||
* @param array $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getSearchList(array $where = [], array $field = ['*'])
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getSearchList($where, $page, $limit, $field);
|
||||
foreach ($list as &$item) {
|
||||
$item['image'] = set_file_url($item['image']);
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑保存
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function save(int $id, array $data)
|
||||
{
|
||||
if (!$data['right_type']) throw new AdminException("会员权益类型缺失");
|
||||
if (!$id) throw new AdminException("id参数缺失");
|
||||
if (!$data['title'] || !$data['show_title']) throw new AdminException("请设置权益名称");
|
||||
if (!$data['image']) throw new AdminException("请上传会员权益图标");
|
||||
switch ($data['right_type']) {
|
||||
case "integral":
|
||||
if (!$data['number']) throw new AdminException("请设置返还积分倍数");
|
||||
if ($data['number'] < 0) throw new AdminException("返还积分倍数不能为负数");
|
||||
$save['number'] = abs($data['number']);
|
||||
break;
|
||||
case "express" :
|
||||
if (!$data['number']) throw new AdminException("请设置运费折扣");
|
||||
if ($data['number'] < 0) throw new AdminException("运费折扣不能为负数");
|
||||
$save['number'] = abs($data['number']);
|
||||
break;
|
||||
case "sign" :
|
||||
if (!$data['number']) throw new AdminException("请设置签到积分倍数");
|
||||
if ($data['number'] < 0) throw new AdminException("签到积分倍数不能为负数");
|
||||
$save['number'] = abs($data['number']);
|
||||
break;
|
||||
case "offline" :
|
||||
if (!$data['number']) throw new AdminException("请设置线下付款折扣");
|
||||
if ($data['number'] < 0) throw new AdminException("线下付款不能为负数");
|
||||
$save['number'] = abs($data['number']);
|
||||
}
|
||||
$save['show_title'] = $data['show_title'];
|
||||
$save['image'] = $data['image'];
|
||||
$save['status'] = $data['status'];
|
||||
$save['sort'] = $data['sort'];
|
||||
$this->dao->update($id, $data);
|
||||
$right = $this->dao->get($id);
|
||||
if ($right) {
|
||||
$this->dao->cacheUpdate($right->toArray());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加权益内容
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function save_content(int $id, array $data)
|
||||
{
|
||||
if (!$id) throw new AdminException("id参数缺失");
|
||||
if (!$data['content']) throw new AdminException("请添加权益内容");
|
||||
$this->dao->update($id, $data);
|
||||
$right = $this->dao->get($id);
|
||||
if ($right) {
|
||||
$this->dao->cacheUpdate($right->toArray());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条信息
|
||||
* @param array $where
|
||||
* @param string $field
|
||||
* @return array|false|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getOne(array $where, string $field = '*')
|
||||
{
|
||||
if (!$where) return false;
|
||||
return $this->dao->getOne($where, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看某权益是否开启
|
||||
* @param $rightType
|
||||
* @return bool
|
||||
*/
|
||||
public function getMemberRightStatus($rightType)
|
||||
{
|
||||
if (!$rightType) return false;
|
||||
$status = $this->dao->value(['right_type' => $rightType], 'status');
|
||||
if ($status) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在缓存中查找权益等级
|
||||
* @param string $rightType
|
||||
* @return false|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2022/11/10
|
||||
*/
|
||||
public function getMemberRightCache(string $rightType)
|
||||
{
|
||||
$list = $this->dao->cacheList();
|
||||
if ($list === null || (is_array($list) && !$list)) {
|
||||
$list = $this->dao->getSearchList(['status' => 1]);
|
||||
$this->dao->cacheCreate($list);
|
||||
}
|
||||
|
||||
foreach ($list as $item) {
|
||||
if ($rightType == $item['right_type']) {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
210
app/services/user/member/MemberShipServices.php
Normal file
210
app/services/user/member/MemberShipServices.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\user\member;
|
||||
|
||||
use app\dao\user\member\MemberShipDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\user\UserServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* Class MemberShipServices
|
||||
* @package app\services\user\member
|
||||
* @mixin MemberShipDao
|
||||
*/
|
||||
class MemberShipServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var MemberShipDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected MemberShipDao $dao;
|
||||
|
||||
/**
|
||||
* 获取单个付费会员信息
|
||||
* @param int $id
|
||||
* @param string $field
|
||||
* @return array|\think\Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getMemberInfo(int $id, string $field = '*')
|
||||
{
|
||||
$member = $this->dao->getOne(['id' => $id, 'is_del' => 0], $field);
|
||||
if (!$member) {
|
||||
throw new ValidateException('该会员类型不存在或已删除');
|
||||
}
|
||||
return $member;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台获取会员类型
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function getSearchList(array $where = [])
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getSearchList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员卡api接口
|
||||
* @return mixed
|
||||
*/
|
||||
public function getApiList(array $where)
|
||||
{
|
||||
return $this->dao->getApiList($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 卡类型编辑保存
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function save(int $id, array $data)
|
||||
{
|
||||
if (!$data['title']) throw new AdminException("请填写会员名称");
|
||||
if (!$data['type']) throw new AdminException("会员类型缺失");
|
||||
if ($data['type'] == "ever") {
|
||||
$data['vip_day'] = -1;
|
||||
} else {
|
||||
if (!$data['vip_day']) throw new AdminException("请填写体验天数");
|
||||
if ($data['vip_day'] < 0) throw new AdminException("体验天数不能为负数");
|
||||
}
|
||||
if ($data['type'] == "free") {
|
||||
// $data['price'] = 0.00;
|
||||
$data['pre_price'] = 0.00;
|
||||
} else {
|
||||
if ($data['pre_price'] === '' || $data['price'] === '') throw new AdminException("请填写价格");
|
||||
if ($data['pre_price'] == 0 || $data['price'] == 0) throw new AdminException("请填写价格");
|
||||
}
|
||||
if ($data['pre_price'] < 0 || $data['price'] < 0) throw new AdminException("价格不能为负数");
|
||||
if ($data['pre_price'] > $data['price']) throw new AdminException("优惠价不能大于划线价");
|
||||
if ($data['is_label']) {
|
||||
$this->dao->update(['is_label' => 1], ['is_label' => 0]);
|
||||
}
|
||||
if ($id) {
|
||||
$data['id'] = $id;
|
||||
$this->dao->cacheUpdate($data);
|
||||
return $this->dao->update($id, $data);
|
||||
} else {
|
||||
$res = $this->dao->save($data);
|
||||
$data['id'] = $res->id;
|
||||
$this->dao->cacheUpdate($data);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取卡会员天数
|
||||
* @param array $where
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVipDay(array $where)
|
||||
{
|
||||
return $this->dao->value($where, 'vip_day');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会员类型状态
|
||||
* @param $id
|
||||
* @param $is_del
|
||||
* @return bool
|
||||
*/
|
||||
public function setStatus($id, $is_del)
|
||||
{
|
||||
$res = $this->dao->update($id, ['is_del' => $is_del]);
|
||||
if ($is_del) {
|
||||
$this->cacheDelById($id);
|
||||
} else {
|
||||
$this->cacheSaveValue($id, 'is_del', 0);
|
||||
}
|
||||
if ($res) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询会员类型select
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getShipSelect()
|
||||
{
|
||||
$menus = [];
|
||||
foreach ($this->dao->getSearchList(['is_del' => 0], 0, 0, ['id', 'title']) as $menu) {
|
||||
$menus[] = ['value' => $menu['id'], 'label' => $menu['title']];
|
||||
}
|
||||
$menus[] = ['value' => 'card', 'label' => '卡密激活'];
|
||||
$menus[] = ['value' => 'admin', 'label' => '赠送'];
|
||||
return $menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取过期时间
|
||||
* @param int $uid
|
||||
* @param int $id
|
||||
* @param $userInfo
|
||||
* @param $memberInfo
|
||||
* @return false|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getOverdueTime(int $uid, int $id, $userInfo = [], $memberInfo = [], $is_date = false)
|
||||
{
|
||||
if (!$id) {
|
||||
throw new ValidateException('缺少会员ID');
|
||||
}
|
||||
if (!$memberInfo) {
|
||||
/** @var MemberShipServices $memberShipService */
|
||||
$memberShipService = app()->make(MemberShipServices::class);
|
||||
$memberInfo = $memberShipService->get($id);
|
||||
}
|
||||
if (!$memberInfo) {
|
||||
throw new ValidateException('会员卡类型不存在');
|
||||
}
|
||||
if ($uid && !$userInfo) {
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$userInfo = $userServices->getUserCacheInfo($uid);
|
||||
}
|
||||
$member_type = $memberInfo['type'];
|
||||
$vip_day = $memberInfo['vip_day'];
|
||||
if ($member_type == 'ever') {
|
||||
$overdue_time = 0;
|
||||
$is_ever_level = 1;
|
||||
} else {
|
||||
if (!$userInfo || $userInfo['is_money_level'] == 0) {
|
||||
$overdue_time = bcadd(bcmul($vip_day, 86400, 0), time(), 0);
|
||||
} else {
|
||||
$overdue_time = bcadd(bcmul($vip_day, 86400, 0), $userInfo['overdue_time'], 0);
|
||||
}
|
||||
$is_ever_level = 0;
|
||||
}
|
||||
if ($is_ever_level == 1) {
|
||||
$res = "永久会员";
|
||||
} else {
|
||||
$res = $is_date ? date('Y-m-d', $overdue_time) : $overdue_time;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user