浏览代码

wesmiler 抢表商城

APPLE 3 年之前
父节点
当前提交
c795cf1630
共有 32 个文件被更改,包括 2749 次插入100 次删除
  1. 1 1
      app/Helpers/common.php
  2. 51 0
      app/Http/Controllers/Admin/GoodsController.php
  3. 2 0
      app/Http/Controllers/Admin/IndexController.php
  4. 24 0
      app/Http/Controllers/Admin/MemberController.php
  5. 60 0
      app/Http/Controllers/Admin/ScoreGoodsCateController.php
  6. 50 0
      app/Http/Controllers/Admin/ScoreGoodsController.php
  7. 8 0
      app/Http/Controllers/Admin/ShopController.php
  8. 29 0
      app/Http/Controllers/Api/v1/AccountController.php
  9. 101 0
      app/Http/Controllers/Api/v1/GoodsController.php
  10. 36 0
      app/Http/Controllers/Api/v1/MarketController.php
  11. 139 2
      app/Http/Controllers/Api/v1/MemberController.php
  12. 143 0
      app/Http/Controllers/Api/v1/TradeController.php
  13. 2 2
      app/Http/Controllers/Api/v1/UploadController.php
  14. 4 1
      app/Http/Controllers/Api/webApp.php
  15. 1 1
      app/Http/Validator/MemberValidator.php
  16. 2 2
      app/Models/GoodsModel.php
  17. 39 0
      app/Models/MemberAddressModel.php
  18. 39 0
      app/Models/MemberBankModel.php
  19. 45 0
      app/Models/ScoreGoodsCateModel.php
  20. 45 0
      app/Models/ScoreGoodsModel.php
  21. 8 0
      app/Services/Common/AccountService.php
  22. 23 39
      app/Services/Common/FinanceService.php
  23. 234 3
      app/Services/Common/GoodsService.php
  24. 161 0
      app/Services/Common/MemberAddressService.php
  25. 159 0
      app/Services/Common/MemberBankService.php
  26. 393 23
      app/Services/Common/MemberService.php
  27. 1 6
      app/Services/Common/OrderService.php
  28. 140 0
      app/Services/Common/ScoreGoodsCateService.php
  29. 118 0
      app/Services/Common/ScoreGoodsService.php
  30. 71 0
      app/Services/Common/ShopService.php
  31. 618 20
      app/Services/Common/TradeService.php
  32. 2 0
      app/Services/ConfigService.php

+ 1 - 1
app/Helpers/common.php

@@ -623,7 +623,7 @@ if (!function_exists('get_password')) {
      */
     function get_password($password)
     {
-        return md5(md5($password));
+        return md5(md5($password.md5($password . env('APP_NAME'))));
     }
 
 }

+ 51 - 0
app/Http/Controllers/Admin/GoodsController.php

@@ -0,0 +1,51 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Http\Controllers\Admin;
+
+
+use App\Services\Common\GoodsService;
+
+/**
+ * 商品管理-控制器
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class GoodsController
+ * @package App\Http\Controllers
+ */
+class GoodsController extends Backend
+{
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * GoodsController constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct();
+        $this->service = new GoodsService();
+    }
+
+    public function index()
+    {
+        $pageSize = request()->get('limit', 15);
+        $list = $this->service->getDataList(request()->all(), $pageSize);
+        $message = array(
+            "msg" => '操作成功',
+            "code" => 0,
+            "data" => isset($list['list'])? $list['list']:[],
+            "count" => isset($list['total'])? $list['total']:0,
+        );
+        return $message;
+    }
+
+}

+ 2 - 0
app/Http/Controllers/Admin/IndexController.php

@@ -101,6 +101,8 @@ class IndexController extends Backend
         RedisService::keyDel("caches:advert*");
         RedisService::keyDel("caches:article*");
         RedisService::keyDel("caches:qrcode*");
+        RedisService::keyDel("caches:shop*");
+        RedisService::keyDel("caches:goods*");
         RedisService::keyDel("laravel_cache:model*");
         return message(MESSAGE_OK, true);
     }

+ 24 - 0
app/Http/Controllers/Admin/MemberController.php

@@ -67,6 +67,15 @@ class MemberController extends Backend
     }
 
     /**
+     * 选项列表
+     * @return mixed
+     */
+    public function options(){
+        $result = $this->service->options();
+        return message(1002,true, $result);
+    }
+
+    /**
      * 重置密码
      * @return mixed
      * @since 2020/11/11
@@ -78,4 +87,19 @@ class MemberController extends Backend
         return $result;
     }
 
+    /**
+     * 转换佣金
+     */
+    public function exchange()
+    {
+        // 获取参数
+        $param = request()->all();
+        // 用户ID
+        $userId = getter($param, "id");
+        if(!MemberService::make()->switchBonus($userId)){
+            return message(MemberService::make()->getError(), true);
+        }else{
+            return message(MemberService::make()->getError(), false);
+        }
+    }
 }

+ 60 - 0
app/Http/Controllers/Admin/ScoreGoodsCateController.php

@@ -0,0 +1,60 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Http\Controllers\Admin;
+
+
+use App\Services\Common\ScoreGoodsCateService;
+
+/**
+ * 积分商品分类管理-控制器
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class ScoreGoodsCateController
+ * @package App\Http\Controllers
+ */
+class ScoreGoodsCateController extends Backend
+{
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * ScoreGoodsCateController constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct();
+        $this->service = new ScoreGoodsCateService();
+    }
+
+    public function index()
+    {
+        $pageSize = request()->get('limit', 15);
+        $list = $this->service->getDataList(request()->all(), $pageSize);
+        $message = array(
+            "msg" => '操作成功',
+            "code" => 0,
+            "data" => isset($list['list'])? $list['list']:[],
+            "count" => isset($list['total'])? $list['total']:0,
+        );
+        return $message;
+    }
+
+    /**
+     * 选项列表
+     * @return array
+     */
+    public function options()
+    {
+        $result = $this->service->options();
+        return message(1002,true, $result);
+    }
+}

+ 50 - 0
app/Http/Controllers/Admin/ScoreGoodsController.php

@@ -0,0 +1,50 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Http\Controllers\Admin;
+
+use App\Services\Common\ScoreGoodsService;
+
+/**
+ * 积分商品管理-控制器
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class ScoreGoodsController
+ * @package App\Http\Controllers
+ */
+class ScoreGoodsController extends Backend
+{
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * ScoreGoodsController constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct();
+        $this->service = new ScoreGoodsService();
+    }
+
+    public function index()
+    {
+        $pageSize = request()->get('limit', 15);
+        $list = $this->service->getDataList(request()->all(), $pageSize);
+        $message = array(
+            "msg" => '操作成功',
+            "code" => 0,
+            "data" => isset($list['list'])? $list['list']:[],
+            "count" => isset($list['total'])? $list['total']:0,
+        );
+        return $message;
+    }
+    
+}

+ 8 - 0
app/Http/Controllers/Admin/ShopController.php

@@ -57,4 +57,12 @@ class ShopController extends Backend
         return message(1002,true, $result);
     }
 
+    /**
+     * 选项列表
+     * @return mixed
+     */
+    public function options(){
+        $result = $this->service->options();
+        return message(1002,true, $result);
+    }
 }

+ 29 - 0
app/Http/Controllers/Api/v1/AccountController.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Common\AccountService;
+
+/**
+ * 账户明细
+ * Class AccountController
+ * @package App\Http\Controllers\Api
+ */
+class AccountController extends webApp
+{
+
+    /**
+     * 佣金明细
+     */
+    public function bonus()
+    {
+        $params = request()->all();
+        $pageSize = request()->get('pageSize', 15);
+        $params['status'] = 1;
+        $params['coin_type'] = 2;
+        $params['user_id'] = $this->userId;
+        $list = AccountService::make()->getDataList($params, $pageSize);
+        return message(1010, true, $list);
+    }
+}

+ 101 - 0
app/Http/Controllers/Api/v1/GoodsController.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Common\GoodsService;
+use App\Services\Common\MemberService;
+
+/**
+ * 商品
+ * Class GoodsController
+ * @package App\Http\Controllers\Api
+ */
+class GoodsController extends webApp
+{
+
+    public function index()
+    {
+        $params = request()->all();
+        $pageSize = isset($params['pageSize'])? $params['pageSize'] : 18;
+        $params['shop_id'] = $this->shopId;
+        $params['is_trade'] = 2;
+        $params['time'] = strtotime(date('Y-m-d'));
+        $info = GoodsService::make()->getDataList($params, $pageSize);
+        return message(1010, true, $info);
+    }
+
+    /**
+     * 拆分
+     * @return array
+     */
+    public function split()
+    {
+        $params = request()->all();
+        $goodsId = isset($params['id'])? $params['id'] : 0;
+        if(GoodsService::make()->split($goodsId)){
+            return message(GoodsService::make()->getError(), true);
+        }else{
+            return message(GoodsService::make()->getError(), false);
+        }
+    }
+
+    /**
+     * 转场
+     * @return array
+     */
+    public function change()
+    {
+        $params = request()->all();
+        $goodsId = isset($params['id'])? $params['id'] : 0;
+        if(GoodsService::make()->change($goodsId)){
+            return message(GoodsService::make()->getError(), true);
+        }else{
+            return message(GoodsService::make()->getError(), false);
+        }
+    }
+
+    /**
+     * 转会员
+     * @return array
+     */
+    public function switchUser()
+    {
+        $params = request()->all();
+        if(GoodsService::make()->switchUser($params)){
+            return message(GoodsService::make()->getError(), true);
+        }else{
+            return message(GoodsService::make()->getError(), false);
+        }
+    }
+
+    /**
+     * 封存
+     * @return array
+     */
+    public function lock()
+    {
+        $params = request()->all();
+        $goodsId = isset($params['id'])? $params['id'] : 0;
+        if(GoodsService::make()->lock($goodsId)){
+            return message(GoodsService::make()->getError(), true);
+        }else{
+            return message(GoodsService::make()->getError(), false);
+        }
+    }
+
+    /**
+     * 需改
+     * @return array
+     */
+    public function updateData()
+    {
+        $params = request()->all();
+        $goodsId = isset($params['id'])? $params['id'] : 0;
+        if(GoodsService::make()->updateData($goodsId)){
+            return message(GoodsService::make()->getError(), true);
+        }else{
+            return message(GoodsService::make()->getError(), false);
+        }
+    }
+}

+ 36 - 0
app/Http/Controllers/Api/v1/MarketController.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Common\MemberService;
+
+/**
+ * 分销中心
+ * Class MarketController
+ * @package App\Http\Controllers\Api
+ */
+class MarketController extends webApp
+{
+
+    public function info()
+    {
+        $info = MemberService::make()->getMarketInfo($this->userId);
+        return message(1010, true, $info);
+    }
+
+    /**
+     * 我的团队
+     * @return array
+     */
+    public function teams()
+    {
+        $params = request()->all();
+        $params['show_type'] = 2;
+        $params['status'] = 1;
+        $params['parent_id'] = $this->userId;
+        $pageSize = isset($params['pageSize'])? $params['pageSize'] : 15;
+        $datas = MemberService::make()->getDataList($params,$pageSize);
+        return message(1010, true, $datas);
+    }
+}

+ 139 - 2
app/Http/Controllers/Api/v1/MemberController.php

@@ -3,19 +3,156 @@
 namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\webApp;
+use App\Http\Validator\MemberValidator;
 use App\Services\Common\MemberService;
+use App\Services\Common\ShopService;
+use Illuminate\Http\Request;
 
 /**
- * 测试
- * Class TestController
+ * 用户
+ * Class MemberController
  * @package App\Http\Controllers\Api
  */
 class MemberController extends webApp
 {
+    // 店铺会员管理
+    public function lists()
+    {
+        $params = request()->all();
+        $params['login_shop_id'] = $this->shopId;
+        $params['status'] = 1;
+        $pageSize = isset($params['pageSize'])? $params['pageSize'] : 15;
+        $datas = MemberService::make()->getDataList($params,$pageSize);
+        return message(1010, true, $datas);
+    }
 
+    // 信息
     public function info()
     {
         $info = MemberService::make()->getInfo($this->userId);
         return message(1010, true, $info);
     }
+
+    /**
+     * 修改头像
+     * @param Request $request
+     * @return array
+     */
+    public function saveAvatar(Request $request)
+    {
+        // 上传单图统一调取方法
+        $result = upload_image($request, 'file');
+        if (!$result['success']) {
+            return message($result['msg'],false,['url'=>'']);
+        }
+
+        // 文件路径
+        $file_path = $result['data']['img_path'];
+        if (!$file_path) {
+            return message('上传失败',false,['url'=>'']);
+        }
+
+        // 网络域名拼接
+        if ($file_path && strpos($file_path, IMG_URL) === false) {
+            $file_path = get_image_url($file_path);
+        }
+
+        $avatar = $result['data']['img_path'];
+        if(MemberService::make()->saveAvatar($this->userId, $avatar)){
+            return message('头像修改成功',true,['url'=> $file_path,'path'=> $avatar]);
+        }else{
+            return message('头像修改失败',false,['url'=>'']);
+        }
+    }
+
+    /**
+     * 修改登录密码
+     * @param MemberValidator $validate
+     * @return array
+     */
+    public function password(MemberValidator $validate)
+    {
+        $params = $validate->check(request()->post(),'password');
+        if(!is_array($params)){
+            return message($params, false);
+        }
+
+        if(MemberService::make()->updatePassword($this->userId, $params)){
+            return message(MemberService::make()->getError(), true);
+        }else{
+            return message(MemberService::make()->getError(), false);
+        }
+    }
+
+    /**
+     * 修改支付密码
+     * @param MemberValidator $validate
+     * @return array
+     */
+    public function safePassword(MemberValidator $validate)
+    {
+        $params = $validate->check(request()->post(),'password');
+        if(!is_array($params)){
+            return message($params, false);
+        }
+
+        if(MemberService::make()->updateSafePassword($this->userId, $params)){
+            return message(MemberService::make()->getError(), true);
+        }else{
+            return message(MemberService::make()->getError(), false);
+        }
+    }
+
+    /**
+     * 一键转换佣金
+     */
+    public function switchBonus()
+    {
+        $userId =  request()->post('user_id', 0);
+        if(MemberService::make()->switchBonus($userId, $this->shopId, $this->userId)){
+            return message(MemberService::make()->getError(), true);
+        }else{
+            return message(MemberService::make()->getError(), false);
+        }
+    }
+
+    /**
+     * 设置抢拍状态
+     */
+    public function setTrade()
+    {
+        $status =  request()->post('status', 0);
+        $userId =  request()->post('user_id', 0);
+        if(MemberService::make()->setTrade($userId, $this->shopId, $status)){
+            return message(1014, true);
+        }else{
+            return message(1015, false);
+        }
+    }
+
+    /**
+     * 设置抢拍时间
+     */
+    public function setTime()
+    {
+        $params =  request()->all();
+        if(ShopService::make()->setTime($this->userId, $this->shopId, $params)){
+            return message(1014, true);
+        }else{
+            return message(1015, false);
+        }
+    }
+
+
+    /**
+     * 设置删除
+     */
+    public function setLock()
+    {
+        if(MemberService::make()->setLock($this->userId)){
+            return message(1016, true);
+        }else{
+            return message(1017, false);
+        }
+    }
 }

+ 143 - 0
app/Http/Controllers/Api/v1/TradeController.php

@@ -0,0 +1,143 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Common\MemberService;
+use App\Services\Common\TradeService;
+
+/**
+ * 交易
+ * Class TradeController
+ * @package App\Http\Controllers\Api
+ */
+class TradeController extends webApp
+{
+
+    public function index()
+    {
+        $params = request()->all();
+        $pageSize = isset($params['pageSize'])? $params['pageSize'] : 18;
+        $type = isset($params['type'])? $params['type'] : 1;
+        $status = isset($params['status'])? $params['status'] : 0;
+        // 我的订单
+        if($type == 1){
+            $params['user_id'] = $this->userId;
+            $params['sell_uid'] = $this->userId;
+        }
+        // 推广订单
+        else if($type == 2){
+            $params['parent_id'] = $this->userId;
+        }
+        // 店铺订单
+        else if($type == 3){
+            $params['shop_id'] = $this->shopId;
+        }
+        $params['time'] = strtotime(date('Y-m-d'))-86400*7;
+        $datas = TradeService::make()->getDataList($params, $pageSize);
+        return message(1010, true, $datas);
+    }
+
+    public function info()
+    {
+        $id = request()->post('id', 0);
+        $info = TradeService::make()->getInfo($id);
+        return message(1010, true, $info);
+    }
+
+    /**
+     * 统计
+     * @return array
+     */
+    public function counts()
+    {
+        $params = request()->all();
+        $type = isset($params['type'])? $params['type'] : 1;
+        $status = isset($params['status'])? $params['status'] : 0;
+        // 我的订单
+        if($type == 1){
+            if($status==2){
+                $params['sell_uid'] = $this->userId;
+            }else{
+                $params['user_id'] = $this->userId;
+            }
+        }
+        // 推广订单
+        else if($type == 2){
+            $params['parent_id'] = $this->userId;
+        }
+        // 店铺订单
+        else if($type == 3){
+            $params['shop_id'] = $this->shopId;
+        }
+        $params['time'] = strtotime(date('Y-m-d'))-86400*7;
+        $counts = TradeService::make()->getCounts($params);
+        return message(1010, true, $counts);
+    }
+    /**
+     * 抢拍
+     * @return array
+     */
+    public function buy()
+    {
+        if(TradeService::make()->buy(request()->all(), $this->userId, $this->shopId)){
+            return message(TradeService::make()->getError(), true);
+        }else{
+            return message(TradeService::make()->getError(), false);
+        }
+    }
+
+    /**
+     * 付款
+     * @return array
+     */
+    public function pay()
+    {
+        if(TradeService::make()->pay(request()->all(), $this->userId, $this->shopId)){
+            return message(TradeService::make()->getError(), true);
+        }else{
+            return message(TradeService::make()->getError(), false);
+        }
+    }
+
+
+    /**
+     * 确认收款
+     * @return array
+     */
+    public function confirm()
+    {
+        if(TradeService::make()->confirm(request()->all(), $this->userId)){
+            return message(TradeService::make()->getError(), true);
+        }else{
+            return message(TradeService::make()->getError(), false);
+        }
+    }
+
+
+    /**
+     * 上架
+     * @return array
+     */
+    public function sell()
+    {
+        if(TradeService::make()->sell(request()->all(), $this->userId)){
+            return message(TradeService::make()->getError(), true);
+        }else{
+            return message(TradeService::make()->getError(), false);
+        }
+    }
+
+    /**
+     * 上架审核
+     * @return array
+     */
+    public function sellConfirm()
+    {
+        if(TradeService::make()->sellConfirm(request()->all())){
+            return message(TradeService::make()->getError(), true);
+        }else{
+            return message(TradeService::make()->getError(), false);
+        }
+    }
+}

+ 2 - 2
app/Http/Controllers/Api/v1/UploadController.php

@@ -46,11 +46,11 @@ class UploadController extends webApp
 
         // 网络域名拼接
         if ($file_path && strpos($file_path, IMG_URL) === false) {
-            $file_path = IMG_URL . $file_path;
+            $file_path = get_image_url($file_path);
         }
 
         // 返回结果
-        return ['url'=> $file_path, 'path'=> $result['data']['img_path'], 'error'=> false];
+        return message(MESSAGE_OK, true, ['url'=> $file_path, 'path'=> $result['data']['img_path']]);
     }
 
     /**

+ 4 - 1
app/Http/Controllers/Api/webApp.php

@@ -111,8 +111,11 @@ class webApp extends BaseController
 
         // 登录用户信息
         if ($userId) {
+
             $memberModel = new MemberModel();
-            $userInfo = $memberModel->getInfo($this->userId);
+            $userInfo = $memberModel->where(['id'=> $userId])
+                ->select(['id','nickname','mobile','code','parent_id','login_shop_id'])
+                ->first();
             $this->userInfo = $userInfo;
             $this->shopId = isset($userInfo['login_shop_id'])? $userInfo['login_shop_id'] : 0;
             RedisService::set("auths:info:{$userId}", $this->userInfo, 4*24*3600);

+ 1 - 1
app/Http/Validator/MemberValidator.php

@@ -42,7 +42,7 @@ class MemberValidator extends BaseValidator
         'register'=> ['mobile','nickname','password','safe_password','invite_code'],
         'login'=> ['mobile','password','shop_code'],
         'save'=> ['nickname','avatar','password','safe_password'],
-        'modify_pwd'=> ['password'],
+        'password'=> ['password'],
     ];
 
     /**

+ 2 - 2
app/Models/GoodsModel.php

@@ -24,7 +24,7 @@ class GoodsModel extends BaseModel
     protected $table = 'goods';
 
     /**
-     * 获取店铺信息
+     * 获取信息
      * @param int $id
      * @return array|string
      * @author laravel开发员
@@ -34,7 +34,7 @@ class GoodsModel extends BaseModel
     {
         $info = parent::getInfo($id); // TODO: Change the autogenerated stub
         if ($info) {
-            // 店铺封面
+            // 封面
             if ($info['thumb']) {
                 $info['thumb'] = get_image_url($info['thumb']);
             }

+ 39 - 0
app/Models/MemberAddressModel.php

@@ -0,0 +1,39 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Models;
+
+/**
+ * 用户地址管理-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class MemberAddressModel
+ * @package App\Models
+ */
+class MemberAddressModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'member_address';
+
+    /**
+     * 获取信息
+     * @param int $id
+     * @return array|string
+     * @author laravel开发员
+     * @since 2020/11/11
+     */
+    public function getInfo($id)
+    {
+        $info = parent::getInfo($id); // TODO: Change the autogenerated stub
+        return $info;
+    }
+
+}

+ 39 - 0
app/Models/MemberBankModel.php

@@ -0,0 +1,39 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Models;
+
+/**
+ * 用户银行卡管理-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class MemberBankModel
+ * @package App\Models
+ */
+class MemberBankModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'member_bank';
+
+    /**
+     * 获取信息
+     * @param int $id
+     * @return array|string
+     * @author laravel开发员
+     * @since 2020/11/11
+     */
+    public function getInfo($id)
+    {
+        $info = parent::getInfo($id); // TODO: Change the autogenerated stub
+        return $info;
+    }
+
+}

+ 45 - 0
app/Models/ScoreGoodsCateModel.php

@@ -0,0 +1,45 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Models;
+
+/**
+ * 积分商品分类管理-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class ScoreGoodsCateModel
+ * @package App\Models
+ */
+class ScoreGoodsCateModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'score_goods_cate';
+
+    /**
+     * 获取信息
+     * @param int $id
+     * @return array|string
+     * @author laravel开发员
+     * @since 2020/11/11
+     */
+    public function getInfo($id)
+    {
+        $info = parent::getInfo($id); // TODO: Change the autogenerated stub
+        if ($info) {
+            // 店铺封面
+            if ($info['thumb']) {
+                $info['thumb'] = get_image_url($info['thumb']);
+            }
+        }
+        return $info;
+    }
+
+}

+ 45 - 0
app/Models/ScoreGoodsModel.php

@@ -0,0 +1,45 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Models;
+
+/**
+ * 积分商品管理-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class ScoreGoodsModel
+ * @package App\Models
+ */
+class ScoreGoodsModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'score_goods';
+
+    /**
+     * 获取信息
+     * @param int $id
+     * @return array|string
+     * @author laravel开发员
+     * @since 2020/11/11
+     */
+    public function getInfo($id)
+    {
+        $info = parent::getInfo($id); // TODO: Change the autogenerated stub
+        if ($info) {
+            // 店铺封面
+            if ($info['thumb']) {
+                $info['thumb'] = get_image_url($info['thumb']);
+            }
+        }
+        return $info;
+    }
+
+}

