wesmiler 2 years ago
parent
commit
dc023a0d50

+ 24 - 0
app/Models/AcceptorModel.php

@@ -0,0 +1,24 @@
+<?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
+ * @package App\Models
+ */
+class AcceptorModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'acceptor';
+}

+ 22 - 0
app/Models/MemberModel.php

@@ -24,6 +24,28 @@ class MemberModel extends BaseModel
     protected $table = 'member';
 
     /**
+     * 商家
+     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+     */
+    public function merchant()
+    {
+        return $this->belongsTo(MerchantModel::class, 'id','user_id')
+            ->where(['mark'=>1])
+            ->select(['id','user_id','balance','name','category','type','audit_remark','status']);
+    }
+
+    /**
+     * 承兑商
+     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+     */
+    public function acceptor()
+    {
+        return $this->belongsTo(AcceptorModel::class, 'id','user_id')
+            ->where(['mark'=>1])
+            ->select(['id','user_id','realname','mobile','usdt','quota','audit_remark','status']);
+    }
+
+    /**
      * 获取会员信息
      * @param int $id 会员ID
      * @return array|string

+ 171 - 0
app/Services/Api/MemberAddressService.php

@@ -0,0 +1,171 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Api;
+
+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,'a.status'=>1];
+        $status = isset($params['status']) ? $params['status'] : 0;
+        if ($status > 0) {
+            $where['a.status'] = $status;
+        }
+        $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+        if ($userId > 0) {
+            $where['a.user_id'] = $userId;
+        }
+        $list = $this->model->from('member_address as a')
+            ->where($where)
+            ->select(['a.*'])
+            ->orderBy('a.is_default', 'asc')
+            ->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'] : []
+        ];
+    }
+
+    /**
+     * 保存数据
+     * @param $userId
+     * @param $params
+     * @return mixed
+     */
+    public function saveData($userId, $params)
+    {
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $isDefault = isset($params['is_default']) ? $params['is_default'] : 2;
+        $data = [
+            'user_id'=> $userId,
+            'mobile'=> isset($params['mobile'])? $params['mobile'] : '',
+            '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'])? (is_array($params['codes'])?implode(',', $params['codes']):$params['codes']) : '',
+            'address'=> isset($params['address'])? $params['address'] : '',
+            'is_default'=> $isDefault==1? 1: 2,
+            '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:address:{$userId}");
+        if($id && $this->model->where(['id'=> $id])->value('id')){
+            $this->model->where(['id'=> $id])->update($data);
+            $this->error = $id? 1008 : 1027;
+            return true;
+        }else{
+            $data['create_time'] = time();
+            $this->error = 1027;
+            return $this->model->insertGetId($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();
+        $info = $info? $info->toArray() : [];
+        if($info){
+            RedisService::set($cacheKey, $info, rand(5, 10));
+        }
+
+        return $info;
+    }
+
+    /**
+     * @return array|false
+     */
+    public function delete()
+    {
+        // 参数
+        $id = request()->post('id');
+        if (empty($id)) {
+            $this->error = 2014;
+            return false;
+        }
+
+        $this->error = 1002;
+        $this->model->where(['id'=> $id,'mark'=>0])->where('update_time','<=', time() - 3*86400)->delete();
+        return $this->model->where(['id'=> $id])->update(['mark'=> 0, 'update_time'=> time()]);
+    }
+}

+ 162 - 0
app/Services/Api/MemberBankService.php

@@ -0,0 +1,162 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Api;
+
+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,'a.status'=>1];
+        $status = isset($params['status']) ? $params['status'] : 0;
+        if ($status > 0) {
+            $where['a.status'] = $status;
+        }
+        $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+        if ($userId > 0) {
+            $where['a.user_id'] = $userId;
+        }
+        $list = $this->model->from('member_banks as a')
+            ->where($where)
+            ->select(['a.*'])
+            ->orderBy('a.create_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['bank_card_text'] = $item['bank_card'] ? format_bank_card($item['bank_card']) : '';
+                $item['name_text'] = $item['bank_name'] ? mb_substr($item['bank_name'],0,1,'utf-8') : '';
+                $item['icon'] = $item['bank_code'] ? get_image_url('/images/icons/banks/icon-'.$item['bank_code'].'.png') : '';
+            }
+        }
+
+        return [
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'list' => isset($list['data']) ? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 选项列表
+     * @param $userId
+     * @return array|mixed
+     */
+    public function options($userId)
+    {
+        $cacheKey = "caches:members:banks:{$userId}";
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $datas = $this->model->where(['user_id'=> $userId,'status'=> 1,'mark'=>1])
+            ->select(['id','realname','bank_name','bank_card','status'])
+            ->get();
+        $datas = $datas? $datas->toArrayu() :[];
+        if($datas){
+            RedisService::set($cacheKey, $datas, 7200);
+        }
+
+        return $datas;
+    }
+    /**
+     * 保存数据
+     * @param $userId
+     * @param $params
+     * @return mixed
+     */
+    public function saveData($userId, $params)
+    {
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $data = [
+            'user_id'=> $userId,
+            'realname'=> isset($params['realname'])? $params['realname'] : '',
+            'bank_name'=> isset($params['bank_name'])? $params['bank_name'] : '',
+            'bank_card'=> isset($params['bank_card'])? $params['bank_card'] : '',
+            'bank_code'=> isset($params['bank_code'])? $params['bank_code'] : '',
+            'status'=> isset($params['status'])? $params['status'] : 1,
+            'update_time'=> time(),
+            'mark'=> 1,
+        ];
+        if($id && $this->model->where(['id'=> $id])->value('id')){
+            $this->model->where(['id'=> $id])->update($data);
+            $this->error = $id? 1008 : 1027;
+            return true;
+        }else{
+            $data['create_time'] = time();
+            $this->error = 1027;
+            return $this->model->insertGetId($data);
+        }
+    }
+
+    /**
+     * @return array|false
+     */
+    public function delete()
+    {
+        // 参数
+        $id = request()->post('id');
+        if (empty($id)) {
+            $this->error = 2014;
+            return false;
+        }
+
+        $this->error = 1002;
+        $this->model->where(['mark'=>0])->where('update_time','<=', time() - 3*86400)->delete();
+        return $this->model->where(['id'=> $id])->update(['mark'=> 0, 'update_time'=> time()]);
+    }
+}

+ 212 - 0
app/Services/Api/MemberCollectService.php

