Ken 1 mēnesi atpakaļ
vecāks
revīzija
3d2e7e2983

+ 0 - 113
app/Services/AboutService.php

@@ -1,113 +0,0 @@
-<?php
-
-namespace App\Services;
-use App\Services\BaseService;
-use App\Models\About;
-
-class AboutService extends BaseService
-{
-
-    public static $MODEL= About::class;
-
-    
-    /**
-     * @description: 获取查询条件
-     * @param {array} $search 查询内容
-     * @return {array}
-     */
-    public static function getWhere(array $search = []): array
-    {
-        $where = [];
-        if (isset($search['id']) && $search['id'] !== '') {
-            $where[] = ['id', '=',  $search['id']];
-        }
-        if (isset($search['language']) && $search['language'] !== '') {
-            $where[] = ['language', '=',  $search['language']];
-        }
-        if (isset($search['status']) && $search['status'] !== '') {
-            $where[] = ['status', '=',  $search['status']];
-        }
-        if (isset($search['title']) && $search['title'] !== '') {
-            $where[] = ['title', 'like', '%' . $search['title'] . '%'];
-        }
-        return $where;
-    }
-
-    /**
-     * @description: 查询单条数据
-     * @param array $search
-     * @return 
-     */
-    public static function findOne(array $search)
-    {
-        return static::model()::where(static::getWhere($search))->first();
-    }
-
-    /**
-     * @description: 查询所有数据
-     * @param array $search
-     * @return \Illuminate\Database\Eloquent\Collection
-     */
-    public static function findAll(array $search = [])
-    {
-        return static::model()::where(static::getWhere($search))->get();
-    }
-    
-
-    /**
-     * @description: 分页查询
-     * @param array $search
-     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
-     */
-    public static function paginate(array $search = [])
-    {
-
-        $limit = isset($search['limit']) ? $search['limit'] : 15;
-        $paginator = static::model()::where(static::getWhere($search))
-            ->orderBy('updated_at', 'desc')
-            ->paginate($limit);
-        return ['total' => $paginator->total(), 'data' => $paginator->items()];
-    }
-
-
-     /**
-     * @description: 
-     * @param {*} $params
-     * @return {*}
-     */    
-    public static function submit($params = [])
-    {
-        $result = false;
-        $msg['code'] = self::NOT;
-        $msg['msg'] = '';
-
-        // 2. 判断是否是更新
-        if (!empty($params['id'])) {
-            // 更新
-            $info = self::findOne(['id'=>$params['id']] );
-            if (!$info) {
-                $msg['msg'] = '数据不存在!';
-            }else{
-                $result = $info->update($params);
-                $id = $params['id'];
-            }
-
-        } else {
-            // 创建
-            $result = $info = self::model()::create($params);
-            $id = $result->id;
-        }
-        
-       
-        if($result){
-           $msg['code'] = self::YES;
-           $msg['msg'] = '设置成功';
-        }else{
-            $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
-        }
-
-        return $msg;
-    }
-
-
-}

+ 0 - 76
app/Services/AdminService.php

@@ -1,76 +0,0 @@
-<?php
-
-
-namespace App\Services;
-use App\Services\BaseService;
-use App\Models\Admin;
-
-class AdminService extends BaseService
-{
-    const STATUS_YES = 1;   // 状态正常
-    const STATUS_NOT = 0;   // 状态禁用
-
-
-    public static $MODEL= Admin::class;
-
-
-    
-    /**
-     * @description: 获取查询条件
-     * @param {array} $search 查询内容
-     * @return {array}
-     */
-    public static function getWhere(array $search = []): array
-    {
-        $where = [];
-        if (isset($search['id']) && $search['id'] !== '') {
-            $where[] = ['id', '=',  $search['id']];
-        }
-        if (isset($search['account']) && $search['account'] !== '') {
-            $where[] = ['account', '=',  $search['account']];
-        }
-        if (isset($search['nickname']) && $search['nickname'] !== '') {
-            $where[] = ['nickname', 'like', '%' . $search['nickname'] . '%'];
-        }
-        if (isset($search['status']) && $search['status'] !== '') {
-            $where[] = ['status', '=', intval($search['status'])];
-        }
-        return $where;
-    }
-
-    /**
-     * @description: 查询单条数据
-     * @param array $search
-     * @return 
-     */
-    public static function findOne(array $search)
-    {
-        return static::model()::where(static::getWhere($search))->first();
-    }
-
-    /**
-     * @description: 查询所有数据
-     * @param array $search
-     * @return \Illuminate\Database\Eloquent\Collection
-     */
-    public static function findAll(array $search = [])
-    {
-        return static::model()::where(static::getWhere($search))->get();
-    }
-
-    /**
-     * @description: 分页查询
-     * @param array $search
-     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
-     */
-    public static function paginate(array $search = [])
-    {
-
-        $limit = isset($search['limit']) ? $search['limit'] : 15;
-        $paginator = static::model()::where(static::getWhere($search))
-            ->orderBy('updated_at', 'desc')
-            ->paginate($limit);
-        return ['total' => $paginator->total(), 'data' => $paginator->items()];
-    }
-
-}

+ 0 - 465
app/Services/OrderService.php