+ 8 - 0
app/Services/Common/AccountService.php

@@ -57,6 +57,8 @@ class AccountService extends BaseService
         $status = isset($params['status'])? $params['status'] : 0;
         $type = isset($params['type'])? $params['type'] : 0;
         $coinType = isset($params['coin_type'])? $params['coin_type'] : 0;
+        $userId = isset($params['user_id'])? $params['user_id'] : 0;
+        $shopId = isset($params['shop_id'])? $params['shop_id'] : 0;
         if($status>0){
             $where['a.status'] = $status;
         }
@@ -66,6 +68,12 @@ class AccountService extends BaseService
         if($coinType>0){
             $where['a.coin_type'] = $coinType;
         }
+        if($userId>0){
+            $where['a.user_id'] = $userId;
+        }
+        if($shopId>0){
+            $where['a.shop_id'] = $shopId;
+        }
         $list = $this->model->from('account_log as a')
             ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
             ->leftJoin('shop as c', 'c.id', '=', 'a.shop_id')

+ 23 - 39
app/Services/Common/FinanceService.php

@@ -23,6 +23,8 @@ use App\Services\BaseService;
  */
 class FinanceService extends BaseService
 {
+    protected static $instance=null;
+
     /**
      * 构造函数
      * @author laravel开发员
@@ -107,51 +109,33 @@ class FinanceService extends BaseService
     }
 
     /**
-     * 获取店铺交易统计
-     * @param $shopId
-     * @param int $type
-     * @param int $coinType
-     * @return mixed
-     */
-    public function getShopAccountTotal($shopId, $type = 1, $coinType=1)
-    {
-        $where = ['shop_id'=>$shopId,'status'=>1,'mark'=>1];
-        return $this->model->where($where)
-            ->where(function($query) use($type, $coinType){
-                if($type){
-                    $query->whereIn('type', is_array($type)? $type : [$type]);
-                }
-                if($coinType){
-                    $query->whereIn('coin_type', is_array($coinType)? $coinType : [$coinType]);
-                }
-            })
-            ->sum('money');
-    }
-
-    /**
-     * 获取交易数
-     * @param $shopId
+     * 平台结算
+     * @param $money
+     * @param int $changeType
      * @param int $type
-     * @param int $coinType
      * @return mixed
      */
-    public function getShopAccountCount($shopId, $type = 1, $coinType=1)
+    public function settleBonus($money, $changeType = 1, $type = 1)
     {
-        $where = ['shop_id'=>$shopId,'status'=>1,'mark'=>1];
+        $date = date('Y-m-d');
+        $info = $this->model->where(['date'=> $date,'mark'=>1])->first();
+        if(!$info){
+            $data = ['date'=> $date,'type'=>1,'create_time'=>time(),'update_time'=> time(),'status'=>1];
+            if($changeType==1){
+                $data['income'] = $money;
+            }else{
+                $data['expend'] = $money;
+            }
+            return $this->model->insertGetId($data);
+        }else{
+            if($changeType == 1){
+                $info->income += $money;
+            }else{
+                $info->expend += $money;
+            }
 
-        if($coinType){
-            $where['coin_type'] = $coinType;
+            return $info->save();
         }
-        return $this->model->where($where)
-            ->where(function($query) use($type, $coinType){
-                if($type){
-                    $query->whereIn('type', is_array($type)? $type : [$type]);
-                }
-                if($coinType){
-                    $query->whereIn('coin_type', is_array($coinType)? $coinType : [$coinType]);
-                }
-            })
-            ->count('id');
     }
 
 }

+ 234 - 3
app/Services/Common/GoodsService.php

@@ -12,7 +12,13 @@
 namespace App\Services\Common;
 
 use App\Models\GoodsModel;
+use App\Models\MemberModel;
+use App\Models\ShopModel;
+use App\Models\TradeModel;
 use App\Services\BaseService;
+use App\Services\ConfigService;
+use App\Services\RedisService;
+use Illuminate\Support\Facades\DB;
 
 /**
  * 商品管理-服务类
@@ -62,7 +68,10 @@ class GoodsService extends BaseService
         if($status>0){
             $where['a.status'] = $status;
         }
-
+        $isTrade = isset($params['is_trade'])? $params['is_trade'] : 0;
+        if($isTrade>0){
+            $where['a.is_trade'] = $isTrade;
+        }
         $list = $this->model->from('goods as a')
             ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
             ->leftJoin('shop as c', 'c.id', '=', 'a.shop_id')
@@ -73,9 +82,14 @@ class GoodsService extends BaseService
                     $query->where('a.goods_name','like',"%{$keyword}%")->orWhere('c.name','like',"%{$keyword}%")->orWhere('b.nickname','like',"%{$keyword}%")->orWhere('b.mobile','like',"%{$keyword}%");
 
                 }
-
             })
-            ->select(['a.*','b.nickname','b.mobile as mobile','c.name as shop_name'])
+            ->where(function($query) use ($params){
+                $time = isset($params['time'])? $params['time'] : '';
+                if($time){
+                    $query->where('last_sell_time','<=', $time);
+                }
+            })
+            ->select(['a.*','b.nickname','b.code as user_code','b.mobile as mobile','c.name as shop_name','c.code as shop_code'])
             ->orderBy('a.id','desc')
             ->paginate($pageSize > 0 ? $pageSize : 9999999);
         $list = $list? $list->toArray() :[];
@@ -111,10 +125,49 @@ class GoodsService extends BaseService
             $data['thumb'] = str_replace(IMG_URL, "", $data['thumb']);
         }
 
+        if(!isset($data['code']) || empty($data['code'])){
+            $data['code'] = isset($data['id'])&&$data['id']? 'G'.$data['id'] :'G'.(GoodsModel::max('id')+1);
+        }
+
+        if(!isset($data['price']) || empty($data['price'])){
+            $data['price'] = $data['sell_price'];
+        }
+//
+//        $feeRate = ConfigService::make()->getConfigByCode('sell_fee_rate');
+//        $feeRate = $feeRate? $feeRate : '2.5';
+//        $data['fee'] = round($data['price'] * $feeRate/100, 0);
         return parent::edit($data); // TODO: Change the autogenerated stub
     }
 
     /**
+     * 获取资料详情
+     * @param $where
+     * @param array $field
+     */
+    public function getInfo($where, array $field = [])
+    {
+        $cacheKey = "caches:goods:".(!is_array($where)? $where : md5(json_encode($where)));
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+
+        $field = $field ? $field : '*';
+        if (is_array($where)) {
+            $info = $this->model->where($where)->select($field)->first();
+        } else {
+            $info = $this->model->where(['id' => (int)$where])->select($field)->first();
+        }
+
+        $info = $info ? $info->toArray() : [];
+        if($info){
+            $info['thumb'] = $info['thumb'] ? get_image_url($info['thumb']) : '';
+            RedisService::set($cacheKey, $info, rand(5,10));
+        }
+        return $info;
+    }
+
+    /**
      * 验证是否抢购有新的商品
      * @param $userId
      * @return mixed
@@ -125,4 +178,182 @@ class GoodsService extends BaseService
             ->where('create_time','>=', strtotime(date('Y-m-d')))
             ->count('id');
     }
+
+    /**
+     * 拆分
+     * @param $info
+     * @param $goods
+     * @return bool
+     */
+    public function split($goodsId)
+    {
+        $goods = $this->where(['id'=> $goodsId,'mark'=>1])->first();
+        $splitNum = isset($goods['split_num'])? $goods['split_num'] : 0;
+        if($splitNum<=0){
+            return false;
+        }
+
+        $datas = [];
+        $sumPrice = 0;
+        for($i=1; $i<= $splitNum; $i++){
+            if($i < $splitNum){
+                $price = round($info['price']/$splitNum, 0);
+                $sumPrice += $price;
+            }else{
+                $price = round($info['price'] - $sumPrice, 0);
+            }
+
+            $datas[] = [
+                'user_id'=> $goods['user_id'],
+                'shop_id'=> $goods['shop_id'],
+                'goods_name'=> $goods['goods_name'],
+                'code'=> $goods['code'].'-'.$i,
+                'source_price'=> round($goods['source_price']/$splitNum, 0),
+                'sell_price'=> round($goods['sell_price']/$splitNum, 0),
+                'price'=> $price,
+                'fee'=> 0,
+                'thumb'=> $goods['thumb'],
+                'content'=> $goods['content'],
+                'split_num'=> $goods['split_num'],
+                'split_price'=> $goods['split_price'],
+                'last_sell_time'=> time(),
+                'create_time'=> time(),
+                'update_time'=> time(),
+                'mark'=>1,
+                'status'=>1,
+            ];
+        }
+
+        DB::beginTransaction();
+        if($datas){
+            if(!$this->model->insert($datas)){
+                DB::rollBack();
+                return false;
+            }
+
+            if(!$this->model->where(['id'=> $goods['id'],'mark'=>1])->update(['status'=>2,'mark'=>0,'remark'=>'已被拆分','update_time'=>time()])){
+                DB::rollBack();
+                return false;
+            }
+
+            if($info && !TradeModel::where(['id'=> $info['id'],'mark'=>1])->update(['status'=>-1,'is_split'=>1,'mark'=>0,'remark'=>'已被拆分','update_time'=>time()])){
+                DB::rollBack();
+                return false;
+            }
+        }
+
+        DB::commit();
+        return true;
+    }
+
+    /**
+     * 转场
+     * @param $goodsId
+     */
+    public function change($goodsId)
+    {
+        $params = request()->all();
+        $shopId = isset($params['shop_id'])? $params['shop_id']:0;
+        $goods = $this->where(['id'=> $goodsId,'mark'=>1])->first();
+        if(empty($goods)){
+            $this->error = 2061;
+            return false;
+        }
+
+        $shopInfo = ShopModel::where(['id'=> $shopId,'mark'=>1])->first();
+        if(empty($shopInfo)){
+            $this->error = 2062;
+            return false;
+        }
+
+        if($this->model->where(['id'=> $goodsId])->update(['shop_id'=> $shopId,'update_time'=> time(),'remark'=> '店长转场'])){
+            $this->error = 1002;
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * 转会员
+     * @param $goodsId
+     */
+    public function switchUser($params)
+    {
+        $userId = isset($params['user_id'])? $params['user_id']:0;
+        $ids = isset($params['ids'])? $params['ids']:[];
+        if(empty($ids)){
+            $this->error = 2063;
+            return false;
+        }
+        $goodsList = $this->whereIn('id',$ids)->where(['mark'=>1])->first();
+        if(empty($goodsList)){
+            $this->error = 2061;
+            return false;
+        }
+
+        $memberInfo = MemberModel::where(['id'=> $userId,'mark'=>1])->first();
+        if(empty($memberInfo)){
+            $this->error = 2062;
+            return false;
+        }
+
+        if($this->model->whereIn('id', $ids)->update(['user_id'=> $userId,'update_time'=> time(),'remark'=> '商品转会员'])){
+            $this->error = 1002;
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * 封存/解封
+     * @param $goodsId
+     */
+    public function lock($goodsId)
+    {
+        $params = request()->all();
+        $status = isset($params['status'])? $params['status'] : 2;
+        $goods = $this->where(['id'=> $goodsId,'mark'=>1])->first();
+        if(empty($goods)){
+            $this->error = 2061;
+            return false;
+        }
+
+        if($this->model->where(['id'=> $goodsId])->update(['status'=> $status,'update_time'=> time(),'remark'=> '店长封存'])){
+            $this->error = 1002;
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * 修改商品信息
+     * @param $goodsId
+     * @return bool
+     */
+    public function updateData($goodsId)
+    {
+        $params = request()->all();
+        $goods = $this->where(['id'=> $goodsId,'mark'=>1])->first();
+        if(empty($goods)){
+            $this->error = 2061;
+            return false;
+        }
+
+        $data = [
+            'thumb'=> isset($params['thumb'])? $params['thumb']: '',
+            'goods_name'=> isset($params['goods_name'])? $params['goods_name']: '',
+            'update_time'=>time(),
+        ];
+
+        if($this->model->where(['id'=> $goodsId])->update($data)){
+            $this->error = 1008;
+            return true;
+        }
+
+        $this->error = 1009;
+        return false;
+    }
 }

+ 161 - 0
app/Services/Common/MemberAddressService.php

@@ -0,0 +1,161 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Common;
+
+use App\Models\MemberAddressModel;
+use App\Services\BaseService;
+use App\Services\RedisService;
+
+/**
+ * 用户地址管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class MemberAddressService
+ * @package App\Services\Common
+ */
+class MemberAddressService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * MemberAddressService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new MemberAddressModel();
+    }
+
+    /**
+     * 静态入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = (new static());
+        }
+        return self::$instance;
+    }
+
+    /**
+     * 列表数据
+     * @param $params
+     * @param int $pageSize
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1];
+        $status = isset($params['status']) ? $params['status'] : 0;
+        if ($status > 0) {
+            $where['a.status'] = $status;
+        }
+
+        $list = $this->model->from('member_address as a')
+            ->where($where)
+            ->select(['a.*'])
+            ->orderBy('a.id', 'desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list ? $list->toArray() : [];
+        if ($list) {
+            foreach ($list['data'] as &$item) {
+                $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
+            }
+        }
+
+        return [
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'list' => isset($list['data']) ? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 添加编辑
+     * @return array
+     * @since 2020/11/11
+     * @author laravel开发员
+     */
+    public function edit()
+    {
+        // 请求参数
+        $data = request()->all();
+        return parent::edit($data); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * 保存数据
+     * @param $userId
+     * @return mixed
+     */
+    public function saveData($userId)
+    {
+        $params = request()->all();
+
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $isDefault = isset($params['is_default']) ? $params['is_default'] : 2;
+        $data = [
+            'user_id'=> $userId,
+            'realname'=> isset($params['realname'])? $params['realname'] : '',
+            'province'=> isset($params['province'])? $params['province'] : '',
+            'city'=> isset($params['city'])? $params['city'] : '',
+            'district'=> isset($params['district'])? $params['district'] : '',
+            'codes'=> isset($params['codes'])? implode(',', $params['codes']) : '',
+            'address'=> isset($params['address'])? $params['address'] : '',
+            'is_default'=> isset($params['is_default'])? $params['is_default'] : 2,
+            'status'=> isset($params['status'])? $params['status'] : 1,
+            'create_time'=> time(),
+            'update_time'=> time(),
+            'mark'=> 1,
+        ];
+
+        if($isDefault==1){
+            $this->model->where(['user_id'=> $userId])->update(['is_default'=> 2,'update_time'=> time()]);
+        }
+
+        RedisService::keyDel("caches:address:{$userId}");
+        if(!$id){
+            $data['create_time'] = time();
+            return $this->model->insertGetId($data);
+        }else{
+            return $this->model->where(['id'=> $id])->update($data);
+        }
+    }
+
+
+    /**
+     * @param $userId
+     * @return array|mixed
+     */
+    public function getBindInfo($userId)
+    {
+        $cacheKey = "caches:address:{$userId}";
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+
+        $info = $this->model->where(['user_id'=> $userId,'mark'=>1,'status'=>1])
+            ->orderBy('is_default','asc')
+            ->orderBy('id','desc')
+            ->first();
+        if($info){
+            RedisService::set($cacheKey, $info, rand(5, 10));
+        }
+
+        return $info;
+    }
+}

+ 159 - 0
app/Services/Common/MemberBankService.php

@@ -0,0 +1,159 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Common;
+
+use App\Models\MemberAddressModel;
+use App\Models\MemberBankModel;
+use App\Services\BaseService;
+use App\Services\RedisService;
+
+/**
+ * 用户银行卡管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class MemberBankService
+ * @package App\Services\Common
+ */
+class MemberBankService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * MemberBankService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new MemberBankModel();
+    }
+
+    /**
+     * 静态入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = (new static());
+        }
+        return self::$instance;
+    }
+
+    /**
+     * 列表数据
+     * @param $params
+     * @param int $pageSize
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1];
+        $status = isset($params['status']) ? $params['status'] : 0;
+        if ($status > 0) {
+            $where['a.status'] = $status;
+        }
+
+        $list = $this->model->from('member_bank as a')
+            ->where($where)
+            ->select(['a.*'])
+            ->orderBy('a.id', 'desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list ? $list->toArray() : [];
+        if ($list) {
+            foreach ($list['data'] as &$item) {
+                $item['codes'] = $item['codes'] ? explode(',', $item['codes']) : [0, 0, 0];
+                $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
+            }
+        }
+
+        return [
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'list' => isset($list['data']) ? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 添加编辑
+     * @return array
+     * @since 2020/11/11
+     * @author laravel开发员
+     */
+    public function edit()
+    {
+        // 请求参数
+        $data = request()->all();
+        return parent::edit($data); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * 保存数据
+     * @param $userId
+     * @return mixed
+     */
+    public function saveData($userId)
+    {
+        $params = request()->all();
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $isDefault = isset($params['is_default']) ? $params['is_default'] : 2;
+        $data = [
+            'user_id' => $userId,
+            'realname' => isset($params['realname']) ? $params['realname'] : '',
+            'bank_name' => isset($params['bank_name']) ? $params['bank_name'] : '',
+            'bank_num' => isset($params['bank_num']) ? $params['bank_num'] : '',
+            'remark' => isset($params['remark']) ? $params['remark'] : '',
+            'is_default' => $isDefault,
+            'status' => isset($params['status']) ? $params['status'] : 1,
+            'update_time' => time(),
+            'mark' => 1,
+        ];
+
+        if($isDefault==1){
+            $this->model->where(['user_id'=> $userId])->update(['is_default'=> 2,'update_time'=> time()]);
+        }
+
+        RedisService::keyDel("caches:banks:{$userId}");
+        if(!$id){
+            $data['create_time'] = time();
+            return $this->model->insertGetId($data);
+        }else{
+            return $this->model->where(['id'=> $id])->update($data);
+        }
+    }
+
+
+    /**
+     * @param $userId
+     * @return array|mixed
+     */
+    public function getBindInfo($userId)
+    {
+        $cacheKey = "caches:banks:{$userId}";
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+
+        $info = $this->model->where(['user_id'=> $userId,'mark'=>1,'status'=>1])
+            ->orderBy('is_default','asc')
+            ->orderBy('id','desc')
+            ->first();
+        if($info){
+            RedisService::set($cacheKey, $info, rand(5, 10));
+        }
+
+        return $info;
+    }
+}

+ 393 - 23
app/Services/Common/MemberService.php

@@ -12,11 +12,14 @@
 namespace App\Services\Common;
 
 use App\Helpers\Jwt;
+use App\Models\AccountModel;
 use App\Models\ActionLogModel;
 use App\Models\MemberModel;
 use App\Models\ShopModel;
 use App\Services\BaseService;
+use App\Services\ConfigService;
 use App\Services\RedisService;
+use Illuminate\Support\Facades\DB;
 use phpQrcode\QRcode;
 
 /**
@@ -29,7 +32,6 @@ use phpQrcode\QRcode;
 class MemberService extends BaseService
 {
 
-    // 静态对象
     protected static $instance = null;
 
     /**
@@ -62,7 +64,7 @@ class MemberService extends BaseService
      */
     public function getInfo($where, array $field = [])
     {
-        $field = $field ? $field : ['id', 'username', 'realname','mobile', 'nickname','login_shop_id','code','parent_id', 'openid','score_rate', 'idcard', 'idcard_check', 'idcard_front_img', 'idcard_back_img', 'member_level', 'bonus','bonus_total','score', 'status', 'avatar'];
+        $field = $field ? $field : ['id', 'username', 'realname','mobile', 'nickname','is_trade','login_shop_id','code','parent_id', 'openid','score_rate', 'idcard', 'idcard_check', 'idcard_front_img', 'idcard_back_img', 'member_level', 'bonus','bonus_total','score', 'status', 'avatar'];
         if (is_array($where)) {
             $info = $this->model->where($where)->select($field)->first();
         } else {
@@ -72,8 +74,10 @@ class MemberService extends BaseService
         $info = $info ? $info->toArray() : [];
         if ($info) {
 
+            $info['version'] = env('VERSION','v1.1.20');
             $info['avatar'] = $info['avatar'] ? get_image_url($info['avatar']) : '';
             $info['bonus'] = round($info['bonus'],0);
+            $info['mobile_text'] = $info['mobile'];
             $info['mobile'] = $info['mobile']? format_mobile($info['mobile']):'';
             $info['show_bonus'] = GoodsService::make()->checkNewGoods($info['id']);
 
@@ -82,14 +86,92 @@ class MemberService extends BaseService
             $info['qrcode'] = $qrcode? get_image_url($qrcode):'';
             $info['shop_info'] = [];
             if(isset($info['login_shop_id']) && $info['login_shop_id']){
-                $info['shop_info'] = ShopService::make()->getInfo($info['login_shop_id']);
+                $shopInfo = ShopService::make()->getInfo($info['login_shop_id']);
+                $snapTime = ConfigService::make()->getConfigByCode('snap_time');
+                $snapTime = $snapTime? $snapTime : 5;
+
+                $curTime = strtotime(date('H:i:s'));
+                $startTime = isset($shopInfo['start_time'])&&$shopInfo['start_time']? strtotime($shopInfo['start_time']) : 0;
+                $endTime = isset($shopInfo['end_time'])&&$shopInfo['end_time']? strtotime($shopInfo['end_time']) : 0;
+                $timeLock = $startTime - $curTime>0? $startTime - $curTime : 0;
+                $shopInfo['timeData'] = [
+                    'hours'=> 0,
+                    'minutes'=> 0,
+                    'seconds'=> 0,
+                ];
+                $shopInfo['snap_time'] = $snapTime;
+                $shopInfo['time_lock'] = 0;
+                $shopInfo['trade_status'] = 2;
+                if($timeLock ){
+//                if($timeLock && $timeLock<= $snapTime*60){
+                    $shopInfo['time_lock'] = $timeLock;
+                    $shopInfo['timeData']['hours'] = intval($timeLock/3600);
+                    $shopInfo['timeData']['minutes'] = intval($timeLock%3600/60);
+                    $shopInfo['timeData']['seconds'] = intval($timeLock%3600%60);
+                    $shopInfo['trade_status'] = 1;
+                }else if($endTime>=$curTime && $curTime>=$startTime){
+                    $shopInfo['trade_status'] = 1;
+                }
+
+                $info['shop_info'] = $shopInfo;
+            }
+            $info['parent_info'] = [];
+            if(isset($info['parent_id']) && $info['parent_id']){
+                $info['parent_info'] = $this->model->where(['id'=>$info['parent_id'],'mark'=>1])
+                    ->select(['id','nickname','username','code'])
+                    ->first();
             }
 
-            // 交易订单统计
-            $info['orderCounts'] = TradeService::make()->getNewTradeCountByStatus($info['id'],[1,2,3]);
+            $type = request()->post('type', 0);
+
+            if($type == 3){
+                // 银行卡信息
+                $info['bank_info'] = MemberBankService::make()->getBindInfo($info['id']);
+            }
+
+            if($type == 1){
+                // 交易订单统计
+                $info['orderCounts'] = TradeService::make()->getNewTradeCountByStatus($info['id'],[1,2,3]);
+
+                // 积分订单统计
+                $info['scoreOrderCount'] = OrderService::make()->getNewTradeCount($info['id'],[1,2,3,4,5]);
+            }
 
-            // 积分订单统计
-            $info['scoreOrderCount'] = OrderService::make()->getNewTradeCount($info['id'],[1,2,3,4,5]);
+        }
+
+        return $info;
+    }
+
+    public function getMarketInfo($where, array $field = [])
+    {
+        $field = $field ? $field : ['id', 'username', 'realname','mobile', 'nickname','is_trade','login_shop_id','code','parent_id', 'openid','score_rate', 'idcard', 'idcard_check', 'idcard_front_img', 'idcard_back_img', 'member_level', 'bonus','bonus_total','score', 'status', 'avatar'];
+        if (is_array($where)) {
+            $info = $this->model->where($where)->select($field)->first();
+        } else {
+            $info = $this->model->where(['id' => (int)$where])->select($field)->first();
+        }
+
+        $info = $info ? $info->toArray() : [];
+        if ($info) {
+
+            $info['avatar'] = $info['avatar'] ? get_image_url($info['avatar']) : '';
+            $info['bonus'] = round($info['bonus'],0);
+            $info['bonus_total'] = round($info['bonus_total'],0);
+            $info['mobile'] = $info['mobile']? format_mobile($info['mobile']):'';
+            $info['show_bonus'] = GoodsService::make()->checkNewGoods($info['id']);
+
+            // 二维码
+            $qrcode = $this->makeQrcode(env('WEB_URL').'h5/#/pages/register/index?code='.$info['code']);
+            $info['qrcode'] = $qrcode? get_image_url($qrcode):'';
+
+            // 团队人数
+            $info['team_num'] = MemberService::make()->getInviteNums($info['id']);
+
+            // 本月业绩
+            $info['merits_month'] = TradeService::make()->getTeamTradeTotal($info['id'],[3,4], 1);
+
+            // 总业绩
+            $info['merits_total'] = TradeService::make()->getTeamTradeTotal($info['id'],[3,4]);
         }
 
         return $info;
@@ -129,7 +211,7 @@ class MemberService extends BaseService
         }
 
         // 密码校验
-        $password = get_password($password . md5($password . env('APP_NAME')));
+        $password = get_password($password);
         if ($password != $info['password']) {
             $this->error = 2002;
             return false;
@@ -193,8 +275,8 @@ class MemberService extends BaseService
         $data = [
             'nickname' => $nickname,
             'username' => strtoupper('U'.get_random_code(7)),
-            'password' => get_password($password . md5($password . env('APP_NAME'))),
-            'safe_password' => get_password($safePassword . md5($safePassword . env('APP_NAME'))),
+            'password' => get_password($password),
+            'safe_password' => get_password($safePassword),
             'mobile' => $mobile,
             'parents' => $parents,
             'parent_id' => $parentId,
@@ -214,6 +296,7 @@ class MemberService extends BaseService
     }
 
     /**
+     * 列表
      * @param $params
      * @param int $pageSize
      * @return array
@@ -226,12 +309,16 @@ class MemberService extends BaseService
         if($parentId>0){
             $where['a.parent_id'] = $parentId;
         }
+        $loginShopId = isset($params['login_shop_id'])? $params['login_shop_id'] : 0;
+        if($loginShopId>0){
+            $where['a.login_shop_id'] = $loginShopId;
+        }
         if($status>0){
             $where['a.status'] = $status;
         }
 
         $list = $this->model->from('member as a')
-            ->leftJoin('shop as b', 'b.user_id', '=', 'a.id')
+//            ->leftJoin('shop as b', 'b.user_id', '=', 'a.id')
             ->leftJoin('member as c', 'c.id', '=', 'a.parent_id')
             ->where($where)
             ->where(function ($query) use($params){
@@ -241,17 +328,25 @@ class MemberService extends BaseService
                 }
 
             })
-            ->select(['a.*','b.id as shop_id','b.name as shop_name','c.code as parent_code','c.nickname as parent_name'])
+            ->select(['a.*','c.code as parent_code','c.nickname as parent_name'])
             ->orderBy('a.create_time','desc')
             ->paginate($pageSize > 0 ? $pageSize : 9999999);
         $list = $list? $list->toArray() :[];
         if($list){
             foreach($list['data'] as &$item){
+                $item['rank_num'] = $item['id']%10+1;
                 $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
                 $item['login_time'] = $item['login_time']? datetime($item['login_time'],'Y-m-d H.i.s') : '';
                 $item['avatar'] = isset($item['avatar']) && $item['avatar']? get_image_url($item['avatar']) : '';
                 $item['parent_code'] = isset($item['parent_code']) && $item['parent_code']? $item['parent_code'] : '无';
-                $item['invite_num'] = MemberService::make()->getInviteNums($item['id']);
+
+                $showType = isset($params['show_type'])? $params['show_type'] : 1;
+                if($showType==1){
+                    $item['invite_num'] = MemberService::make()->getInviteNums($item['id']);
+                }else if ($showType == 2){
+                    $item['merits_month'] = TradeService::make()->getUserTradeTotal($item['id'],[3,4], 1);
+                    $item['merits_total'] = TradeService::make()->getUserTradeTotal($item['id'],[3,4]);
+                }
             }
         }
 
@@ -284,6 +379,42 @@ class MemberService extends BaseService
     }
 
     /**
+     * 用户选项
+     * @return array
+     */
+    public function options()
+    {
+        // 获取参数
+        $param = request()->all();
+        // 用户ID
+        $keyword = getter($param, "keyword");
+        $parentId = getter($param, "parent_id");
+        $userId = getter($param, "user_id");
+        $datas = $this->model->where(function($query) use($parentId){
+            if($parentId){
+                $query->where(['id'=> $parentId,'mark'=>1]);
+            }else{
+                $query->where(['status'=> 1,'mark'=>1]);
+            }
+        })
+            ->where(function($query) use($userId){
+                if($userId){
+                    $query->whereNotIn('id', [$userId]);
+                }
+            })
+            ->where(function($query) use($keyword){
+                if($keyword){
+                    $query->where('nickname','like',"%{$keyword}%")->orWhere('mobile','like',"%{$keyword}%");
+                }
+            })
+            ->select(['id','username','mobile','code','nickname','status'])
+            ->get();
+
+        return $datas? $datas->toArray() : [];
+
+    }
+
+    /**
      * 上级用户列表
      * @return array
      */
@@ -418,6 +549,17 @@ class MemberService extends BaseService
     }
 
     /**
+     * 修改头像
+     * @param $userId
+     * @param $avatar
+     * @return mixed
+     */
+    public function saveAvatar($userId, $avatar)
+    {
+        return $this->model->where(['id'=> $userId])->update(['avatar'=> $avatar,'update_time'=> time()]);
+    }
+
+    /**
      * 重置密码
      * @return array
      * @since 2020/11/14
@@ -438,7 +580,7 @@ class MemberService extends BaseService
         }
         // 设置新密码
         $password = '123456';
-        $userInfo['password'] = get_password($password . md5($password.env('APP_NAME')));
+        $userInfo['password'] = get_password($password);
         $result = $this->model->edit($userInfo);
         if (!$result) {
             return message("重置密码失败", false);
@@ -476,7 +618,7 @@ class MemberService extends BaseService
         }
 
         // 密码校验
-        $password = get_password($password . md5($password . 'otc'));
+        $password = get_password($password);
         if ($password != $info['password']) {
             $this->error = 2002;
             return false;
@@ -505,29 +647,95 @@ class MemberService extends BaseService
      */
     public function updatePassword($userId, $params)
     {
-        $username = isset($params['username']) ? $params['username'] : '';
         $password = isset($params['password']) ? $params['password'] : '';
-        if (empty($username) || empty($password)) {
-            $this->error = 1013;
+        $oldPassword = isset($params['old_password']) ? $params['old_password'] : '';
+        if (empty($oldPassword)) {
+            $this->error = 2014;
             return false;
         }
 
+        if (empty($password)) {
+            $this->error = 2015;
+            return false;
+        }
+
+
+
         // 用户验证
-        $info = $this->model->getOne([['username', '=', $username]]);
-        if (!$info || $info['id'] != $userId) {
+        $info = $this->model->getOne([['id', '=', $userId,'mark'=>1]]);
+        if (!$info) {
             $this->error = 2001;
             return false;
         }
 
         // 使用状态校验
         if ($info['status'] != 1) {
-            $this->error = 2009;
+            $this->error = 2012;
+            return false;
+        }
+
+        // 更新登录密码
+        $passwordStr = get_password($password);
+        $oldPasswordStr = get_password($oldPassword);
+        if($info['password'] != $oldPasswordStr){
+            $this->error = 2002;
+            return false;
+        }
+        if($oldPassword == $password){
+            $this->error = 2016;
+            return false;
+        }
+        if (!$this->model->where(['id' => $info['id']])->update(['password' => $passwordStr, 'update_time' => time()])) {
+            $this->error = 2025;
+            return false;
+        }
+
+        $this->error = 2024;
+        return true;
+    }
+
+
+    /**
+     * 修改更新支付密码
+     * @param $userId
+     * @param $params
+     * @return bool
+     */
+    public function updateSafePassword($userId, $params)
+    {
+        $password = isset($params['password']) ? $params['password'] : '';
+        $safePassword = isset($params['safe_password']) ? $params['safe_password'] : '';
+        if (empty($safePassword)) {
+            $this->error = 2017;
+            return false;
+        }
+
+        if (empty($password)) {
+            $this->error = 2018;
+            return false;
+        }
+
+        // 用户验证
+        $info = $this->model->getOne([['id', '=', $userId,'mark'=>1]]);
+        if (!$info) {
+            $this->error = 2001;
+            return false;
+        }
+
+        // 使用状态校验
+        if ($info['status'] != 1) {
+            $this->error = 2012;
             return false;
         }
 
         // 更新登录密码
-        $password = get_password($password . md5($password . 'otc'));
-        if (!$this->model->where(['id' => $info['id']])->update(['password' => $password, 'update_time' => time()])) {
+        $safePassword = get_password($safePassword);
+        $oldPasswordStr = get_password($password);
+        if($info['password'] != $oldPasswordStr){
+            $this->error = 2002;
+            return false;
+        }
+        if (!$this->model->where(['id' => $info['id']])->update(['safe_password' => $safePassword, 'update_time' => time()])) {
             $this->error = 2025;
             return false;
         }
@@ -536,4 +744,166 @@ class MemberService extends BaseService
         return true;
     }
 
+    /**
+     * 转换佣金
+     * @param $userId
+     * @param int $shopId
+     * @param int $catchUid
+     * @return bool
+     */
+    public function switchBonus($userId, $shopId=0, $catchUid=0)
+    {
+
+        if($userId>0){
+            $info = $this->model->where(['id'=> $userId,'mark'=>1])
+                ->select(['id','bonus','login_shop_id','bonus','score','status'])
+                ->first();
+            $score = isset($info['score'])? $info['score'] : 0;
+            $bonus = isset($info['bonus'])? $info['bonus'] : 0;
+            $status = isset($info['status'])? $info['status'] : 0;
+            if(empty($info) || $status != 1){
+                $this->error = 2019;
+                return false;
+            }
+
+            if($bonus<=0){
+                $this->error = 2026;
+                return false;
+            }
+
+            DB::beginTransaction();
+            if(!$this->model->where(['id'=> $userId])->update(['bonus'=> 0,'score'=> intval($score * $bonus), 'update_time'=> time()])){
+                DB::rollBack();
+                return false;
+            }
+
+            $logDatas[0] = [
+                'user_id'=> $userId,
+                'shop_id'=> $info['login_shop_id'],
+                'type'=> 5,
+                'coin_type'=> 2,
+                'money'=> -$info['bonus'],
+                'balance'=> $info['bonus'],
+                'create_time'=>time(),
+                'update_time'=>time(),
+                'remark'=> '店长一键转换佣金',
+                'status'=>1,
+                'mark'=> 1,
+            ];
+            $logDatas[1] = [
+                'user_id'=> $userId,
+                'shop_id'=> $info['login_shop_id'],
+                'type'=> 5,
+                'coin_type'=> 3,
+                'money'=> $info['bonus'],
+                'balance'=> $info['score'],
+                'create_time'=>time(),
+                'update_time'=>time(),
+                'remark'=> '店长一键转换佣金',
+                'status'=>1,
+                'mark'=> 1,
+            ];
+            if(!AccountModel::insert($logDatas)){
+                DB::rollBack();
+                return false;
+            }
+
+            DB::commit();
+            $this->error = 1002;
+            return true;
+
+        }
+        // 店铺一键转换
+        else if ($shopId>0){
+            $datas = $this->model->where(['login_shop_id'=> $shopId,'mark'=>1,'status'=>1])
+                ->where('bonus','>', 0)
+                ->select(['id','bonus','login_shop_id','bonus','score'])
+                ->get();
+
+            if($datas){
+                $logDatas = [];
+                $scoreRate = ConfigService::make()->getConfigByCode('score_rate');
+                $scoreRate = $scoreRate? $scoreRate : 1;
+
+                foreach($datas as $v){
+
+                    // 佣金
+                    $logDatas[] = [
+                        'user_id'=> $v['id'],
+                        'shop_id'=> $v['login_shop_id'],
+                        'type'=> 5,
+                        'coin_type'=> 2,
+                        'money'=> -$v['bonus'],
+                        'balance'=> $v['bonus'],
+                        'create_time'=>time(),
+                        'update_time'=>time(),
+                        'remark'=> '店长一键转换佣金',
+                        'status'=>1,
+                        'mark'=> 1,
+                    ];
+
+                    // 积分
+                    $logDatas[] = [
+                        'user_id'=> $v['id'],
+                        'shop_id'=> $v['login_shop_id'],
+                        'type'=> 5,
+                        'coin_type'=> 3,
+                        'money'=> $v['bonus']*$scoreRate,
+                        'balance'=> $v['score'],
+                        'create_time'=>time(),
+                        'update_time'=>time(),
+                        'remark'=> '店长一键转换佣金',
+                        'status'=>1,
+                        'mark'=> 1,
+                    ];
+                }
+
+                $sql = "UPDATE lev_member set `score`=`score`+(`bonus`)*{$scoreRate},`bonus`=0,update_time=".time()." where login_shop_id={$shopId} and status=1 and mark=1 and bonus >0";
+
+                DB::beginTransaction();
+                if(!DB::update(DB::raw($sql))){
+                    DB::rollBack();
+                    return false;
+                }
+
+                if(!AccountModel::insert($logDatas)){
+                    DB::rollBack();
+                    return false;
+                }
+
+                DB::commit();
+                $this->error = 1002;
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * 设置抢拍状态
+     * @param $userId
+     * @param $shopId
+     * @param int $status
+     * @return mixed
+     */
+    public function setTrade($userId, $shopId, $status=1)
+    {
+        if($userId>0){
+            return $this->model->where(['id'=> $userId])->update(['is_trade'=>$status,'update_time'=> time()]);
+        }else if($shopId){
+
+            return $this->model->where(['login_shop_id'=> $shopId,'mark'=>1])->update(['is_trade'=>$status,'update_time'=> time()]);
+        }
+    }
+
+    /**
+     * 删除用户
+     * @param $userId
+     * @return mixed
+     */
+    public function setLock($userId)
+    {
+        return $this->model->where(['id'=> $userId])->update(['status'=> 2,'update_time'=> time()]);
+    }
 }

+ 1 - 6
app/Services/Common/OrderService.php

@@ -67,18 +67,13 @@ class OrderService extends BaseService
      * @param int $status 状态
      * @return mixed
      */
-    public function getNewTradeCount($userId, $status=0, $time=30)
+    public function getNewTradeCount($userId, $status=0)
     {
         $where = ['user_id'=>$userId,'mark'=>1,'is_read'=>0];
         return $this->model->where($where)
             ->where(function($query) use($status){
                 $query->whereIn('status',is_array($status)? $status:[$status]);
             })
-            ->where(function($query) use($time){
-                if($time){
-                    $query->where('update_time','>', $time);
-                }
-            })
             ->count('id');
     }
 }

+ 140 - 0
app/Services/Common/ScoreGoodsCateService.php

@@ -0,0 +1,140 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Common;
+
+use App\Models\GoodsModel;
+use App\Models\ScoreGoodsCateModel;
+use App\Models\ScoreGoodsModel;
+use App\Services\BaseService;
+
+/**
+ * 积分商品分类管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class ScoreGoodsCateService
+ * @package App\Services\Common
+ */
+class ScoreGoodsCateService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * ScoreGoodsCateService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new ScoreGoodsCateModel();
+    }
+
+    /**
+     * 静态入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = (new static());
+        }
+        return self::$instance;
+    }
+
+    /**
+     * 列表数据
+     * @param $params
+     * @param int $pageSize
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1];
+        $status = isset($params['status'])? $params['status'] : 0;
+        if($status>0){
+            $where['a.status'] = $status;
+        }
+
+        $list = $this->model->from('score_goods_cate as a')
+            ->where($where)
+            ->where(function ($query) use($params){
+                $keyword = isset($params['keyword'])? $params['keyword'] : '';
+                if($keyword){
+                    $query->where('a.name','like',"%{$keyword}%");
+
+                }
+            })
+            ->select(['a.*'])
+            ->orderBy('a.id','desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list? $list->toArray() :[];
+        if($list){
+            foreach($list['data'] as &$item){
+                $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
+                $item['icon'] = isset($item['icon']) && $item['icon']? get_image_url($item['icon']) : '';
+            }
+        }
+
+        return [
+            'pageSize'=> $pageSize,
+            'total'=>isset($list['total'])? $list['total'] : 0,
+            'list'=> isset($list['data'])? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 选项
+     * @return array
+     */
+    public function options()
+    {
+        // 获取参数
+        $param = request()->all();
+
+        // 用户ID
+        $keyword = getter($param, "keyword");
+        $datas = $this->model->where(['mark'=>1])->where(function($query) use($keyword){
+                if($keyword){
+                    $query->where('name','like',"%{$keyword}%");
+                }
+            })
+            ->select(['id','name','status'])
+            ->get();
+
+        return $datas? $datas->toArray() : [];
+
+    }
+
+
+    /**
+     * 添加编辑
+     * @return array
+     * @since 2020/11/11
+     * @author laravel开发员
+     */
+    public function edit()
+    {
+        // 请求参数
+        $data = request()->all();
+        // thumb处理
+        $thumb = isset($data['icon'])? trim($data['icon']) : '';
+        if ($thumb && strpos($thumb, "temp")) {
+            $data['icon'] = save_image($thumb, 'member');
+        } else if($thumb){
+            $data['icon'] = str_replace(IMG_URL, "", $data['icon']);
+        }
+
+        return parent::edit($data); // TODO: Change the autogenerated stub
+    }
+
+}

+ 118 - 0
app/Services/Common/ScoreGoodsService.php

@@ -0,0 +1,118 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Common;
+
+use App\Models\GoodsModel;
+use App\Models\ScoreGoodsModel;
+use App\Services\BaseService;
+
+/**
+ * 积分商品管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class ScoreGoodsService
+ * @package App\Services\Common
+ */
+class ScoreGoodsService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * ScoreGoodsService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new ScoreGoodsModel();
+    }
+
+    /**
+     * 静态入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = (new static());
+        }
+        return self::$instance;
+    }
+
+    /**
+     * 列表数据
+     * @param $params
+     * @param int $pageSize
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1];
+        $status = isset($params['status'])? $params['status'] : 0;
+        if($status>0){
+            $where['a.status'] = $status;
+        }
+
+        $list = $this->model->from('score_goods as a')
+            ->leftJoin('score_goods_cate as c', 'c.id', '=', 'a.cate_id')
+            ->where($where)
+            ->where(function ($query) use($params){
+                $keyword = isset($params['keyword'])? $params['keyword'] : '';
+                if($keyword){
+                    $query->where('a.goods_name','like',"%{$keyword}%")->orWhere('c.name','like',"%{$keyword}%");
+
+                }
+            })
+            ->select(['a.*','c.name as cate_name'])
+            ->orderBy('a.id','desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list? $list->toArray() :[];
+        if($list){
+            foreach($list['data'] as &$item){
+                $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
+                $item['thumb'] = isset($item['thumb']) && $item['thumb']? get_image_url($item['thumb']) : '';
+            }
+        }
+
+        return [
+            'pageSize'=> $pageSize,
+            'total'=>isset($list['total'])? $list['total'] : 0,
+            'list'=> isset($list['data'])? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 添加编辑
+     * @return array
+     * @since 2020/11/11
+     * @author laravel开发员
+     */
+    public function edit()
+    {
+        // 请求参数
+        $data = request()->all();
+        // thumb处理
+        $thumb = isset($data['thumb'])? trim($data['thumb']) : '';
+        if ($thumb && strpos($thumb, "temp")) {
+            $data['thumb'] = save_image($thumb, 'member');
+        } else if($thumb){
+            $data['thumb'] = str_replace(IMG_URL, "", $data['thumb']);
+        }
+        if(!isset($data['code']) || empty($data['code'])){
+            $data['code'] = isset($data['id'])&&$data['id']? 'G'.$data['id'] :'G'.(ScoreGoodsModel::max('id')+1);
+        }
+        return parent::edit($data); // TODO: Change the autogenerated stub
+    }
+
+}

+ 71 - 0
app/Services/Common/ShopService.php

@@ -13,6 +13,8 @@ namespace App\Services\Common;
 
 use App\Models\ShopModel;
 use App\Services\BaseService;
+use App\Services\ConfigService;
+use App\Services\RedisService;
 
 /**
  * 店铺管理-服务类
@@ -55,6 +57,12 @@ class ShopService extends BaseService
      */
     public function getInfo($where, array $field = [])
     {
+        $cacheKey = "caches:shop:".(!is_array($where)? $where : md5(json_encode($where)));
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+
         $field = $field ? $field : ['id', 'name', 'user_id', 'logo', 'code', 'theme_id', 'start_time', 'end_time', 'status'];
         if (is_array($where)) {
             $info = $this->model->where($where)->select($field)->first();
@@ -65,6 +73,7 @@ class ShopService extends BaseService
         $info = $info ? $info->toArray() : [];
         if($info){
             $info['logo'] = $info['logo'] ? get_image_url($info['logo']) : '';
+            RedisService::set($cacheKey, $info, rand(5,10));
         }
         return $info;
     }
@@ -130,6 +139,42 @@ class ShopService extends BaseService
     }
 
     /**
+     * 选项
+     * @return array
+     */
+    public function options()
+    {
+        // 获取参数
+        $param = request()->all();
+        // 用户ID
+        $keyword = getter($param, "keyword");
+        $parentId = getter($param, "parent_id");
+        $id = getter($param, "id");
+        $datas = $this->model->where(function($query) use($parentId){
+            if($parentId){
+                $query->where(['id'=> $parentId,'mark'=>1]);
+            }else{
+                $query->where(['status'=> 1,'mark'=>1]);
+            }
+        })
+            ->where(function($query) use($id){
+                if($id){
+                    $query->whereNotIn('id', [$id]);
+                }
+            })
+            ->where(function($query) use($keyword){
+                if($keyword){
+                    $query->where('name','like',"%{$keyword}%")->orWhere('code','like',"%{$keyword}%");
+                }
+            })
+            ->select(['id','name','code','status'])
+            ->get();
+
+        return $datas? $datas->toArray() : [];
+
+    }
+
+    /**
      * 推荐人列表
      * @return array
      */
@@ -187,4 +232,30 @@ class ShopService extends BaseService
         return parent::edit($data); // TODO: Change the autogenerated stub
     }
 
+    /**
+     * 设置抢拍时间
+     * @param $userId
+     * @param $shopId
+     * @return mixed
+     */
+    public function setTime($userId, $shopId, $params)
+    {
+        $shopInfo = $this->model->where(['id'=> $shopId,'mark'=>1])->first();
+        $shopUid = isset($shopInfo['user_id'])? $shopInfo['user_id'] : 0;
+        if(empty($shopInfo) || $userId != $shopUid){
+            $this->error = 2020;
+            return false;
+        }
+
+        $startTime = isset($params['start_time'])? $params['start_time'] : '';
+        $endTime = isset($params['end_time'])? $params['end_time'] : '';
+        if($endTime <  $startTime){
+            $this->error = 2021;
+            return false;
+        }
+
+        RedisService::keyDel('caches:shop:'.$shopId);
+        return $this->model->where(['id'=> $shopId])->update(['start_time'=> $startTime,'end_time'=> $endTime,'update_time'=>time()]);
+    }
+
 }

+ 618 - 20
app/Services/Common/TradeService.php

@@ -11,8 +11,15 @@
 
 namespace App\Services\Common;
 
+use App\Models\AccountModel;
+use App\Models\GoodsModel;
+use App\Models\MemberModel;
 use App\Models\TradeModel;
 use App\Services\BaseService;
+use App\Services\ConfigService;
+use \App\Services\Common\FinanceService;
+use App\Services\RedisService;
+use Illuminate\Support\Facades\DB;
 
 /**
  * 交易管理-服务类
@@ -49,6 +56,177 @@ class TradeService extends BaseService
         return self::$instance;
     }
 
+
+    /**
+     * @param $params
+     * @param int $pageSize
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1];
+        $status = isset($params['status']) ? $params['status'] : 0;
+        $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+        $shopId = isset($params['shop_id']) ? $params['shop_id'] : 0;
+        $parentId = isset($params['parent_id']) ? $params['parent_id'] : 0;
+        $isAppeal = isset($params['is_appeal']) ? $params['is_appeal'] : 0;
+        $sellUid = isset($params['sell_uid']) ? $params['sell_uid'] : 0;
+        if ($shopId > 0) {
+            $where['a.shop_id'] = $shopId;
+        }
+        if ($parentId > 0) {
+            $where['b.parent_id'] = $parentId;
+        }
+
+        if ($isAppeal > 0) {
+            $where['a.is_appeal'] = $isAppeal;
+        }
+        if ($status > 0) {
+            $where['a.status'] = $status;
+        }
+
+        $list = $this->model->from('trade as a')
+            ->leftJoin('member as b', 'a.user_id', '=', 'b.id')
+            ->leftJoin('member as c', 'c.id', '=', 'a.sell_uid')
+            ->leftJoin('goods as g', 'g.id', '=', 'a.goods_id')
+            ->where($where)
+            ->where(function ($query) use ($params) {
+                $keyword = isset($params['keyword']) ? $params['keyword'] : '';
+                if ($keyword) {
+                    $query->where('b.nickname', 'like', "%{$keyword}%")->orWhere('b.mobile', 'like', "%{$keyword}%")->orWhere('g.goods_name', 'like', "%{$keyword}%");
+                }
+            })
+            ->where(function ($query) use ($params) {
+                $time = isset($params['time']) ? $params['time'] : 0;
+                if ($time) {
+                    $query->where('a.pay_time', '>=', $time)->orWhere('a.create_time', '>=', $time);
+                }
+            })
+            ->where(function ($query) use ($userId,$sellUid, $status) {
+
+                if ($sellUid && $userId) {
+                    $query->where(function($query) use($userId, $sellUid){
+                        $query->where('a.user_id', $userId)->orWhere('a.sell_uid', $sellUid);
+                    })->where('a.status','<=', 2);
+                }else if($userId){
+                    $query->where('a.user_id', '=', $userId);
+                }else if($sellUid){
+                    $query->where('a.sell_uid', '=', $sellUid);
+                }
+            })
+            ->select(['a.*', 'b.nickname', 'b.mobile as buy_mobile', 'c.nickname as sell_nickname', 'c.mobile as sell_mobile', 'g.goods_name', 'g.code', 'g.thumb'])
+            ->orderBy('a.pay_time', 'desc')
+            ->orderBy('a.id', 'desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list ? $list->toArray() : [];
+        if ($list) {
+            foreach ($list['data'] as &$item) {
+                $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H:i:s') : '';
+                $item['pay_time'] = $item['pay_time'] ? datetime($item['pay_time'], 'Y-m-d H:i:s') : '';
+                $item['confirm_time'] = $item['confirm_time'] ? datetime($item['confirm_time'], 'Y-m-d H:i:s') : '';
+                $item['thumb'] = isset($item['thumb']) && $item['thumb'] ? get_image_url($item['thumb']) : '';
+                $item['price'] = intval($item['price']);
+                $item['real_price'] = intval($item['real_price']);
+                $item['fee'] = intval($item['fee']);
+            }
+        }
+
+
+        return [
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'counts' => [
+                ''
+            ],
+            'list' => isset($list['data']) ? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 详情
+     * @param $id
+     * @return mixed
+     */
+    public function getInfo($id)
+    {
+        $info = $this->model->from('trade as a')
+            ->leftJoin('member as b', 'a.user_id', '=', 'b.id')
+            ->leftJoin('member as c', 'c.id', '=', 'a.sell_uid')
+            ->leftJoin('goods as g', 'g.id', '=', 'a.goods_id')
+            ->where(['a.id'=>$id,'a.mark'=>1])
+            ->select(['a.*', 'b.nickname', 'b.mobile as buy_mobile', 'c.nickname as sell_nickname', 'c.mobile as sell_mobile', 'g.goods_name', 'g.code', 'g.thumb'])
+            ->first();
+        if($info){
+            $info['create_time_text'] = $info['create_time'] ? datetime($info['create_time'], 'Y-m-d H:i:s') : '';
+            $info['pay_time'] = $info['pay_time'] ? datetime($info['pay_time'], 'Y-m-d H:i:s') : '';
+            $info['confirm_time'] = $info['confirm_time'] ? datetime($info['confirm_time'], 'Y-m-d H:i:s') : '';
+            $info['thumb'] = isset($info['thumb']) && $info['thumb'] ? get_image_url($info['thumb']) : '';
+            $info['pay_img'] = isset($info['pay_img']) && $info['pay_img'] ? get_image_url($info['pay_img']) : '';
+            $info['price'] = intval($info['price']);
+            $info['real_price'] = intval($info['real_price']);
+            $info['fee'] = intval($info['fee']);
+
+            $info['bank_info'] = MemberBankService::make()->getBindInfo($info['sell_uid']);
+        }
+
+        return $info;
+    }
+
+    /**
+     * 统计
+     * @param $params
+     * @return int[]
+     */
+    public function getCounts($params)
+    {
+        $counts = ['total' => 0, 'service_fee' => 0, 'bonus' => 0, 'fee' => 0];
+        $where = ['a.mark' => 1];
+        $status = isset($params['status']) ? $params['status'] : 0;
+        $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+        $shopId = isset($params['shop_id']) ? $params['shop_id'] : 0;
+        $parentId = isset($params['parent_id']) ? $params['parent_id'] : 0;
+        $isAppeal = isset($params['is_appeal']) ? $params['is_appeal'] : 0;
+        $sellUid = isset($params['sell_uid']) ? $params['sell_uid'] : 0;
+        if ($shopId > 0) {
+            $where['a.shop_id'] = $shopId;
+        }
+        if ($parentId > 0) {
+            $where['b.parent_id'] = $parentId;
+        }
+        if ($userId > 0) {
+            $where['a.user_id'] = $userId;
+        }
+        if ($sellUid > 0) {
+            $where['a.sell_uid'] = $sellUid;
+        }
+        if ($isAppeal > 0) {
+            $where['a.is_appeal'] = $isAppeal;
+        }
+        if ($status > 0) {
+            $where['a.status'] = $status;
+        }
+        $type = isset($params['type']) ? $params['type'] : 0;
+
+        $counts['total'] = intval($this->model->from('trade as a')
+            ->where($where)
+            ->sum('real_price'));
+
+
+        $bonusRate = ConfigService::make()->getConfigByCode('bonus_rate');
+        $bonusRate = $bonusRate ? $bonusRate : 5;
+        $counts['bonus'] = intval($counts['total'] * $bonusRate / 100);
+        $counts['fee'] = intval($this->model->from('trade as a')
+            ->where($where)
+            ->sum('fee'));
+
+            $serviceRate = ConfigService::make()->getConfigByCode('service_fee_rate');
+            $serviceRate = $serviceRate ? $serviceRate : 8;
+            $counts['service_fee'] = intval($counts['total'] * $serviceRate / 100);
+        
+
+        return $counts;
+    }
+
     /**
      * 添加或编辑
      * @return array
@@ -64,14 +242,13 @@ class TradeService extends BaseService
     /**
      * 获取店铺交易统计
      * @param $shopId
-     * @param int $type
-     * @param int $coinType
+     * @param int $status
      * @return mixed
      */
-    public function getShopTradeTotal($shopId, $status=0)
+    public function getShopTradeTotal($shopId, $status = 0)
     {
-        $where = ['shop_id'=>$shopId,'mark'=>1];
-        if($status){
+        $where = ['shop_id' => $shopId, 'mark' => 1];
+        if ($status) {
             $where['status'] = $status;
         }
         return $this->model->where($where)
@@ -81,14 +258,13 @@ class TradeService extends BaseService
     /**
      * 获取交易数
      * @param $shopId
-     * @param int $type
-     * @param int $coinType
+     * @param int $status
      * @return mixed
      */
     public function getShopTradeCount($shopId, $status = 0)
     {
-        $where = ['shop_id'=>$shopId,'mark'=>1];
-        if($status){
+        $where = ['shop_id' => $shopId, 'mark' => 1];
+        if ($status) {
             $where['status'] = $status;
         }
         return $this->model->where($where)
@@ -96,24 +272,446 @@ class TradeService extends BaseService
     }
 
     /**
-     * 抢拍交易订单数
-     * @param $userId 用户ID
-     * @param int $status 状态
+     * 获取用户交易统计
+     * @param $userId
+     * @param int $status
+     * @param int $time
      * @return mixed
      */
-    public function getNewTradeCountByStatus($userId, $status=0, $time=30)
+    public function getUserTradeTotal($userId, $status = 0, $time = 0)
     {
-        $where = ['user_id'=>$userId,'mark'=>1,'is_read'=>0];
+        $where = ['user_id' => $userId, 'mark' => 1];
         return $this->model->where($where)
-            ->where(function($query) use($status){
-                $query->whereIn('status',is_array($status)? $status:[$status]);
+            ->where(function ($query) use ($status, $time) {
+                $query->whereIn('status', is_array($status) ? $status : [$status]);
+
+                // 本月
+                if ($time == 1) {
+                    $query->where('pay_time', '>=', strtotime(date('Y-m-01')));
+                } // 今日
+                else if ($time == 2) {
+                    $query->where('pay_time', '>=', strtotime(date('Y-m-d')));
+                }
             })
-            ->where(function($query) use($time){
-                if($time){
-                    $query->where('update_time','>', $time);
+            ->sum('price');
+    }
+
+    /**
+     * 获取用户团队交易统计
+     * @param $userId
+     * @param int $status
+     * @param int $time
+     * @return mixed
+     */
+    public function getTeamTradeTotal($userId, $status = 0, $time = 0)
+    {
+        $where = ['b.parent_id' => $userId, 'a.mark' => 1];
+        return $this->model->from('trade as a')
+            ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
+            ->where($where)
+            ->where(function ($query) use ($status, $time) {
+                $query->whereIn('a.status', is_array($status) ? $status : [$status]);
+
+                // 本月
+                if ($time == 1) {
+                    $query->where('a.pay_time', '>=', strtotime(date('Y-m-01')));
+                } // 今日
+                else if ($time == 2) {
+                    $query->where('a.pay_time', '>=', strtotime(date('Y-m-d')));
                 }
             })
+            ->sum('a.price');
+    }
+
+    /**
+     * 抢拍交易订单数
+     * @param $userId 用户ID
+     * @param int $status 状态
+     * @return mixed
+     */
+    public function getNewTradeCountByStatus($userId, $status = 0)
+    {
+        $where = ['user_id' => $userId, 'mark' => 1, 'is_read' => 0];
+        $counts = $this->model->where($where)
+            ->where(function ($query) use ($status) {
+                $query->whereIn('status', is_array($status) ? $status : [$status]);
+            })
+            ->select(['status', DB::raw('count(*) as count')])
             ->groupBy('status')
-            ->count();
+            ->get();
+
+        if ($counts) {
+            $temps = ['status1' => 0, 'status2' => 0, 'status3' => 0];
+            foreach ($counts as $v) {
+                $temps['status' . $v['status']] = $v['count'];
+            }
+            $counts = $temps;
+        } else {
+            $counts = ['status1' => 0, 'status2' => 0, 'status3' => 0];
+        }
+
+        return $counts;
+    }
+
+    /**
+     * 抢购
+     * @param $params
+     * @param $userId
+     * @param $shopId
+     * @return bool
+     */
+    public function buy($params, $userId, $shopId)
+    {
+        $goodsId = isset($params['id']) ? $params['id'] : 0;
+        $info = GoodsService::make()->getInfo(['id' => $goodsId, 'status' => 1, 'mark' => 1]);
+        $goodsUserId = isset($info['user_id']) ? $info['user_id'] : 0;
+        $isTrade = isset($info['is_trade']) ? $info['is_trade'] : 0;
+        if (empty($info)) {
+            $this->error = 2031;
+            return false;
+        }
+
+        if ($isTrade == 1) {
+            $this->error = 2032;
+            return false;
+        }
+
+        if ($goodsUserId == $userId) {
+            $this->error = 2036;
+            return false;
+        }
+
+        $shopInfo = ShopService::make()->getInfo($shopId);
+        if (empty($shopInfo)) {
+            $this->error = 2033;
+            return false;
+        }
+
+        // 营业时间
+        $curTime = time();
+        $startTime = isset($shopInfo['start_time']) ? $shopInfo['start_time'] : '';
+        $endTime = isset($shopInfo['end_time']) ? $shopInfo['end_time'] : '';
+
+        // 店长自己抢
+        if ($shopInfo['user_id'] == $userId) {
+            $snapTime = ConfigService::make()->getConfigByCode('snap_time');
+            $snapTime = $snapTime ? $snapTime : 5;
+            $curTime = strtotime(date('Y-m-d') . ' ' . $startTime) + 1;
+            if (time() < strtotime(date('Y-m-d') . ' ' . $startTime) - $snapTime * 60) {
+                $this->error = 2034;
+                return false;
+            } else if (time() > strtotime(date('Y-m-d') . ' ' . $endTime)) {
+                $this->error = 2035;
+                return false;
+            }
+        } else {
+            if (time() < strtotime(date('Y-m-d') . ' ' . $startTime)) {
+                $this->error = 2034;
+                return false;
+            } else if (time() > strtotime(date('Y-m-d') . ' ' . $endTime)) {
+                $this->error = 2035;
+                return false;
+            }
+        }
+
+
+        // 验证收款账号
+        if (!MemberBankService::make()->getBindInfo($userId)) {
+            $this->error = 2037;
+            return false;
+        }
+
+        $feeRate = ConfigService::make()->getConfigByCode('sell_fee_rate');
+        $feeRate = $feeRate ? $feeRate : '2.5';
+        $realPrice = intval($info['price'] - $info['sell_price'] + $info['source_price']);
+        $fee = round($realPrice * $feeRate / 100, 0);
+
+        $lockCacheKey = "caches:trade:lock:{$goodsId}";
+        if (RedisService::get($lockCacheKey)) {
+            $this->error = 2032;
+            return false;
+        }
+
+        RedisService::set($lockCacheKey, $info, rand(1, 2));
+        $data = [
+            'order_sn' => get_order_num('T'),
+            'goods_id' => $goodsId,
+            'user_id' => $userId,
+            'shop_id' => $shopId,
+            'sell_uid' => $info['user_id'],
+            'num' => 1,
+            'price' => $info['price'],
+            'source_price' => $info['source_price'],
+            'sell_price' => $info['sell_price'],
+            'real_price' => $realPrice,
+            'fee' => $fee,
+            'new_price' => $info['price'],
+            'remark' => '抢拍交易',
+            'create_time' => $curTime,
+            'update_time' => $curTime,
+            'status' => 1
+        ];
+
+        DB::beginTransaction();
+        if (!TradeModel::insertGetId($data)) {
+            DB::rollBack();
+            $this->error = 2040;
+            return false;
+        }
+
+        if (!GoodsModel::where(['id' => $goodsId])->update(['is_trade' => 1, 'update_time' => time()])) {
+            DB::rollBack();
+            $this->error = 2040;
+            return false;
+        }
+
+
+        DB::commit();
+        RedisService::keyDel($lockCacheKey);
+        $this->error = 2041;
+
+        return true;
+    }
+
+    /**
+     * 付款
+     * @param $params
+     * @param $userId
+     * @param $shopId
+     * @return bool
+     */
+    public function pay($params, $userId, $shopId)
+    {
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $payImg = isset($params['pay_img']) ? $params['pay_img'] : '';
+        if (empty($payImg)) {
+            $this->error = 2043;
+            return false;
+        }
+
+        $info = $this->model->where(['id' => $id, 'mark' => 1])->first();
+        if (empty($id) || empty($info)) {
+            $this->error = 2042;
+            return false;
+        }
+
+        if ($info['status'] != 1) {
+            $this->error = 2044;
+            return false;
+        }
+
+        if ($info['user_id'] != $userId) {
+            $this->error = 2045;
+            return false;
+        }
+
+        if ($this->model->where(['id' => $id, 'mark' => 1])->update(['pay_time' => time(), 'pay_img' => $payImg, 'status' => 2, 'update_time' => time()])) {
+            $this->error = 2046;
+            return true;
+        }
+
+        $this->error = 2047;
+        return false;
+    }
+
+    /**
+     * 确认收款
+     * @param $params
+     * @param $userId
+     * @return bool
+     */
+    public function confirm($params, $userId)
+    {
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $info = $this->model->where(['id' => $id, 'mark' => 1])->first();
+        if (empty($id) || empty($info)) {
+            $this->error = 2042;
+            return false;
+        }
+
+        if (!in_array($info['status'], [1, 2])) {
+            $this->error = 2044;
+            return false;
+        }
+
+//        if($info['sell_uid'] != $userId){
+//            $this->error = 2045;
+//            return false;
+//        }
+
+        DB::beginTransaction();
+        $data = ['confirm_time' => time(), 'status' => 3, 'update_time' => time()];
+        if (!$this->model->where(['id' => $id, 'mark' => 1])->update($data)) {
+            $this->error = 2050;
+            DB::rollBack();
+            return false;
+        }
+
+        // 更改商品归属人
+        if (!GoodsModel::where(['id' => $info['goods_id'], 'mark' => 1])->update(['user_id'=> $info['user_id'],'update_time'=> time()])) {
+            $this->error = 2050;
+            DB::rollBack();
+            return false;
+        }
+
+        // 佣金结算
+        $memberInfo = MemberModel::where(['id' => $info['user_id'], 'mark' => 1])->first();
+        $parentId = isset($memberInfo['parent_id']) ? $memberInfo['parent_id'] : 0;
+        $parentInfo = MemberModel::where(['id' => $parentId, 'mark' => 1])->first();
+        if ($memberInfo && $parentId && $parentInfo) {
+            $bonusRate = ConfigService::make()->getConfigByCode('bonus_rate');
+            $bonusRate = $bonusRate ? $bonusRate : 5;
+            $bonus = $info['real_price'] * $bonusRate / 100;
+
+            if ($bonus > 0) {
+                if (!MemberModel::where(['id' => $parentId, 'mark' => 1])->update(['bonus' => $parentInfo['bonus'] + $bonus, 'update_time' => time()])) {
+                    $this->error = 2051;
+                    DB::rollBack();
+                    return true;
+                }
+
+                $data = [
+                    'user_id' => $parentId,
+                    'shop_id' => $info['shop_id'],
+                    'source_uid' => $userId,
+                    'source_order_sn' => $info['order_sn'],
+                    'type' => 2,
+                    'coin_type' => 2,
+                    'money' => $bonus,
+                    'balance' => $parentInfo['bonus'],
+                    'create_time' => time(),
+                    'update_time' => time(),
+                    'remark' => '交易成功佣金结算',
+                    'status' => 1,
+                    'mark' => 1
+                ];
+
+                if (!AccountModel::insertGetId($data)) {
+                    $this->error = 2051;
+                    DB::rollBack();
+                    return true;
+                }
+
+                // 结算统计
+//                FinanceService::make()->settle($bonus, 1);
+                FinanceService::make()->settleBonus($bonus, 1);
+            }
+        }
+
+
+        DB::commit();
+        $this->error = 2049;
+        return true;
+    }
+
+    /**
+     * 申请待售
+     * @param $params
+     * @param $userId
+     * @return false
+     */
+    public function sell($params, $userId)
+    {
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $info = $this->model->where(['id' => $id, 'mark' => 1])->first();
+        if (empty($id) || empty($info)) {
+            $this->error = 2042;
+            return false;
+        }
+
+        if ($info['status'] != 3) {
+            $this->error = 2053;
+            return false;
+        }
+
+        if ($info['user_id'] != $userId) {
+            $this->error = 2045;
+            return false;
+        }
+
+        if (!$this->model->where(['id' => $id])->update(['status' => 4, 'is_sell' => 1, 'update_time' => time()])) {
+            $this->error = 2054;
+            return false;
+        }
+
+        $this->error = 2055;
+        return false;
+    }
+
+    /**
+     * 申请待售审核
+     * @param $params
+     * @param $userId
+     * @return false
+     */
+    public function sellConfirm($params)
+    {
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $info = $this->model->where(['id' => $id, 'mark' => 1])->first();
+        if (empty($id) || empty($info)) {
+            $this->error = 2042;
+            return false;
+        }
+
+        if ($info['status'] != 3) {
+            $this->error = 2053;
+            return false;
+        }
+
+        DB::beginTransaction();
+        $priceRate = ConfigService::make()->getConfigByCode('price_rate');
+        $priceRate = $priceRate? $priceRate : 4;
+
+        $stopSplitPrice = ConfigService::make()->getConfigByCode('stop_split_price');
+        $stopSplitPrice = $stopSplitPrice? $stopSplitPrice : 500;
+
+        // 判断是否可以上架或拆分
+        $realPrice = $info['real_price'];
+        $price = $info['price']; // 特价
+        $addPrice = $realPrice*$priceRate/100;
+
+        // 满足涨价上架
+        if($price+$addPrice < $info['split_price']){
+            if (!$this->model->where(['id' => $id])->update(['status' => 4,'new_price'=> $price+$addPrice,'real_price'=> $realPrice + $addPrice, 'is_sell' => 2, 'update_time' => time()])) {
+                $this->error = 2056;
+                DB::rollBack();
+                return false;
+            }
+
+            if (!GoodsModel::where(['id' => $info['goods_id']])->update(['last_sell_time'=>time(),'real_price' => $realPrice + $addPrice, 'price' => $price+$addPrice,'is_trade'=> 2, 'update_time' => time()])) {
+                $this->error = 2056;
+                DB::rollBack();
+                return false;
+            }
+
+            DB::commit();
+            $this->error = 2057;
+            return true;
+        }
+        // 停止拆分
+        else if($info['sell_price'] == $stopSplitPrice){
+            if (!GoodsModel::where(['id' => $id])->update(['status' => 2,'stop_split'=>1, 'update_time' => time()])) {
+                $this->error = 2054;
+                DB::rollBack();
+                return false;
+            }
+        }
+
+        // 满足拆分
+        else {
+            if(!GoodsService::make()->split($info['goods_id'])){
+                $this->error = 2058;
+                DB::rollBack();
+                return false;
+            }
+
+            $this->error = 2059;
+            DB::commit();
+            return false;
+        }
+
+
+        $this->error = 2056;
+        return false;
     }
 }

+ 2 - 0
app/Services/ConfigService.php

@@ -22,6 +22,8 @@ use App\Models\ConfigModel;
  */
 class ConfigService extends BaseService
 {
+    public static $instance = null;
+
     /**
      * 构造函数
      * @author laravel开发员