Kirin hace 1 año
padre
commit
b1c73fc4a7

+ 2 - 0
app/controller/admin/v1/supplier/SystemSupplier.php

@@ -72,6 +72,7 @@ class SystemSupplier extends AuthController
             ['area', 0],
             ['street', 0],
             ['detailed_address', ''],
+            ['valid_time', ''],
             ['mark', '']
         ]);
         $this->validate($data, \app\validate\supplier\SystemSupplierValidate::class, 'save');
@@ -109,6 +110,7 @@ class SystemSupplier extends AuthController
             ['city', 0],
             ['area', 0],
             ['street', 0],
+            ['valid_time', 0],
             ['detailed_address', ''],
             ['mark', '']
         ]);

+ 7 - 0
app/controller/supplier/AuthController.php

@@ -12,6 +12,7 @@ namespace app\controller\supplier;
 
 
 use crmeb\basic\BaseController;
+use crmeb\exceptions\AdminException;
 
 /**
  * 基类 所有控制器继承的类
@@ -50,6 +51,12 @@ class AuthController extends BaseController
         $this->supplierId = $this->request->hasMacro('supplierId') ? $this->request->supplierId() : 0;
         $this->supplierInfo = $this->request->hasMacro('supplierInfo') ? $this->request->supplierInfo() : [];
         $this->auth = $this->supplierInfo['rule'] ?? [];
+        if (!$this->supplierInfo->status || !$this->supplierInfo->is_show) {
+            throw new AdminException('您已被禁止登录!');
+        }
+        if ($this->supplierInfo->valid_time > 0 && $this->supplierInfo->valid_time < time()) {
+            throw new AdminException('供应商授权已到期,请联系客服!');
+        }
     }
 
 }

+ 34 - 29
app/services/supplier/LoginServices.php

@@ -86,19 +86,24 @@ class LoginServices extends BaseServices
     public function login($account, $password, $type)
     {
         $supplierInfo = $this->adminDao->getOne(['admin_type' => 4, 'account' => $account, 'is_del' => 0], '*', ['supplier']);
-		$key = 'supplier_login_captcha_' . $account;
+        $key = 'supplier_login_captcha_' . $account;
         if (!$supplierInfo) {
-			Cache::inc($key);
+            Cache::inc($key);
             throw new AdminException('账号不存在!');
         }
         if ($password) {//平台还可以登录
             if (!$supplierInfo->status || !$supplierInfo->is_show) {
-				Cache::inc($key);
+                Cache::inc($key);
                 throw new AdminException('您已被禁止登录!');
             }
 
+            if ($supplierInfo->valid_time > 0 && $supplierInfo->valid_time < time()) {
+                Cache::inc($key);
+                throw new AdminException('供应商授权已到期,请联系客服!');
+            }
+
             if (!password_verify($password, $supplierInfo->pwd)) {
-				Cache::inc($key);
+                Cache::inc($key);
                 throw new AdminException('账号或密码错误,请重新输入');
             }
         }
@@ -127,7 +132,7 @@ class LoginServices extends BaseServices
             'logo_square' => sys_config('site_logo_square'),
             'version' => get_crmeb_version(),
             'newOrderAudioLink' => get_file_link(sys_config('new_order_audio_link', '')),
-			'prefix' => config('admin.supplier_prefix')
+            'prefix' => config('admin.supplier_prefix')
         ];
     }
 
@@ -193,21 +198,21 @@ class LoginServices extends BaseServices
             }
             throw new AuthException(ApiErrorCode::ERR_LOGIN_INVALID);
         }
-		//获取管理员信息
-		$adminInfo = $this->adminDao->getOne(['id' => $id, 'is_del' => 0, 'status' => 1]);
-		if(!$adminInfo){
-			throw new AuthException(ApiErrorCode::ERR_ADMINID_VOID);
-		}
-		if ($auth !== md5($adminInfo->pwd)) {
-			throw new AuthException(ApiErrorCode::ERR_LOGIN_INVALID);
-		}
-		$supplierInfo = $this->dao->getOne(['id' =>(int)$adminInfo->relation_id, 'is_del' => 0], '*', ['admin']);
-		if (!$supplierInfo || !$supplierInfo->account || $supplierInfo->admin_is_del) {
-			if (!request()->isCli()) {
-				$cacheService->clearToken($md5Token);
-			}
-			throw new AuthException(ApiErrorCode::ERR_LOGIN_STATUS);
-		}
+        //获取管理员信息
+        $adminInfo = $this->adminDao->getOne(['id' => $id, 'is_del' => 0, 'status' => 1]);
+        if (!$adminInfo) {
+            throw new AuthException(ApiErrorCode::ERR_ADMINID_VOID);
+        }
+        if ($auth !== md5($adminInfo->pwd)) {
+            throw new AuthException(ApiErrorCode::ERR_LOGIN_INVALID);
+        }
+        $supplierInfo = $this->dao->getOne(['id' => (int)$adminInfo->relation_id, 'is_del' => 0], '*', ['admin']);
+        if (!$supplierInfo || !$supplierInfo->account || $supplierInfo->admin_is_del) {
+            if (!request()->isCli()) {
+                $cacheService->clearToken($md5Token);
+            }
+            throw new AuthException(ApiErrorCode::ERR_LOGIN_STATUS);
+        }
 
         $supplierInfo->type = $type;
         return $supplierInfo->hidden(['pwd', 'is_del', 'status'])->toArray();
@@ -225,22 +230,22 @@ class LoginServices extends BaseServices
         if (in_array($rule, ['supplier/logout', 'menuslist'])) {
             return true;
         }
-		$method = trim(strtolower($request->method()));
+        $method = trim(strtolower($request->method()));
         /** @var SystemRoleServices $roleServices */
         $roleServices = app()->make(SystemRoleServices::class);
         $auth = $roleServices->getAllRoles(2, 4, self::SUPPLIER_RULES_LEVEL);
         //验证访问接口是否存在