@@ -1,465 +0,0 @@
-<?php
-
-namespace App\Services;
-use App\Services\BaseService;
-use App\Services\UserService;
-use App\Services\ProductService;
-use App\Models\Order;
-use Illuminate\Support\Str;
-use Illuminate\Support\Facades\DB;
-
-class OrderService extends BaseService
-{
-
-    public static $MODEL= Order::class;
-
-    const STATUS_YES = 1;
-    const STATUS_NOT = 0;
-    
-    /**
-     * @description: 获取查询条件
-     * @param {array} $search 查询内容
-     * @return {array}
-     */
-    public static function getWhere(array $search = []): array
-    {
-        $where = [];
-        if (isset($search['id']) && $search['id'] !== '') {
-            $where[] = ['id', '=',  $search['id']];
-        }
-        if (isset($search['user_id']) && $search['user_id'] !== '') {
-            $where[] = ['user_id', '=',  $search['user_id']];
-        }
-        if (isset($search['order_no']) && $search['order_no'] !== '') {
-            $where[] = ['order_no', '=',  $search['order_no']];
-        }
-        if (isset($search['status']) && $search['status'] !== '') {
-            $where[] = ['status', '=',  $search['status']];
-        }
-        if (isset($search['order_date']) && $search['order_date'] !== '') {
-            $where[] = ['order_date', '=',  $search['order_date']];
-        }
-        if (isset($search['paid_date']) && $search['paid_date'] !== '') {
-            $where[] = ['paid_date', '=',  $search['paid_date']];
-        }
-        if (isset($search['product_id']) && $search['product_id'] !== '') {
-            $where[] = ['product_id', '=',  $search['product_id']];
-        }
-        return $where;
-    }
-
-    /**
-     * @description: 查询单条数据
-     * @param array $search
-     * @return 
-     */
-    public static function findOne(array $search)
-    {
-        return static::model()::where(static::getWhere($search))->first();
-    }
-
-    /**
-     * @description: 查询所有数据
-     * @param array $search
-     * @return \Illuminate\Database\Eloquent\Collection
-     */
-    public static function findAll(array $search = [])
-    {
-        return static::model()::where(static::getWhere($search))->get();
-    }
-    
-
-    /**
-     * @description: 分页查询
-     * @param array $search
-     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
-     */
-    public static function paginate(array $search = [])
-    {
-
-        $limit = isset($search['limit']) ? $search['limit'] : 15;
-        $paginator = static::model()::where(static::getWhere($search))
-            ->orderBy('id', 'desc')
-            ->paginate($limit);
-        return ['total' => $paginator->total(), 'data' => $paginator->items()];
-    }
-
-
-     /**
-     * @description: 
-     * @param {*} $params
-     * @return {*}
-     */    
-    public static function submit($params = [])
-    {
-        $result = false;
-        $msg['code'] = self::NOT;
-        $msg['msg'] = '';
-
-        // 2. 判断是否是更新
-        if (!empty($params['id'])) {
-            // 更新
-            $info = self::findOne(['id'=>$params['id']] );
-            if (!$info) {
-                $msg['msg'] = '数据不存在!';
-            }else{
-                $result = $info->update($params);
-                $id = $params['id'];
-            }
-
-        } else {
-            // 创建
-            $result = $info = self::model()::create($params);
-            $id = $result->id;
-        }
-        
-       
-        if($result){
-           $msg['code'] = self::YES;
-           $msg['msg'] = '设置成功';
-        }else{
-            $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
-        }
-
-        return $msg;
-    }
-
-    /**
-     * @description: 分配订单
-     * @param {*} $user_id 用户ID
-     * @return {*}
-     */    
-    public static function assignOrder($user_id)
-    {
-        $result = [];
-        $result['code'] = self::NOT;
-        $result['data'] = [];
- 
-        $today = date('Y-m-d');
-        // // 查找个人待处理订单
-        // $pendingOrder = self::findOne(['user_id' => $user_id,'status' => self::STATUS_NOT]);
-
-        // 用户信息
-        $userInfo = UserService::findOne(['id' => $user_id]);
-        $balance = $userInfo->balance;  // 余额
-
-        $productPriceMax = config_val('product_price_max');   // 商品最高价
-
-        $maxOrderQuantity = $userInfo->membership->quantity;    // 用户每日可完单限制
-        if($maxOrderQuantity > 0){
-            // 今日完单数
-            $todayCompleteQuantity = static::model()::where(self::getWhere(['user_id' => $user_id ,'status' => self::STATUS_YES]))->count();
-            if($todayCompleteQuantity >= $maxOrderQuantity){
-                if($userInfo->membership_level_code =='silver'){
-                    $result['msg'] = '恭喜您,今日订单已完成!可在升级黄金会员后继续新一轮订单';
-                }else{
-                    $result['msg'] = '恭喜您,今日订单已完成!可在升级钻石会员后继续新一轮订单';
-                }
-                return $result;
-            }
-        }
-
-        $minPrice = 0;  // 最低消费
-
-        // 已完成数量
-        $completeQuantity = static::model()::where(self::getWhere(['user_id' => $user_id ,'status' => self::STATUS_YES]))->count();
-        // 达到卡单数
-        if(($completeQuantity + 1) == $userInfo->blocked_order){
-            $minPrice = bcadd($balance, $userInfo->blocked_amount, 4);  // 计算最低消息
-        }
-
-        
-        $product_commission_min = config_val('product_commission_min'); // 商品佣金最低
-        $product_commission_max = config_val('product_commission_max'); // 商品佣金最高
-
-           
-
-        // 已下单的商品id集合
-        // $productIds = static::model()::where(self::getWhere(['user_id' => $user_id]))->pluck('product_id');  
-        $productIds = [];  
-        
-        // 随机的商品信息
-        $randomProduct = ProductService::getRandom($productIds,$balance,$minPrice);
-        if(empty($randomProduct)){
-            $result['msg'] = '暂无适合的商品,请稍后再试';
-            return $result;
-        }
-
-        $productPrice = $randomProduct->price; // 商品价格
-
-        if($minPrice > 0){
-            $price = $minPrice;
-        }else{
-            if($balance < $productPrice){
-                $price = bcadd($productPrice,rand(10,50),2);
-            }else{
-                $priceMin = bcmul($balance,0.3,2);    // 最低价
-                if($balance > 10000){
-                    $priceMin = 1000;
-                }
-                if($priceMin < $productPrice){
-                    $priceMin = $productPrice;
-                }
-                $priceMax = bcmul($balance,0.7,2);    // 最高价
-                if($priceMax < $productPrice){
-                    $priceMax = $productPrice;
-                }
-                if($priceMax > $productPriceMax){
-                    $priceMax = $productPriceMax;
-                }
-                $price = random_float($priceMin,$priceMax,4);
-            }
-        }
-
-        $price = retain_number_format($price);
-
-        $commission = bcmul($price,random_float($product_commission_min,$product_commission_max,4),4); 
-
-        if($minPrice > 0){
-            $commission = $userInfo->blocked_profit; //  卡單默認佣金
-        }
-        $commission = retain_number_format($commission);
-
-        $data = [];
-        $data['order_no'] = self::generalOrderNo($user_id); // 订单号
-        $data['user_id'] = $user_id;    // 用户
-        $data['product_id'] = $randomProduct->id;   // 商品ID
-        $data['price'] = $price;   // 商品价格
-        $data['commission'] = $commission;   // 商品佣金
-        $data['product_snapshot'] = json_encode($randomProduct,JSON_UNESCAPED_UNICODE); // 商品快照
-        $data['status'] = self::STATUS_NOT; // 订单待处理
-        $data['order_date'] = date('Y-m-d');    // 订单日期
-        // $data['paid_date'] = date('Y-m-d');    // 完单日期
-
-        $order =  static::model()::create($data);
-
-        if($order){
-            $result['code'] = self::YES;
-            $result['msg'] = '订单已生成,请尽快支付';
-            $result['data'] = $order;
-        }else{
-            $result['msg'] = '分配订单失败,请稍后再试';
-        }
-        return $result;
-
-    }
-
-    // 生成随机的订单号
-    public static function generalOrderNo($user_id = 0)
-    {
-        $orderNo = 'ORD' . now()->format('YmdHis') . Str::random(6).'_'.$user_id;
-        return $orderNo;
-    }
-
-    /**
-     * @description: 订单支付
-     * @param {*} $orderNo 订单号
-     * @param {*} $userId 用户ID
-     * @return {*}
-     */    
-    public static function paymentOrder($orderNo,$userId)
-    {
-        $result = [];
-        $result['code'] = self::NOT;
-        $orderInfo = self::findOne(['order_no' => $orderNo ,'user_id' => $userId]);
-        if(!$orderInfo){
-            $result['msg'] = '未找到相关订单数据';
-            return $result;
-        }
-
-        if($orderInfo->status == self::STATUS_YES){
-            $result['msg'] = '订单已支付,请勿重复提交';
-            return $result;
-        }
-
-        $userInfo = UserService::findOne(['id' => $userId]);
-
-        $balance = $userInfo->balance;  // 余额
-        $chaMoney = bcsub($orderInfo->price,$balance,2);
-        if($balance < $orderInfo->price){
-            $result['msg'] = lang('当前账户余额不足,完成此订单还差{money},请先完成充值');
-            $result['msg'] = str_replace('{money}',$chaMoney,$result['msg']);
-            $result['money'] =  $chaMoney;
-            return $result;
-        }
-        // $afterBalance = bcsub($balance,$orderInfo->price,4);
-        if(bcsub($balance,$orderInfo->price,4) < 0){
-            $result['msg'] = lang('当前账户余额不足,完成此订单还差{money},请先完成充值');
-            $result['msg'] = str_replace('{money}',$chaMoney,$result['msg']);
-            $result['money'] =  $chaMoney;
-            return $result;
-        }
-
-        // 能支付成功直接返佣
-        $afterBalance = bcadd($balance,$orderInfo->commission,4);
-        
-        DB::beginTransaction();
-        try {
-            // 更新用户余额
-            $userInfo->balance = $afterBalance;
-            $userInfo->save();
-          
-          	
-          
-
-            $orderInfo->status = self::STATUS_YES;
-            $orderInfo->paid_date = date('Y-m-d');
-            $orderInfo->save();
-
-            // 支付
-            $log = UserBalanceLogService::addLog(
-                $userId,
-                '佣金',
-                $balance,
-                $orderInfo->commission,
-                '订单:'.$orderNo
-            );
-          
-          	// 60单发奖励
-            if(static::model()::where(self::getWhere(['user_id' => $userId ,'status' => self::STATUS_YES]))->count() == 60){
-                $profit = rand(config_val('bonus_min'),config_val('bonus_max'));
-                // 一级返
-                if($userInfo->inviter_id_1){
-                    self::inviterBonus($userInfo->inviter_id_1,$profit,$orderNo);
-                }
-            }
-          
-            if($log['code'] == self::NOT){
-                DB::rollBack();
-                return $log;
-            }
-            
-            // // 一级返
-            // if($userInfo->inviter_id_1){
-            //     $percentage = config_val('inviter_commission_1');
-            //     self::inviterCommission($userInfo->inviter_id_1,$orderInfo->commission,$percentage,$orderNo);
-            // }
-            // // 二级返
-            // if($userInfo->inviter_id_2){
-            //     $percentage = config_val('inviter_commission_2');
-            //     self::inviterCommission($userInfo->inviter_id_2,$orderInfo->commission,$percentage,$orderNo);
-            // }
-            // // 三级返
-            // if($userInfo->inviter_id_3){
-            //     $percentage = config_val('inviter_commission_3');
-            //     self::inviterCommission($userInfo->inviter_id_3,$orderInfo->commission,$percentage,$orderNo);
-            // }
-
-            DB::commit();
-
-            $msg['code'] = self::YES;
-            $msg['msg'] = '刷单成功';
-            return $msg;
-
-        } catch (\Exception $e) {
-            DB::rollBack();
-            
-            $msg['msg'] = $e->getMessage();
-            return $msg;
-        }
-
-    }
-
-    /**
-     * @description: 分佣
-     * @param {*} $user_id 用户ID
-     * @param {*} $amount   分佣金额
-     * @param {*} $percentage 比例
-     * @return {*}
-     */    
-    public static function inviterCommission($userId, $amount, $percentage, $orderNo)
-    {
-        $userInfo = UserService::findOne(['id' => $userId]);
-        if($userInfo){
-            $balance = $userInfo->balance;
-            
-            // 使用高精度乘法,设置合适的精度(比如4位小数)
-            $changeAmount = bcmul($amount, $percentage, 8); // 中间计算使用较高精度
-            
-            // 如果需要最终结果保留4位小数
-            $changeAmount = bcadd($changeAmount, '0', 4);
-            
-            // 支付
-            UserBalanceLogService::addLog(
-                $userId,
-                '分佣',
-                $balance,
-                $changeAmount,
-                '订单:'.$orderNo
-            );
-        }
-    }
-
-    /**
-     * @description: 
-     * @param {*} $user_id 用户ID
-     * @param {*} $profit   奖金
-     * @param {*} $orderNo 订单
-     * @return {*}
-     */    
-    public static function inviterBonus($userId, $profit, $orderNo)
-    {
-        $userInfo = UserService::findOne(['id' => $userId]);
-        if($userInfo){
-            $balance = $userInfo->balance;
-            
-            $changeAmount = $profit;
-            
-            // 支付
-            UserBalanceLogService::addLog(
-                $userId,
-                '代理奖金',
-                $balance,
-                $changeAmount,
-                '订单:'.$orderNo
-            );
-          	$userInfo->balance = bcadd($balance,$profit,2);
-            $userInfo->save();
-        }
-    }
-
-    /**
-     * @description: 统计订单数据
-     * @param {*} $user_id
-     * @return {*}
-     */    
-    public static function statOrder($userId)
-    {
-        $result = [];
-        $userInfo = UserService::findOne(['id' => $userId]);
-        $result['balance'] = $userInfo->balance??0;
-        $result['membership_name'] = $userInfo->membership_name??'';
-        $result['membership_level_code'] = $userInfo->membership_level_code??'';
-        // $result['userInfo'] = $userInfo;
-
-        $today = date('Y-m-d');
-        $yesterday = date('Y-m-d',(time() - 86400));
-
-        // 总收益
-        $result['total_profit'] = static::model()::where(self::getWhere(['user_id' => $userId ,'status' => self::STATUS_YES]))->sum('commission');
-
-        // 今日收益
-        $result['today_profit'] = static::model()::where(self::getWhere(['user_id' => $userId ,'status' => self::STATUS_YES ,'order_date' => $today]))->sum('commission');
-
-        // 昨日收益
-        $result['yesterday_profit'] = static::model()::where(self::getWhere(['user_id' => $userId ,'status' => self::STATUS_YES ,'order_date' => $yesterday]))->sum('commission');
-
-        // 总单数
-        $result['total_count'] = static::model()::where(self::getWhere(['user_id' => $userId ,'status' => self::STATUS_YES]))->count();
-
-        // 未完成
-        $result['total_pending_count'] = static::model()::where(self::getWhere(['user_id' => $userId ,'status' => self::STATUS_NOT]))->count();
-
-        // 今日单数
-        $result['today_count'] = static::model()::where(self::getWhere(['user_id' => $userId ,'status' => self::STATUS_YES ,'order_date' => $today]))->count();
-
-        // 昨日单数
-        $result['yesterday_count'] = static::model()::where(self::getWhere(['user_id' => $userId ,'status' => self::STATUS_YES ,'order_date' => $yesterday]))->count();
-
-
-
-        return $result;
-
-    }
-
-}

+ 0 - 146
app/Services/ProductService.php

@@ -1,146 +0,0 @@
-<?php
-
-namespace App\Services;
-use App\Services\BaseService;
-use App\Models\Product;
-
-class ProductService extends BaseService
-{
-
-    public static $MODEL= Product::class;
-
-    const STATUS_YES = 1;
-    const STATUS_NOT = 0;
-    
-    /**
-     * @description: 获取查询条件
-     * @param {array} $search 查询内容
-     * @return {array}
-     */
-    public static function getWhere(array $search = []): array
-    {
-        $where = [];
-        if (isset($search['id']) && $search['id'] !== '') {
-            $where[] = ['id', '=',  $search['id']];
-        }
-        if (isset($search['is_top']) && $search['is_top'] !== '') {
-            $where[] = ['is_top', '=',  $search['is_top']];
-        }
-        if (isset($search['status']) && $search['status'] !== '') {
-            $where[] = ['status', '=',  $search['status']];
-        }
-        if (isset($search['min_price']) && $search['min_price'] !== '') {
-            $where[] = ['price', '>',  $search['min_price']];
-        }
-        if (isset($search['max_price']) && $search['max_price'] !== '') {
-            $where[] = ['price', '<',  $search['max_price']];
-        }
-        if (isset($search['name']) && $search['name'] !== '') {
-            $where[] = ['name', 'like', '%' . $search['name'] . '%'];
-        }
-        return $where;
-    }
-
-    /**
-     * @description: 查询单条数据
-     * @param array $search
-     * @return 
-     */
-    public static function findOne(array $search)
-    {
-        return static::model()::where(static::getWhere($search))->first();
-    }
-
-    /**
-     * @description: 查询所有数据
-     * @param array $search
-     * @return \Illuminate\Database\Eloquent\Collection
-     */
-    public static function findAll(array $search = [])
-    {
-        return static::model()::where(static::getWhere($search))->get();
-    }
-    
-
-    /**
-     * @description: 分页查询
-     * @param array $search
-     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
-     */
-    public static function paginate(array $search = [])
-    {
-
-        $limit = isset($search['limit']) ? $search['limit'] : 15;
-        $paginator = static::model()::where(static::getWhere($search))
-            ->orderBy('id', 'desc')
-            ->paginate($limit);
-        return ['total' => $paginator->total(), 'data' => $paginator->items()];
-    }
-
-
-     /**
-     * @description: 
-     * @param {*} $params
-     * @return {*}
-     */    
-    public static function submit($params = [])
-    {
-        $result = false;
-        $msg['code'] = self::NOT;
-        $msg['msg'] = '';
-
-        // 2. 判断是否是更新
-        if (!empty($params['id'])) {
-            // 更新
-            $info = self::findOne(['id'=>$params['id']] );
-            if (!$info) {
-                $msg['msg'] = '数据不存在!';
-            }else{
-                $result = $info->update($params);
-                $id = $params['id'];
-            }
-
-        } else {
-            // 创建
-            $result = $info = self::model()::create($params);
-            $id = $result->id;
-        }
-        
-       
-        if($result){
-           $msg['code'] = self::YES;
-           $msg['msg'] = '设置成功';
-        }else{
-            $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
-        }
-
-        return $msg;
-    }
-
-    /**
-     * @description: 获取随机的商品
-     * @param {*} $notInIds 排除的商品
-     * @param {*} $maxPrice 最高金额
-     * @param {*} $minPrice 最低金额
-     * @return {*}
-     */    
-    public static function getRandom($notInIds = [] ,$maxPrice = 0 ,$minPrice = 0)
-    {
-        // // 有最低消费 优先找大于最低消费的
-        // if($minPrice > 0){
-        //     $info = static::model()::where(self::getWhere(['min_price' => $minPrice ,'status' => self::STATUS_YES]))->whereNotIn('id',$notInIds)->orderBy('price','asc')->first();
-        //     return $info;
-        // }
-
-        // 先找适合自己余额的商品
-        $info = static::model()::where(self::getWhere(['max_price' => $maxPrice ,'status' => self::STATUS_YES]))->whereNotIn('id',$notInIds)->inRandomOrder()->first();
-        if(!$info){
-            // 随机商品
-            $info = static::model()::where(self::getWhere(['min_price' => $minPrice ,'status' => self::STATUS_YES]))->whereNotIn('id',$notInIds)->orderBy('price','asc')->first();
-            return $info;
-        }
-        return $info;
-    }
-
-
-}

+ 0 - 142
app/Services/UserBalanceLogService.php

@@ -1,142 +0,0 @@
-<?php
-
-namespace App\Services;
-
-use App\Services\BaseService;
-use App\Models\UserBalanceLog;
-
-class UserBalanceLogService extends BaseService
-{
-
-    public static $MODEL = UserBalanceLog::class;
-
-
-    /**
-     * @description: 获取查询条件
-     * @param {array} $search 查询内容
-     * @return {array}
-     */
-    public static function getWhere(array $search = []): array
-    {
-        $where = [];
-        if (isset($search['id']) && $search['id'] !== '') {
-            $where[] = ['id', '=', $search['id']];
-        }
-        if (isset($search['user_id']) && $search['user_id'] !== '') {
-            $where[] = ['user_id', '=', $search['user_id']];
-        }
-        if (isset($search['change_type']) && $search['change_type'] !== '') {
-            $where[] = ['change_type', '=', $search['change_type']];
-        }
-        if (isset($search['type']) && $search['type'] !== '') {
-            if ($search['type'] == self::YES) {
-                $where[] = ['change_amount', '>', 0];
-            } else {
-                $where[] = ['change_amount', '<', 0];
-            }
-        }
-        return $where;
-    }
-
-    /**
-     * @description: 查询单条数据
-     * @param array $search
-     * @return
-     */
-    public static function findOne(array $search)
-    {
-        return static::model()::where(static::getWhere($search))->first();
-    }
-
-    /**
-     * @description: 查询所有数据
-     * @param array $search
-     * @return \Illuminate\Database\Eloquent\Collection
-     */
-    public static function findAll(array $search = [])
-    {
-        return static::model()::where(static::getWhere($search))->get();
-    }
-
-
-    /**
-     * @description: 分页查询
-     * @param array $search
-     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
-     */
-    public static function paginate(array $search = [])
-    {
-
-        $limit = isset($search['limit']) ? $search['limit'] : 15;
-        $paginator = static::model()::where(static::getWhere($search))
-            ->orderBy('updated_at', 'desc')
-            ->paginate($limit);
-        return ['total' => $paginator->total(), 'data' => $paginator->items()];
-    }
-
-
-    /**
-     * @description:
-     * @param {*} $params
-     * @return {*}
-     */
-    public static function submit($params = [])
-    {
-        $result = false;
-        $msg['code'] = self::NOT;
-        $msg['msg'] = '';
-
-        // 2. 判断是否是更新
-        if (!empty($params['id'])) {
-            // 更新
-            $info = self::findOne(['id' => $params['id']]);
-            if (!$info) {
-                $msg['msg'] = '数据不存在!';
-            } else {
-                $result = $info->update($params);
-                $id = $params['id'];
-            }
-
-        } else {
-            // 创建
-            $result = $info = self::model()::create($params);
-            $id = $result->id;
-        }
-
-
-        if ($result) {
-            $msg['code'] = self::YES;
-            $msg['msg'] = '设置成功';
-        } else {
-            $msg['msg'] = empty($msg['msg']) ? '操作失败' : $msg['msg'];
-        }
-
-        return $msg;
-    }
-
-    /**
-     * 添加日志
-     *
-     * @param int $userId
-     * @param string|null $changeType 类型
-     * @param string|null $beforeBalance 变动前余额
-     * @param string|null $changeAmount 变动金额
-     * @param string|null $remark 备注
-     * @return array
-     */
-    public static function addLog($userId, $changeType = '', $beforeBalance = '', $changeAmount = '', $remark = '', $withdrawsId = null)
-    {
-        $afterBalance = bcadd($beforeBalance, $changeAmount, 4);
-        $params = [
-            'user_id' => $userId,
-            'change_type' => $changeType,
-            'before_balance' => $beforeBalance,
-            'change_amount' => $changeAmount,
-            'after_balance' => $afterBalance,
-            'remark' => $remark,
-            'withdraws_id' => $withdrawsId
-        ];
-
-        return self::submit($params);
-    }
-}