@@ -0,0 +1,212 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Api;
+
+use App\Models\MemberCollectModel;
+use App\Services\BaseService;
+use App\Services\RedisService;
+
+/**
+ * 用户收藏点赞管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class MemberCollectService
+ * @package App\Services\Api
+ */
+class MemberCollectService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * MemberCollectService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new MemberCollectModel();
+    }
+
+    /**
+     * 静态入口
+     * @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($userId, $params, $pageSize = 15, $field='')
+    {
+        $where = ['a.mark' => 1,'a.status'=>1,'a.user_id'=> $userId,'b.mark'=>1];
+        $field = $field? $field : 'lev_a.id,lev_a.user_id,lev_a.type,lev_a.collect_uid,lev_a.create_time,lev_b.nickname,lev_b.avatar';
+        $sortType = isset($params['sort_type']) ? $params['sort_type'] : 1;
+        $order = 'id desc';
+        if($sortType == 1){
+            $order = 'create_time desc, lev_a.id desc';
+        }
+        $list = $this->model->with(['mechanic'])
+            ->from('member_collect as a')
+            ->leftJoin('member as b', 'b.id', '=', 'a.collect_uid')
+            ->where($where)
+            ->where(function ($query) use ($params) {
+                $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+                if ($userId > 0) {
+                    $query->where('a.user_id', $userId);
+                }
+
+                $status = isset($params['status'])? $params['status'] : 0;
+                $status = $status>0? $status : 1;
+                if ($status > 0) {
+                    $query->where('a.status', $status);
+                }
+
+                $type = isset($params['type'])? $params['type'] : 0;
+                $type = $type>0? $type : 1;
+                if ($type > 0) {
+                    $query->where('a.type', $type);
+                }
+
+            })
+            ->where(function ($query) use ($params) {
+                $keyword = isset($params['kw']) ? $params['kw'] : '';
+                if ($keyword) {
+                    $query->where('b.nickname', 'like', "%{$keyword}%")->orWhere('b.username','like',"%{$keyword}%");
+                }
+            })
+            ->selectRaw($field)
+            ->orderByRaw($order)
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list ? $list->toArray() : [];
+        if ($list) {
+            foreach ($list['data'] as &$item) {
+                $item['time_text'] = isset($item['create_time']) && $item['create_time']? dateFormat($item['create_time']) : '';
+                $item['avatar'] = isset($item['avatar']) && $item['avatar'] ? get_image_url($item['avatar']) : '';
+                $mechaic = isset($item['mechanic'])? $item['mechanic'] : [];
+                if($mechaic){
+                    $mechaic['avatar'] = isset($mechaic['avatar'])? get_image_url($mechaic['avatar']) : '';
+                    $mechaic['nickname'] = isset($mechaic['nickname']) && $mechaic['nickname']?  $mechaic['nickname']: $mechaic['realname'];
+                }
+                $item['checked'] = false;
+                $item['mechanic'] = $mechaic;
+            }
+        }
+
+        return [
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'list' => isset($list['data']) ? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 是否已经收藏或点赞过
+     * @param $userId
+     * @param $collectUid
+     * @param int $type
+     * @return array|mixed
+     */
+    public function checkCollect($userId, $collectUid, $type=1)
+    {
+        $cacheKey = "caches:member:collect:u{$userId}_c{$collectUid}_{$type}";
+        $data = RedisService::get($cacheKey);
+        if($data){
+            return $data? 1: 2;
+        }
+
+        $data = $this->model->where(['user_id'=> $userId,'collect_uid'=> $collectUid,'type'=> $type,'status'=>1,'mark'=>1])->value('id');
+        if($data){
+            RedisService::set($cacheKey, $data, rand(5, 10));
+        }
+
+        return $data? 1 : 2;
+    }
+
+    /**
+     * 收藏点赞
+     * @param $userId
+     * @param $dynamicId
+     * @param $type
+     * @param int $status
+     * @return mixed
+     */
+    public function collect($userId, $params)
+    {
+        $collectUid = isset($params['id'])? intval($params['id']) : 0;
+        $type = isset($params['type'])? intval($params['type']) : 2;
+        $status = isset($params['status'])? intval($params['status']) : 1;
+        if($collectUid<=0 || !in_array($type, [1,2]) || !in_array($status, [1,2])){
+            $this->error = 2501;
+            return false;
+        }
+
+        $id = $this->model->where(['user_id'=> $userId,'collect_uid'=> $collectUid,'type'=> $type])->value('id');
+        $data = [
+            'user_id'=> $userId,
+            'type'=> $type,
+            'collect_uid'=> $collectUid,
+            'update_time'=> time(),
+            'status'=> $status,
+            'mark'=> 1,
+        ];
+        if(!$id){
+            $data['create_time'] = time();
+            $this->error = '1002';
+            return $this->model->insertGetId($data);
+        }else{
+            if($status == 2){
+                RedisService::clear("caches:member:collect:u{$userId}_c{$collectUid}_{$type}");
+            }
+            $this->error = '1002';
+            return $this->model->where('id', $id)->update($data);
+        }
+    }
+
+    /**
+     * 取消
+     * @param $userId
+     * @return bool
+     */
+    public function cancel($userId)
+    {
+        // 参数
+        $ids = request()->post('ids','');
+        $ids = $ids? explode(',', $ids) : [];
+        $type = request()->post('type',0);
+        if (empty($ids) && $type == 0) {
+            $this->error = 1033;
+            return false;
+        }
+
+        if($type){
+            $this->model->where(['user_id'=> $userId,'status'=>1,'mark'=>1])->update(['status'=>2,'update_time'=>time()]);
+        }else {
+            $this->model->where(['user_id'=> $userId,'status'=>1,'mark'=>1])->whereIn('id', $ids)->update(['status'=>2,'update_time'=>time()]);
+        }
+
+        $this->error = 1002;
+        return true;
+    }
+
+
+}

+ 10 - 301
app/Services/Api/MemberService.php

