272 lines
8.8 KiB
PHP
272 lines
8.8 KiB
PHP
<?php
|
|
/**
|
|
* ThinkShop商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 成都云之牛科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.cdcloudshop.com
|
|
|
|
* =========================================================
|
|
*/
|
|
namespace app\model\web;
|
|
use app\model\BaseModel;
|
|
use app\model\system\Config as ConfigModel;
|
|
use think\facade\Cache;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 系统站点信息管理
|
|
* @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,$rate=[])
|
|
{
|
|
model('website')->startTrans();
|
|
try {
|
|
if ($data['site_area_id'] == 0) {
|
|
return $this->error('', '请选择城市地址');
|
|
}
|
|
// $user_count = model("website")->getCount([['member_id', '=', $data['member_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());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Common: 获取全部合伙人信息列表
|
|
* Author: wu-hui
|
|
* Time: 2023/01/29 11:39
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function newGetWebsiteList(){
|
|
// 参数获取
|
|
$page = input('page',1);
|
|
$pageSize = input('page_size',PAGE_LIST_ROWS);
|
|
$search_text = input('search_text','');
|
|
// 列表获取
|
|
$field = [
|
|
'a.id',
|
|
'a.web_contacts',
|
|
'a.web_phone',
|
|
'a.role_ids',
|
|
'a.alipay_account',
|
|
'sum(al.rate) as rate',
|
|
'al.level_id'
|
|
];
|
|
$result = Db::name('website')
|
|
->alias('a')
|
|
->field($field)
|
|
->join('agent_level al',"find_in_set(al.level_id,a.role_ids)",'left')
|
|
->when(!empty($search_text),function($query) use ($search_text){
|
|
$query->where('web_contacts','like',"%{$search_text}%");
|
|
})
|
|
->group('a.id')
|
|
->paginate(['list_rows' => $pageSize,'page' => $page]);
|
|
if($result) $result = $result->toArray();
|
|
|
|
$list = [
|
|
'count' => $result['total'],
|
|
'list' => $result['data'],
|
|
'page_count' => $result['last_page'],
|
|
];
|
|
|
|
return $this->success($list);
|
|
}
|
|
/**
|
|
* Common: 删除合伙人
|
|
* Author: wu-hui
|
|
* Time: 2023/01/29 16:35
|
|
* @param $id
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function delWebsiteinfo($id){
|
|
// 判断:如果存在分账关系 则不允许删除
|
|
$isHas = (int)Db::name('site_website')->where('website_id',$id)->count();
|
|
if($isHas > 0) return $this->error('','存在店铺绑定关系,请先解除绑定关系后删除!');
|
|
|
|
$res = model('website')->delete(['id' => $id]);
|
|
return $this->success($res);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |