| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop100%开源免费商用商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | 商业版本务必购买商业授权,以免引起法律纠纷
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshopTeam
- // +----------------------------------------------------------------------
- namespace app\openapi\logic\user;
- use app\common\enum\PayEnum;
- use app\common\model\
- {
- User,
- Order,
- UserLevel
- };
- /**
- * 会员等级逻辑层
- * Class UserLevelLogic
- * @package app\adminapi\logic\user
- */
- class UserLevelLogic
- {
- /*
- * 获取等级列表
- * */
- public function getUserLevelLists($params){
- $where = [];
- if(isset($params['level_name'])){
- $where[] = ['name','like','%'.$params['level_name'].'%'];
- }
- $level_list = UserLevel::where($where)->field('id,name,discount,rank,condition,offline_user_level_id,create_time')->select()->toArray();
- return $level_list;
- }
- /**
- * @notes 添加会员等级
- * @param array $params
- * @return bool
- * @author cjhao
- * @date 2021/7/28 15:08
- */
- public function addUserLevelInfo(array $params)
- {
- $userLevel = new UserLevel();
- $condition = '';
- if(isset($params['condition'])){
- $condition = json_encode($params['condition'],JSON_UNESCAPED_UNICODE);
- }
- $userLevel->offline_user_level_id = $params['offline_user_level_id'];
- $userLevel->name = $params['name'];
- $userLevel->rank = $params['rank'];
- $userLevel->image = '/resource/image/adminapi/user/user_level_icon.png';
- $userLevel->background_image = '/resource/image/adminapi/user/user_level_bg.png';
- $userLevel->remark = isset($params['remark'])?$params['remark']:'';
- $userLevel->discount = $params['discount'] ;
- $userLevel->condition =$condition;
- $userLevel->save();
- return true;
- }
- // /**
- // * @notes 获取用户等级
- // * @param $id
- // * @return array
- // * @author cjhao
- // * @date 2021/7/29 17:14
- // */
- // public function detail($id){
- // $userLevel = UserLevel::find($id);
- //
- // $detail = [
- // 'id' => $userLevel->id,
- // 'name' => $userLevel->name,
- // 'rank' => $userLevel->rank,
- // 'image' => $userLevel->image,
- // 'background_image' => $userLevel->background_image,
- // 'remark' => $userLevel->remark,
- // 'level_discount' => $userLevel->discount > 0 ? 1 :0,
- // 'discount' => $userLevel->discount,
- // 'condition' => \app\common\logic\UserLogic::formatLevelCondition($userLevel->condition),
- // ];
- //
- // return $detail;
- // }
- /**
- * @notes 编辑会员等级
- * @param array $params
- * @author cjhao
- * @date 2021/7/28 15:15
- */
- public function updateUserLevel(array $params)
- {
- $condition = '';
- if (isset($params['condition'])) {
- $condition = json_encode($params['condition'], JSON_UNESCAPED_UNICODE);
- }
- $where['name'] = $params['name'];
- $userlevel = UserLevel::where($where)->findOrEmpty();
- if ($userlevel->isEmpty()) {
- $userLevels = new UserLevel();
- $userLevels->offline_user_level_id = $params['offline_user_level_id'];
- $userLevels->name = $params['name'];
- $userLevels->image = '/resource/image/adminapi/user/user_level_icon.png';
- $userLevels->rank = $params['rank'];
- $userLevels->background_image = '/resource/image/adminapi/user/user_level_bg.png';
- $userLevels->remark = isset($params['remark']) ? $params['remark'] : '';
- $userLevels->discount = $params['discount'];
- $userLevels->condition = $condition;
- $userLevels->save();
- } else {
- $updateWhere['name'] = $params['name'];
- $update['offline_user_level_id'] = $params['offline_user_level_id'];
- $update['rank'] = $params['rank'];
- $update['image'] = '/resource/image/adminapi/user/user_level_icon.png';
- $update['background_image'] = '/resource/image/adminapi/user/user_level_bg.png';
- $update['remark'] = isset($params['remark']) ? $params['remark'] : '';
- $update['discount'] = $params['discount'];
- $update['condition'] = $condition;
- $ret = UserLevel::where($updateWhere)->update($update);
- }
- return true;
- }
- /**
- * @notes 删除会员等级
- * @param int $id
- * @return bool
- * @author cjhao
- * @date 2021/7/28 16:59
- */
- public function del($params)
- {
- $where['name'] = $params['name'];
- $user_level = UserLevel::where($where)->find();
- if ($user_level) {
- $user_level->delete_time = time();
- $user_level->save();
- //todo 将该等级的用户全部降到系统默认等级
- $level = UserLevel::where(['rank' => 1])->find();
- if ($level) {
- User::where(['level' => $user_level['id']])->update(['level' => $level->id]);
- }
- }
- return true;
- }
- /**
- * @notes 处理前端传过来的等级数据
- * @param $condition
- * @author cjhao
- * @date 2022/4/28 17:05
- */
- public function disposeCondition($condition){
- //默认满足任意条件
- $condition_type = $condition['condition_type'] ?? 0;
- //默认不勾选
- $isSingleMoney = $condition['is_single_money'];
- //单笔消费金额
- $singleMoney =$condition['single_money'] ?? '';
- //默认不勾选
- $isTotalMoney = $condition['is_total_money'];
- //累计消费金额
- $totalMoney = $condition['total_money'] ?? '';
- //默认不勾选
- $isTotalNum = $condition['is_total_num'];
- //累计消费次数
- $totalNum = $condition['total_num'] ?? '';
- return [
- 'condition_type' => (int)$condition_type, //默认满足任意条件
- 'is_single_money' => (int)$isSingleMoney, //默认不勾选
- 'single_money' => $singleMoney ? round($singleMoney,2) : '',
- 'is_total_money' => (int)$isTotalMoney,
- 'total_money' => $totalMoney ? round($totalMoney,2) : '',
- 'is_total_num' => (int)$isTotalNum,
- 'total_num' => $totalNum ? (int)$totalNum : '',
- ];
- }
- }
|