Преглед изворни кода

add - 邀约门店、工程师入驻-销售API

liugc пре 1 година
родитељ
комит
b5af66b130

+ 10 - 2
app/adminapi/validate/tenant/TenantRegisterValidate.php

@@ -35,14 +35,16 @@ class TenantRegisterValidate extends BaseValidate
         'name' => 'require',
         'head_name' => 'require',
         'mobile' => 'require',
+        'door_images' => 'require',
+        'business_images' => 'require',
         'city' => 'require',
+        'area_name' => 'require',
         'lon' => 'require',
         'lat' => 'require',
         'sale_id' => 'require',
         'openid' => 'require',
     ];
 
-
     /**
      * 参数描述
      * @var string[]
@@ -52,7 +54,10 @@ class TenantRegisterValidate extends BaseValidate
         'name' => '门店名称',
         'head_name' => '负责人名称',
         'mobile' => '电话',
+        'door_images' => '门头照片',
+        'business_images' => '营业执照',
         'city' => '城市',
+        'area_name' => '地区名称',
         'lon' => '经度',
         'lat' => '维度',
         'sale_id' => '所属销售id',
@@ -70,7 +75,10 @@ class TenantRegisterValidate extends BaseValidate
     {
         return $this->only(['name','head_name','mobile','city','lon','lat','sale_id']);
     }
-
+    public function sceneApiAdd()
+    {
+        return $this->only(['name','head_name','mobile','business_images','city','area_name','lon','lat','sale_id','openid']);
+    }
 
     /**
      * @notes 编辑场景

+ 109 - 0
app/workerapi/controller/SaleController.php

@@ -0,0 +1,109 @@
+<?php
+// +----------------------------------------------------------------------
+// | whitef快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/whitef
+// | github下载:https://github.com/likeshop-github/whitef
+// | 访问官网:https://www.whitef.cn
+// | whitef团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: whitefTeam
+// +----------------------------------------------------------------------
+
+namespace app\workerapi\controller;
+
+use app\common\enum\notice\NoticeEnum;
+use app\common\model\master_worker\MasterWorker;
+use app\common\model\master_worker_register\MasterWorkerRegister;
+use app\common\model\notice\NoticeSetting;
+use app\common\model\sale\Sale;
+use app\common\service\wechat\WeChatOaService;
+use app\workerapi\lists\MasterWorkerRegisterLists;
+use app\workerapi\lists\TenantRegisterLists;
+use app\workerapi\logic\DictLogic;
+use app\workerapi\logic\LoginLogic;
+use app\workerapi\logic\MasterWorkerRegisterLogic;
+use app\workerapi\logic\SaleLogic;
+use app\workerapi\logic\TenantRegisterLogic;
+use app\workerapi\validate\LoginAccountValidate;
+use app\workerapi\validate\RegisterValidate;
+
+
+/**
+ * 销售
+ * Class SaleController
+ * @package app\workerapi\controller
+ */
+class SaleController extends BaseApiController
+{
+
+    public array $notNeedLogin = ['register', 'account'];
+
+
+    /**
+     * @notes 注册账号
+     * @return \think\response\Json
+     * @author 段誉
+     * @date 2022/9/7 15:38
+     */
+    public function register()
+    {
+        return $this->success('注册成功', [], 1, 1);
+    }
+
+    /**
+     * @notes 手机号密码/手机号验证码登录
+     * @return \think\response\Json
+     * @author 段誉
+     * @date 2022/9/16 10:42
+     */
+    public function account()
+    {
+        $params = request()->post();
+        $result = SaleLogic::login($params);
+        if (false === $result) {
+            return $this->fail(SaleLogic::getError());
+        }
+        return $this->data($result);
+    }
+
+    /**
+     * 销售查看门店入驻情况列表
+     */
+    public function getTenantList()
+    {
+        return $this->dataLists(new TenantRegisterLists());
+    }
+    /**
+     * 销售查看门店入驻详情
+     */
+    public function getTenantDetail()
+    {
+        $params = request()->get();
+        $result = TenantRegisterLogic::detail($params);
+        return $this->data($result);
+    }
+
+    /**
+     * 销售查看工程师入驻情况列表
+     */
+    public function getWorkerList()
+    {
+        return $this->dataLists(new MasterWorkerRegisterLists());
+    }
+    /**
+     * 销售查看工程师入驻详情
+     */
+    public function getWorkerDetail()
+    {
+        $params = request()->get();
+        $result = MasterWorkerRegisterLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+
+
+}

+ 36 - 0
app/workerapi/controller/TenantController.php

@@ -0,0 +1,36 @@
+<?php
+namespace app\workerapi\controller;
+
+
+use app\adminapi\validate\tenant\TenantRegisterValidate;
+use app\workerapi\logic\TenantRegisterLogic;
+
+/**
+ * 门店H5注册
+ * Class TenantController
+ * @package app\workerapi\controller
+ */
+class TenantController extends BaseApiController
+{
+
+    public array $notNeedLogin = ['register'];
+
+
+    /**
+     * @notes 注册账号
+     * @return \think\response\Json
+     * @author 段誉
+     * @date 2022/9/7 15:38
+     */
+    public function register()
+    {
+        $params = (new TenantRegisterValidate())->post()->goCheck('apiadd');
+        $result = TenantRegisterLogic::add($params);
+        if (true === $result) {
+            return $this->success('入驻成功', [], 1, 1);
+        }
+        return $this->fail(TenantRegisterLogic::getError());
+    }
+
+
+}

+ 66 - 0
app/workerapi/lists/MasterWorkerRegisterLists.php

@@ -0,0 +1,66 @@
+<?php
+namespace app\workerapi\lists;
+
+use app\common\model\master_worker_register\MasterWorkerRegister;
+use app\common\lists\ListsSearchInterface;
+use app\workerapi\logic\SaleLogic;
+
+
+/**
+ * MasterWorkerRegister列表
+ * Class MasterWorkerRegisterLists
+ * @package app\workerapi\lists
+ */
+class MasterWorkerRegisterLists extends BaseWorkerDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2025/02/25 09:29
+     */
+    public function setSearch(): array
+    {
+        $sale_id = SaleLogic::getSaleIdByToken($this->params['sale_token']??'00000');
+        $this->params['sale_id'] = $sale_id;
+        return [
+            '=' => ['maintain_exp_type', 'other_exp_type', 'city', 'vehicle_type', 'status','is_credential','sale_id'],
+            '%like%' => ['name', 'mobile'],
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2025/02/25 09:29
+     */
+    public function lists(): array
+    {
+        return MasterWorkerRegister::where($this->searchWhere)
+            ->field(['*'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2025/02/25 09:29
+     */
+    public function count(): int
+    {
+        return MasterWorkerRegister::where($this->searchWhere)->count();
+    }
+
+}

+ 66 - 0
app/workerapi/lists/TenantRegisterLists.php

@@ -0,0 +1,66 @@
+<?php
+namespace app\workerapi\lists;
+
+use app\common\model\tenant\TenantRegister;
+use app\common\lists\ListsSearchInterface;
+use app\workerapi\logic\SaleLogic;
+
+
+/**
+ * TenantRegister列表
+ * Class TenantRegisterLists
+ * @package app\workerapi\lists
+ */
+class TenantRegisterLists extends BaseWorkerDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2025/02/25 09:29
+     */
+    public function setSearch(): array
+    {
+        $sale_id = SaleLogic::getSaleIdByToken($this->params['sale_token']??'00000');
+        $this->params['sale_id'] = $sale_id;
+        return [
+            '=' => ['door_images', 'business_images', 'province', 'city', 'area_name', 'lon', 'lat', 'status', 'sale_id', 'openid'],
+            '%like%' => ['name', 'head_name','mobile'],
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2025/02/25 09:29
+     */
+    public function lists(): array
+    {
+        return TenantRegister::with(['sale'])->where($this->searchWhere)
+            ->field(['id', 'name', 'head_name', 'mobile', 'door_images', 'business_images', 'province', 'city', 'area_name', 'lon', 'lat', 'status', 'sale_id', 'openid'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2025/02/25 09:29
+     */
+    public function count(): int
+    {
+        return TenantRegister::where($this->searchWhere)->count();
+    }
+
+}

+ 3 - 1
app/workerapi/logic/LoginLogic.php

@@ -98,7 +98,8 @@ class LoginLogic extends BaseLogic
                     'lon' => !empty($params['lon'])?$params['lon']:0,
                     'lat' => !empty($params['lat'])?$params['lat']:0,
                     'address' => !empty($params['address'])?$params['address']:'',
-                    'status'=>0
+                    'status'=>0,
+                    'sale_id' => $params['sale_id']??0,
                 ]);
             }else{
                 MasterWorkerRegister::create([
@@ -119,6 +120,7 @@ class LoginLogic extends BaseLogic
                     'lon' => !empty($params['lon'])?$params['lon']:0,
                     'lat' => !empty($params['lat'])?$params['lat']:0,
                     'address' => !empty($params['address'])?$params['address']:'',
+                    'sale_id' => $params['sale_id']??0,
                 ]);
             }
 

+ 24 - 0
app/workerapi/logic/MasterWorkerRegisterLogic.php

@@ -0,0 +1,24 @@
+<?php
+namespace app\workerapi\logic;
+
+use app\common\model\master_worker_register\MasterWorkerRegister;
+use app\common\logic\BaseLogic;
+
+/**
+ * MasterWorkerRegister逻辑
+ * Class MasterWorkerRegisterLogic
+ * @package app\workerapi\logic\master_worker_register
+ */
+class MasterWorkerRegisterLogic extends BaseLogic
+{
+
+    /**
+     * 获取详情
+     */
+    public static function detail($params): array
+    {
+        return MasterWorkerRegister::findOrEmpty($params['id'])->toArray();
+    }
+
+
+}

+ 95 - 0
app/workerapi/logic/SaleLogic.php

@@ -0,0 +1,95 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\workerapi\logic;
+
+
+use app\common\enum\LoginEnum;
+use app\common\enum\notice\NoticeEnum;
+use app\common\model\sale\Sale;
+use app\common\logic\BaseLogic;
+use app\common\service\sms\SmsDriver;
+use think\facade\Config;
+use think\facade\Db;
+
+
+/**
+ * Sale逻辑
+ * Class SaleLogic
+ * @package app\workerapi\logic
+ */
+class SaleLogic extends BaseLogic
+{
+
+
+    public static function login($params)
+    {
+        try {
+            // 账号/手机号 密码登录
+            $where = ['mobile' => $params['mobile']];
+            $user = Sale::where($where)->findOrEmpty();
+            if ($user->isEmpty()) {
+                throw new \Exception('无此用户');
+            }
+
+            // 账号密码登录
+            if (LoginEnum::ACCOUNT_PASSWORD == $params['scene']) {
+                if (!isset($params['password'])) {
+                    throw new \Exception('请输入密码');
+                }
+                $passwordSalt = Config::get('project.unique_identification');
+                if ($user['password'] !== create_password($params['password'], $passwordSalt)) {
+                    throw new \Exception('密码错误');
+                }
+            }
+
+            // 手机验证码登录
+            if (LoginEnum::MOBILE_CAPTCHA == $params['scene']) {
+                if (!isset($params['code'])) {
+                    throw new \Exception('请输入手机验证码');
+                }
+                $smsDriver = new SmsDriver();
+                $result = $smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::LOGIN_CAPTCHA);
+                if (!$result) {
+                    throw new \Exception('验证码错误');
+                }
+            }
+
+            //获取token
+            $token = create_token($params['mobile']);
+            $user->token = $token;
+            $user->save();
+
+            return [
+                'id' => $user['id'],
+                'mobile' => $user['mobile'],
+                'sale_token' => $token,
+            ];
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+    public static function getSaleIdByToken($sale_token)
+    {
+        $user = Sale::where('token',$sale_token)->findOrEmpty();
+        if ($user->isEmpty()) {
+            return -1;
+        }
+        return $user['id'];
+    }
+
+
+}

+ 76 - 0
app/workerapi/logic/TenantRegisterLogic.php

@@ -0,0 +1,76 @@
+<?php
+namespace app\workerapi\logic;
+
+use app\common\logic\BaseLogic;
+use app\common\model\master_worker\MasterWorker;
+use app\common\model\master_worker_register\MasterWorkerRegister;
+use app\common\model\tenant\Tenant;
+use app\common\model\tenant\TenantRegister;
+use think\facade\Db;
+
+
+/**
+ * TenantRegisterLogic逻辑
+ * Class TenantRegisterLogic
+ * @package app\workerapi\logic\master_worker_register
+ */
+class TenantRegisterLogic extends BaseLogic
+{
+    /**
+     *  添加
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            $info = TenantRegister::where('mobile',$params['mobile'])->findOrEmpty();
+            if(!$info->isEmpty()){
+                throw new \Exception('手机号已入驻门店');
+            }
+            $info = Tenant::where('tel',$params['mobile'])->findOrEmpty();
+            if(!$info->isEmpty()){
+                throw new \Exception('手机号已存在门店');
+            }
+            $info = MasterWorkerRegister::where('mobile',$params['mobile'])->findOrEmpty();
+            if(!$info->isEmpty()){
+                throw new \Exception('手机号已注册工程师');
+            }
+            $info = MasterWorker::where('mobile',$params['mobile'])->findOrEmpty();
+            if(!$info->isEmpty()){
+                throw new \Exception('手机号已占用');
+            }
+
+            TenantRegister::create([
+                'name' => $params['name'],
+                'head_name' => $params['head_name']??'',
+                'mobile' => $params['mobile'],
+                'door_images' => $params['door_images']??'',
+                'business_images' => $params['business_images']??'',
+                'province' => $params['province'],
+                'city' => $params['city'],
+                'area_name' => $params['area_name'],
+                'lon' => $params['lon'],
+                'lat' => $params['lat'],
+                'status' => $params['status']??0,
+                'sale_id' => $params['sale_id'],
+                'openid' => $params['openid']??''
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+    /**
+     * 获取详情
+     */
+    public static function detail($params): array
+    {
+        return TenantRegister::findOrEmpty($params['id'])->toArray();
+    }
+
+
+}