+ 0 - 117
app/Services/UserBankCardService.php

@@ -1,117 +0,0 @@
-<?php
-
-namespace App\Services;
-use App\Services\BaseService;
-use App\Models\UserBankCard;
-
-class UserBankCardService extends BaseService
-{
-
-    public static $MODEL= UserBankCard::class;
-
-
-    
-    /**
-     * @description: 获取查询条件
-     * @param {array} $search 查询内容
-     * @return {array}
-     */
-    public static function getWhere(array $search = []): array
-    {
-        $where = [];
-        if (isset($search['id']) && $search['id'] !== '') {
-            $where[] = ['id', '=',  $search['id']];
-        }
-        if (isset($search['user_id']) && $search['user_id'] !== '') {
-            $where[] = ['user_id', '=',  $search['user_id']];
-        }
-        if (isset($search['bank_name']) && $search['bank_name'] !== '') {
-            $where[] = ['bank_name', '=',  $search['bank_name']];
-        }
-        if (isset($search['card_number']) && $search['card_number'] !== '') {
-            $where[] = ['card_number', '=',  $search['card_number']];
-        }
-        if (isset($search['card_holder']) && $search['card_holder'] !== '') {
-            $where[] = ['card_holder', '=',  $search['card_holder']];
-        }
-
-        return $where;
-    }
-
-    /**
-     * @description: 查询单条数据
-     * @param array $search
-     * @return 
-     */
-    public static function findOne(array $search)
-    {
-        return static::model()::where(static::getWhere($search))->first();
-    }
-
-    /**
-     * @description: 查询所有数据
-     * @param array $search
-     * @return \Illuminate\Database\Eloquent\Collection
-     */
-    public static function findAll(array $search = [])
-    {
-        return static::model()::where(static::getWhere($search))->get();
-    }
-    
-
-    /**
-     * @description: 分页查询
-     * @param array $search
-     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
-     */
-    public static function paginate(array $search = [])
-    {
-
-        $limit = isset($search['limit']) ? $search['limit'] : 15;
-        $paginator = static::model()::where(static::getWhere($search))
-            ->orderBy('updated_at', 'desc')
-            ->paginate($limit);
-        return ['total' => $paginator->total(), 'data' => $paginator->items()];
-    }
-
-
-     /**
-     * @description: 
-     * @param {*} $params
-     * @return {*}
-     */    
-    public static function submit($params = [])
-    {
-        $result = false;
-        $msg['code'] = self::NOT;
-        $msg['msg'] = '';
-
-        // 2. 判断是否是更新
-        if (!empty($params['id'])) {
-            // 更新
-            $info = self::findOne(['id'=>$params['id']] );
-            if (!$info) {
-                $msg['msg'] = '数据不存在';
-            }else{
-                $result = $info->update($params);
-                $id = $params['id'];
-            }
-
-        } else {
-            // 创建
-            $result = $info = self::model()::create($params);
-            $id = $result->id;
-        }
-        
-       
-        if($result){
-           $msg['code'] = self::YES;
-           $msg['msg'] = '设置成功';
-        }else{
-            $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
-        }
-
-        return $msg;
-    }
-
-}

