442 lines
18 KiB
PHP
442 lines
18 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
|
|
namespace addon\saas\shop\controller;
|
|
|
|
use addon\saas\model\ManageUser as ManageModel;
|
|
use addon\weapp\model\Config as WeappConfigModel;
|
|
use app\model\system\Address as AddressModel;
|
|
use app\model\system\SiteGroup;
|
|
use app\model\system\User;
|
|
use think\facade\Db;
|
|
use addon\saas\model\AgentSelect;
|
|
|
|
class Site extends SaasBase
|
|
{
|
|
/***
|
|
* 商家列表
|
|
* @return array|void
|
|
*/
|
|
public function lists()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$search_text = input('search_text', '');
|
|
$status = input('status', '');
|
|
$group_id = input('group_id', '');
|
|
$start_time = input("start_time", '');
|
|
$end_time = input("end_time", '');
|
|
$isBingSite = input("isBingSite", '');
|
|
$shop_id = input("shop_id", '');
|
|
$mini_text = input("mini_text", 'mini_text');
|
|
if ($mini_text) {
|
|
$w = [
|
|
['value', 'like', '%' . $mini_text . '%']
|
|
];
|
|
$site_ids = Db::name('uni_account')
|
|
->where($w)
|
|
->column('site_id');
|
|
if (empty($site_ids)) {
|
|
$w = [
|
|
['config_key', 'in', ['WEAPP_CONFIG', 'ALI_PAY_CONFIG']],
|
|
['value', 'like', '%' . $mini_text . '%']
|
|
];
|
|
$site_ids = Db::name('config')
|
|
->where($w)
|
|
->column('site_id');
|
|
}
|
|
if ($site_ids) {
|
|
$condition[] = ['site_id', 'in', $site_ids];
|
|
}
|
|
}
|
|
if ($shop_id != '') {
|
|
$condition[] = ['shop_id', '=', $shop_id];
|
|
}
|
|
if ($isBingSite) {
|
|
$_c = $isBingSite == 'NO' ? '=' : '>';
|
|
$condition[] = ['bing_site_id', $_c, 0];
|
|
}
|
|
$condition[] = ['agent_id', '=', $this->site_id];
|
|
if ($search_text) {
|
|
$condition[] = ['site_name|username|contacts_name|contacts_mobile|remarks', 'like', '%' . $search_text . '%'];
|
|
}
|
|
//商家状态
|
|
if ($status != '') {
|
|
$condition[] = ['status', '=', $status];
|
|
}
|
|
//套餐分组
|
|
if ($group_id != '') {
|
|
$condition[] = ['group_id', '=', $status];
|
|
}
|
|
if (!empty($start_time) && empty($end_time)) {
|
|
$condition[] = ['expire_time', '>=', strtotime($start_time)];
|
|
} elseif (empty($start_time) && !empty($end_time)) {
|
|
$condition[] = ["expire_time", "<=", strtotime($end_time)];
|
|
} elseif (!empty($start_time) && !empty($end_time)) {
|
|
$condition[] = ["expire_time", ">=", strtotime($start_time)];
|
|
$condition[] = ["expire_time", "<=", strtotime($end_time)];
|
|
}
|
|
$order = 'site_id desc';
|
|
$field = '*';
|
|
$shop_model = new \app\model\system\Site();
|
|
$shopInfo = $shop_model->getSitePageList($condition, $page, $page_size, $order, $field);
|
|
$site_ids = array_column($shopInfo['data']['list'], 'site_id');
|
|
$Counts = Db::name('member')->where('site_id', 'in', $site_ids)->group('site_id')->column('count(site_id) as count', 'site_id');
|
|
$order = Db::name('order')->where('site_id', 'in', $site_ids)->group('site_id')->column('count(order_id) as count', 'site_id');
|
|
//微信小程序配置
|
|
$weapp_config_model = new WeappConfigModel();
|
|
$config = new \addon\aliapp\model\Config();
|
|
foreach ($shopInfo['data']['list'] as $key => $val) {
|
|
$weapp_config = $weapp_config_model->getWeappConfig($val['site_id'])['data']['value'];
|
|
$config_info = $config->getAppConfig($this->site_id)['data']['value'];
|
|
$shopInfo['data']['list'][$key]['app_name'] = '';
|
|
if (isset($config_info['weapp_name'])) {
|
|
$shopInfo['data']['list'][$key]['app_name'] .= $config_info['weapp_name'];
|
|
}
|
|
if (isset($weapp_config['app_name'])) {
|
|
$shopInfo['data']['list'][$key]['app_name'] .= $weapp_config['app_name'];
|
|
}
|
|
if (isset($Counts[$val['site_id']])) {
|
|
$shopInfo['data']['list'][$key]['member_count'] = $Counts[$val['site_id']];
|
|
} else {
|
|
$shopInfo['data']['list'][$key]['member_count'] = 0;
|
|
}
|
|
if (isset($order[$val['site_id']])) {
|
|
$shopInfo['data']['list'][$key]['order_count'] = $order[$val['site_id']];
|
|
} else {
|
|
$shopInfo['data']['list'][$key]['order_count'] = 0;
|
|
}
|
|
}
|
|
return $shopInfo;
|
|
}
|
|
$this->forthMenu();
|
|
//应用套餐
|
|
$shop_group_model = new SiteGroup();
|
|
$site_group_list = $shop_group_model->getSiteGroupList([['site_id', '=', $this->site_id]], 'group_id,group_name,fee,remark', 'fee asc');
|
|
$this->assign('site_group_list', $site_group_list['data']);
|
|
$this->assign('info', $this->AgentInfo);
|
|
return $this->fetch('site/lists');
|
|
}
|
|
|
|
|
|
/***
|
|
* 添加站点
|
|
*/
|
|
public function addSite()
|
|
{
|
|
$site_group_model = new SiteGroup();
|
|
if (request()->isAjax()) {
|
|
$group_id = input('group_id');
|
|
$expire_time = input('expire_time', 0);
|
|
$is_operated = input('is_operated', 0);
|
|
//店铺信息
|
|
$shop_data = [
|
|
'site_name' => input('site_name', ''), //店铺名称
|
|
'contacts_name' => input('contacts_name', ''), //联系人
|
|
'contacts_mobile' => input('contacts_mobile', ''), //联系电话
|
|
'fee_commission' => input('fee_commission', 0), //独立佣金
|
|
'agent_id' => $this->site_id, //所属代理
|
|
'group_id' => $group_id,
|
|
'expire_time' => $expire_time,
|
|
'is_try' => $expire_time ? 1 : 0, //是否体验用户
|
|
'is_operated' => $is_operated, //是代营运
|
|
'province_id' => input('province_id', 0),//所在省份
|
|
'city_id' => input('city_id', 0),//所在城市
|
|
'district_id' => input('district_id', 0),//所在地区
|
|
'address' => input('address'), //具体地址
|
|
'full_address' => input('full_address'), //具体地址
|
|
];
|
|
$user_info = [
|
|
'username' => input('username', ''),
|
|
'password' => data_md5(input('password', '')),
|
|
];
|
|
$site_model = new \app\model\system\Site();
|
|
$result = $site_model->addSite($shop_data, $user_info);
|
|
if ($result['code'] == 0) {
|
|
$log = array(
|
|
"uid" => $this->uid,
|
|
"username" => $this->user_info['username'],
|
|
"site_id" => $this->site_id,
|
|
"url" => '',
|
|
"ip" => request()->ip(),
|
|
"data" => json_encode($shop_data),
|
|
"action_name" => '添加店铺',
|
|
"create_time" => time(),
|
|
);
|
|
model("user_log")->add($log);
|
|
return success('0', '注册成功');
|
|
} else {
|
|
return $result;
|
|
}
|
|
}
|
|
$def = [];
|
|
if ($this->site_id != 1) {
|
|
$def = $site_group_model->getSiteGroupList([['group_id', '=', 1]], 'group_id,group_name,fee,remark')['data'];
|
|
}
|
|
//查询省级数据列表
|
|
$address_model = new AddressModel();
|
|
$list = $address_model->getAreaList([["pid", "=", 0], ["level", "=", 1]]);
|
|
//应用套餐
|
|
$site_group_list = $site_group_model->getSiteGroupList([['site_id', '=', $this->site_id]], 'group_id,group_name,fee,remark', 'fee asc');
|
|
$this->assign("province_list", $list["data"]);
|
|
$this->assign("agent_type", $this->AgentInfo['agent_type']);
|
|
$this->assign("group_info", array_merge($def, $site_group_list['data']));
|
|
$this->assign("reg_info", []);
|
|
$this->assign("agInfo", $this->AgentInfo);
|
|
return $this->fetch('site/addsite');
|
|
}
|
|
|
|
/***
|
|
* 编辑站点
|
|
*/
|
|
public function editSite()
|
|
{
|
|
$site_id = input('site_id');
|
|
$site_group_model = new SiteGroup();
|
|
$shop_model = new \app\model\system\Site();
|
|
$shop_info = $shop_model->getSiteInfo(['site_id' => $site_id], '*')['data'];
|
|
if (request()->isAjax()) {
|
|
$where = [['site_id', '=', $site_id]];
|
|
$expire_time = input('expire_time', 0);
|
|
$data = [
|
|
'group_id' => input('group_id'),
|
|
'group_name' => input('group_name'),
|
|
'contacts_name' => input('contacts_name'),
|
|
'contacts_mobile' => input('contacts_mobile'),
|
|
'fee_commission' => input('fee_commission'),
|
|
'is_operated' => input('is_operated', 0),
|
|
'is_try' => input('is_try'),
|
|
'province_id' => input('province_id', 0),//所在省份
|
|
'city_id' => input('city_id', 0),//所在城市
|
|
'district_id' => input('district_id', 0),//所在地区
|
|
'address' => input('address'), //具体地址
|
|
'full_address' => input('full_address'), //具体地址
|
|
];
|
|
if ($expire_time) {
|
|
$data['is_try'] = 1;
|
|
if ($this->AgentInfo['agent_number'] >= $expire_time) {
|
|
if ($shop_info['expire_time'] < time()) {
|
|
$data['expire_time'] = strtotime("+{$expire_time} month");
|
|
} else {
|
|
$data['expire_time'] = strtotime("+{$expire_time} month") + $shop_info['expire_time'] - time();
|
|
}
|
|
model('website')->setDec(['site_id' => $this->site_id], 'agent_number', $expire_time);
|
|
$log = array(
|
|
"uid" => $this->uid,
|
|
"username" => $this->user_info['username'],
|
|
"site_id" => $this->site_id,
|
|
"url" => '',
|
|
"ip" => request()->ip(),
|
|
"data" => json_encode($data),
|
|
"action_name" => '店铺调时',
|
|
"create_time" => time(),
|
|
);
|
|
model("user_log")->add($log);
|
|
} else {
|
|
return error(-1, '余额时长不足请充值');
|
|
}
|
|
} else if ($expire_time == 0) {
|
|
$data['expire_time'] = 0;
|
|
}
|
|
$res = $shop_model->editSite($data, $where);
|
|
return $res;
|
|
}
|
|
$condition = [];
|
|
$condition[] = ['site_id', '=', $this->site_id];//获取分组
|
|
$info = $site_group_model->getSiteGroupList($condition, '*', 'fee asc');
|
|
//查询省级数据列表
|
|
$address_model = new AddressModel();
|
|
$list = $address_model->getAreaList([["pid", "=", 0], ["level", "=", 1]]);
|
|
$this->assign("province_list", $list["data"]);
|
|
$this->assign("agent_type", $this->AgentInfo['agent_type']);
|
|
$this->assign("group_info", $info['data']);
|
|
$this->assign("userinfo", $shop_info);
|
|
$this->assign("agInfo", $this->AgentInfo);
|
|
return $this->fetch('site/editSite');
|
|
}
|
|
|
|
/***
|
|
* 关闭店铺
|
|
* @return array|void
|
|
*/
|
|
public function closeshop()
|
|
{
|
|
$unisid = input('unisid', 0);
|
|
if (request()->isAjax()) {
|
|
model('site')->update([
|
|
'status' => 0,
|
|
'shop_status' => 0
|
|
], ['site_id' => $unisid, 'agent_id' => $this->site_id]);
|
|
$data['message'] = '店铺关闭成功';
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
/***
|
|
* 打开店铺
|
|
* @return array|void
|
|
*/
|
|
public function openshop()
|
|
{
|
|
$unisid = input('unisid', 0);
|
|
if (request()->isAjax()) {
|
|
model('site')->update([
|
|
'status' => 1,
|
|
'shop_status' => 1
|
|
], ['site_id' => $unisid, 'agent_id' => $this->site_id]);
|
|
$data['message'] = '店铺打开成功';
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
/***
|
|
* 搜索店铺
|
|
* @return array
|
|
*/
|
|
public function searchShop()
|
|
{
|
|
$search_text = input('search_text', '');
|
|
$site_id = input('site_id', '');
|
|
$condition[] = ['agent_id', '=', $this->site_id];
|
|
if ($site_id) {
|
|
$condition[] = ['site_id', '=', $site_id];
|
|
} else if ($search_text) {
|
|
$condition[] = ['site_id|site_name|contacts_name|contacts_mobile', 'like', '%' . $search_text . '%'];
|
|
}
|
|
$field = '*';
|
|
$shop_model = new \app\model\system\Site();
|
|
$shopInfo = $shop_model->getSiteInfo($condition, $field);
|
|
return $shopInfo;
|
|
}
|
|
|
|
|
|
/***
|
|
* 修改密码
|
|
* @param $site_id
|
|
*/
|
|
public function repass($site_id)
|
|
{
|
|
if (request()->isAjax() && $site_id) {
|
|
$password = trim(input('password', '123456'));
|
|
$shop_model = new User();
|
|
return $shop_model->modifyAdminUserPassword([['site_id', '=', $site_id], ['app_module', '=', 'shop']], $password);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 备注
|
|
* @return int|void
|
|
*/
|
|
public function remarks($site_id)
|
|
{
|
|
if (request()->isAjax()&&$site_id) {
|
|
$remarks = input('remarks', '');
|
|
$shop_model = new \app\model\system\Site();
|
|
return $shop_model->editSite(['remarks' => $remarks], ['site_id' => $site_id]);
|
|
}
|
|
}
|
|
|
|
/***
|
|
* 修改客服
|
|
*/
|
|
public function change()
|
|
{
|
|
$parent_id = input('parent_id', 0);
|
|
$site_id = input('site_id');
|
|
$model = new \addon\saas\model\ManageUser();
|
|
if (request()->isAjax()) {
|
|
if ($this->site_id == 1) {
|
|
$condition = [];
|
|
} else {
|
|
$condition[] = ['f.site_id', '=', $this->site_id];
|
|
}
|
|
$real_name = input('real_name', '');
|
|
if ($real_name) {
|
|
$condition[] = ['f.real_name', 'like', '%' . $real_name . '%'];
|
|
}
|
|
$mobile = input('mobile', '');
|
|
if ($mobile) {
|
|
$condition[] = ['m.mobile', 'like', '%' . $mobile . '%'];
|
|
}
|
|
$start_time = input('start_time', '');
|
|
$end_time = input('end_time', '');
|
|
if ($start_time && $end_time) {
|
|
$condition[] = ['f.create_time', 'between', [date_to_time($start_time), date_to_time($end_time)]];
|
|
} elseif (!$start_time && $end_time) {
|
|
$condition[] = ['f.create_time', '<=', date_to_time($end_time)];
|
|
|
|
} elseif ($start_time && !$end_time) {
|
|
$condition[] = ['f.create_time', '>=', date_to_time($start_time)];
|
|
}
|
|
$status = input('status', '');
|
|
if (!empty($status)) {
|
|
$condition[] = ['f.status', '=', $status];
|
|
}
|
|
if ($parent_id) {
|
|
$condition[] = ['f.id', '<>', $parent_id];
|
|
}
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$field = 'f.id,f.level_name,f.real_name,f.status,f.mobile,pf.real_name as parent_name';
|
|
$list = $model->getManagePageList($condition, $page, $page_size, 'f.create_time desc', $field);
|
|
return $list;
|
|
}
|
|
$parent_info = $model->getManageInfo(['f.id' => $parent_id])['data'];
|
|
$this->assign("parent_info", $parent_info);
|
|
$this->assign("parent_id", $parent_id);
|
|
$this->assign("site_id", $site_id);
|
|
return $this->fetch('site/change');
|
|
}
|
|
/**
|
|
* 确认变更
|
|
*/
|
|
public function confirmChange()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$old_id = input('id', '');
|
|
$parent = input('parent', '');
|
|
$type = input('type', '');
|
|
$site_id = input('site_id', 0);
|
|
$manage_name = input('manage_name', '');
|
|
$shop_model = new \app\model\system\Site();
|
|
$condition = [
|
|
'agent_id' => $this->site_id,
|
|
'site_id' => $site_id,
|
|
];
|
|
if ($type == 1) {
|
|
$updata = [
|
|
'manage_id' => $parent,
|
|
'manage_name' => $manage_name,
|
|
];
|
|
if ($parent) {
|
|
Db::name('manage_user')->where(['id' => $parent, 'site_id' => $site_id])->inc('one_child_num', 1);
|
|
}
|
|
//修改变更后的商团队人数
|
|
if ($old_id) {
|
|
Db::name('manage_user')->where(['id' => $old_id, 'site_id' => $site_id])->dec('one_child_num', 1);
|
|
}
|
|
} else {
|
|
$updata = [
|
|
'manage_id' => 0,
|
|
'manage_name' => '',
|
|
];
|
|
Db::name('manage_user')->where(['id' => $parent, 'site_id' => $site_id])->dec('one_child_num', 1);
|
|
}
|
|
$res = $shop_model->editSite($updata, $condition);
|
|
return $res;
|
|
}
|
|
}
|
|
}
|