moonsflyer пре 4 месеци
родитељ
комит
9260596d34

+ 8 - 1
app/common/enum/AccountLogEnum.php

@@ -96,6 +96,9 @@ class AccountLogEnum
     const BW_INC_PAYMENT_FAIL           = 402;
     const BW_INC_TRANSFER_FAIL          = 403;
     const BW_INC_ADMIN                  = 404;
+
+    const OFFLINE_INC_MONEY             =405;
+    const OFFLINE_DEC_MONEY             =406;
     /**
      * 成长值减少类型
      */
@@ -155,6 +158,7 @@ class AccountLogEnum
         self::BNW_INC_LOTTERY,
         self::BNW_INC_INTEGRAL_ORDER,
         self::BNW_INC_USER_REGISTER,
+        self::OFFLINE_INC_MONEY,
     ];
 
     /**
@@ -163,6 +167,7 @@ class AccountLogEnum
     const BW_DEC = [
         self::BW_DEC_ADMIN,
         self::BW_DEC_WITHDRAWAL,
+        self::OFFLINE_DEC_MONEY,
     ];
 
     /**
@@ -173,7 +178,7 @@ class AccountLogEnum
         self::BW_INC_DISTRIBUTION_SETTLE,
         self::BW_INC_PAYMENT_FAIL,
         self::BW_INC_TRANSFER_FAIL,
-        self::BW_INC_ADMIN
+        self::BW_INC_ADMIN,
     ];
 
     /**
@@ -291,6 +296,8 @@ class AccountLogEnum
             self::INTEGRAL_INC_AWARD => '消费赠送积分',
             self::INTEGRAL_INC_CANCEL_INTEGRAL => '取消积分订单返还积分',
             self::INTEGRAL_INC_USER_REGISTER    => '用户注册赠送积分',
+            self::OFFLINE_DEC_MONEY             =>  '线下消费减少余额',
+            self::OFFLINE_INC_MONEY             =>  '线下充值增加金额'
         ];
         if($flag) {
             return $desc;

+ 4 - 0
app/common/enum/UserTerminalEnum.php

@@ -36,6 +36,7 @@ class UserTerminalEnum
     const IOS        = 5;//苹果app
     const ANDROID    = 6;//安卓app
     const TOUTIAO    = 7;//字节小程序(头条)
+    const CASH    = 8;//收银台
 
     const ALL_TERMINAL = [
         self::WECHAT_MMP,
@@ -45,6 +46,7 @@ class UserTerminalEnum
         self::IOS,
         self::ANDROID,
         self::TOUTIAO,
+        self::CASH,
     ];
 
 
@@ -65,6 +67,7 @@ class UserTerminalEnum
             self::IOS           => '苹果APP',
             self::ANDROID       => '安卓APP',
             self::TOUTIAO       => '字节小程序',
+            self::CASH          => '收银台',
         ];
         if(true === $from){
             return $desc;
@@ -89,6 +92,7 @@ class UserTerminalEnum
             self::IOS           => 5,
             self::ANDROID       => 5,
             self::TOUTIAO       => 7,
+            self::CASH       => 8,
         ];
         return $desc[$scene] ?? 0;
 

+ 87 - 0
app/openapi/controller/OrderController.php

@@ -0,0 +1,87 @@
+<?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\controller;
+
+use app\adminapi\logic\toutiao\ToutiaoSettingLogic;
+use app\openapi\logic\user\UserLogic;
+use app\openapi\validate\UserValidate;
+use app\openapi\validate\OrderValidate;
+use app\openapi\logic\order\OrderLogic;
+/**
+ * 订单接口示例
+ * Class UserController
+ * @package app\openapi\controller
+ */
+class OrderController extends BaseOpenController
+{
+    /**
+     * 获取用户信息
+     * @return \think\response\Json
+     */
+    public function info()
+    {
+
+        $params = (new UserValidate())->post()->goCheckStrict('info');
+
+        // 模拟用户数据
+        $userData = [
+            'user_id' => $params['user_id'],
+            'nickname' => '测试用户',
+            'avatar' => 'https://example.com/avatar.jpg',
+            'mobile' => '138****8888',
+            'created_time' => date('Y-m-d H:i:s'),
+        ];
+        
+        return $this->success('获取成功', $userData);
+    }
+    /*
+     * 查询会员订单信息
+     * */
+    public function getUserOrderList(){
+        $params = (new OrderValidate())->get()->goCheckStrict('getOrderList');
+        $order_list = (new OrderLogic)->getUserOrderList($params);
+        return $this->success('获取成功', $order_list);
+    }
+    /*
+     * 订单推送
+     * */
+    public function orderPush(){
+        $params = (new OrderValidate())->post()->goCheckStrict('orderPush');
+        $result = (new OrderLogic)->orderPush($params);
+        if ($result) {
+            return $this->success('订单推送成功', [],1,1);
+        }
+        return $this->fail(OrderLogic::getError());
+    }
+
+    /*
+     * 退款
+     * */
+    public function orderRefundMoney(){
+        $params = (new OrderValidate())->post()->goCheckStrict('orderRefundMoney');
+        $result = (new OrderLogic)->orderRefundMoney($params);
+        if ($result) {
+            return $this->success('退款成功', [],1,1);
+        }
+        return $this->fail(OrderLogic::getError());
+    }
+
+
+}

+ 38 - 2
app/openapi/controller/UserController.php

@@ -19,6 +19,7 @@
 
 namespace app\openapi\controller;
 
+use app\adminapi\logic\toutiao\ToutiaoSettingLogic;
 use app\openapi\logic\user\UserLogic;
 use app\openapi\validate\UserValidate;
 
@@ -50,13 +51,48 @@ class UserController extends BaseOpenController
         return $this->success('获取成功', $userData);
     }
     /*
-     *
+     * 查询会员信息
      * */
     public function getUserInfo(){
-        $params = (new UserValidate())->post()->goCheckStrict('getUserInfo');
+        $params = (new UserValidate())->get()->goCheckStrict('getUserInfo');
         $detail = (new UserLogic)->detail($params['mobile']);
         return $this->success('获取成功', $detail);
     }
+    /*
+     * 查询会员信息
+     * */
+    public function addUser(){
+        $params = (new UserValidate())->post()->goCheckStrict('addUser');
+        $result = (new UserLogic)->addUserInfo($params);
+        if ($result) {
+            return $this->success('新增会员成功', [],1,1);
+        }
+        return $this->fail(UserLogic::getError());
+    }
+
+    /*
+     * 更新会员信息
+     * */
+    public function updateUserInfo(){
+        $params = (new UserValidate())->post()->goCheckStrict('updateUserInfo');
+        $result = (new UserLogic)->updateUserInfo($params);
+        if ($result) {
+            return $this->success('编辑会员成功', [],1,1);
+        }
+        return $this->fail(UserLogic::getError());
+    }
+
+    /*
+     * 会员充值
+     * */
+    public function userRecharge(){
+        $params = (new UserValidate())->post()->goCheckStrict('userRecharge');
+        $result = (new UserLogic)->userRecharge($params);
+        if ($result) {
+            return $this->success('会员充值同步成功', [],1,1);
+        }
+        return $this->fail(UserLogic::getError());
+    }
     /**
      * 更新用户信息
      * @return \think\response\Json

+ 79 - 0
app/openapi/controller/UserLevelController.php

@@ -0,0 +1,79 @@
+<?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\controller;
+
+use app\adminapi\logic\toutiao\ToutiaoSettingLogic;
+use app\openapi\logic\user\UserLogic;
+use app\openapi\validate\UserValidate;
+use app\openapi\logic\user\UserLevelLogic;
+use app\openapi\validate\UserLevelValidate;
+/**
+ * 用户登记接口示例
+ * Class UserController
+ * @package app\openapi\controller
+ */
+class UserLevelController extends BaseOpenController
+{
+
+    /*
+     * 查询会员信息
+     * */
+    public function getUserLevelList(){
+        $params = (new UserLevelValidate())->get()->goCheckStrict('getUserLevelLists');
+        $list = (new UserLevelLogic)->getUserLevelLists($params);
+        return $this->success('获取成功', $list);
+    }
+    /*
+     * 新增会员等级信息
+     * */
+    public function addUserLevel(){
+        $params = (new UserLevelValidate())->post()->goCheckStrict('addUserLevel');
+        $result = (new UserLevelLogic)->addUserLevelInfo($params);
+        if ($result) {
+            return $this->success('新增会员等级成功', [],1,1);
+        }
+        return $this->fail(UserLevelLogic::getError());
+    }
+
+    /*
+     * 更新会员等级信息
+     * */
+    public function updateUserLevel(){
+        $params = (new UserLevelValidate())->post()->goCheckStrict('updateUserLevelInfo');
+        $result = (new UserLevelLogic)->updateUserLevel($params);
+        if ($result) {
+            return $this->success('编辑会员等级成功', [],1,1);
+        }
+        return $this->fail(UserLevelLogic::getError());
+    }
+
+    /*
+     * 删除会员等级
+     * */
+    public function delUserLevel(){
+        $params = (new UserLevelValidate())->post()->goCheckStrict('delUserLevel');
+        $result = (new UserLevelLogic)->del($params);
+        if ($result) {
+            return $this->success('删除会员等级成功', [],1,1);
+        }
+        return $this->fail(UserLevelLogic::getError());
+    }
+
+}

+ 293 - 0
app/openapi/logic/order/OrderLogic.php

@@ -0,0 +1,293 @@
+<?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\order;
+use app\adminapi\logic\distribution\DistributionLogic;
+use app\common\{logic\BaseLogic,
+    model\AfterSale,
+    model\OrderGoods,
+    model\User,
+    model\Order,
+    enum\PayEnum,
+    model\UserLevel,
+    model\UserLabel,
+    enum\CouponEnum,
+    model\CouponList,
+    enum\AccountLogEnum,
+    model\UserLabelIndex,
+    logic\AccountLogLogic,
+    enum\UserTerminalEnum,
+    service\ConfigService};
+use think\facade\Config;
+use think\facade\Db;
+use think\Model;
+
+
+/**
+ * 订单逻辑层
+ * Class UserLogic
+ * @package app\adminapi\logic\user
+ */
+class OrderLogic extends BaseLogic
+{
+
+    /**
+     * @notes 用户详情
+     * @param $params array
+     * @return list array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author cjhao
+     * @date 2021/8/18 15:52
+     */
+    public function getUserOrderList($params)
+    {
+        $where=[];
+        $order_source = 0;
+        if(isset($params['type'])) {
+            if (($params['type']) == 1) {
+                $order_source =1;
+                $where['order_source'] = 1; //平台
+            } else if (($params['type']) == 2) {
+                $order_source=2;
+                $where['order_source'] = 2; //线下
+            }
+        }
+        $user_info = User::where(['mobile'=>$params['mobile']])->findOrEmpty();
+        if($user_info->isEmpty()){
+            return [];
+        }
+        $user_id = $user_info['id'];
+        $where['user_id'] = $user_id;
+        $pageNo = 1;
+
+        if(isset($params['pageNo']) && !empty($params['pageNo'])){
+            $pageNo = $params['pageNo']??1; //页码
+        }
+        if(isset($params['orderSn']) && !empty($params['orderSn'])){
+            if($order_source == 1){
+                $where['sn']=$params['orderSn'];
+            }else if($order_source == 2){
+                $where['transaction_id'] = $params['orderSn'];
+            }else{
+                $where['sn|transaction_id'] = $params['orderSn'];
+            }
+
+        }
+        $pageSize = 10; //每页数量
+
+        $index = (int)($pageNo-1)*$pageSize;
+        $order_list = Order::field('id,sn,user_id,order_type,order_status,pay_status,pay_way,pay_time,address,delivery_type,
+                        goods_price,order_amount,discount_amount,member_amount,integral_amount,total_amount,total_num,express_status,confirm_take_time,
+                        create_time,order_source,order_goods')
+                    ->with('user')
+                    ->where($where)->order('id desc')->limit($index,$pageSize)->select()->toArray();
+
+        foreach($order_list as &$v){
+            if($v['order_source'] == 1){
+                $gwhere['order_id'] = $v['id'];
+                $order_goods = OrderGoods::field('id,goods_name,goods_snap,goods_num,goods_price,total_price,total_pay_price')->where($gwhere)->select()->toArray();
+                $order_goods_list =$order_goods;
+                $v['order_goods'] = $order_goods_list;
+            }
+
+
+        }
+        $data['order_count'] = Order::where($where)->count();
+        $data['order_list'] = $order_list;
+        $data['page_index'] = $pageNo;
+        $data['page_num'] = $pageSize;
+        return $data;
+    }
+    /*
+     *
+     * 线下订单推送
+     * */
+    public function orderPush($params){
+
+        $userInfo = User::where(['mobile'=>$params['mobile']])->findOrEmpty();
+        if($userInfo->isEmpty()){
+            outFileLog($params,'orderPush','$params');
+            self::setError('会员数据查询为空');
+            return false;
+        }
+
+        $order_info = Order::where(['sn'=> $params['orderSn']])->findOrEmpty();
+        if(!$order_info->isEmpty()){
+            outFileLog($params,'orderPush','$params');
+            self::setError('该订单号已存在');
+            return false;
+        }
+        $goods_price = 0;
+        if(isset($params['goods_price']) && !empty($params['goods_price'])){
+            $goods_price = $params['goods_price'];
+        }
+        $order_amount = 0;
+        if(isset($params['order_amount']) && !empty($params['order_amount'])){
+            $order_amount = $params['order_amount'];
+        }
+        $discount_amount = 0;
+        if(isset($params['discount_amount']) && !empty($params['discount_amount'])){
+            $discount_amount = $params['discount_amount'];
+        }
+        $member_amount = 0;
+        if(isset($params['member_amount']) && !empty($params['member_amount'])){
+            $member_amount = $params['member_amount'];
+        }
+        $integral_amount = 0;
+        if(isset($params['integral_amount']) && !empty($params['integral_amount'])){
+            $integral_amount = $params['integral_amount'];
+        }
+        $total_amount = 0;
+        if(isset($params['total_amount']) && !empty($params['total_amount'])){
+            $total_amount = $params['total_amount'];
+        }
+        $total_num = 0;
+        if(isset($params['total_num']) && !empty($params['total_num'])){
+            $total_num = $params['total_num'];
+        }
+        $user_id = $userInfo['id'];
+
+        $saveData['sn'] = $params['orderSn'];
+        $saveData['transaction_id'] = $params['orderSn'];
+        $saveData['user_id'] = $user_id;
+        $saveData['order_type'] = 1;
+        $saveData['pay_way'] =$params['pay_way'];
+        $saveData['order_terminal'] = 7;
+        $saveData['order_status'] = 3;
+        $saveData['pay_status'] = 1;
+        $saveData['pay_time'] = $params['create_time'];
+        $saveData['delivery_type'] = 2;
+        $saveData['goods_price'] = $goods_price;
+        $saveData['order_amount'] = $order_amount;
+        $saveData['discount_amount'] = $discount_amount;
+        $saveData['member_amount'] = $member_amount;
+        $saveData['integral_amount'] = $integral_amount;
+        $saveData['total_amount'] = $total_amount;
+        $saveData['total_num'] = $total_num;
+        $saveData['express_status'] = 1;
+        $saveData['express_time'] =$params['create_time'];
+        $saveData['confirm_take_time'] = $params['create_time'];
+        $saveData['create_time'] = $params['create_time'];
+        $saveData['order_source'] = 2;
+        $saveData['order_goods'] = $params['order_goods'];
+
+        $ret = Order::create($saveData);
+        if($ret){
+            //减少金额
+            $userInfo->user_money = $userInfo->user_money - $order_amount;
+            $userInfo->save();
+
+            //记录用户金额变动记录
+            //记录日志
+            AccountLogLogic::add($userInfo->id, AccountLogEnum::BNW_DEC_ORDER, AccountLogEnum::DEC,  $order_amount,  $params['orderSn'], '线下收银台销售扣减用户金额');
+
+        }
+        return true;
+    }
+    /*
+     * 新增会员信息
+     * */
+    public function orderRefundMoney(array $params):bool{
+        try {
+
+            $mobile = $params['mobile'];
+            $where['mobile'] = $mobile;
+            $user_info = User::where($where)->findOrEmpty();
+
+            if($user_info->isEmpty()){
+                outFileLog($params,'orderRefundMoney','会员信息有无');
+                self::setError('传入的会员信息有误,不存在,请同步');
+                return false;
+            }
+            $refund_money = $params['refund_money'];
+            if(isset($params['orderSn']) && !empty($params['orderSn'])) {
+
+                $order_info = Order::where(['sn' => $params['orderSn']])->findOrEmpty();
+
+                if ($order_info->isEmpty()) {
+                    outFileLog($params, 'orderRefundMoney', '传入订单信息有误');
+                    self::setError('传入订单信息有误');
+                    return false;
+                }
+
+                if($order_info['order_amount']<$refund_money){
+                    outFileLog($params, 'orderRefundMoney', '传入退款金额有误');
+                    self::setError('传入退款金额有误');
+                    return false;
+                }
+
+                $afersaleInfo = AfterSale::where(['order_id'=>$order_info['id']])->findOrEmpty();
+                if(!$afersaleInfo->isEmpty()){
+                    outFileLog($params, 'orderRefundMoney', '已申请售后');
+                    self::setError('该订单号已经售后');
+                    return false;
+                }
+                //插入售后表
+                $afterSale = AfterSale::create([
+                    'sn'              => generate_sn((new AfterSale()), 'sn'),
+                    'user_id'         => $order_info['user_id'],
+                    'order_id'        => $order_info['id'],
+                    'order_goods_id'  => 0,
+                    'refund_reason'   => '线下收银退款-'.$params['remark'],
+                    'refund_remark'   => '收银台系统发起退款',
+                    'refund_type'     => 2,
+                    'refund_method'   => 1,
+                    'refund_total_amount' =>$refund_money,
+                    'refund_way'      => 1,
+                    'refund_status'   => 3,
+                    'status'          => 2,
+                    'sub_status'      => 21,
+                ]);
+
+                if ($order_info['pay_way'] == 5) {
+                    return true;
+                } else {
+
+                    $user_info->user_money = $user_info->user_money + $refund_money;
+                    $user_info->save();
+
+                    //记录用户金额变动记录
+                    //记录日志
+                    AccountLogLogic::add($user_info->id, AccountLogEnum::BNW_INC_CANCEL_ORDER, AccountLogEnum::INC, $refund_money, $params['orderSn'], '线下收银台退款增加用户金额');
+                    return true;
+                }
+            }
+            outFileLog($params,'orderRefundMoney','传入的订单编号有误');
+           self::setError('传入的订单编号有误');
+           return false;
+        }catch(\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+}

+ 201 - 0
app/openapi/logic/user/UserLevelLogic.php

@@ -0,0 +1,201 @@
+<?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 : '',
+        ];
+
+
+    }
+
+}