+ 0 - 129
app/Services/UserLoginLogService.php

@@ -1,129 +0,0 @@
-<?php
-
-namespace App\Services;
-use App\Services\BaseService;
-use App\Models\UserLoginLog;
-
-class UserLoginLogService extends BaseService
-{
-
-    public static $MODEL= UserLoginLog::class;
-
-
-    
-    /**
-     * @description: 获取查询条件
-     * @param {array} $search 查询内容
-     * @return {array}
-     */
-    public static function getWhere(array $search = []): array
-    {
-        $where = [];
-        if (isset($search['id']) && $search['id'] !== '') {
-            $where[] = ['id', '=',  $search['id']];
-        }
-        if (isset($search['user_id']) && $search['user_id'] !== '') {
-            $where[] = ['user_id', '=',  $search['user_id']];
-        }
-        if (isset($search['ip_address']) && $search['ip_address'] !== '') {
-            $where[] = ['ip_address', '=',  $search['ip_address']];
-        }
-        return $where;
-    }
-
-    /**
-     * @description: 查询单条数据
-     * @param array $search
-     * @return 
-     */
-    public static function findOne(array $search)
-    {
-        return static::model()::where(static::getWhere($search))->first();
-    }
-
-    /**
-     * @description: 查询所有数据
-     * @param array $search
-     * @return \Illuminate\Database\Eloquent\Collection
-     */
-    public static function findAll(array $search = [])
-    {
-        return static::model()::where(static::getWhere($search))->get();
-    }
-    
-
-    /**
-     * @description: 分页查询
-     * @param array $search
-     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
-     */
-    public static function paginate(array $search = [])
-    {
-
-        $limit = isset($search['limit']) ? $search['limit'] : 15;
-        $paginator = static::model()::where(static::getWhere($search))
-            ->orderBy('updated_at', 'desc')
-            ->paginate($limit);
-        return ['total' => $paginator->total(), 'data' => $paginator->items()];
-    }
-
-
-     /**
-     * @description: 
-     * @param {*} $params
-     * @return {*}
-     */    
-    public static function submit($params = [])
-    {
-        $result = false;
-        $msg['code'] = self::NOT;
-        $msg['msg'] = '';
-
-        // 2. 判断是否是更新
-        if (!empty($params['id'])) {
-            // 更新
-            $info = self::findOne(['id'=>$params['id']] );
-            if (!$info) {
-                $msg['msg'] = '数据不存在!';
-            }else{
-                $result = $info->update($params);
-                $id = $params['id'];
-            }
-
-        } else {
-            // 创建
-            $result = $info = self::model()::create($params);
-            $id = $result->id;
-        }
-        
-       
-        if($result){
-           $msg['code'] = self::YES;
-           $msg['msg'] = '设置成功';
-        }else{
-            $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
-        }
-
-        return $msg;
-    }
-
-    /**
-     * 添加登录日志
-     *
-     * @param int $userId
-     * @param string|null $ipAddress
-     * @param string|null $device
-     * @return array
-     */
-    public static function addLog($userId, $ipAddress = null, $device = null)
-    {
-        $params = [
-            'user_id' => $userId,
-            'ip_address' => $ipAddress,
-            'device' => $device,
-            'login_at' => now(),
-        ];
-
-        return self::submit($params);
-    }
-}

+ 0 - 111
app/Services/UserMembershipLevelService.php

@@ -1,111 +0,0 @@
-<?php
-
-namespace App\Services;
-use App\Services\BaseService;
-use App\Models\UserMembershipLevel;
-
-class UserMembershipLevelService extends BaseService
-{
-
-    public static $MODEL= UserMembershipLevel::class;
-
-
-    
-    /**
-     * @description: 获取查询条件
-     * @param {array} $search 查询内容
-     * @return {array}
-     */
-    public static function getWhere(array $search = []): array
-    {
-        $where = [];
-        if (isset($search['id']) && $search['id'] !== '') {
-            $where[] = ['id', '=',  $search['id']];
-        }
-        if (isset($search['code']) && $search['code'] !== '') {
-            $where[] = ['code', '=',  $search['code']];
-        }
-        if (isset($search['name']) && $search['name'] !== '') {
-            $where[] = ['name', 'like', '%' . $search['name'] . '%'];
-        }
-        return $where;
-    }
-
-    /**
-     * @description: 查询单条数据
-     * @param array $search
-     * @return 
-     */
-    public static function findOne(array $search)
-    {
-        return static::model()::where(static::getWhere($search))->first();
-    }
-
-    /**
-     * @description: 查询所有数据
-     * @param array $search
-     * @return \Illuminate\Database\Eloquent\Collection
-     */
-    public static function findAll(array $search = [])
-    {
-        return static::model()::where(static::getWhere($search))->get();
-    }
-    
-
-    /**
-     * @description: 分页查询
-     * @param array $search
-     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
-     */
-    public static function paginate(array $search = [])
-    {
-
-        $limit = isset($search['limit']) ? $search['limit'] : 15;
-        $paginator = static::model()::where(static::getWhere($search))
-            ->orderBy('updated_at', 'desc')
-            ->paginate($limit);
-        return ['total' => $paginator->total(), 'data' => $paginator->items()];
-    }
-
-
-     /**
-     * @description: 
-     * @param {*} $params
-     * @return {*}
-     */    
-    public static function submit($params = [])
-    {
-        $result = false;
-        $msg['code'] = self::NOT;
-        $msg['msg'] = '';
-
-        // 2. 判断是否是更新
-        if (!empty($params['id'])) {
-            // 更新
-            $info = self::findOne(['id'=>$params['id']] );
-            if (!$info) {
-                $msg['msg'] = '数据不存在!';
-            }else{
-                $result = $info->update($params);
-                $id = $params['id'];
-            }
-
-        } else {
-            // 创建
-            $result = $info = self::model()::create($params);
-            $id = $result->id;
-        }
-        
-       
-        if($result){
-           $msg['code'] = self::YES;
-           $msg['msg'] = '设置成功';
-        }else{
-            $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
-        }
-
-        return $msg;
-    }
-
-
-}

+ 0 - 262
app/Services/UserService.php