-		if ($auth && !in_array($method . '@@' . $rule, array_map(function ($item) {
-				return trim(strtolower($item['methods'])). '@@'. trim(strtolower(str_replace(' ', '', $item['api_url'])));
-			}, $auth))) {
-			return true;
-		}
+        if ($auth && !in_array($method . '@@' . $rule, array_map(function ($item) {
+                return trim(strtolower($item['methods'])) . '@@' . trim(strtolower(str_replace(' ', '', $item['api_url'])));
+            }, $auth))) {
+            return true;
+        }
         $auth = $roleServices->getRolesByAuth($request->supplierInfo()['roles'], 2, 4, self::SUPPLIER_RULES_LEVEL);
         //验证访问接口是否有权限
         if ($auth && empty(array_filter($auth, function ($item) use ($rule, $method) {
-            if (trim(strtolower($item['api_url'])) === $rule && $method === trim(strtolower($item['methods'])))
-                return true;
-        }))) {
+                if (trim(strtolower($item['api_url'])) === $rule && $method === trim(strtolower($item['methods'])))
+                    return true;
+            }))) {
             throw new AuthException(ApiErrorCode::ERR_AUTH);
         }
     }

+ 156 - 154
app/services/supplier/SystemSupplierServices.php

@@ -59,40 +59,40 @@ class SystemSupplierServices extends BaseServices
         return $info;
     }
 