@@ -78,30 +78,24 @@ class MemberService extends BaseService
      */
     public function getInfo($where, $type = 'detail', array $field = [])
     {
-        $defaultField = ['id', 'username', 'realname', 'mobile', 'nickname', 'code', 'parent_id', 'openid', 'balance', 'score','pay_password', 'wxpay_qrcode', 'alipay_qrcode','realname','idcard_check','idcard','idcard_front_img','idcard_back_img','idcard_audit_remark', 'member_level', 'status', 'avatar'];
-        if ($type == 'home') {
-            $defaultField = ['id', 'username', 'realname', 'mobile', 'nickname', 'code', 'parent_id', 'openid', 'balance', 'score', 'member_level', 'status', 'avatar'];
-        } else if ($type == 'team') {
-            $defaultField = ['id', 'username', 'nickname', 'code', 'balance', 'score', 'withdraw_total', 'bonus_total', 'bonus_level1_total', 'bonus_level2_total','bonus_level3_total', 'status', 'avatar'];
+        $defaultField = ['id', 'username','email', 'realname', 'mobile','gender', 'nickname', 'code','supper_point', 'parent_id','province_id','city_id','signature','power_num','trade_state','trc_url','recharge_trc_url', 'point_id', 'balance','trx','usdt','wait_score', 'score','pay_password','realname','idcard_check', 'member_level', 'status', 'avatar'];
+        if ($type == 'team') {
+            $defaultField = ['id', 'username','email', 'nickname', 'code', 'balance', 'score','point_id','power_num','parent_id', 'status', 'avatar'];
         }else if($type == 'share'){
-            $defaultField = ['id', 'username', 'nickname', 'code', 'balance', 'score', 'withdraw_total', 'bonus_total', 'bonus_level1_total', 'bonus_level2_total','bonus_level3_total', 'status', 'avatar'];
-        }else if($type == 'login'){
-            $defaultField = ['id', 'username', 'nickname', 'code','push_cid', 'balance', 'score', 'status'];
+            $defaultField = ['id', 'username', 'nickname', 'code', 'balance','usdt','trx','trc_url', 'score', 'status', 'avatar'];
+        }else if($type == 'check'){
+            $defaultField = ['id', 'username', 'nickname', 'code', 'balance','usdt','trx','trc_url','wait_score', 'score', 'status', 'avatar'];
         }
         $field = $field ? $field : $defaultField;
         if (is_array($where)) {
-            $info = $this->model->where('mark',1)->where($where)->select($field)->first();
+            $info = $this->model->with(['merchant','acceptor'])->where('mark',1)->where($where)->select($field)->first();
         } else {
-            $info = $this->model->where('mark',1)->where(['id' => (int)$where])->select($field)->first();
+            $info = $this->model->with(['merchant','acceptor'])->where('mark',1)->where(['id' => (int)$where])->select($field)->first();
         }
 
         $info = $info ? $info->toArray() : [];
         if ($info && !in_array($type, ['auth', 'check','login'])) {
             $info['avatar'] = $info['avatar'] ? get_image_url($info['avatar']) : get_image_url('/images/member/logo.png');
-            $info['balance'] = round($info['balance'], 2);
-            $info['mobile_text'] = isset($info['mobile']) ? $info['mobile'] : '';
-            $info['mobile'] = $info['mobile_text'] ? format_mobile($info['mobile_text']) : '';
-            $info['show_my_job'] = intval(ConfigService::make()->getConfigByCode('show_my_job'));
 
             if (isset($info['wxpay_qrcode'])) {
                 $info['wxpay_qrcode'] = $info['wxpay_qrcode'] ? get_image_url($info['wxpay_qrcode']) : '';
@@ -110,26 +104,6 @@ class MemberService extends BaseService
                 $info['alipay_qrcode'] = $info['alipay_qrcode'] ? get_image_url($info['alipay_qrcode']) : '';
             }
 
-            if (!in_array($type, ['team', 'bonus'])) {
-                // 是否技师
-                $mechanic = MechanicService::make()->getCacheInfoByUser($info['id'], '', $type);
-                $info['mechanic'] = $mechanic ? $mechanic : ['id' => 0, 'status' => 0,'bonus_wait'=>'0.00','views'=>0];
-                if($mechanic){
-                    $info['mechanic']['bonus_wait'] = BonusLogModel::where(['mech_id'=> $mechanic['id'],'status'=>1])
-                        ->where('settle_at','>',date('Y-m-d H:i:s'))
-                        ->sum('mech_money');
-                }
-
-
-                // 是否商家
-                $merchant = MerchantService::make()->getCacheInfoByUser($info['id']);
-                $info['merchant'] = $merchant ? $merchant : ['id' => 0, 'status' => 0];
-
-                // 是否代理
-                $agent = AgentService::make()->getCacheInfoByUser($info['id']);
-                $info['agent'] = $agent ? $agent : ['id' => 0, 'status' => 0];
-            }
-
             // 二维码
             if (in_array($type, ['detail','share'])) {
                 $inviteUrl = get_web_url('/#/pages/register/index?scene=' . $info['code']);
@@ -165,25 +139,10 @@ class MemberService extends BaseService
 
 
             } // 商家后台
-            else if ($type == 'mech') {
-
-            } // 技师后台
-            else if ($type == 'merch') {
-            } // 代理后台
-            else if ($type == 'agent') {
 
-            }
             else if ($type == 'team') {
-                $info['bonus_level1_count'] = (int)$this->getTeamsUserCountByLevel($info['id'], 1);
-                $info['bonus_level2_count'] = (int)$this->getTeamsUserCountByLevel($info['id'], 2);
-            }else if ($type == 'bonus') {
-                $info['counts'] = BonusService::make()->bonusCountByTime($info['id'], 0);
-
-            }else if($type == 'payment'){
-                $data =  ['ac'=> $info['username'],'ut'=>1,'scene'=>'pay'];
-                $qrcode = $this->makeQrcode(json_encode($data, 256));
-                $info['payment_qrcode'] = $qrcode ? get_image_url($qrcode) : '';
-            } else {
+
+            }else {
                 // 默认地址
                 $info['addressData'] = MemberAddressService::make()->getBindInfo($info['id']);
             }
@@ -193,59 +152,6 @@ class MemberService extends BaseService
     }
 
     /**
-     * 获取收款二维码
-     * @param $account 账号ID
-     * @param $params
-     * @return string|\图片地址
-     */
-    public function getSceneQrcode($account, $params)
-    {
-        $type = isset($params['type']) && $params['type']? $params['type'] : 1;
-        $scene = isset($params['scene']) && $params['scene']? $params['scene'] : '';
-        $room = isset($params['room']) && $params['room']? $params['room'] : '';
-        $merchId = isset($params['merch_id']) && $params['merch_id']? $params['merch_id'] : '';
-        $money = isset($params['money']) && $params['money']? floatval($params['money'])  : '';
-        $data =  ['ac'=> $account,'scene'=>$scene];
-        if($type){
-            $data['ut'] = $type;
-        }
-        if($money){
-            $data['my'] = $money;
-        }
-        if($merchId){
-            $data['mid'] = $merchId;
-        }
-        if($room){
-            $data['rm'] = $room;
-            unset($data['ac']);
-            unset($data['ut']);
-        }
-        $qrcode = $this->makeQrcode(json_encode($data, 256));
-        return $qrcode ? get_image_url($qrcode) : '';
-    }
-
-    /**
-     * 主页信息
-     * @param $id
-     * @param int $userId
-     * @return array
-     */
-    public function getHomeInfo($id, $userId = 0)
-    {
-        $info = $this->getInfo($id, 'home');
-        if ($info) {
-            $info['collect_num'] = (int)MemberCollectModel::where(['collect_uid' => $id, 'status' => 1, 'mark' => 1])->count('id');
-            $info['is_collect'] = (int)MemberCollectModel::where(['collect_uid' => $id, 'user_id' => $userId, 'status' => 1, 'mark' => 1])->value('id');
-            $services = isset($info['mechanic']['services']) ? explode(',', $info['mechanic']['services']) : [];
-            $info['services'] = [];
-            if ($services) {
-                $info['services'] = GoodsService::make()->getListByIds($services);
-            }
-        }
-        return $info;
-    }
-
-    /**
      * 获取用户缓存信息
      * @param $where
      * @param array $field
@@ -275,50 +181,6 @@ class MemberService extends BaseService
     }
 
     /**
-     * 获取用户聊天显示缓存信息
-     * @param $where
-     * @param array $field
-     * @param int $expired
-     * @return array|mixed
-     */
-    public function getChatInfo($userId, $field = [], $domain = '')
-    {
-        try {
-
-            $cacheKey = "caches:member:chatInfo:cache_{$userId}" . ($field ? '_' . md5(json_encode($field, 256)) : '');
-            $info = RedisService::get($cacheKey);
-            if ($info) {
-                return $info;
-            }
-
-            $defaultField = ['id', 'username', 'nickname', 'avatar'];
-            $field = $field ? $field : $defaultField;
-            $info = $this->model->where(['id' => $userId])->where('mark', 1)->select($field)->first();
-            $info = $info ? $info->toArray() : [];
-            if ($info) {
-                if (isset($info['avatar'])) {
-                    $info['avatar'] = get_image_url($info['avatar']);
-                }
-
-                $merchInfo = MerchantModel::where(['user_id' => $userId])->whereIn('status', [2, 3])->select(['name', 'logo'])->first();
-                $merchInfo = $merchInfo ? $merchInfo->toArray() : [];
-                if ($merchInfo && isset($info['nickname'])) {
-                    $info['nickname'] = isset($merchInfo['name']) ? $merchInfo['name'] : $info['nickname'];
-                }
-
-                if ($merchInfo && isset($info['avatar'])) {
-                    $info['avatar'] = isset($merchInfo['logo']) && $merchInfo['logo'] ? get_image_url($merchInfo['logo'], $domain) : $info['avatar'];
-                }
-                RedisService::set($cacheKey, $info, rand(5, 10));
-            }
-
-            return $info;
-        } catch (\Exception $exception) {
-            return false;
-        }
-    }
-
-    /**
      * 生成普通参数二维码
      * @param $str 参数
      * @param bool $refresh 是否重新生成
@@ -801,37 +663,6 @@ class MemberService extends BaseService
     }
 
     /**
-     * 修改收款码
-     * @param $userId
-     * @param $params
-     * @return mixed
-     */
-    public function saveQrcode($userId, $params)
-    {
-        if (isset($params['wxpay']) && $params['wxpay']) {
-            $qrcode = $this->model->where(['id' => $userId])->value('wxpay_qrcode');
-            if ($this->model->where(['id' => $userId])->update(['wxpay_qrcode' => $params['wxpay'], 'update_time' => time()])) {
-                if ($qrcode && file_exists(ATTACHMENT_PATH . $qrcode)) {
-                    @unlink(ATTACHMENT_PATH . $qrcode);
-                }
-                return true;
-            }
-        }
-
-        if (isset($params['alipay']) && $params['alipay']) {
-            $qrcode = $this->model->where(['id' => $userId])->value('alipay_qrcode');
-            if ($this->model->where(['id' => $userId])->update(['alipay_qrcode' => $params['alipay'], 'update_time' => time()])) {
-                if ($qrcode && file_exists(ATTACHMENT_PATH . $qrcode)) {
-                    @unlink(ATTACHMENT_PATH . $qrcode);
-                }
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    /**
      * 修改账号
      * @param $userId
      * @param $params
@@ -988,65 +819,6 @@ class MemberService extends BaseService
     }
 
     /**
-     * 更新用户定位信息
-     * @param $userId
-     * @param $params
-     * @return bool
-     */
-    public function updateMap($userId, $params)
-    {
-        $cacheKey = "caches:map:{$userId}";
-        if (RedisService::get($cacheKey)) {
-            $this->error = 1015;
-            return false;
-        }
-
-        $lng = isset($params['lng']) ? $params['lng'] : '';
-        $lat = isset($params['lat']) ? $params['lat'] : '';
-        if (empty($lng) || empty($lat)) {
-            $this->error = 2014;
-            return false;
-        }
-
-        $address = [];
-        $data = ['update_time' => time(), 'lng' => $lng, 'lat' => $lat];
-        $addressData = isset($params['address']) && $params['address'] ? json_decode($params['address'], true) : [];
-        $city = isset($addressData['city']) ? $addressData['city'] : '';
-        $address[] = isset($addressData['province']) ? $addressData['province'] : '';
-        $address[] = $city;
-        $address[] = isset($addressData['district']) ? $addressData['district'] : '';
-        $ids = CityModel::whereIn('name',$address)->where(['mark'=>1])->pluck('id');
-        $address = array_filter($address);
-        if ($address) {
-            $data['province_id'] = isset($ids[0])? $ids[0] : 0;
-            $data['city_id'] = isset($ids[1])? $ids[1] : 0;
-            $data['district_id'] = isset($ids[2])? $ids[2] : 0;
-            $data['address'] = implode(' ', $address);
-            $data['city'] = $city;
-        }
-
-        RedisService::set("caches:maps:{$userId}",['data'=> $data,'params'=>$params], 300);
-        if ($this->model->where(['id' => $userId])->update($data)) {
-            // 如果是个人商家
-            $updateData = [
-                'province' => isset($addressData['province']) ? $addressData['province'] : '',
-                'city' => isset($addressData['city']) ? $addressData['city'] : '',
-                'district' => isset($addressData['district']) ? $addressData['district'] : '',
-                'lng' => $lng,
-                'lat' => $lat,
-            ];
-            MerchantModel::where(['user_id' => $userId, 'type' => 2, 'mark' => 1])->whereIn('status', [1, 2])->update($updateData);
-            RedisService::set($cacheKey, $data, rand(30, 60));
-            $this->error = 1016;
-            return true;
-        } else {
-            RedisService::set($cacheKey.'_error', $data, rand(30, 60));
-            $this->error = 1016;
-            return false;
-        }
-    }
-
-    /**
      * 转账
      * @param $userId
      * @param $params
@@ -1642,69 +1414,6 @@ class MemberService extends BaseService
     }
 
     /**
-     * 商家上级分销佣金入账
-     * @param $info
-     * @return false
-     */
-    public function settleMerchBonus($info, $level=1)
-    {
-        $money = isset($info['money'])? floatval($info['money']) : 0;
-        $merchId = isset($info['merch_id'])? intval($info['merch_id']) : 0;
-
-        // 分销佣金
-        $settleUserId = isset($info["merch_level{$level}_id"])? $info["merch_level{$level}_id"] : 0;
-        $settleMoney = isset($info["merch_level{$level}_money"])? $info["merch_level{$level}_money"] : 0;
-        if($settleUserId>0 && $settleMoney>0){
-            $userInfo = $this->model->where(['id'=> $settleUserId,'mark'=>1])
-                ->select(['id','nickname','balance'])
-                ->first();
-
-            $balance = isset($userInfo['balance'])? $userInfo['balance'] : 0;
-            if($settleUserId && $userInfo){
-                // 更新账户
-                $updateData = [
-                    'balance'=>DB::raw("balance + {$settleMoney}"),
-                    'bonus_total'=>DB::raw("bonus_total + {$settleMoney}"),
-                    "bonus_level{$level}_total"=>DB::raw("bonus_level{$level}_total + {$settleMoney}"),
-                    'update_time'=> time()
-                ];
-                if(!MemberModel::where(['id'=> $settleUserId,'mark'=>1])->update($updateData)){
-                    $this->error = lang(3413, ['level'=> $level]);
-                    return false;
-                }
-
-                $log = [
-                    'user_id'=> $settleUserId,
-                    'merch_id'=> $merchId,
-                    'source_uid'=> $merchId,
-                    'source_order_no'=> isset($info['order_no'])? $info['order_no'] :'',
-                    'type'=> 3,
-                    'coin_type'=> 2,
-                    'user_type'=> 1,
-                    'money'=> $settleMoney,
-                    'balance'=>$balance? $balance : 0.00,
-                    'create_time'=> time(),
-                    'update_time'=> time(),
-                    'remark'=> "服务订单[{$money}]元的{$level}级分销佣金",
-                    'status'=>1,
-                    'mark'=>1
-                ];
-                if(!AccountLogModel::insertGetId($log)){
-                    $this->error = lang(3414, ['level'=> $level]);
-                    return false;
-                }
-
-                $this->error = lang(3415, ['level'=> $level]);
-                return true;
-            }
-        }
-
-
-        $this->error = lang(3412, ['level'=> $level]);
-        return true;
-    }
-
-    /**
      * 获取点对点上级节点
      * @param $userId 推荐人ID
      * @return int|mixed

+ 928 - 0
app/Services/Api/MerchantService.php

@@ -0,0 +1,928 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Api;
+
+use App\Models\AccountLogModel;
+use App\Models\MerchantCategoryModel;
+use App\Models\MerchantModel;
+use App\Services\BaseService;
+use App\Services\ConfigService;
+use App\Services\RedisService;
+use App\Services\SmsService;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 商户服务管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class MerchantService
+ * @package App\Services\Api
+ */
+class MerchantService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * MerchantService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new MerchantModel();
+    }
+
+    /**
+     * 静态入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = (new static());
+        }
+        return self::$instance;
+    }
+
+    /**
+     * 获取缓存列表
+     * @param $position
+     * @param int $num
+     * @return array|mixed
+     */
+    public function getDataList($params, $pageSize = 15, $refresh = false, $field = '')
+    {
+        $page = request()->post('page', 1);
+        $cacheKey = "caches:merchant:page_{$page}_" . md5(json_encode($params).$pageSize);
+        $datas = RedisService::get($cacheKey);
+        $data = isset($datas['data'])? $datas['data'] : [];
+        if ($datas && $data && !$refresh) {
+            return [
+                'list'=> $data,
+                'total'=> isset($datas['total'])? $datas['total'] : 0,
+                'pageSize'=>$pageSize
+            ];
+        }
+        $field = $field ? $field : 'lev_a.id,lev_a.user_id,lev_a.name,lev_a.logo,lev_a.type,lev_a.category,lev_a.business_scope,lev_a.service_time,lev_a.deposit,lev_a.service_order_num,lev_a.score_rate,lev_a.city,lev_a.lng,lev_a.lat,lev_a.status';
+        $lat = isset($params['lat']) ? $params['lat'] : 0.00;
+        $lng = isset($params['lng']) ? $params['lng'] : 0.00;
+        $sortType = isset($params['sort_type']) ? $params['sort_type'] : 0;
+        $order = 'lev_a.id desc';
+
+        $datas = $this->model->from('merchant as a')
+            ->leftJoin('member as b','b.id','=','a.user_id')
+            ->where(['a.mark' => 1,'b.mark'=>1])
+            ->where(function ($query) use ($params) {
+                $kw = isset($params['kw']) ? trim($params['kw']) : '';
+                if ($kw) {
+                    $query->where('a.name', 'like', "%{$kw}%")->orWhere('a.business_scope', 'like', "%{$kw}%");
+                }
+            })
+            ->where(function ($query) use ($params) {
+                // 商户类型
+                $type = isset($params['type']) ? intval($params['type']) : 0;
+                if ($type) {
+                    $query->where('a.type', $type);
+                }
+
+                // 状态
+                $status = isset($params['status']) && $params['status']>=0 ? intval($params['status']) : 2;
+                if ($status>0) {
+                    $query->where('a.status', $status);
+                }else{
+                    $query->whereIn('a.status',[1,2]);
+                }
+
+                // 经营类目
+                $category = isset($params['category']) ? intval($params['category']) : 0;
+                if ($category) {
+                    $query->where('a.category', $category);
+                }
+
+                // 省
+                $province = isset($params['province']) ? trim($params['province']) : '';
+                $city = isset($params['city']) ? trim($params['city']) : '';
+                if ($province && empty($city)) {
+                    $query->where('a.province', 'like',"{$province}%");
+                }
+
+                // 市
+                if ($city) {
+                    $query->where(function($query) use($city){
+                        $query->where('a.city', $city)->orWhere('a.address','like',"%{$city}%");
+                    });
+                }
+
+                // 是否保障金
+                $isDeposit = isset($params['deposit']) ? intval($params['deposit']) : 0;
+                if ($isDeposit) {
+                    $query->where('a.deposit', '>', 0);
+                }
+            })
+            ->selectRaw($field)
+            ->orderByRaw($order)
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+
+        $datas = $datas ? $datas->toArray() : [];
+        if ($datas) {
+            foreach($datas['data'] as &$item){
+                $item['logo'] = $item['logo'] ? get_image_url($item['logo']) : '';
+                $item['score_rate'] = max(0, moneyFormat($item['score_rate'], 1));
+            }
+            unset($item);
+            RedisService::set($cacheKey, $datas, rand(3, 5));
+        }
+
+        return [
+            'list'=> isset($datas['data'])? $datas['data'] : [],
+            'total'=> isset($datas['total'])? $datas['total'] : 0,
+            'pageSize'=>$pageSize
+        ];
+    }
+
+    /**
+     * 获取详情
+     * @param $id 商家ID
+     * @param string $type
+     * @return array|mixed
+     */
+    public function getInfoById($id, $type='info', $userId=0)
+    {
+        $cacheKey = "caches:merch:{$type}_{$id}";
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+        $field = ['a.id','a.name','a.user_id','a.type','a.logo','a.category','a.business_scope','a.balance','a.usdt','a.service_time','a.deposit','a.delivery_fee','a.bonus_rate','a.power_rate','a.status','a.trade_status','b.username','b.nickname'];
+        $info = $this->model->from('merchant as a')->with(['category'])
+            ->leftJoin('member as b','b.id','=','a.user_id')
+            ->where(['a.id'=> $id,'a.mark'=>1,'b.mark'=>1])
+            ->select($field)
+            ->first();
+        $info = $info? $info->toArray() : [];
+        if($info){
+            if(isset($info['logo'])){
+                $info['logo'] = $info['logo']? get_image_url($info['logo']) : '';
+            }
+
+            if(isset($info['albums'])){
+                $info['albums'] = $info['albums']? json_decode($info['albums'], true) : [];
+                $info['albums'] = $info['albums']? get_images_preview($info['albums']) : [];
+            }
+
+            $info['service_status'] = 2;
+            $info['service_time'] = isset($info['service_time']) && $info['service_time']? $info['service_time']:'08点~22点';
+            $serviceTime = $info['service_time']? str_replace('~','~',$info['service_time']):'';
+            $times = $serviceTime? explode('~',$serviceTime) : [];
+            $times[0] = isset($times[0]) && $times[0]? $times[0] : '08点';
+            $times[1] = isset($times[1]) && $times[1]? $times[1] : '22点';
+            if($times && date('H点')>= $times[0] && date('H点')<=$times[1]){
+                $info['service_status'] = 1;
+            }
+
+            if($info['trade_status'] != 1){
+                $info['service_status'] = 2;
+            }
+
+            RedisService::set($cacheKey, $info, rand(3, 5));
+        }
+
+        return $info;
+    }
+
+    /**
+     * 添加或编辑
+     * @return array
+     * @since 2020/11/11
+     * @author laravel开发员
+     */
+    public function edit()
+    {
+        $data = request()->all();
+        // 图片处理
+        $cover = $data['cover'] ? trim($data['cover']) : '';
+        if (strpos($cover, "temp")) {
+            $data['cover'] = save_image($cover, 'ad');
+        } else {
+            $data['cover'] = str_replace(IMG_URL, "", $data['cover']);
+        }
+        // 开始时间
+        if (isset($data['start_time'])) {
+            $data['start_time'] = strtotime($data['start_time']);
+        }
+        // 结束时间
+        if (isset($data['end_time'])) {
+            $data['end_time'] = strtotime($data['end_time']);
+        }
+        return parent::edit($data); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * 修改信息
+     * @param $userId
+     * @param $params
+     * @return array|false|int[]
+     */
+    public function saveInfo($userId, $params)
+    {
+        // 验证是否入驻过和入驻状态
+        $info = $this->model->where(['user_id'=> $userId])->select('id','name','status','mark')->first();
+        $status = isset($info['status'])? $info['status'] : 0;
+        $mark = isset($info['mark'])? $info['mark'] : 0;
+        $merchId = isset($info['id'])? $info['id'] : 0;
+        if($merchId && empty($info)){
+            $this->error = 2216;
+            return false;
+        }
+
+        // 是否被冻结
+        if($merchId && $status == 3 && $mark){
+            $this->error = 2202;
+            return false;
+        }
+
+        // 验证是否是技师
+        if(MechanicModel::where(['user_id'=> $userId,'status'=>2,'mark'=>1])->value('id')) {
+            $this->error = 2687;
+            return false;
+        }
+
+        // 验证账户是否正常
+        $userInfo = MemberService::make()->getCacheInfo(['id'=>$userId], ['id','status']);
+        $status = isset($userInfo['status'])? $userInfo['status'] : 0;
+        if(empty($userInfo) || $status != 1){
+            $this->error = 2017;
+            return false;
+        }
+
+        $type = isset($params['type'])? intval($params['type']) : 0;
+        $category = isset($params['category'])? intval($params['category']) : 0;
+        $lng = isset($params['lng'])? floatval($params['lng']) : 0;
+        $lat = isset($params['lat'])? floatval($params['lat']) : 0;
+        $address = isset($params['address'])? trim($params['address']) : '';
+        $albums = isset($params['albums'])? get_format_images($params['albums']) : '';
+        $file1 = isset($params['file1'])? get_format_images($params['file1']) : '';
+        $file2 = isset($params['file2'])? get_format_images($params['file2']) : '';
+        $file3 = isset($params['file3'])? get_format_images($params['file3']) : '';
+        $alipayQrcodeData = isset($params['alipay_qrcode'])? $params['alipay_qrcode'] : [];
+        $alipayQrcode = isset($alipayQrcodeData[0]['url'])? get_image_path($alipayQrcodeData[0]['url']) : '';
+        $wxpayQrcodeData = isset($params['wxpay_qrcode'])? $params['wxpay_qrcode'] : [];
+        $wxpayQrcode = isset($wxpayQrcodeData[0]['url'])? get_image_path($wxpayQrcodeData[0]['url']) : '';
+        $logoData = isset($params['logo'])? $params['logo'] : [];
+        $logo = isset($logoData[0]['url'])? get_image_path($logoData[0]['url']) : '';
+        $name = isset($params['name'])? $params['name'] : '';
+
+        // 验证分类
+        if($category && !MerchantCategoryModel::where(['id'=> $category,'status'=>1,'mark'=>1])->value('id')){
+            $this->error = 2203;
+            return false;
+        }
+
+        // 验证logo
+        if(empty($logo)){
+            $this->error = 2204;
+            return false;
+        }
+
+        // 位置信息
+        if($type == 1 && (empty($lat) || empty($lng) || empty($address))){
+            $this->error = 2210;
+            //return false;
+        }
+
+        // 证书
+        if(empty($file1)){
+            $this->error = $type == 1? 2206 : 2211;
+            return false;
+        }
+
+        if(empty($file2)){
+            $this->error = 2207;
+            return false;
+        }
+
+        if(empty($file3)){
+            $this->error = $type==1? 2208 : 2209;
+            return false;
+        }
+
+        // 收款码
+        if(empty($alipayQrcode) || empty($wxpayQrcode)){
+            $this->error = 2205;
+            return false;
+        }
+
+        // 入驻数据
+        $data = [
+            'name' => $name,
+            'user_id' => $userId,
+            'category'=> $category,
+            'type'=> $type,
+            'logo'=> $logo,
+            'albums'=> $albums? $albums : '',
+            'qualification_imgs'=> $file1? $file1 : '',
+            'other_certificates'=> $file2? $file2 : '',
+            'idcard_imgs'=> $file3? $file3 : '',
+            'alipay_qrcode'=> $alipayQrcode? $alipayQrcode : '',
+            'wxpay_qrcode'=> $wxpayQrcode? $wxpayQrcode : '',
+            'lng'=> $lng,
+            'lat'=> $lat,
+            'address'=> $address,
+            'province'=> isset($params['province'])? trim($params['province']) : '',
+            'city'=> isset($params['city'])? trim($params['city']) : '',
+            'district'=> isset($params['district'])? trim($params['district']) : '',
+            'intro'=> isset($params['intro'])? trim($params['intro']) : '',
+            'mobile'=> isset($params['mobile'])? trim($params['mobile']) : '',
+            'business_scope'=> isset($params['business_scope'])? trim($params['business_scope']) : '',
+            'service_time'=> isset($params['service_time'])? trim($params['service_time']) : '',
+            'create_time'=> time(),
+            'update_time'=> time(),
+            'status'=> 1,
+            'mark'=> 1,
+        ];
+
+        // 写入数据
+        if($merchId){
+            if($this->model->where(['id'=> $merchId])->update($data)){
+                $this->error = 2228;
+                RedisService::keyDel("caches:merchant:info:temp_{$userId}*");
+                return ['id'=> $merchId];
+            }else{
+                $this->error = 2229;
+                return false;
+            }
+        }else{
+            if($merchId = $this->model->insertGetId($data)){
+                $this->error = 2228;
+                RedisService::keyDel("caches:merchant:info:temp_{$userId}*");
+                return ['id'=> $merchId];
+            }else{
+                $this->error = 2229;
+                return false;
+            }
+        }
+    }
+
+    /**
+     * 申请入驻
+     * @param $userId
+     * @param $params
+     * @return array|false|int[]
+     */
+    public function apply($userId, $params)
+    {
+        // 验证是否入驻过和入驻状态
+        $info = $this->model->where(['user_id'=> $userId])->select('id','name','status','mark')->first();
+        $status = isset($info['status'])? $info['status'] : 0;
+        $mark = isset($info['mark'])? $info['mark'] : 0;
+        $merchId = isset($info['id'])? $info['id'] : 0;
+        if($merchId && $status == 2 && $mark){
+            $this->error = 2201;
+            return false;
+        }
+
+        // 是否被冻结
+        if($merchId && $status == 3 && $mark){
+            $this->error = 2202;
+            return false;
+        }
+
+        // 验证是否是技师
+        if(MechanicModel::where(['user_id'=> $userId,'status'=>2,'mark'=>1])->value('id')) {
+            $this->error = 2687;
+            return false;
+        }
+
+        // 验证账户是否正常
+        $userInfo = MemberService::make()->getCacheInfo(['id'=>$userId], ['id','status']);
+        $status = isset($userInfo['status'])? $userInfo['status'] : 0;
+        if(empty($userInfo) || $status != 1){
+            $this->error = 2017;
+            return false;
+        }
+
+        $type = isset($params['type'])? intval($params['type']) : 0;
+        $category = isset($params['category'])? intval($params['category']) : 0;
+        $lng = isset($params['lng'])? floatval($params['lng']) : 0;
+        $lat = isset($params['lat'])? floatval($params['lat']) : 0;
+        $address = isset($params['address'])? trim($params['address']) : '';
+        $albums = isset($params['albums'])? get_format_images($params['albums']) : '';
+        $file1 = isset($params['file1'])? get_format_images($params['file1']) : '';
+        $file2 = isset($params['file2'])? get_format_images($params['file2']) : '';
+        $file3 = isset($params['file3'])? get_format_images($params['file3']) : '';
+        $alipayQrcodeData = isset($params['alipay_qrcode'])? $params['alipay_qrcode'] : [];
+        $alipayQrcode = isset($alipayQrcodeData[0]['url'])? get_image_path($alipayQrcodeData[0]['url']) : '';
+        $wxpayQrcodeData = isset($params['wxpay_qrcode'])? $params['wxpay_qrcode'] : [];
+        $wxpayQrcode = isset($wxpayQrcodeData[0]['url'])? get_image_path($wxpayQrcodeData[0]['url']) : '';
+        $logoData = isset($params['logo'])? $params['logo'] : [];
+        $logo = isset($logoData[0]['url'])? get_image_path($logoData[0]['url']) : '';
+        $name = isset($params['name'])? $params['name'] : '';
+
+        // 验证分类
+        if($category && !MerchantCategoryModel::where(['id'=> $category,'status'=>1,'mark'=>1])->value('id')){
+            $this->error = 2203;
+            return false;
+        }
+
+        // 验证logo
+        if(empty($logo)){
+            $this->error = 2204;
+            return false;
+        }
+
+        // 位置信息
+        if($type == 1 && (empty($lat) || empty($lng) || empty($address))){
+            $this->error = 2210;
+            //return false;
+        }
+
+        // 证书
+        if(empty($file1)){
+            $this->error = $type == 1? 2206 : 2211;
+            return false;
+        }
+
+        if(empty($file2)){
+            $this->error = 2207;
+            return false;
+        }
+
+        if(empty($file3)){
+            $this->error = $type==1? 2208 : 2209;
+            return false;
+        }
+
+        // 收款码
+        if(empty($alipayQrcode) || empty($wxpayQrcode)){
+            $this->error = 2205;
+            return false;
+        }
+
+        // 入驻数据
+        $data = [
+            'name' => $name,
+            'user_id' => $userId,
+            'category'=> $category,
+            'type'=> $type,
+            'logo'=> $logo,
+            'albums'=> $albums? $albums : '',
+            'qualification_imgs'=> $file1? $file1 : '',
+            'other_certificates'=> $file2? $file2 : '',
+            'idcard_imgs'=> $file3? $file3 : '',
+            'alipay_qrcode'=> $alipayQrcode? $alipayQrcode : '',
+            'wxpay_qrcode'=> $wxpayQrcode? $wxpayQrcode : '',
+            'lng'=> $lng,
+            'lat'=> $lat,
+            'address'=> $address,
+            'province'=> isset($params['province'])? trim($params['province']) : '',
+            'city'=> isset($params['city'])? trim($params['city']) : '',
+            'district'=> isset($params['district'])? trim($params['district']) : '',
+            'intro'=> isset($params['intro'])? trim($params['intro']) : '',
+            'mobile'=> isset($params['mobile'])? trim($params['mobile']) : '',
+            'business_scope'=> isset($params['business_scope'])? trim($params['business_scope']) : '',
+            'service_time'=> isset($params['service_time'])? trim($params['service_time']) : '',
+            'create_time'=> time(),
+            'update_time'=> time(),
+            'status'=> 1,
+            'mark'=> 1,
+        ];
+
+        // 写入数据
+        if($merchId){
+            if($this->model->where(['id'=> $merchId])->update($data)){
+                $this->error = 2213;
+                return ['id'=> $merchId];
+            }else{
+                $this->error = 2214;
+                return false;
+            }
+        }else{
+            if($merchId = $this->model->insertGetId($data)){
+                $this->error = 2215;
+                return ['id'=> $merchId];
+            }else{
+                $this->error = 2214;
+                return false;
+            }
+        }
+    }
+
+    /**
+     * 获取商家入驻信息
+     * @param $userId
+     * @return mixed
+     */
+    public function getApplyInfo($userId)
+    {
+        $info = $this->model->with(['category'])->where(['user_id'=> $userId,'mark'=>1])
+            ->orderBy('id','desc')
+            ->first();
+        $info = $info? $info->setHidden(['balance','deposit','update_time','mark'])->toArray() : [];
+        if($info){
+            $info['logo'] = isset($info['logo']) && $info['logo']? [['url'=> get_image_url($info['logo'])]] : [];
+            $info['alipay_qrcode'] = isset($info['alipay_qrcode']) && $info['alipay_qrcode']? [['url'=> get_image_url($info['alipay_qrcode'])]] : [];
+            $info['wxpay_qrcode'] = isset($info['wxpay_qrcode']) && $info['wxpay_qrcode']? [['url'=> get_image_url($info['wxpay_qrcode'])]] : [];
+            $file1 = isset($info['qualification_imgs']) && $info['qualification_imgs']? json_decode($info['qualification_imgs'], true) : [];
+            $info['file1'] = $file1? get_images_preview($file1) : [];
+            $file2 = isset($info['other_certificates']) && $info['other_certificates']? json_decode($info['other_certificates'], true) : [];
+            $info['file2'] = $file2? get_images_preview($file2) : [];
+            $file3 = isset($info['idcard_imgs']) && $info['idcard_imgs']? json_decode($info['idcard_imgs'], true) : [];
+            $info['file3'] = $file3? get_images_preview($file3) : [];
+            $albums = isset($info['albums']) && $info['albums']? json_decode($info['albums'], true) : [];
+            $info['albums'] = $albums? get_images_preview($albums) : [];
+            if(isset($info['category']) && $info['category']){
+                $info['category_name'] = isset($info['category']['name'])? $info['category']['name'] : '';
+                $info['category'] = isset($info['category']['id'])? $info['category']['id'] : '';
+            }
+
+            unset($info['qualification_imgs']);
+            unset($info['other_certificates']);
+            unset($info['idcard_imgs']);
+        }
+
+        return $info;
+    }
+
+    /**
+     * @param $userId
+     * @param $params
+     * @return bool
+     */
+    public function applyConfirm($userId, $params)
+    {
+        $id = isset($params['id'])? $params['id'] : 0;
+        $info = $this->model->where(['id'=> $id,'mark'=>1])->select('id','user_id','name','status','mark')->first();
+        $status = isset($info['status'])? $info['status'] : 0;
+        if(empty($info) || $id<=0){
+            $this->error = 2230;
+            return false;
+        }
+
+        if($status != 1){
+            $this->error = 2231;
+            return false;
+        }
+
+        $status = isset($params['status'])? intval($params['status']) : 0;
+        $auditRemark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
+        if(!in_array($status,[2,3])){
+            $this->error = 2232;
+            return false;
+        }
+
+        if($this->model->where(['id'=> $id])->update(['status'=> $status,'audit_remark'=>$auditRemark,'update_time'=>time()])){
+            $this->error = 1040;
+            return true;
+        }else{
+            $this->error = 1041;
+            return false;
+        }
+    }
+
+    /**
+     * @param $userId
+     * @param $params
+     * @return bool
+     */
+    public function lock($userId, $params)
+    {
+        $id = isset($params['id'])? $params['id'] : 0;
+        $info = $this->model->where(['id'=> $id,'mark'=>1])->select('id','user_id','name','status','mark')->first();
+        $status = isset($info['status'])? $info['status'] : 0;
+        if(empty($info) || $id<=0){
+            $this->error = 2230;
+            return false;
+        }
+
+        if($status <= 1){
+            $this->error = 2234;
+            return false;
+        }
+
+        $agentInfo = AgentModel::where(['user_id'=> $userId,'mark'=>1])->select(['id','user_id','realname'])->first();
+        $agentId = isset($agentInfo['id'])? $agentInfo['id'] : 0;
+        if(empty($agentInfo)){
+            $this->error = 2024;
+            return false;
+        }
+
+        $status = isset($params['status'])? intval($params['status']) : 0;
+        $remark = isset($params['remark'])? trim($params['remark']) : '';
+        if(!in_array($status,[2,3])){
+            $this->error = 2232;
+            return false;
+        }
+
+        if($this->model->where(['id'=> $id])->update(['agent_lock'=>1,'agent_lock_id'=> $agentId,'agent_lock_status'=> $status,'agent_lock_remark'=>$remark,'update_time'=>time()])){
+            $this->error = 1035;
+            return true;
+        }else{
+            $this->error = 1036;
+            return false;
+        }
+    }
+
+    /**
+     * 删除
+     * @return array|false
+     */
+    public function delete()
+    {
+        // 参数
+        $id = request()->post('id');
+        if (empty($id)) {
+            $this->error = 2014;
+            return false;
+        }
+
+        $this->error = 1002;
+        $this->model->where(['id'=> $id,'mark'=>0])->where('update_time','<=', time() - 3*86400)->delete();
+        return $this->model->where(['id'=> $id])->update(['mark'=> 0, 'update_time'=> time()]);
+    }
+
+    /**
+     * @param $userId
+     * @param $params
+     * @return bool
+     */
+    public function modify($userId, $params)
+    {
+        // 用户验证
+        $info = $this->model->where(['user_id' => $userId, 'mark' => 1])
+            ->select(['id','user_id', 'status'])
+            ->first();
+        if (!$info) {
+            $this->error = 2001;
+            return false;
+        }
+
+        // 使用状态校验
+        if ($info['status'] != 2) {
+            $this->error = 2015;
+            return false;
+        }
+
+        // 密码校验
+        $data = ['update_time' => time()];
+        $payPassword = isset($params['pay_password']) ? $params['pay_password'] : '';
+
+        // 手机号验证
+        $oldMobile = isset($params['old_mobile']) ? $params['old_mobile'] : '';
+        if (isset($params['old_mobile']) && $oldMobile) {
+            // 短信验证码
+            $code = isset($params['old_code']) ? $params['old_code'] : '';
+            if (empty($code)) {
+                $this->error = 2013;
+                return false;
+            }
+
+            if (!SmsService::make()->check($oldMobile, $code, 'modify')) {
+                $this->error = 1044;
+                return false;
+            }
+        }
+
+        // 手机号验证
+        $mobile = isset($params['mobile']) ? $params['mobile'] : '';
+        if (isset($params['mobile']) && $mobile) {
+            $data['mobile'] = $mobile;
+            $checkInfo = $this->model->where(['mobile' => $mobile, 'mark' => 1])->select(['id','user_id', 'status'])->first();
+            if ($checkInfo && $checkInfo['user_id'] != $userId) {
+//                $this->error = 2009;
+//                return false;
+            }
+
+            // 短信验证码
+            $code = isset($params['sms_code']) ? $params['sms_code'] : '';
+            if (empty($code)) {
+                $this->error = 2013;
+                return false;
+            }
+
+            if (!SmsService::make()->check($mobile, $code, 'modify')) {
+                $this->error = SmsService::make()->getError();
+                return false;
+            }
+        }
+
+        if(isset($params['settle_type']) && in_array($params['settle_type'],[0,1,2,3])){
+            $data['settle_type'] = intval($params['settle_type']);
+        }
+
+        if(isset($params['trade_status']) && in_array($params['trade_status'],[1,2])){
+            $data['trade_status'] = intval($params['trade_status']);
+        }
+
+        if (isset($params['pay_password']) && $payPassword) {
+            $payPassword = get_password($payPassword);
+            $data['pay_password'] = $payPassword;
+        }
+
+        // 修改数据
+        RedisService::clear("caches:merch:detail_{$info['id']}");
+        RedisService::keyDel("caches:merchant:info:temp*");
+        $this->model->where(['user_id' => $userId])->update($data);
+        $this->error = 1008;
+        return true;
+    }
+
+    /**
+     * 缴纳保证金
+     * @param $userId 商家用户
+     * @param $params
+     * @return array|false
+     */
+    public function deposit($userId, $params)
+    {
+        $merchId = isset($params['id'])? $params['id'] : 0;
+        $money = isset($params['money'])? $params['money'] : 0;
+        $payType = isset($params['pay_type']) && $params['pay_type']? intval($params['pay_type']) : 10;
+        if($money<=0){
+            $this->error = 2031;
+            return false;
+        }
+
+        if(!in_array($payType, [10,20])){
+            $this->error = 2032;
+            return false;
+        }
+
+        $info = $this->model->where(['id'=> $merchId,'mark'=>1])
+            ->select(['id','name','mobile','balance','deposit','status'])
+            ->first();
+        $deposit = isset($info['deposit'])? $info['deposit'] : 0;
+        $status = isset($info['status'])? $info['status'] : 0;
+        if($merchId<=0 || empty($info) || $status != 2){
+            $this->error = 2015;
+            return false;
+        }
+
+        // 充值订单
+        $orderNo = get_order_num('DP');
+        $data = [
+            'source_order_no'=> $orderNo,
+            'user_id'=> $userId,
+            'merch_id'=> $merchId,
+            'type'=> 14,
+            'coin_type'=> 1,
+            'user_type'=> 2,
+            'money'=> $money,
+            'balance'=> $deposit,
+            'date'=> date('Y-m-d'),
+            'create_time'=> time(),
+            'update_time'=> time(),
+            'remark'=> $payType == 10?'微信支付商家保证金':'支付宝支付商家保证金',
+            'status'=> 2,
+            'mark'=> 1,
+        ];
+
+        if(!$orderId = AccountLogModel::insertGetId($data)){
+            $this->error = 2037;
+            return false;
+        }
+
+        // 支付方式
+        $order = [
+            'order_no'=> $orderNo,
+            'type'=> 0,
+            'pay_type'=> $payType,
+            'pay_money'=> $money,
+            'body'=> '缴纳保证金订单支付',
+        ];
+
+        switch($payType){
+            case 20: // 支付宝
+                $payment = PaymentService::make()->aliPay($info, $order,'deposit');
+                if(empty($payment)){
+                    DB::rollBack();
+                    $this->error = PaymentService::make()->getError();
+                    return false;
+                }
+                break;
+            case 10: // 微信支付
+                $payment = PaymentService::make()->wechatPay($info, $order,'deposit');
+                if(empty($payment)){
+                    DB::rollBack();
+                    $this->error = PaymentService::make()->getError();
+                    return false;
+                }
+                break;
+            default:
+                $this->error = 1030;
+                return false;
+        }
+
+        $this->error = 2038;
+        return [
+            'id'=> $orderId,
+            'payment'=> $payment,
+            'total'=> $money,
+            'order_no'=> $orderNo,
+            'pay_type'=> $payType,
+        ];
+    }
+
+    /**
+     * 退还保证金处理
+     * @param $userId 用户
+     * @param $params
+     * @return bool
+     */
+    public function rebackDeposit($userId, $params)
+    {
+        $merchId = isset($params['id'])? $params['id'] : 0;
+        if($merchId<=0){
+            $this->error = 2039;
+            return false;
+        }
+
+        $info = $this->model->where(['id'=> $merchId,'mark'=>1])
+            ->select(['id','name','mobile','balance','deposit','status'])
+            ->first();
+        $deposit = isset($info['deposit'])? floatval($info['deposit']) : 0;
+        $balance = isset($info['balance'])? floatval($info['balance']) : 0;
+        $status = isset($info['status'])? $info['status'] : 0;
+        if($merchId<=0 || empty($info) || $status != 2){
+            $this->error = 2015;
+            return false;
+        }
+
+        if($deposit<=0){
+            $this->error = 2041;
+            return false;
+        }
+
+        // 时间限制
+        $depositTime = ConfigService::make()->getConfigByCode('shop_deposit_time');
+        $depositTime = $depositTime>=0? $depositTime : 0;
+        $paymentTime = AccountLogModel::where(['merch_id'=> $merchId,'type'=>14,'coin_type'=>1,'status'=>1,'mark'=>1])->orderBy('create_time','desc')->value('create_time');
+        if($depositTime>0 && $paymentTime>0 && $paymentTime + ($depositTime*86400)> time()){
+            $this->error = lang(2040,['time'=> $depositTime]);
+            return false;
+        }
+
+        DB::beginTransaction();
+        // 余额
+        $updateData = ['balance' => DB::raw("balance + {$deposit}"),'deposit'=>0.00, 'update_time' => time()];
+        if(!$this->model->where(['id'=> $merchId])->update($updateData)){
+            DB::rollBack();
+            $this->error = 2042;
+            return false;
+        }
+
+        // 退还记录
+        $data = [
+            'source_order_no'=> '',
+            'user_id'=> $userId,
+            'merch_id'=> $merchId,
+            'type'=> 14,
+            'coin_type'=> 4,
+            'user_type'=> 2,
+            'money'=> -$deposit,
+            'balance'=> $balance,
+            'date'=> date('Y-m-d'),
+            'create_time'=> time(),
+            'update_time'=> time(),
+            'remark'=> '商家保证金退还',
+            'status'=> 1,
+            'mark'=> 1,
+        ];
+
+        if(!$id = AccountLogModel::insertGetId($data)){
+            DB::rollBack();
+            $this->error = 2042;
+            return false;
+        }
+
+        DB::commit();
+
+        $params = [
+            'title' => '商家保证金退还到账通知',
+            'body' => "您的商家保证金申请退还已成功,请点击查看详情",
+            'type' => 3, // 1-公告通知,2-订单通知,3-交易通知,4-其他
+            'content' => [
+                'pay_time' => ['name' => '退还时间', 'text' => date('Y-m-d H:i:s')],
+                'money' => ['name' => '金额', 'text' => $deposit],
+                'balance' => ['name' => '当前余额', 'text' => moneyFormat($balance + $deposit,2)],
+                'status' => ['name' => '状态', 'text' => '已到账'],
+            ],
+            'click_type' => 'payload',
+            'url' => '/pages/account/index?type=3',
+        ];
+
+        PushService::make()->pushMessageByUser($userId, $params, 0);
+        $this->error = 2043;
+        return true;
+    }
+}