@@ -1,262 +0,0 @@
-<?php
-
-namespace App\Services;
-use App\Services\BaseService;
-use App\Models\User;
-use Illuminate\Support\Facades\DB;
-
-use App\Services\OrderService;
-
-class UserService extends BaseService
-{
-    const STATUS_YES = 1;   // 状态正常
-    const STATUS_NOT = 0;   // 状态禁用
-
-    const LOGIN_IP_LIMIT = 2; // 同一IP允许登录用户数量
-
-    public static $MODEL= User::class;
-
-
-    
-    /**
-     * @description: 获取查询条件
-     * @param {array} $search 查询内容
-     * @return {array}
-     */
-    public static function getWhere(array $search = []): array
-    {
-        $where = [];
-        if (isset($search['id']) && $search['id'] !== '') {
-            $where[] = ['id', '=',  $search['id']];
-        }
-        // if (isset($search['username']) && $search['username'] !== '') {
-        //     $where[] = ['username', '=',  $search['username']];
-        // }
-        if (isset($search['username']) && $search['username'] !== '') {
-            $where[] = ['username', 'like', '%' . $search['username'] . '%'];
-        }
-        if (isset($search['nickname']) && $search['nickname'] !== '') {
-            $where[] = ['nickname', 'like', '%' . $search['nickname'] . '%'];
-        }
-        if (isset($search['status']) && $search['status'] !== '') {
-            $where[] = ['status', '=', intval($search['status'])];
-        }
-        if (isset($search['flag']) && $search['flag'] !== '') {
-            $where[] = ['flag', '=', intval($search['flag'])];
-        }
-        if (isset($search['mobile']) && $search['mobile'] !== '') {
-            $where[] = ['mobile', '=', $search['mobile']];
-        }
-        if (isset($search['membership_level_code']) && $search['membership_level_code'] !== '') {
-            $where[] = ['membership_level_code', '=', $search['membership_level_code']];
-        }
-        if (isset($search['last_login_ip']) && $search['last_login_ip'] !== '') {
-            $where[] = ['last_login_ip', '=', $search['last_login_ip']];
-        }
-        if (isset($search['invite_code']) && $search['invite_code'] !== '') {
-            $where[] = ['invite_code', '=', $search['invite_code']];
-        }
-        if (isset($search['inviter_id_1']) && $search['inviter_id_1'] !== '') {
-            $where[] = ['inviter_id_1', '=', $search['inviter_id_1']];
-        }
-        if (isset($search['inviter_id_2']) && $search['inviter_id_2'] !== '') {
-            $where[] = ['inviter_id_2', '=', $search['inviter_id_2']];
-        }
-        if (isset($search['inviter_id_3']) && $search['inviter_id_3'] !== '') {
-            $where[] = ['inviter_id_3', '=', $search['inviter_id_3']];
-        }
-        return $where;
-    }
-
-    /**
-     * @description: 查询单条数据
-     * @param array $search
-     * @return 
-     */
-    public static function findOne(array $search)
-    {
-        return static::model()::with(
-            [
-                'inviterLevel1' => fn($query) => $query->select('id', 'username', 'nickname'),
-                'inviterLevel2' => fn($query) => $query->select('id', 'username', 'nickname'),
-                'inviterLevel3' => fn($query) => $query->select('id', 'username', 'nickname'),
-            ]
-            )->where(static::getWhere($search))->first();
-    }
-
-    /**
-     * @description: 查询所有数据
-     * @param array $search
-     * @return \Illuminate\Database\Eloquent\Collection
-     */
-    public static function findAll(array $search = [])
-    {
-        return static::model()::where(static::getWhere($search))->get();
-    }
-    
-
-    /**
-     * @description: 分页查询
-     * @param array $search
-     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
-     */
-    public static function paginate(array $search = [])
-    {
-
-        $limit = isset($search['limit']) ? $search['limit'] : 15;
-        $paginator = static::model()::with(
-            [
-                'inviterLevel1' => fn($query) => $query->select('id', 'username', 'nickname'),
-                'inviterLevel2' => fn($query) => $query->select('id', 'username', 'nickname'),
-                'inviterLevel3' => fn($query) => $query->select('id', 'username', 'nickname'),
-            ]
-            )->where(static::getWhere($search))
-            ->orderBy('id', 'desc')
-            ->paginate($limit);
-            $data = $paginator->items();
-            foreach($data as $k=> $v){
-                $data[$k]['total_order_count'] = OrderService::model()::where(OrderService::getWhere(['user_id' => $v->id]))->count();
-                $data[$k]['total_order_profit'] = OrderService::model()::where(OrderService::getWhere(['user_id' => $v->id ,'status' => OrderService::STATUS_YES]))->sum('commission');
-                $data[$k]['today_order_count'] =  OrderService::model()::where(OrderService::getWhere(['user_id' => $v->id ,'status' => OrderService::STATUS_YES ,'order_date' => date('Y-m-d')]))->count();
-                time() - $v['last_active_time'] >180 ? $data[$k]['is_online'] = 0 : $data[$k]['is_online'] = 1;
-            }
-        return ['total' => $paginator->total(), 'data' => $data];
-    }
-
-
-     /**
-     * @description: 
-     * @param {*} $params
-     * @return {*}
-     */    
-    public static function submit($params = [])
-    {
-        $result = false;
-        $msg['code'] = self::NOT;
-        $msg['msg'] = '';
-        
-        if(isset($params['password'])){
-            if(empty($params['password'])){
-                unset($params['password']);
-            }
-        }
-        if(isset($params['transaction_password'])){
-            if(empty($params['transaction_password'])){
-                unset($params['transaction_password']);
-            }
-        }
-
-        // 2. 判断是否是更新
-        if (!empty($params['id'])) {
-            // 更新
-            $info = self::findOne(['id'=>$params['id']] );
-            if (!$info) {
-                $msg['msg'] = '数据不存在!';
-            }else{
-                $result = $info->update($params);
-                $id = $params['id'];
-            }
-
-        } else {
-            // 创建
-            $result = $info = self::model()::create($params);
-            $id = $result->id;
-        }
-        
-       
-        if($result){
-           $msg['code'] = self::YES;
-           $msg['msg'] = '设置成功';
-        }else{
-            $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
-        }
-
-        return $msg;
-    }
-
-    /**
-     * @description: 检查IP登录数量
-     * @param string $ip
-     * @return int
-     */
-    public static function checkIpLimit($ip)
-    {
-        // $count = static::model()::where(self::getWhere(['last_login_ip' => $ip]))->count();
-        // if($count > self::LOGIN_IP_LIMIT){
-        //     static::model()::where(self::getWhere(['last_login_ip' => $ip]))->update(['status' => self::STATUS_NOT]);
-        //     return false;
-        // }
-        return true;
-    }
-
-    /**
-     * @description: 更新登录iP
-     * @param {*} $id
-     * @param {*} $ip
-     * @return {*}
-     */    
-    public static function updateLoginIp($id,$ip)
-    {
-        static::model()::where('id',$id)->update(['last_login_ip' => $ip,'last_login_at' => date('Y-m-d H:i:s')]);
-    }
-
-    /**
-     * @description: 调整用户余额
-     * @param int $userId 用户ID
-     * @param float $amount 调整金额,正数为增加,负数为减少
-     * @param string $changeType 变动类型
-     * @param string $remark 备注
-     * @return bool
-     */
-    public static function adjustBalance($userId, $amount, $changeType, $remark = '')
-    {
-        $result = false;
-        $msg['code'] = self::NOT;
-        $msg['msg'] = '';
-        $user = static::model()::where(self::getWhere(['id' => $userId]))->lockForUpdate()->first();
-        if (!$user) {
-            $msg['msg'] = '用户不存在';
-            return $msg;
-        }
-
-        $beforeBalance = $user->balance;
-        $afterBalance = $beforeBalance + $amount;
-        if($afterBalance < 0){
-            $msg['msg'] = '用户余额不足,无法扣款';
-            return $msg;
-
-        }
-        
-        DB::beginTransaction();
-        try {
-            // 更新用户余额
-            $user->balance = $afterBalance;
-            $user->save();
-
-            // 记录余额变动日志
-            $log = UserBalanceLogService::addLog(
-                $userId,
-                $changeType,
-                $beforeBalance,
-                $amount,
-                $remark
-            );
-            if($log['code'] == self::NOT){
-                DB::rollBack();
-                return $log;
-            }
-            DB::commit();
-
-            $msg['code'] = self::YES;
-            $msg['msg'] = '用户余额调整成功';
-            return $msg;
-
-        } catch (\Exception $e) {
-            DB::rollBack();
-            
-            $msg['msg'] = $e->getMessage();
-            return $msg;
-        }
-
-    }
-}