-	/**
-	 * 供应商列表
-	 * @param array $where
-	 * @param array $field
-	 * @return array
-	 * @throws \think\db\exception\DataNotFoundException
-	 * @throws \think\db\exception\DbException
-	 * @throws \think\db\exception\ModelNotFoundException
-	 */
+    /**
+     * 供应商列表
+     * @param array $where
+     * @param array $field
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
     public function getSupplierList(array $where, array $field = ['*'])
     {
         [$page, $limit] = $this->getPageValue();
         $list = $this->dao->getSupplierList($where, $field, $page, $limit);
-		if ($list) {
-			$prefix = config('admin.supplier_prefix');
-			foreach ($list as &$item) {
-				if (isset($item['add_time']) && $item['add_time']) $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
-				$item['prefix'] = $prefix;
-			}
-		}
+        if ($list) {
+            $prefix = config('admin.supplier_prefix');
+            foreach ($list as &$item) {
+                if (isset($item['add_time']) && $item['add_time']) $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
+                $item['prefix'] = $prefix;
+            }
+        }
         $count = $this->dao->count($where);
         return compact('list', 'count');
     }
 
-	/**
-	 * 保存供应商
-	 * @param array $data
-	 * @return mixed
-	 */
+    /**
+     * 保存供应商
+     * @param array $data
+     * @return mixed
+     */
     public function create(array $data)
     {
-		if ($this->adminDao->count(['account' => $data['account'], 'admin_type' => 4, 'is_del' => 0])) {
-			throw new AdminException('管理员账号已存在');
-		}
+        if ($this->adminDao->count(['account' => $data['account'], 'admin_type' => 4, 'is_del' => 0])) {
+            throw new AdminException('管理员账号已存在');
+        }
         return $this->transaction(function () use ($data) {
             $adminData = [
                 'pwd' => $this->passwordHash($data['pwd']),
@@ -104,17 +104,18 @@ class SystemSupplierServices extends BaseServices
                 'add_time' => time(),
                 'level' => 0
             ];
-			unset($data['pwd'], $data['conf_pwd'], $data['account']);
+            unset($data['pwd'], $data['conf_pwd'], $data['account']);
 
             // 创建管理员
             $res = $this->adminDao->save($adminData);
             if (!$res) throw new AdminException('管理员添加失败');
-			$data['admin_id'] = (int)$res->id;
-			$data['add_time'] = time();
+            $data['admin_id'] = (int)$res->id;
+            $data['add_time'] = time();
 
-			// 创建供应商
-			$relation_id = $this->dao->save($data)->id;
-			if (!$relation_id) throw new AdminException('供应商添加失败');
+            // 创建供应商
+            if ($data['valid_time'] ?? '') $data['valid_time'] = strtotime($data['valid_time']);
+            $relation_id = $this->dao->save($data)->id;
+            if (!$relation_id) throw new AdminException('供应商添加失败');
 
             $this->adminDao->update($res->id, ['relation_id' => $relation_id]);
             return $relation_id;
@@ -128,76 +129,77 @@ class SystemSupplierServices extends BaseServices
      */
     public function save(int $id, array $data)
     {
-		if (!$supplierInfo = $this->dao->get($id)) {
-			throw new AdminException('供应商不存在,无法修改');
-		}
-		if ($supplierInfo->is_del) {
-			throw new AdminException('供应商已经删除');
-		}
-		if (!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])) {
-			throw new AdminException('管理员不存在,无法修改');
-		}
-		if ($adminInfo->is_del) {
-			throw new AdminException('管理员已经删除');
-		}
-		//修改账号
-		if (isset($data['account']) && $data['account'] != $adminInfo->account && $this->adminDao->isAccountUsable($data['account'], $supplierInfo['admin_id'], 4)) {
-			throw new AdminException('管理员账号已存在');
-		}
+        if (!$supplierInfo = $this->dao->get($id)) {
+            throw new AdminException('供应商不存在,无法修改');
+        }
+        if ($supplierInfo->is_del) {
+            throw new AdminException('供应商已经删除');
+        }
+        if (!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])) {
+            throw new AdminException('管理员不存在,无法修改');
+        }
+        if ($adminInfo->is_del) {
+            throw new AdminException('管理员已经删除');
+        }
+        //修改账号
+        if (isset($data['account']) && $data['account'] != $adminInfo->account && $this->adminDao->isAccountUsable($data['account'], $supplierInfo['admin_id'], 4)) {
+            throw new AdminException('管理员账号已存在');
+        }
         return $this->transaction(function () use ($id, $data, $adminInfo, $supplierInfo) {
 
-			$adminData = [
-				'pwd' => $this->passwordHash($data['pwd']),
-            	'real_name' => $data['name'] ?? $adminInfo->real_name,
-				'phone' => $data['phone'] ?? $adminInfo->phone,
-            	'account' => $data['account'] ?? $adminInfo->account
-			];
+            $adminData = [
+                'pwd' => $this->passwordHash($data['pwd']),
+                'real_name' => $data['name'] ?? $adminInfo->real_name,
+                'phone' => $data['phone'] ?? $adminInfo->phone,
+                'account' => $data['account'] ?? $adminInfo->account
+            ];
             // 修改管理员
             $res = $this->adminDao->update($adminInfo['id'], $adminData);
             if (!$res) throw new AdminException('管理员修改失败');
 
-			// 修改供应商
-			unset($data['pwd'], $data['conf_pwd'], $data['account']);
-			$this->dao->update($id, $data);
+            // 修改供应商
+            unset($data['pwd'], $data['conf_pwd'], $data['account']);
+            if ($data['valid_time'] ?? '') $data['valid_time'] = strtotime($data['valid_time']);
+            $this->dao->update($id, $data);
             $res1 = $supplierInfo->save();
             if (!$res1) throw new AdminException('供应商修改失败');
             return true;
         });
     }
 
