multi-store/app/admin/logic/user_ship/UserShipLogic.php
mkm 40ec3e5ee0 feat: 修改了订单相关的API,优化了支付逻辑;
fix: 修复了用户地址、商品库存等错误;
refactor: 重构了登录逻辑,提高了代码可读性;
style: 调整了代码格式,使其更加规范;
test: 增加了订单支付的测试用例;
docs: 更新了相关文档;
build: 更新了依赖;
ops: 优化了服务器性能;
chore: 更新了.gitignore文件;
2024-08-27 11:56:48 +08:00

140 lines
3.6 KiB
PHP

<?php
namespace app\admin\logic\user_ship;
use app\common\model\user_ship\UserShip;
use app\common\logic\BaseLogic;
use app\common\model\user\User;
use app\common\model\user\UserAddress;
use support\exception\BusinessException;
use think\facade\Db;
/**
* 会员类型逻辑
* Class UserShipLogic
* @package app\admin\logic\user_ship
*/
class UserShipLogic extends BaseLogic
{
/**
* @notes 添加会员类型
* @param array $params
* @return bool
* @author admin
* @date 2024/06/29 14:18
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserShip::create([
'title' => $params['title'],
'limit' => $params['limit'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑会员类型
* @param array $params
* @return bool
* @author admin
* @date 2024/06/29 14:18
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserShip::where('id', $params['id'])->update([
'title' => $params['title'],
'limit' => $params['limit'],
'sort' => $params['sort']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除会员类型
* @param array $params
* @return bool
* @author admin
* @date 2024/06/29 14:18
*/
public static function delete(array $params): bool
{
return UserShip::destroy($params['id']);
}
/**
* @notes 获取会员类型详情
* @param $params
* @return array
* @author admin
* @date 2024/06/29 14:18
*/
public static function detail($params): array
{
return UserShip::findOrEmpty($params['id'])->toArray();
}
/**
* 判断是否有村长或者对长
* @param $params array 参数数组
*/
public static function user_ship($params){
$user_ship=$params['user_ship']??0;
if($user_ship==2){
if(!isset($params['village'])){
throw new BusinessException('请设置村参数');
}
$arr=User::where('user_ship',$user_ship)->column('id');
if($arr){
$find=UserAddress::where('uid','in',$arr)->where('village',$params['village'])->find();
if($find){
if($params['uid']==$find['uid']){
return true;
}
throw new BusinessException('该区域已有村长请重新选择');
}
}
}elseif($user_ship==3){
if(!isset($params['brigade'])){
throw new BusinessException('请设置队参数');
}
$arr=User::where('user_ship',$user_ship)->column('id');
if($arr){
$find=UserAddress::where('uid','in',$arr)->where('village',$params['village'])->where('brigade',$params['brigade'])->find();
if($find){
if($params['uid']==$find['uid']){
return true;
}
throw new BusinessException('该区域已有队长请重新选择');
}
}
}
return true;
}
}