565 lines
22 KiB
PHP
565 lines
22 KiB
PHP
<?php
|
||
|
||
namespace addon\saasagent\shop\controller;
|
||
|
||
use extend\Time;
|
||
use think\facade\Cache;
|
||
use app\model\system\Site;
|
||
use app\model\system\User;
|
||
use app\model\system\SiteGroup;
|
||
use app\model\system\Address as AddressModel;
|
||
use app\model\web\WebSite as WebsiteModel;
|
||
use addon\saasagent\model\OrderCreate;
|
||
use addon\saasagent\model\CloudOrder;
|
||
use think\facade\Db;
|
||
|
||
class Saas extends SaasBsae
|
||
{
|
||
protected $replace = []; //视图输出字符串内容替换相当于配置文件中的'view_replace_str'
|
||
protected $openPlatform;
|
||
protected $weapp_model;
|
||
protected $config_info;
|
||
|
||
public function __construct()
|
||
{
|
||
parent::__construct();
|
||
$this->replace = [
|
||
'WEAPP_CSS' => __ROOT__ . '/addon/weapp/admin/view/public/css',
|
||
'WEAPP_JS' => __ROOT__ . '/addon/weapp/admin/view/public/js',
|
||
'WEAPP_IMG' => __ROOT__ . '/addon/weapp/admin/view/public/img',
|
||
'WEAPP_SVG' => __ROOT__ . '/addon/weapp/admin/view/public/svg',
|
||
];
|
||
}
|
||
|
||
/**
|
||
* 概要
|
||
* @return mixed
|
||
*/
|
||
public function index()
|
||
{
|
||
$condition = [
|
||
['agent_id', '=', $this->site_id]
|
||
];
|
||
$info = model('site')->getList($condition, 'expire_time,is_try');
|
||
$total = [
|
||
'expire_count' => 0, //到期
|
||
'effective_count' => 0, //有效时间
|
||
'experience_count' => 0,//体验
|
||
];
|
||
foreach ($info as $item) {
|
||
if ($item['is_try'] == 1) {
|
||
$total['experience_count'] += 1;
|
||
}
|
||
if ($item['expire_time'] < time()) {
|
||
$total['expire_count'] += 1;
|
||
} else {
|
||
$total['effective_count'] += 1;
|
||
}
|
||
}
|
||
$website_model = new WebsiteModel();
|
||
$agent_info = $website_model->getWebSite(['site_id' => $this->site_id, 'is_agent' => 1], 'agent_number,agent_arrears', false)['data'];
|
||
$pay_total = model('pay_shop')->getCount(['ag_site_id'=>$this->site_id]);
|
||
$this->assign('pay_total', $pay_total);
|
||
$this->assign('total', count($info));
|
||
$this->assign('tInfo', $total);
|
||
$this->assign('agentInfo', $agent_info);
|
||
return $this->fetch('saas/index');
|
||
}
|
||
|
||
/**
|
||
* 商家列表
|
||
* @return array|mixed
|
||
*/
|
||
public function list()
|
||
{
|
||
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", '');
|
||
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', '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 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');
|
||
foreach ($shopInfo['data']['list'] as $key => $val) {
|
||
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;
|
||
}
|
||
//应用套餐
|
||
$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->agent_info);
|
||
return $this->fetch('saas/list');
|
||
}
|
||
|
||
/***
|
||
* 云订单
|
||
* @return mixed
|
||
*/
|
||
public function cloudorder()
|
||
{
|
||
if (request()->isAjax()) {
|
||
$cloud = new CloudOrder();
|
||
$page = input('page', 1);
|
||
$page_size = input('page_size', PAGE_LIST_ROWS);
|
||
$search_text = input('search_text', '');
|
||
$condition[] = ['a.ag_site_id', '=', $this->site_id];
|
||
//下单时间
|
||
$start_time = input('start_time', '');
|
||
$end_time = input('end_time', '');
|
||
if ($start_time && $end_time) {
|
||
$condition[] = ['a.create_time', 'between', [date_to_time($start_time), date_to_time($end_time)]];
|
||
} elseif (!$start_time && $end_time) {
|
||
$condition[] = ['a.create_time', '<=', date_to_time($end_time)];
|
||
} elseif ($start_time && !$end_time) {
|
||
$condition[] = ['a.create_time', '>=', date_to_time($start_time)];
|
||
}
|
||
if ($search_text) {
|
||
$condition[] = ['a.third_order_id|a.goods_name|a.cloud_account', 'like', '%' . $search_text . '%'];
|
||
}
|
||
$res = $cloud->getPageList($condition, $page, $page_size);
|
||
return $res;
|
||
}
|
||
$this->forthMenu();
|
||
return $this->fetch('saas/order');
|
||
}
|
||
|
||
public function orderInfo()
|
||
{
|
||
$order_id = input('order_id');
|
||
|
||
// $this->error();
|
||
}
|
||
|
||
/**
|
||
* 支付二维码
|
||
*/
|
||
public function recharge()
|
||
{
|
||
if (request()->isAjax()) {
|
||
$order_model = new OrderCreate();
|
||
$money = input('money');
|
||
$res = $order_model->rechargeOrderCreate($money, $this->uid, $this->site_id);
|
||
return $res;
|
||
}
|
||
return $this->fetch('saas/recharge');
|
||
}
|
||
|
||
/***
|
||
* 编辑商家
|
||
* @return mixed
|
||
*/
|
||
public function edituser()
|
||
{
|
||
$unisid = input('uid');
|
||
$site_group_model = new SiteGroup();
|
||
$shop_model = new Site();
|
||
$shop_info = $shop_model->getSiteInfo(['site_id' => $unisid], '*')['data'];
|
||
if (request()->isAjax()) {
|
||
$where = [['site_id', '=', $unisid]];
|
||
$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'),
|
||
'is_try' => input('is_try'),
|
||
];
|
||
if ($expire_time) {
|
||
if ($this->agent_info['agent_number'] >= $expire_time) {
|
||
if ($shop_info['expire_time'] < time()) {
|
||
$data['expire_time'] = time() + $expire_time * 30 * 86400;
|
||
} else {
|
||
$data['expire_time'] = $shop_info['expire_time'] + $expire_time * 30 * 86400;
|
||
}
|
||
model('website')->setDec(['site_id' => $this->site_id], 'agent_number', $expire_time);
|
||
Cache::tag("website")->clear();
|
||
$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, '余额时长不足');
|
||
}
|
||
}
|
||
$res = $shop_model->editSite($data, $where);
|
||
return $res;
|
||
}
|
||
$condition = [];
|
||
$condition[] = ['site_id', '=', $this->site_id];//获取分组
|
||
$info = $site_group_model->getSiteGroupList($condition, '*', 'fee asc');
|
||
$this->assign("group_info", $info['data']);
|
||
$this->assign("userinfo", $shop_info);
|
||
return $this->fetch('saas/edit_user');
|
||
}
|
||
|
||
/***
|
||
* 代理入驻
|
||
* @param string $type
|
||
* @return array|mixed
|
||
*/
|
||
public function apply($type = '')
|
||
{
|
||
//查询省级数据列表
|
||
$address_model = new AddressModel();
|
||
$list = $address_model->getAreaList([["pid", "=", 0], ["level", "=", 1]]);
|
||
|
||
$level_agent = [
|
||
1 => [
|
||
'level_name' => '城市一级代理',
|
||
'desc' => '多重返利分红,具有一定市场资源,技术能力沟通能力,城市只限1个名额,须在一定时间内完成任务,否则降级普通技术服务商,司培训后期自行为客户及代理商提供技术服务咨询。',
|
||
'site_rate' => 70,
|
||
'order_rate' => 65,
|
||
'disabled' => 'disabled'
|
||
],
|
||
2 => [
|
||
'level_name' => '城市二级代理',
|
||
'desc' => '需要有一定服务能力与市场沟通能力,通过公司培训后期自行为客户提供技术服务咨询。',
|
||
'site_rate' => 65,
|
||
'order_rate' => 30
|
||
],
|
||
3 => [
|
||
'level_name' => '城市三级代理',
|
||
'desc' => '负责联系客户,开通账户,后期工作技术服务咨询有公司统一完成',
|
||
'site_rate' => 35,
|
||
'order_rate' => 10
|
||
]
|
||
];
|
||
$website_model = new WebsiteModel();
|
||
$info = [];
|
||
if ($type == 'edit') {
|
||
$info = $website_model->getWebSite(['site_id' => $this->site_id])['data'];
|
||
}
|
||
if (request()->isAjax()) {
|
||
$shop_model = new Site();
|
||
$getSiteInfo = $shop_model->getSiteInfo([['site_id', '=', $this->site_id]]);
|
||
$data = [
|
||
'site_id' => $this->site_id,
|
||
'member_id' => $this->uid,
|
||
'title' => input('title', ''),
|
||
'is_agent' => 1,
|
||
'is_apply' => 0,
|
||
'website_pid' => $getSiteInfo['data']['agent_id'] ?? 0,
|
||
'logo' => input('logo', ''),
|
||
'desc' => input('desc', ''),
|
||
'keywords' => input('keywords', ''),
|
||
'web_address' => input('web_address', ''),
|
||
'web_qrcode' => input('web_qrcode', ''),
|
||
'web_email' => input('web_email', ''),
|
||
'web_contacts' => input('web_contacts', ''),
|
||
'web_phone' => input('web_phone', ''),
|
||
'web_qq' => input('web_qq', ''),
|
||
'web_weixin' => input('web_weixin', ''),
|
||
'wap_status' => input('wap_status', ''),
|
||
'wap_domain' => input('wap_domain', ''),
|
||
'site_area_id' => input('site_area_id', ''),
|
||
'site_area_name' => input('site_area_name', ''),
|
||
'settlement_bank_account_name' => input('settlement_bank_account_name', ''),
|
||
'settlement_bank_account_number' => input('settlement_bank_account_number', ''),
|
||
'settlement_bank_name' => input('settlement_bank_name', ''),
|
||
'settlement_bank_address' => input('settlement_bank_address', ''),
|
||
];
|
||
$rate = $level_agent[input('level_agent', 3)];
|
||
$data['status'] = -1;
|
||
$data['agent_level'] = input('level_agent', 3);
|
||
$data['site_rate'] = $rate['site_rate'];
|
||
$data['order_rate'] = $rate['order_rate'];
|
||
if (empty($this->agent_info)) {
|
||
$res = $website_model->addWebsite($data, $rate);
|
||
} else {
|
||
$res = $website_model->setWebSite($data, ['id' => $this->agent_info['id']]);
|
||
}
|
||
return $res;
|
||
}
|
||
$this->assign("apply_info", $info);
|
||
$this->assign("level_agent", $level_agent);
|
||
$this->assign("province_list", $list["data"]);
|
||
return $this->fetch('saas/apply');
|
||
}
|
||
|
||
/***
|
||
* 修改密码
|
||
* @param $site_id
|
||
*/
|
||
public function repass($site_id)
|
||
{
|
||
if (isset($this->agent_info['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);
|
||
}
|
||
} else {
|
||
return $this->error('你的信息已记录,请勿搞破坏!');
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 即将到期
|
||
* @return mixed
|
||
*/
|
||
public function expireuser()
|
||
{
|
||
$info = $this->agent_info;
|
||
if (request()->isAjax()) {
|
||
$page = input('page', 1);
|
||
$page_size = input('page_size', PAGE_LIST_ROWS);
|
||
$search_text = input('search_text', '');
|
||
$category_id = input('category_id', 0);
|
||
$group_id = input('group_id', 0);
|
||
$shop_status = input('shop_status', '');
|
||
$cert_id = input('cert_id', '');
|
||
$is_own = input('is_own', '');
|
||
$start_time = input("start_time", '');
|
||
$end_time = input("end_time", '');
|
||
$condition[] = ['agent_id', '=', $info['site_id']];
|
||
if ($search_text) {
|
||
$condition[] = ['site_name|username', 'like', '%' . $search_text . '%'];
|
||
}
|
||
//商家分类
|
||
if ($category_id != 0) {
|
||
$condition[] = ['category_id', '=', $category_id];
|
||
}
|
||
//店铺等级
|
||
if ($group_id != 0) {
|
||
$condition[] = ['group_id', '=', $group_id];
|
||
}
|
||
//商家状态
|
||
if ($shop_status != '') {
|
||
$condition[] = ['shop_status', '=', $shop_status];
|
||
}
|
||
if ($cert_id) {
|
||
switch ($cert_id) {
|
||
case 1: //未认证
|
||
$condition[] = ['cert_id', '=', 0];
|
||
break;
|
||
case 2: //已认证
|
||
$condition[] = ['cert_id', '>', 0];
|
||
break;
|
||
}
|
||
}
|
||
if ($is_own != '') {
|
||
$condition[] = ['is_own', '=', $is_own];
|
||
}
|
||
$condition[] = ["expire_time", ">", 0];
|
||
$condition[] = ["expire_time", "<=", Time::daysAfter(10)];
|
||
|
||
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 = 'expire_time asc';
|
||
$field = 'site_id,site_name,group_name,username,is_try,contacts_name,contacts_mobile,expire_time,shop_status';
|
||
$shop_model = new Site();
|
||
$shopInfo = $shop_model->getSitePageList($condition, $page, $page_size, $order, $field);
|
||
return $shopInfo;
|
||
}
|
||
|
||
//应用套餐
|
||
$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', $info);
|
||
return $this->fetch('saas/expirelist');
|
||
}
|
||
|
||
/***
|
||
* 临时加时
|
||
* @return mixed
|
||
*/
|
||
public function exptime()
|
||
{
|
||
$unisid = input('unisid', 0);
|
||
if (request()->isAjax()) {
|
||
if ($unisid) {
|
||
$site_info = model('site')->getInfo(['site_id' => $unisid]);
|
||
if (($site_info['expire_time'] - 86400) >= time() || $site_info['expire_time'] == 0) {
|
||
$data['message'] = '临近72小时可紧急延长,当前时间充足';
|
||
return $data;
|
||
} else {
|
||
if ($site_info['expire_time'] < time()) {
|
||
$expire_time = time() + 86400;
|
||
} else {
|
||
$expire_time = $site_info['expire_time'] + 86400;
|
||
}
|
||
model('site')->update([
|
||
'expire_time' => $expire_time
|
||
, 'shop_status' => 1
|
||
, 'status' => 1
|
||
], ['site_id' => $unisid]);
|
||
$data['code'] = 0;
|
||
$data['message'] = '临时加时24小时';
|
||
return $data;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/***
|
||
* 注册商家
|
||
* @return array|mixed|void
|
||
*/
|
||
public function reg()
|
||
{
|
||
$site_group_model = new SiteGroup();
|
||
if (request()->isAjax()) {
|
||
if ($this->site_id != 1) {
|
||
return $this->error('您还不是代理商');
|
||
}
|
||
$data['username'] = trim(input("username", ''));//账户
|
||
$data['password'] = trim(input("password", ''));//密码
|
||
$group_id = input('group_id');
|
||
$expire_time = input('expire_time');
|
||
//店铺信息
|
||
$shop_data = [
|
||
'site_name' => input('site_name', ''), //店铺名称
|
||
'contacts_name' => input('contacts_name', ''), //联系人
|
||
'contacts_mobile' => input('contacts_mobile', ''), //联系电话
|
||
'agent_id' => $this->site_id, //所属代理
|
||
'group_id' => $group_id,
|
||
'expire_time' => $expire_time,
|
||
'is_try' => $expire_time ? 1 : 0, //是否体验用户
|
||
];
|
||
$user_info = [
|
||
'username' => input('username', ''),
|
||
'password' => data_md5(input('password', '')),
|
||
];
|
||
$site_model = new 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;
|
||
}
|
||
}
|
||
//应用套餐
|
||
$site_group_list = $site_group_model->getSiteGroupList([['site_id', '=', $this->site_id]], 'group_id,group_name,fee,remark', 'fee asc');
|
||
$this->assign("group_info", $site_group_list['data']);
|
||
$this->assign("reg_info", []);
|
||
return $this->fetch('saas/reg');
|
||
}
|
||
|
||
|
||
/***
|
||
* 关闭店铺
|
||
* @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;
|
||
}
|
||
}
|
||
|
||
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 Site();
|
||
$shopInfo = $shop_model->getSiteInfo($condition, $field);
|
||
return $shopInfo;
|
||
}
|
||
|
||
|
||
|
||
|
||
} |