-	/**
-	 * @param int $id
-	 * @return mixed
-	 * @throws \think\db\exception\DataNotFoundException
-	 * @throws \think\db\exception\DbException
-	 * @throws \think\db\exception\ModelNotFoundException
-	 */
+    /**
+     * @param int $id
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
     public function delete(int $id)
     {
-		if (!$supplierInfo = $this->dao->get($id)) {
-			throw new AdminException('供应商不存在,无法修改');
-		}
-		if ($supplierInfo->is_del) {
-			throw new AdminException('供应商已经删除');
-		}
-		if (!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])) {
-			throw new AdminException('管理员不存在,无法删除');
-		}
-		if ($adminInfo->is_del) {
-			throw new AdminException('管理员已经删除');
-		}
-		/** @var StoreOrderServices $storeOrderServices */
-		$storeOrderServices = app()->make(StoreOrderServices::class);
-		$orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 0]);
-		if (!$orderCount) {
-			$orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 1]);
-			if (!$orderCount) {
-				$orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 5]);
-			}
-		}
-		if ($orderCount) {
-			return $this->fail('删除失败,该供应商还有待处理订单');
-		}
+        if (!$supplierInfo = $this->dao->get($id)) {
+            throw new AdminException('供应商不存在,无法修改');
+        }
+        if ($supplierInfo->is_del) {
+            throw new AdminException('供应商已经删除');
+        }
+        if (!$adminInfo = $this->adminDao->get($supplierInfo['admin_id'])) {
+            throw new AdminException('管理员不存在,无法删除');
+        }
+        if ($adminInfo->is_del) {
+            throw new AdminException('管理员已经删除');
+        }
+        /** @var StoreOrderServices $storeOrderServices */
+        $storeOrderServices = app()->make(StoreOrderServices::class);
+        $orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 0]);
+        if (!$orderCount) {
+            $orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 1]);
+            if (!$orderCount) {
+                $orderCount = $storeOrderServices->count(['supplier_id' => $id, 'status' => 5]);
+            }
+        }
+        if ($orderCount) {
+            return $this->fail('删除失败,该供应商还有待处理订单');
+        }
         return $this->transaction(function () use ($id, $supplierInfo, $adminInfo) {
             $adminInfo->status = 0;
             $adminInfo->is_del = 1;
@@ -211,14 +213,14 @@ class SystemSupplierServices extends BaseServices
             $res1 = $supplierInfo->save();
             if (!$res1) throw new AdminException('供应商删除失败');
 
-			/** @var StoreBranchProductServices $storeBranchProducesServices */
-			$storeBranchProducesServices = app()->make(StoreBranchProductServices::class);
-			//删除供应商商品
-			$storeBranchProducesServices->deleteProducts([], 2, $id);
-			/** @var SystemAttachmentServices $attach */
-			$attach = app()->make(SystemAttachmentServices::class);
-			//删除附件
-			$attach->delAttachment([], 4, $id);
+            /** @var StoreBranchProductServices $storeBranchProducesServices */
+            $storeBranchProducesServices = app()->make(StoreBranchProductServices::class);
+            //删除供应商商品
+            $storeBranchProducesServices->deleteProducts([], 2, $id);
+            /** @var SystemAttachmentServices $attach */
+            $attach = app()->make(SystemAttachmentServices::class);
+            //删除附件
+            $attach->delAttachment([], 4, $id);
             return true;
         });
     }
@@ -254,71 +256,71 @@ class SystemSupplierServices extends BaseServices
         return $list;
     }
 
-	/**
-	 * 供应商选择列表
-	 * @param array $where
-	 * @param array $field
-	 * @return array
-	 * @throws \think\db\exception\DataNotFoundException
-	 * @throws \think\db\exception\DbException
-	 * @throws \think\db\exception\ModelNotFoundException
-	 */
+    /**
+     * 供应商选择列表
+     * @param array $where
+     * @param array $field
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
     public function getSupplierSearch(array $where, array $field = ['*'])
     {
         return $this->dao->getSupplierList($where, $field, 0, 0);
     }
 
-	/**
-	 * 供应商入住审核通过创建数据
-	 * @param int $applyId
-	 * @param array $info
-	 * @return array
-	 * @throws \think\db\exception\DataNotFoundException
-	 * @throws \think\db\exception\DbException
-	 * @throws \think\db\exception\ModelNotFoundException
-	 */
-	public function verifyAgreeCreate(int $applyId, array $info = [])
-	{
-		if (!$applyId) {
-			throw new ValidateException('缺少申请ID');
-		}
-		/** @var SystemUserApplyServices $applyServices */
-		$applyServices = app()->make(SystemUserApplyServices::class);
-		if (!$info) {
-			$info = $applyServices->get($applyId);
-			if (!$info) {
-				throw new ValidateException('申请数据不存在');
-			}
-			$info = $info->toArray();
-		}
-		$data = [
-			'supplier_name' => $info['system_name'],
-			'account' => $this->getAccount($info['phone']),
-			'phone' => $info['phone'],
-			'name' => $info['name'],
-			'pwd' => substr($info['phone'], -6)
-		];
-		$supplier_id = $this->create($data);
-		return $this->dao->get($supplier_id)->toArray();
-	}
+    /**
+     * 供应商入住审核通过创建数据
+     * @param int $applyId
+     * @param array $info
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function verifyAgreeCreate(int $applyId, array $info = [])
+    {
+        if (!$applyId) {
+            throw new ValidateException('缺少申请ID');
+        }
+        /** @var SystemUserApplyServices $applyServices */
+        $applyServices = app()->make(SystemUserApplyServices::class);
+        if (!$info) {
+            $info = $applyServices->get($applyId);
+            if (!$info) {
+                throw new ValidateException('申请数据不存在');
+            }
+            $info = $info->toArray();
+        }
+        $data = [
+            'supplier_name' => $info['system_name'],
+            'account' => $this->getAccount($info['phone']),
+            'phone' => $info['phone'],
+            'name' => $info['name'],
+            'pwd' => substr($info['phone'], -6)
+        ];
+        $supplier_id = $this->create($data);
+        return $this->dao->get($supplier_id)->toArray();
+    }
 
-	/**
-	 * 获取同意申请 创建账号
-	 * @param string $phone
-	 * @return string
-	 */
-	public function getAccount(string $phone)
-	{
-		$account = '';
-		if ($phone) {
-			//当前手机号当作账号是否存在
-			$adminDCount = $this->adminDao->count(['account' => $phone, 'admin_type' => 4, 'is_del' => 0]);
-			$account = $phone;
-			if ($adminDCount) {
-				$account = $account . '_' . $adminDCount;
-			}
-		}
-		return $account;
-	}
+    /**
+     * 获取同意申请 创建账号
+     * @param string $phone
+     * @return string
+     */
+    public function getAccount(string $phone)
+    {
+        $account = '';
+        if ($phone) {
+            //当前手机号当作账号是否存在
+            $adminDCount = $this->adminDao->count(['account' => $phone, 'admin_type' => 4, 'is_del' => 0]);
+            $account = $phone;
+            if ($adminDCount) {
+                $account = $account . '_' . $adminDCount;
+            }
+        }
+        return $account;
+    }
 
 }