其余文件

This commit is contained in:
2026-04-14 17:46:22 +08:00
parent 294b68fe37
commit 3691f4db22
1343 changed files with 189847 additions and 0 deletions

View File

@ -0,0 +1,235 @@
<?php
namespace app\admin\logic\shop;
use app\common\basics\Logic;
use app\common\enum\NoticeEnum;
use app\common\enum\ShopEnum;
use app\common\model\shop\Shop;
use app\common\model\shop\ShopAdmin;
use app\common\model\shop\ShopApply;
use app\common\server\UrlServer;
use Exception;
use think\facade\Db;
class ApplyLogic extends Logic
{
/**
* NOTE: 获取申请列表
* @param array $get
* @return array
* @author 张无忌
*/
public static function lists($get)
{
try {
$type = [
['audit_status', '=', ShopEnum::AUDIT_STATUS_STAY],
['audit_status', '=', ShopEnum::AUDIT_STATUS_OK],
['audit_status', '=', ShopEnum::AUDIT_STATUS_REFUSE]
];
$get['type'] = $get['type'] ?? 1;
$where[] = $type[intval($get['type']) - 1];
if (!empty($get['name']) and $get['name'])
$where[] = ['name', 'like', '%'.$get['name'].'%'];
if (!empty($get['nickname']) and $get['nickname'])
$where[] = ['nickname', 'like', '%'.$get['nickname'].'%'];
if (!empty($get['apply_start_time']) and $get['apply_start_time'])
$where[] = ['apply_time', '>=', strtotime($get['apply_start_time'])];
if (!empty($get['apply_end_time']) and $get['apply_end_time'])
$where[] = ['apply_time', '<=', strtotime($get['apply_end_time'])];
$model = new ShopApply();
$lists = $model->field(true)
->where($where)
->where(['del'=>0])
->with(['category'])
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
foreach ($lists['data'] as &$item) {
$item['category'] = $item['category']['name'] ?? '未知类目';
$item['audit_status_desc'] = ShopEnum::getAuditStatusDesc($item['audit_status']);
$license = [];
foreach ($item['license'] as $url) {
$license[] = UrlServer::getFileUrl($url);
}
$item['license'] = $license;
}
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
} catch (Exception $e) {
return ['error'=>$e->getMessage()];
}
}
/**
* NOTE: 统计
* @author: 张无忌
* @return array
*/
public static function totalCount()
{
$type = [
['audit_status', '=', ShopEnum::AUDIT_STATUS_STAY],
['audit_status', '=', ShopEnum::AUDIT_STATUS_OK],
['audit_status', '=', ShopEnum::AUDIT_STATUS_REFUSE]
];
$model = new ShopApply();
$ok = $model->where(['del'=>0])->where([$type[ShopEnum::AUDIT_STATUS_OK - 1]])->count();
$stay = $model->where(['del'=>0])->where([$type[ShopEnum::AUDIT_STATUS_STAY - 1]])->count();
$refuse = $model->where(['del'=>0])->where([$type[ShopEnum::AUDIT_STATUS_REFUSE - 1]])->count();
return [
'ok' => $ok,
'stay' => $stay,
'refuse' => $refuse
];
}
/**
* NOTE: 详细
* @param $id
* @return array
* @author: 张无忌
*/
public static function detail($id)
{
$model = new ShopApply();
$detail = $model->field(true)
->where(['id'=>(int)$id])
->with(['category'])
->findOrEmpty()->toArray();
$detail['category'] = $detail['category']['name'] ?? '未知类目';
$detail['audit_status'] = ShopEnum::getAuditStatusDesc($detail['audit_status']);
$detail['audit_explain'] = $detail['audit_explain'] == '' ? '无' : $detail['audit_explain'];
return $detail;
}
/**
* NOTE: 审核
* @param $post
* @return bool
* @author: 张无忌
*/
public static function audit($post)
{
Db::startTrans();
try {
ShopApply::update([
'audit_status' => $post['audit_status'],
'audit_explain' => $post['audit_explain'] ?? ''
], ['id'=>(int)$post['id']]);
$model = new ShopApply();
$shopApply = $model->field(true)->findOrEmpty((int)$post['id'])->toArray();
if ($post['audit_status'] == ShopEnum::AUDIT_STATUS_OK) {
// 新增商家信息
$shop = Shop::create([
'cid' => $shopApply['cid'],
'type' => ShopEnum::SHOP_TYPE_IN,
'name' => $shopApply['name'],
'nickname' => $shopApply['nickname'],
'mobile' => $shopApply['mobile'],
'license' => $shopApply['license'],
'logo' => '',
'background' => '',
'keywords' => '',
'intro' => '',
'weight' => 0,
'trade_service_fee' => 0,
'is_run' => ShopEnum::SHOP_RUN_CLOSE,
'is_freeze' => ShopEnum::SHOP_FREEZE_NORMAL,
'is_product_audit' => ShopEnum::PRODUCT_AUDIT_TRUE,
'is_recommend' => ShopEnum::SHOP_RECOMMEND_FALSE,
'del' => 0,
'expire_time' => 0,
]);
// 新增商家登录账号
$time = time();
$salt = substr(md5($time . $shopApply['name']), 0, 4);//随机4位密码盐
ShopAdmin::create([
'shop_id' => $shop->id,
'name' => '超级管理员',
'account' => $shopApply['account'],
'password' => generatePassword($shopApply['password'], $salt),
'salt' => $salt,
'role_id' => 0,
'create_time' => $time,
'update_time' => $time,
'disable' => 0,
'del' => 0
]);
//成功通知
event('Notice', [
'scene' => NoticeEnum::SHOP_APPLY_SUCCESS_NOTICE,
'mobile' => $shopApply['mobile'],
'params' => [
'user_id' => $shopApply['user_id'],
'shop_name' => $shopApply['name'],
// 'shop_admin_url' => request()->domain().'/shop',
'shop_admin_account' => $shopApply['account'],
]
]);
} else {
//失败通知
event('Notice', [
'scene' => NoticeEnum::SHOP_APPLY_ERROR_NOTICE,
'mobile' => $shopApply['mobile'],
'params' => [
'user_id' => $shopApply['user_id'],
'shop_name' => $shopApply['name'],
]
]);
}
Db::commit();
return true;
} catch (Exception $e) {
Db::rollback();
static::$error = $e->getMessage();
return false;
}
}
/**
* NOTE: 删除
* @author: 张无忌
* @param $id
* @return bool
*/
public static function del($id)
{
try {
ShopApply::update([
'del' => 1,
'update_time' => time()
], ['id'=>(int)$id]);
return true;
} catch (Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
}

View File

@ -0,0 +1,258 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\admin\logic\shop;
use app\common\basics\Logic;
use app\common\model\shop\ShopAuth;
use app\common\server\ArrayServer;
/**
* 商家菜单逻辑
* Class AuthLogic
* @package app\admin\logic\shop
*/
class AuthLogic extends Logic
{
/**
* Notes: 列表
* @author 段誉(2021/4/12 16:38)
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function lists()
{
$authModel = new ShopAuth();
$lists = $authModel
->where(['del' => 0])
->field(['id', 'type', 'system', 'pid', 'name', 'sort', 'icon', 'uri', 'disable'])
->order(['sort' => 'desc', 'type' => 'asc'])
->select()->toArray();
$pids = $authModel
->where(['del'=>0,'type'=>1])
->column('pid');
foreach ($lists as $k => $v) {
$lists[$k]['type_str'] = $v['type'] == 1 ? '菜单' : '权限';
$lists[$k]['open'] = in_array($v['id'],$pids) ? true : false;
}
return ArrayServer::linear_to_tree($lists);
}
/**
* Notes: 添加
* @param $post
* @author 段誉(2021/4/12 16:38)
* @return int|string
*/
public static function addMenu($post)
{
$level = self::getParent($post['pid']);
if ($level > 3) {
self::$error = '菜单不允许超出三级';
return false;
}
$data = [
'pid' => $post['pid'],
'type' => $post['type'],
'name' => $post['name'],
'icon' => $post['icon'],
'sort' => $post['sort'],
'uri' => $post['uri'],
'disable' => $post['disable'],
];
return (new ShopAuth())->insert($data);
}
/**
* Notes: 修改
* @param $post
* @author 段誉(2021/4/12 16:38)
* @return Auth|string
*/
public static function editMenu($post)
{
$level = self::getParent($post['pid']);
if ($level > 3) {
self::$error = '菜单不允许超出三级';
return false;
}
$data = [
'pid' => $post['pid'],
'type' => $post['type'],
'name' => $post['name'],
'icon' => $post['icon'],
'sort' => $post['sort'],
'uri' => $post['uri'],
'disable' => $post['disable'],
];
return ShopAuth::where(['id' => $post['id'], 'system' => 0])->update($data);
}
/**
* Notes: 菜单选项
* @param string $id
* @author 段誉(2021/4/12 16:38)
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function chooseMenu($id = '')
{
$authModel = new ShopAuth();
$lists = $authModel
->field(['id', 'pid', 'name'])
->where(['del' => 0, 'type' => 1])
->select();
if ($id) {
$remove_ids = self::getChildIds($lists, $id);
$remove_ids[] = $id;
foreach ($lists as $key => $row) {
if (in_array($row['id'], $remove_ids)) {
unset($lists[$key]);
}
}
$lists = array_values($lists);
}
return ArrayServer::multilevel_linear_sort($lists, '|-');
}
/**
* Notes: 查找层级
* @param $pid
* @author 段誉(2021/4/12 16:38)
* @return int
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getParent($pid)
{
static $count = 0;
$auth = (new ShopAuth())->where(['id' => $pid, 'type' => 1])->find();
if ($auth) {
$count += 1;
if ($count < 3) {
self::getParent($auth['pid']);
}
return $count;
}
return $count;
}
/**
* Notes: 子级id
* @param $lists
* @param $id
* @author 段誉(2021/4/12 16:39)
* @return array
*/
public static function getChildIds($lists, $id)
{
$ids = [];
foreach ($lists as $key => $row) {
if ($row['pid'] == $id) {
$ids[] = $row['id'];
$child_ids = self::getChildIds($lists, $row['id']);
foreach ($child_ids as $child_id) {
$ids[] = $child_id;
}
}
}
return $ids;
}
/**
* Notes: 详情
* @param $id
* @author 段誉(2021/4/12 16:39)
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function detail($id)
{
return ShopAuth::where(['del' => 0, 'id' => $id])
->field(['id', 'pid', 'type', 'name', 'sort', 'icon', 'uri', 'disable'])
->find();
}
/**
* Notes: 删除
* @param $ids
* @author 段誉(2021/4/12 16:39)
* @return Auth
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function delMenu($ids)
{
$lists = ShopAuth::where(['del' => 0])
->field(['id', 'pid', 'name', 'sort', 'icon', 'disable'])
->select();
$del_ids = $ids;
foreach ($ids as $id) {
$temp = self::getChildIds($lists, $id);
$del_ids = array_merge($del_ids, $temp);
}
ShopAuth::where('id', 'in', $del_ids)
->where(['del' => 0, 'system' => 0])
->update(['del' => 1]);
}
/**
* Notes: 设置状态
* @param $post
* @author 段誉(2021/4/12 16:39)
* @return Auth
*/
public static function setStatus($post)
{
$data = [
'disable' => $post['disable'],
'update_time' => time(),
];
return ShopAuth::where(['id' => $post['id'], 'system' => 0])
->update($data);
}
}

View File

@ -0,0 +1,170 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\admin\logic\shop;
use app\common\basics\Logic;
use app\common\model\shop\Shop;
use app\common\model\shop\ShopApply;
use app\common\model\shop\ShopCategory;
use Exception;
class CategoryLogic extends Logic
{
/**
* NOTE: 主营类目列表
* @author: 张无忌
* @param $get
* @return array|bool
*/
public static function lists($get)
{
try {
$where = [
['del', '=', 0]
];
if (!empty($get['name']) and $get['name'])
$where[] = ['name', 'like', '%'.$get['name'].'%'];
$model = new ShopCategory();
$lists = $model->field(true)
->where($where)
->order('sort', 'desc')
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
} catch (Exception $e) {
return ['error'=>$e->getMessage()];
}
}
/**
* NOTE: 主营类目详细
* @author: 张无忌
* @param $id
* @return array
*/
public static function detail($id)
{
$model = new ShopCategory();
return $model->field(true)->findOrEmpty((int)$id)->toArray();
}
/**
* NOTE: 获取主营类目
* @author: 张无忌
* @return array
*/
public static function getCategory()
{
try {
$model = new ShopCategory();
return $model->field(true)
->where('del', 0)
->order('id', 'desc')
->order('sort', 'desc')
->select()->toArray();
} catch (\Exception $e) {
return [];
}
}
/**
* NOTE: 新增主营类目
* @author: 张无忌
* @param $post
* @return bool
*/
public static function add($post)
{
try {
ShopCategory::create([
'name' => $post['name'],
'image' => $post['image'] ?? '',
'sort' => $post['sort'] ?? 0
]);
return true;
} catch (Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* NOTE: 编辑主营类目
* @author: 张无忌
* @param $post
* @return bool
*/
public static function edit($post)
{
try {
ShopCategory::update([
'name' => $post['name'],
'image' => $post['image'] ?? '',
'sort' => $post['sort'] ?? 0
], ['id'=>(int)$post['id']]);
return true;
} catch (Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* NOTE: 删除主营类目
* @author: 张无忌
* @param $id
* @return bool
*/
public static function del($id)
{
try {
$shopModel = new Shop();
$shopApplyModel = new ShopApply();
$shop = $shopModel->where(['cid'=>(int)$id, 'del'=>0])->findOrEmpty()->toArray();
$apply = $shopApplyModel->where(['cid'=>(int)$id, 'del'=>0])->findOrEmpty()->toArray();
if ($shop or $apply) {
static::$error = '类目已被使用,不允许删除';
return false;
}
ShopCategory::update([
'del' => 1,
'create_time' => time()
], ['id'=>(int)$id]);
return true;
} catch (Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
}

View File

@ -0,0 +1,348 @@
<?php
namespace app\admin\logic\shop;
use app\common\basics\Logic;
use app\common\enum\ShopEnum;
use app\common\model\shop\Shop;
use app\common\model\shop\ShopAdmin;
use app\common\server\UrlServer;
use Exception;
use think\facade\Db;
class StoreLogic extends Logic
{
/**
* NOTE: 商家列表
* @author: 张无忌
* @param $get
* @return array|bool
*/
public static function lists($get)
{
try {
$where = [
['del', '=', 0]
];
if (!empty($get['name']) and $get['name'])
$where[] = ['name', 'like', '%'.$get['name'].'%'];
if (!empty($get['type']) and is_numeric($get['type']))
$where[] = ['type', '=', $get['type']];
if (!empty($get['cid']) and is_numeric($get['cid']))
$where[] = ['cid', '=', $get['cid']];
if (isset($get['is_recommend']) && $get['is_recommend'] != '')
$where[] = ['is_recommend', '=', $get['is_recommend']];
if (isset($get['is_run']) && $get['is_run'] != '')
$where[] = ['is_run', '=', $get['is_run']];
if (isset($get['is_freeze']) and $get['is_freeze'] != '')
$where[] = ['is_freeze', '=', $get['is_freeze']];
if (!empty($get['expire_start_time']) and $get['expire_start_time'])
$where[] = ['expire_time', '>=', strtotime($get['expire_start_time'])];
if (!empty($get['expire_end_time']) and $get['expire_end_time'])
$where[] = ['expire_time', '<=', strtotime($get['expire_end_time'])];
$condition = 'del=0';
// 到期状态
if (isset($get['expire_status']) and $get['expire_status'] != '') {
if ($get['expire_status']) {
// 已到期
$where[] = ['expire_time', '<', time()];
$where[] = ['expire_time', '>', 0];
} else {
// 未到期
$condition = "expire_time=0 OR expire_time >". time();
}
}
$model = new Shop();
$lists = $model->field(true)
->where($where)
->whereRaw($condition)
->order('id', 'desc')
->order('weight', 'asc')
->with(['category', 'admin'])
->append(['expire_desc'])
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
foreach ($lists['data'] as &$item) {
$item['category'] = $item['category']['name'] ?? '未知';
$item['type'] = ShopEnum::getShopTypeDesc($item['type']);
$item['is_run'] = ShopEnum::getShopIsRunDesc($item['is_run']);
$item['is_freeze'] = ShopEnum::getShopFreezeDesc($item['is_freeze']);
$item['is_recommend'] = ShopEnum::getShopIsRecommendDesc($item['is_recommend']);
$item['account'] = $item['admin']['account'] ?? '';
}
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
} catch (Exception $e) {
return ['error'=>$e->getMessage()];
}
}
/**
* NOTE: 商家详细
* @author: 张无忌
* @param $id
* @return array
*/
public static function detail($id)
{
$model = new Shop();
$detail = $model->json(['other_qualifications'],true)->findOrEmpty($id)->toArray();
$detail['expire_time'] = $detail['expire_time'] == '无期限' ? 0 : $detail['expire_time'];
$detail['business_license'] = $detail['business_license'] ? UrlServer::getFileUrl($detail['business_license']) : '';
if (!empty($detail['other_qualifications'])) {
foreach ($detail['other_qualifications'] as &$val) {
$val = UrlServer::getFileUrl($val);
}
}
return $detail;
}
public static function getAccountInfo($id)
{
$detail = ShopAdmin::field('id,account')->where(['shop_id' => $id, 'root' => 1])->findOrEmpty()->toArray();
return $detail;
}
/**
* NOTE: 新增商家
* @author: 张无忌
* @param $post
* @return bool
*/
public static function add($post)
{
Db::startTrans();
try {
// 校验配送方式
self::checkDeliveryType($post);
// 创建商家
$shop = Shop::create([
'cid' => $post['cid'],
'type' => $post['type'],
'name' => $post['name'],
'nickname' => $post['nickname'],
'mobile' => $post['mobile'],
'logo' => $post['logo'] ?? '',
'background' => $post['background'] ?? '',
'license' => $post['license'] ?? '',
'keywords' => $post['keywords'] ?? '',
'intro' => $post['intro'] ?? '',
'weight' => $post['weight'] ?? 0,
'trade_service_fee' => $post['trade_service_fee'],
'is_run' => $post['is_run'],
'is_freeze' => $post['is_freeze'],
'is_product_audit' => $post['is_product_audit'],
'is_recommend' => $post['is_recommend'] ?? 0,
'expire_time' => !empty($post['expire_time']) ? strtotime($post['expire_time']) : 0,
'province_id' => $post['province_id'] ?? 0,
'city_id' => $post['city_id'] ?? 0,
'district_id' => $post['district_id'] ?? 0,
'address' => $post['address'] ?? '',
'longitude' => $post['longitude'] ?? '',
'latitude' => $post['latitude'] ?? '',
'delivery_type' => $post['delivery_type'] ?? [1]
]);
// 创建账号
// 新增商家登录账号
$time = time();
$salt = substr(md5($time . $post['name']), 0, 4);//随机4位密码盐
ShopAdmin::create([
'root' => 1,
'shop_id' => $shop->id,
'name' => '超级管理员',
'account' => $post['account'],
'password' => generatePassword($post['password'], $salt),
'salt' => $salt,
'role_id' => 0,
'create_time' => $time,
'update_time' => $time,
'disable' => 0,
'del' => 0
]);
Db::commit();
return true;
} catch (Exception $e) {
Db::rollback();
static::$error = $e->getMessage();
return false;
}
}
/**
* NOTE: 编辑商家
* @author: 张无忌
* @param $post
* @return bool
*/
public static function edit($post)
{
try {
// 校验配送方式
self::checkDeliveryType($post);
Shop::update([
'cid' => $post['cid'],
'type' => $post['type'],
'name' => $post['name'],
'nickname' => $post['nickname'],
'mobile' => $post['mobile'],
'logo' => $post['logo'] ?? '',
'keywords' => $post['keywords'] ?? '',
'intro' => $post['intro'] ?? '',
'trade_service_fee' => $post['trade_service_fee'],
'is_run' => $post['is_run'],
'is_freeze' => $post['is_freeze'],
'is_product_audit' => $post['is_product_audit'],
'expire_time' => !empty($post['expire_time']) ? strtotime($post['expire_time']) : 0,
'province_id' => $post['province_id'] ?? 0,
'city_id' => $post['city_id'] ?? 0,
'district_id' => $post['district_id'] ?? 0,
'address' => $post['address'] ?? '',
'longitude' => $post['longitude'] ?? '',
'latitude' => $post['latitude'] ?? '',
'delivery_type' => $post['delivery_type'] ?? [1],
'business_license' => empty($post['business_license']) ? '' : UrlServer::setFileUrl($post['business_license']),
'other_qualifications' => isset($post['other_qualifications']) ? json_encode($post['other_qualifications'], JSON_UNESCAPED_UNICODE) : '',
], ['id'=>$post['id']]);
return true;
} catch (Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* NOTE: 设置商家
* @author: 张无忌
* @param $post
* @return bool
*/
public static function set($post)
{
try {
Shop::update([
'is_distribution' => $post['is_distribution'] ?? 0,
'is_recommend' => $post['is_recommend'] ?? 0,
'is_pay' => $post['is_pay'] ?? 1, //是否开启支付功能,默认开启
'weight' => $post['weight']
], ['id'=>$post['id']]);
return true;
} catch (Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* NOTE: 更新账号密码
* @author: 张无忌
* @param $post
* @return bool
*/
public static function account($post)
{
Db::startTrans();
try {
if(!isset($post['account']) || empty($post['account'])) {
throw new \think\Exception('账户不能为空');
}
$shopAdmin = ShopAdmin::where([
['account', '=', trim($post['account'])],
['shop_id', '<>', $post['id']]
])->findOrEmpty();
if(!$shopAdmin->isEmpty()) {
throw new \think\Exception('账户已存在,请更换其他名称重试');
}
$shopAdmin = ShopAdmin::where(['shop_id' => $post['id'], 'root' => 1])->findOrEmpty();
$shopAdminUpdateData = [
'account' => $post['account'],
'update_time' => time()
];
if (!empty($post['password'])) {
$shopAdminUpdateData['password'] = generatePassword($post['password'], $shopAdmin->salt);
}
ShopAdmin::where(['shop_id' => $post['id'], 'root' => 1])->update($shopAdminUpdateData);
Db::commit();
return true;
} catch (Exception $e) {
Db::rollback();
static::$error = $e->getMessage();
return false;
}
}
/**
* @notes 批量更新商家营业状态或冻结状态
* @param $ids
* @param $field
* @param $value
* @return Shop|false
* @author 段誉
* @date 2022/3/17 10:42
*/
public static function batchOperation($ids, $field, $value)
{
try {
$result = Shop::whereIn('id', $ids)->update([
$field => $value,
'update_time' => time()
]);
return $result;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 校验配送方式
* @param $post
* @return bool
* @throws \Exception
* @author 段誉
* @date 2022/11/1 11:30
*/
public static function checkDeliveryType($post)
{
// 校验配送方式
if (empty($post['delivery_type'])) {
throw new \Exception('至少选择一种配送方式');
}
// 线下自提时,商家地址必填
if (in_array(ShopEnum::DELIVERY_SELF, $post['delivery_type'])) {
if (empty($post['province_id']) || empty($post['city_id']) || empty($post['district_id']) || empty($post['address'])) {
throw new \Exception('线下自提需完善商家地址');
}
}
return true;
}
}

View File

@ -0,0 +1,75 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\admin\logic\shop;
use app\common\basics\Logic;
use app\common\enum\TreatyEnum;
use app\common\model\Treaty;
class TreatyLogic extends Logic
{
/**
* NOTE: 设置入驻协议
* @author: 张无忌
* @param $post
* @return bool
*/
public static function set($post)
{
try {
$treaty = Treaty::where(['type'=>TreatyEnum::SHOP_ENTER_TYPE])->findOrEmpty();
$time = time();
if($treaty->isEmpty()) { // 新增
$addData = [
'name' => '入驻协议',
'content' => $post['content'] ?? '',
'type' => TreatyEnum::SHOP_ENTER_TYPE,
'create_time' => $time,
'update_time' => $time
];
Treaty::create($addData);
}else{ // 更新
Treaty::update([
'name' => '入驻协议',
'content' => $post['content'] ?? '',
'update_time' => $time
], ['type'=>TreatyEnum::SHOP_ENTER_TYPE]);
}
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
/**
* NOTE: 获取协议详细
* @author: 张无忌
* @return array
*/
public static function detail()
{
$model = new Treaty();
return $model->field(true)
->where(['type'=>TreatyEnum::SHOP_ENTER_TYPE])
->findOrEmpty()->toArray();
}
}