209 lines
6.6 KiB
PHP
209 lines
6.6 KiB
PHP
<?php
|
|
/**
|
|
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 成都SAAS云科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.gobuysaas.com
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace app\model\web;
|
|
|
|
use app\model\BaseModel;
|
|
use app\model\system\Config as ConfigModel;
|
|
use think\facade\Cache;
|
|
|
|
/**
|
|
* 系统站点信息管理
|
|
* @author Administrator
|
|
*
|
|
*/
|
|
class WebSite extends BaseModel
|
|
{
|
|
/**
|
|
* 获取系统银行账户
|
|
*/
|
|
public function getSystemBankAccount()
|
|
{
|
|
$config = new ConfigModel();
|
|
$res = $config->getConfig([['site_id', '=', 1], ['app_module', '=', 'shop'], ['config_key', '=', 'SYSTEM_BANK_ACCOUNT']]);
|
|
if (empty($res['data']['value'])) {
|
|
$res['data']['value'] = [
|
|
'bank_account_name' => '',
|
|
'bank_account_no' => '',
|
|
'bank_name' => '',
|
|
'bank_address' => ''
|
|
];
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 设置系统银行账户
|
|
* @param unknown $data
|
|
* @return Ambigous <multitype:unknown , multitype:number unknown >
|
|
*/
|
|
public function setSystemBankAccount($data)
|
|
{
|
|
$config = new ConfigModel();
|
|
$res = $config->setConfig($data, '平台银行账户', 1, [['site_id', '=', 1], ['app_module', '=', 'shop'], ['config_key', '=', 'SYSTEM_BANK_ACCOUNT']]);
|
|
return $res;
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取发票设置
|
|
*/
|
|
public function getInvoiceConfig()
|
|
{
|
|
$config = new ConfigModel();
|
|
$res = $config->getConfig([['site_id', '=', 1], ['app_module', '=', 'shop'], ['config_key', '=', 'SYSTEM_INVOICE_CONFIG']]);
|
|
if (empty($res['data']['value'])) {
|
|
$res['data']['value'] = [
|
|
'status' => 0,
|
|
'rate' => 0,
|
|
'content' => '',
|
|
'money' => 0
|
|
];
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 设置发票设置
|
|
* @param unknown $data
|
|
* @return Ambigous <multitype:unknown , multitype:number unknown >
|
|
*/
|
|
public function setInvoiceConfig($data)
|
|
{
|
|
$config = new ConfigModel();
|
|
$res = $config->setConfig($data, '发票设置', 1, [['site_id', '=', 1], ['app_module', '=', 'shop'], ['config_key', '=', 'SYSTEM_INVOICE_CONFIG']]);
|
|
return $res;
|
|
}
|
|
|
|
|
|
/***
|
|
* 获取站点
|
|
* @param $condition
|
|
* @param string $field
|
|
* @param int $page
|
|
* @param int $list_rows
|
|
* @param string $order
|
|
* @return array
|
|
*/
|
|
public function getWebSiteList($condition, $page = 1, $list_rows = PAGE_LIST_ROWS, $field = '*', $order = '')
|
|
{
|
|
$res = model('website')->pageList($condition, $field, $order, $page, $list_rows);
|
|
return $this->success($res);
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取站点信息
|
|
* @param $condition
|
|
* @param string $field
|
|
* @param bool $cache_use
|
|
* @return array
|
|
*/
|
|
public function getWebSite($condition, $field = '*', $cache_use = true)
|
|
{
|
|
$data = json_encode([$condition, $field]);
|
|
$cache = Cache::get("weisite_getWebSite_" . $data);
|
|
if ($cache_use && !empty($cache)) {
|
|
return $this->success($cache);
|
|
}
|
|
|
|
$res = model('website')->getInfo($condition, $field);
|
|
if (empty($res)) {
|
|
$check_condition = array_column($condition, 2, 0);
|
|
//初始化站点信息
|
|
if (isset($check_condition['site_id']) && $check_condition['site_id'] == 0) {
|
|
model('website')->add(['site_id' => $check_condition['site_id']]);
|
|
$res = model('website')->getInfo($condition, $field);
|
|
}
|
|
}
|
|
Cache::tag("website")->set("weisite_getWebSite_" . $data, $res);
|
|
return $this->success($res);
|
|
}
|
|
|
|
/**
|
|
* 设置站点信息
|
|
* @param $data
|
|
* @param $condition
|
|
* @return array
|
|
*/
|
|
public function setWebSite($data, $condition)
|
|
{
|
|
$data['modify_time'] = time();
|
|
$res = model('website')->update($data, $condition);
|
|
Cache::tag("website")->clear();
|
|
return $this->success($res);
|
|
}
|
|
|
|
/**
|
|
* 添加分站
|
|
* @param $data
|
|
* @param $user_data
|
|
* @return array
|
|
*/
|
|
public function addWebsite($data)
|
|
{
|
|
model('website')->startTrans();
|
|
try {
|
|
$user_count = model("website")->getCount([['site_id', '=', $data['site_id']]]);
|
|
if ($user_count > 0) {
|
|
model("website")->rollback();
|
|
return $this->error('', '会员已存在');
|
|
}
|
|
$data['create_time'] = time();
|
|
$website_id = model('website')->add($data);
|
|
model('website')->commit();
|
|
return $this->success($website_id);
|
|
} catch (\Exception $e) {
|
|
model('website')->rollback();
|
|
return $this->error('', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除分站
|
|
* @param $site_id
|
|
* @return array
|
|
*/
|
|
public function deleteWebsite($site_id)
|
|
{
|
|
$shop_count = model('shop')->getCount([['website_id', '=', $site_id]]);
|
|
if ($shop_count > 0) {
|
|
return $this->error('', '该分站下已有商家,不能删除');
|
|
}
|
|
$shop_apply_count = model('shop_apply')->getCount([['website_id', '=', $site_id]]);
|
|
if ($shop_apply_count > 0) {
|
|
return $this->error('', '该分站下已有商家,不能删除');
|
|
}
|
|
model('website')->startTrans();
|
|
try {
|
|
//站点信息
|
|
$website_info = model('website')->getInfo([['site_id', '=', $site_id]], 'username');
|
|
$res = model('website')->delete([['site_id', '=', $site_id]]);
|
|
if (!empty($website_info)) {
|
|
//获取用户信息
|
|
$user_info = model('user')->getInfo(
|
|
[['username', '=', $website_info['username']], ['app_module', '=', 'city']],
|
|
'group_id'
|
|
);
|
|
if (!empty($user_info)) {
|
|
//删除用户
|
|
model('user')->delete([['username', '=', $website_info['username']], ['app_module', '=', 'city']]);
|
|
//删除用户组
|
|
model('group')->delete([['group_id', '=', $user_info['group_id']]]);
|
|
}
|
|
}
|
|
model('website')->commit();
|
|
return $this->success($res);
|
|
} catch (\Exception $e) {
|
|
model('website')->rollback();
|
|
return $this->error('', $e->getMessage());
|
|
}
|
|
}
|
|
} |