+ 203 - 251
app/openapi/logic/user/UserLogic.php

@@ -29,7 +29,9 @@ use app\common\{logic\BaseLogic,
     enum\AccountLogEnum,
     model\UserLabelIndex,
     logic\AccountLogLogic,
-    enum\UserTerminalEnum};
+    enum\UserTerminalEnum,
+    service\ConfigService};
+use think\facade\Config;
 use think\facade\Db;
 use think\Model;
 
@@ -43,139 +45,228 @@ class UserLogic extends BaseLogic
 {
 
     /**
-     * @notes 用户概况页面
-     * @return array
+     * @notes 用户详情
+     * @param int $userId
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      * @author cjhao
-     * @date 2021/8/17 14:58
+     * @date 2021/8/18 15:52
      */
-    public function index():array
+    public function detail($mobile)
     {
-        $today = strtotime(date('Y-m-d'));
-        //用户数
-        $userCount = User::count();
-        //今日新增用户数
-        $userNewCount = User::where('create_time','>=',$today)->count();
-        //成交用户数
-        $repetitionCount = Order::where(['pay_status'=>PayEnum::ISPAID])->count();
-        //复购用户数
-        $purchaseCount = Order::where(['pay_status'=>PayEnum::ISPAID])
-                        ->group('user_id')
-                        ->having('count(user_id) >= 2')
-                        ->count();
-
-        $dayList = day_time(14,true);
-        $dayList = array_reverse($dayList);
-        $echarts_data = [];
-        //图表数据
-        foreach ($dayList as $dayKey => $dayVal){
-            $newUserCount = User::whereTime('create_time','between',[$dayVal,$dayVal+86399])->count();
-            $echarts_data[] = [
-                'day'               => date('m-d',$dayVal),
-                'user_new_count'    => $newUserCount,
-            ];
+           $user = User::field('id,nickname,avatar,sex,mobile,birthday,level,create_time,user_money,user_earnings,user_money+user_earnings as total_user_money,user_integral,disable,user_delete')
+            ->with('user_level')
+            ->where(['mobile'=>$mobile])->find()->toArray();
+        if($user){
+            $user['user_level_name'] = $user['name'];
+            unset($user['name']);
+            unset($user['rank']);
+            unset($user['discount']);
         }
-
-        $data = [
-            'user_count'        => $userCount,
-            'user_new_count'    => $userNewCount,
-            'repetition_count'  => $repetitionCount,
-            'purchase_count'    => $purchaseCount,
-            'echarts_data'      => $echarts_data,
-        ];
-        return $data;
+        return $user;
     }
 
+    /*
+     * 新增会员信息
+     * */
+    public function addUserInfo(array $params):bool{
+        try {
 
-    /**
-     * @notes  用户搜索条件列表
-     * @return array
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @author cjhao
-     * @date 2021/8/10 16:58
-     */
-    public function otherLists(): array
-    {
+            $mobile = $params['mobile'];
+            $where['mobile'] = $mobile;
+            $user_info = User::where($where)->findOrEmpty();
+            $offline_user_id = 0;
+            if(isset($params['offline_user_id'])){
+                $offline_user_id = $params['offline_user_id'];
+            }
+            if($user_info->isEmpty()){
+
+                $result = self::createUserData($params);
+                if($result){
+                    return true;
+                }else{
+                    outFileLog($params,'insert_member_error_log','saveData');
+                    self::setError('插入会员数据失败');
+                    return false;
+                }
 
-        $userLevel = UserLevel::order('rank', 'asc')->field('id,name')->select();
-        $userLabel = UserLabel::field('id,name')->select();
-        $sourceList = UserTerminalEnum::getTermInalDesc();
-        return [
-            'user_level_list'   => $userLevel,
-            'user_label_list'   => $userLabel,
-            'source_list'       => $sourceList,
-        ];
+            }
+           self::setError('线上商城已存在该会员信息');
+           return false;
+        }catch(\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
     }
 
+    public function updateUserInfo(array $params):bool{
+        try {
 
-    /**
-     * @notes 设置用户标签
-     * @param array $param
-     * @return bool
-     * @throws \Exception
-     * @author cjhao
-     * @date 2021/8/17 11:43
-     */
-    public function setLabel(array $param): bool
-    {
-        $userIds = $param['user_ids'] ?? [];
-        $labelIds = $param['label_ids'] ?? [];
-        $labelIds = UserLabel::where(['id' => $labelIds])->column('id');
-        //当前用户已绑定的标签
-        $userLabelIndexList = UserLabelIndex::where(['user_id' => $userIds])
-            ->group('user_id')
-            ->column('group_concat(label_id  Separator \',\') as user_label_id', 'user_id');
-
-        $addData = [];
-        foreach ($userIds as $userId) {
-            $userLabelIndex = $userLabelIndexList[$userId]['user_label_id'] ?? '';
-            $userLabelIds = explode(',', $userLabelIndex);
-
-            foreach ($labelIds as $labelId) {
-                //该用户已有该标签,跳过
-                if (in_array($labelId, $userLabelIds)) {
-                    continue;
+            $mobile = $params['mobile'];
+            $where['mobile'] = $mobile;
+            $user_info = User::where($where)->findOrEmpty();
+
+            if($user_info->isEmpty()){
+                $result = self::createUserData($params);
+                if($result){
+                    return true;
+                }else{
+                    outFileLog($params,'insert_member_error_log','saveData');
+                    self::setError('插入会员数据失败');
+                    return false;
                 }
 
-                $addData[] = [
-                    'user_id'   => $userId,
-                    'label_id'  => $labelId,
-                ];
+            }else{
+                $result = self::updateUserData($params);
+                if($result){
+                    return true;
+                }else{
+                    outFileLog($params,'update_member_error_log','updateData');
+                    self::setError('更新会员数据失败');
+                    return false;
+                }
             }
+            self::setError('更新失败,请稍后再试');
+            return false;
+        }catch(\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+    public function createUserData($params){
+        $avatar = ConfigService::get('config', 'default_avatar', '');
+        $mobile = $params['mobile'];
+        $offline_user_id = 0;
+        if(isset($params['offline_user_id'])){
+            $offline_user_id = $params['offline_user_id'];
         }
-        //写入数据
-        if ($addData) {
 
-            (new UserLabelIndex)->saveAll($addData);
+        $user_integral = 0;
+        if(isset($params['user_integral'])){
+            $user_integral = $params['user_integral'];
         }
-        return true;
 
+        $user_money = 0;
+        if(isset($params['user_money'])){
+            $user_money = $params['user_money'];
+        }
+
+        if(isset($params['nickname'])){
+            $nickname = $params['nickname'];
+            if(empty($nickname)){
+                $nickname = $params['mobile'];
+            }
+        }else{
+            $nickname = $params['mobile'];
+        }
+        $passwordSalt = Config::get('project.unique_identification');
+        $password = create_password('123456', $passwordSalt);
+
+        //todo 后续补充用户资料
+        $saveData['nickname']           = $nickname;
+        $saveData['mobile']             = $mobile;
+        $saveData['sn']                 = create_user_sn();
+        $saveData['avatar']             = $avatar;
+        $saveData['password']           = $password;
+        $saveData['user_money']         = $user_money;
+        $saveData['user_integral']         = $user_integral;
+        $saveData['password']           = $password;
+        $saveData['code']               = generate_code();
+        $saveData['register_source']    = 8;
+        $saveData['is_new_user']        = 1;
+        $saveData['is_register_award']  = 0;
+        $saveData['offline_user_id']  = $offline_user_id;
+        $result = User::create($saveData);
+        return $result;
     }
 
+    public function updateUserData($params){
 
-    /**
-     * @notes 用户详情
-     * @param int $userId
-     * @return mixed
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @author cjhao
-     * @date 2021/8/18 15:52
-     */
-    public function detail($mobile)
-    {
-        $user = User::field('id,nickname,avatar,sex,mobile,birthday,level,create_time,user_money,user_earnings,user_money+user_earnings as total_user_money,user_integral,disable,user_delete')
-            ->with('user_level')
-            ->where(['mobile'=>$mobile])->find()->toArray();
-        if($user){
-            $user['user_level_name'] = $user['name'];
-            unset($user['name']);
-            unset($user['rank']);
-            unset($user['discount']);
+        $mobile = $params['mobile'];
+        $offline_user_id = 0;
+        if(isset($params['offline_user_id'])){
+            $offline_user_id = $params['offline_user_id'];
+        }
+
+        if(isset($params['nickname'])){
+            $nickname = $params['nickname'];
+            if(!empty($nickname)){
+                $updateData['nickname'] = $nickname;
+            }
+        }
+        if(isset($params['user_money'])){
+            $updateData['user_money'] = $params['user_money'];
+        }
+
+        if(isset($params['user_integral'])){
+            $updateData['user_integral'] = $params['user_integral'];
+        }
+        if(isset($params['user_level'])){
+            $updateData['level'] = $params['user_level'];
+            $updateData['offline_user_level'] = $params['user_level'];
+        }
+
+        if(isset($params['offline_user_id'])){
+            $offline_user_id = $params['offline_user_id'];
+            if($offline_user_id<>0){
+                $updateData['offline_user_id'] = $offline_user_id;
+            }
+        }
+
+
+        $result = User::where(['mobile'=>$params['mobile']])->update($updateData);
+        return $result;
+    }
+
+    /*
+     * 用户充值方法
+     * */
+    public function userRecharge(array $params):bool{
+        try {
+
+            $mobile = $params['mobile'];
+            $where['mobile'] = $mobile;
+            $user_info = User::where($where)->findOrEmpty();
+
+            if($user_info->isEmpty()) {
+                outFileLog($params, 'userRecharge', 'saveData');
+                self::setError('会员信息查询失败');
+                return false;
+            }else{
+                $online_user_money= round($user_info->user_money + $params['change_money'],2);
+                if(isset($params['user_money'])){
+                    if($online_user_money <> $params['user_money']){
+                        outFileLog($user_info,'userRecharge','数据不同-$user_info');
+                        outFileLog($params,'userRecharge','数据不同-$params');
+                        $online_user_money = $params['user_money'];
+                    }
+                }
+
+                $user_info->user_money = $online_user_money;
+                $result = $user_info->save();
+                if($result){
+                    //记录用户余额变动记录
+                    //记录日志
+                    AccountLogLogic::add($user_info->id, AccountLogEnum::OFFLINE_INC_MONEY, AccountLogEnum::INC,  $params['change_money'], '', '线下收银台充值同步增加用户余额');
+
+                    return true;
+                }else{
+                    outFileLog($params,'userRecharge','updateData');
+                    self::setError('更新会员数据失败');
+                    return false;
+                }
+            }
+            self::setError('同步失败,请稍后再试');
+            return false;
+        }catch(\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
         }
-        return $user;
     }
 
     /**
@@ -192,30 +283,7 @@ class UserLogic extends BaseLogic
 
     }
 
-    /**
-     * @notes 设置用户标签
-     * @param array $params
-     * @return bool
-     * @throws \Exception
-     * @author cjhao
-     * @date 2021/8/19 11:31
-     */
-    public function setUserLabel(array $params):bool {
-        //先删除用户标签,在重新设置用户标签
-        UserLabelIndex::where(['user_id'=>$params['user_id']])->delete();
-        $addData = [];
-        foreach ($params['label_ids'] as $labelId){
-            $addData[] = [
-                'user_id'   => $params['user_id'],
-                'label_id'  => $labelId,
-            ];
-        }
-        if($addData){
-            (new UserLabelIndex)->saveAll($addData);
-        }
-        return true;
 
-    }
 
     /**
      * @notes 调整用户余额
@@ -298,57 +366,7 @@ class UserLogic extends BaseLogic
 
     }
 
-    /**
-     * @notes 用户信息
-     * @author Tab
-     * @date 2021/9/13 19:33
-     */
-    public static function info($params)
-    {
-        $info = User::findOrEmpty($params['user_id'])->toArray();
-        if (empty($info)) {
-            $info = '';
-        } else {
-            $info = $info['sn'] . '(' . $info['nickname'] . ')';
-        }
-        $count = User::where('inviter_id', $params['user_id'])->count();
-        return [
-            'name' => $info,
-            'count' => $count
-        ];
-    }
 
-    /**
-     * @notes 上级分销商调整信息
-     * @param $params
-     * @return array
-     * @author Tab
-     * @date 2021/9/14 10:50
-     */
-    public static function adjustFirstLeaderInfo($params)
-    {
-        $userField = [
-            'id',
-            'sn',
-            'nickname',
-            'first_leader'
-        ];
-        $user = User::field($userField)->findOrEmpty($params['user_id'])->toArray();
-        if(empty($user['first_leader'])) {
-            $firstLeader = '系统';
-        } else {
-            $firstLeaderField = [
-                'id',
-                'sn',
-                'nickname',
-            ];
-            $firstLeader = User::field($firstLeaderField)->findOrEmpty($user['first_leader'])->toArray();
-        }
-        return [
-            'user' => $user,
-            'first_leader' => $firstLeader
-        ];
-    }
 
     /**
      * @notes
@@ -424,71 +442,5 @@ class UserLogic extends BaseLogic
         }
     }
 
-    /**
-     * @notes 指定上级分销商
-     * @param $params
-     * @return array
-     * @throws \think\Exception
-     * @author Tab
-     * @date 2021/9/14 11:44
-     */
-    public static function assignFirstLeader($params)
-    {
-        if (empty($params['first_id'])) {
-            throw new \think\Exception('请选择上级分销商');
-        }
-        if ($params['first_id'] ==  $params['user_id']) {
-            throw new \think\Exception('上级分销商不可以选择自己');
-        }
-        $firstLeader = User::field(['id', 'first_leader', 'second_leader', 'third_leader', 'ancestor_relation'])
-            ->where('id', $params['first_id'])
-            ->findOrEmpty()
-            ->toArray();
-        if(empty($firstLeader)) {
-            throw new \think\Exception('分销商不存在');
-        }
-        $ancestorRelation =explode(',', $firstLeader['ancestor_relation']);
-        if(!empty($ancestorRelation) && in_array($params['user_id'], $ancestorRelation)) {
-            throw new \think\Exception('不允许填写自己任一下级的邀请码');
-        }
 
-        // 上级
-        $first_leader_id = $firstLeader['id'];
-        // 上上级
-        $second_leader_id = $firstLeader['first_leader'];
-        // 上上上级
-        $third_leader_id = $firstLeader['second_leader'];
-        // 拼接关系链
-        $firstLeader['ancestor_relation'] = $firstLeader['ancestor_relation'] ?: ''; // 清空null值及0
-        $my_ancestor_relation = $first_leader_id. ',' . $firstLeader['ancestor_relation'];
-        // 去除两端逗号
-        $my_ancestor_relation = trim($my_ancestor_relation, ',');
-        $data = [
-            'first_leader'          => $first_leader_id,
-            'second_leader'         => $second_leader_id,
-            'third_leader'          => $third_leader_id,
-            'ancestor_relation'     => $my_ancestor_relation,
-            'admin_update_leader'   => 1,
-        ];
-        return $data;
-    }
-
-    /**
-     * @notes 清空上级
-     * @param $params
-     * @return array
-     * @author Tab
-     * @date 2021/9/14 11:46
-     */
-    public static function clearFirstLeader($params)
-    {
-        $data = [
-            'first_leader'          => 0,
-            'second_leader'         => 0,
-            'third_leader'          => 0,
-            'ancestor_relation'     => '',
-            'admin_update_leader'   => 1,
-        ];
-        return $data;
-    }
 }

+ 91 - 0
app/openapi/validate/OrderValidate.php

@@ -0,0 +1,91 @@
+<?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\validate;
+
+use app\common\model\UserLevel;
+
+/**
+ * 订单验证器
+ * Class UserValidate
+ * @package app\openapi\validate
+ */
+class OrderValidate extends BaseOpenValidate
+{
+    protected $rule = [
+
+        'type' => 'requireif:type,0|in:1,2',
+        'pageNo'=> 'requireif:pageNo,1|integer',
+        'orderSn' => 'requireif:orderSn,""',
+        'mobile' => 'require|mobile',
+        'goods_price'=>'requireif:goods_price,0|float|egt:0',
+        'order_amount'=>'requireif:order_amount,0|float|egt:0',
+        'discount_amount'=>'requireif:discount_amount,0|float|egt:0',
+        'member_amount'=>'requireif:member_amount,0|float|egt:0',
+        'integral_amount'=>'requireif:integral_amount,0|float|egt:0',
+        'total_amount'=>'require|float|gt:0',
+        'total_num'=>'require|integer|gt:0',
+        'create_time'=>'require|integer|gt:0',
+        'order_goods' =>'requireif:order_goods,""',
+        'refund_money'=>'require|float|gt:0',
+        'pay_way'=>'require|in:1,5',
+    ];
+    
+    protected $message = [
+        'mobile.require' => '请传入会员手机号',
+        'mobile.mobile' => '手机号格式不正确',
+        'goods_price.egt' => '订单商品总价必须大于等于0',
+        'order_amount.egt' => '应付款金额必须大于等于0',
+        'discount_amount.egt' => '优惠券金额必须大于等于0',
+        'member_amount.egt' => '会员价优惠金额必须大于等于0',
+        'integral_amount.egt' => '积分抵扣金额必须大于等于0',
+        'total_amount.gt' => '订单总价必须大于0',
+        'total_num.gt' => '订单商品数量必须大于0',
+        'create_time.gt' => '订单添加时间必须大于0',
+        'refund_money.require' => '请输入退款金额',
+        'refund_money.gt' => '退款金额必须大于0',
+        'pay_way.require' => '请传入支付方式',
+
+    ];
+    
+    protected $scene = [
+        'getOrderList' => ['mobile','type','pageNo','orderSn'],
+        'orderPush' => ['orderSn','mobile','pay_way','goods_price','order_amount','discount_amount','member_amount','integral_amount','total_amount','total_num','create_time','order_goods'],
+        'orderRefundMoney' => ['mobile','refund_money','orderSn','remark'],
+    ];
+
+    /**
+     * @notes 检查订单商品id是否存在
+     * @param $value
+     * @param $rule
+     * @param $data
+     * @return bool|string
+     * @author ljj
+     * @date 2021/8/10 2:00 下午
+     */
+    public function checkUserLevel($value,$rule,$data)
+    {
+        if($value == 0) return true;
+        $user_level = UserLevel::where('offline_user_level_id', $value)->findOrEmpty();
+        if ($user_level->isEmpty()) {
+            return '会员等级不存在';
+        }
+        return true;
+    }
+}

+ 100 - 0
app/openapi/validate/UserLevelValidate.php

@@ -0,0 +1,100 @@
+<?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\validate;
+
+use app\common\model\UserLevel;
+use app\shopapi\validate\DistributionValidate;
+
+/**
+ * 用户等级验证器
+ * Class UserValidate
+ * @package app\openapi\validate
+ */
+class UserLevelValidate extends BaseOpenValidate
+{
+    protected $rule = [
+        'name' => 'require|checkName',
+        'discount'=>'require|float|egt:0',
+        'rank'=>'require|integer|egt:0',
+        'offline_user_level_id'=>'require',
+        'remark'=>'requireif:remark,""',
+        'condition'=>'requireif:condition,""',
+    ];
+    
+    protected $message = [
+        'name.require' => '等级名称不能为空',
+//        'name.max' => '等级名称不能超过50个字符',
+        'discount.require' => '等级折扣必传',
+        'rank.require' => '等级权重必传',
+        'rank.egt' => '等级权重大于等于0',
+        'discount.egt' => '等级折扣大于等于0',
+        'offline_user_level_id.require' => '线下会员等级id必传',
+    ];
+    
+    protected $scene = [
+        'getUserLevelLists' => ['level_name'],
+        'addUserLevel' => ['offline_user_level_id','name','discount','rank','remark','condition'],
+        'updateUserLevelInfo' => ['offline_user_level_id','name','discount','rank','remark','condition'],
+        'delUserLevel' => ['name']
+    ];
+
+    /**
+     * @notes 检查等级名称是否存在
+     * @param $value
+     * @param $rule
+     * @param $data
+     * @return bool|string
+     * @author ljj
+     * @date 2021/8/10 2:00 下午
+     */
+    public function checkName($value,$rule,$data)
+    {
+        if($value == 0) return true;
+        $user_level = UserLevel::where('name', $value)->findOrEmpty();
+        if ($user_level->isEmpty()) {
+            return true;
+        }else{
+            return '已存在该会员等级名称';
+        }
+
+    }
+
+    /**
+     * @notes
+     * @return DistributionValidate
+     * @author Tab
+     * @date 2021/7/17 10:18
+     */
+    public function sceneUpdateUserLevelInfo()
+    {
+        return $this->remove('name', 'checkName');
+    }
+    /**
+     * @notes
+     * @return DistributionValidate
+     * @author Tab
+     * @date 2021/7/17 10:18
+     */
+    public function sceneDelUserLevel()
+    {
+        return $this->remove('name', 'checkName')->remove('discount', 'require')
+            ->remove('rank', 'require')->remove('offline_user_level_id', 'require');
+    }
+}

+ 36 - 1
app/openapi/validate/UserValidate.php

@@ -19,6 +19,8 @@
 
 namespace app\openapi\validate;
 
+use app\common\model\UserLevel;
+
 /**
  * 用户验证器
  * Class UserValidate
@@ -31,6 +33,11 @@ class UserValidate extends BaseOpenValidate
         'nickname' => 'max:50',
         'avatar' => 'url',
         'mobile' => 'require|mobile',
+        'user_money'=>'requireif:user_money,0|float|gt:0',
+        'change_money'=>'require|float|egt:0',
+        'user_integral'=>'integer|egt:0',
+        'offline_user_id'=>'gt:0',
+        'user_level' =>'integer|gt:0|checkUserLevel',
     ];
     
     protected $message = [
@@ -41,11 +48,39 @@ class UserValidate extends BaseOpenValidate
         'avatar.url' => '头像必须是有效的URL',
         'mobile.require' => '请传入会员手机号',
         'mobile.mobile' => '手机号格式不正确',
+        'user_money.require' => '用户余额必传',
+        'user_money.egt' => '用户余额必须大于等于0',
+        'user_integral.egt' => '用户积分必须大于等于0',
+        'user_level.integer' => '用户等级ID必须为整数',
+        'user_level.gt' => '用户等级ID必须大于0',
+        'change_money.require' => '充值金额必传',
+        'change_money.gt' => '充值金额必须大于0',
     ];
     
     protected $scene = [
         'info' => ['user_id'],
         'getUserInfo' => ['mobile'],
-        'update' => ['user_id', 'nickname', 'avatar', 'mobile'],
+        'addUser' => ['offline_user_id','mobile','nickname','user_money','user_integral','user_level'],
+        'updateUserInfo' => ['offline_user_id','mobile','nickname','user_money','user_integral','user_level'],
+        'userRecharge' => ['mobile','change_money','user_money'],
     ];
+
+    /**
+     * @notes 检查订单商品id是否存在
+     * @param $value
+     * @param $rule
+     * @param $data
+     * @return bool|string
+     * @author ljj
+     * @date 2021/8/10 2:00 下午
+     */
+    public function checkUserLevel($value,$rule,$data)
+    {
+        if($value == 0) return true;
+        $user_level = UserLevel::where('offline_user_level_id', $value)->findOrEmpty();
+        if ($user_level->isEmpty()) {
+            return '会员等级不存在';
+        }
+        return true;
+    }
 }