<?php
|
|
namespace app\admin\controller;
|
|
use app\admin\validate\SellerAccountAdd;
|
use app\admin\validate\SellerAccountEdit;
|
use think\db\exception\DataNotFoundException;
|
use think\db\exception\DbException;
|
use think\db\exception\ModelNotFoundException;
|
use think\Exception;
|
use think\facade\Db;
|
use think\facade\View;
|
use think\facade\Request;
|
|
class Seller extends Common
|
{
|
|
public function index()
|
{
|
////////
|
View::assign('menuitem', strtolower('seller-index'));
|
|
$other['title'] = '分销商';
|
$guide['one']['text'] = '分销商管理';
|
$guide['two']['text'] = '分销商列表';
|
View::assign('guide', $guide);
|
|
|
View::assign('other', $other);
|
return View::fetch('index');
|
}
|
|
/**
|
* @throws ModelNotFoundException
|
* @throws DbException
|
* @throws DataNotFoundException
|
*/
|
public function seller_list()
|
{
|
if (Request::isPost()) {
|
$kw = input('kw');
|
if (!empty($kw)) {
|
$condition[] = array('a.phone|b.company_name|b.certificate_name', 'like', "%$kw%");
|
}
|
$p = input('p', 1);
|
$_GET['p'] = $p;
|
$other['page_size'] = input('page_size', 20);
|
$order = 'a.id desc';
|
|
$count = Db::name('seller_account')
|
->alias('a')->join('seller_base_info b', 'a.id = b.seller_id')
|
->where($condition)->count();
|
|
$list = Db::name('seller_account')
|
->alias('a')
|
->leftJoin('seller_base_info b', 'a.id = b.seller_id')
|
->field("a.id,a.phone,b.id as seller_id,b.account_type,b.certificate_name,b.first_name,b.last_name,b.company_name,login_time,login_ip,a.end_time,a.start_time,a.sub_ban_access")
|
->where($condition)
|
->order($order)
|
->page($p, $other['page_size'])
|
->select()
|
->toArray();
|
|
$other['count'] = $count;
|
if (!$list) {
|
$list = [];
|
} else {
|
foreach ($list as &$item) {
|
$item['endtime'] = date('Y-m-d', $item['end_time']);
|
}
|
}
|
$other['admin_info'] = $this->cinfo;
|
$d['code'] = 200;
|
$d['list'] = $list;
|
$d['other'] = $other;
|
return $d;
|
}
|
}
|
|
public function update_ban_access()
|
{
|
header('Content-Type:text/html;charset=utf-8');
|
if (Request::isPost()) {
|
$id = input('id');
|
$sub_ban_access = input('sub_ban_access');
|
$info = Db::name('seller_account')->where('id', $id)->find();
|
if (!$info) {
|
$d['code'] = 400;
|
$d['message'] = '信息不存在';
|
return $d;
|
}
|
if ($sub_ban_access == '1') {
|
$dd['sub_ban_access'] = 1;
|
$d['sub_ban_access'] = 1;
|
$d['message'] = '允许登录';
|
} else {
|
$dd['sub_ban_access'] = 0;
|
$d['sub_ban_access'] = 0;
|
$d['message'] = '禁止登录';
|
}
|
$backval = Db::name('seller_account')->where('id', $id)->save($dd);
|
if ($backval === FALSE) {
|
$d['code'] = 400;
|
} else {
|
$d['code'] = 200;
|
}
|
} else {
|
$d['code'] = 400;
|
$d['message'] = '非法请求';
|
}
|
return $d;
|
}
|
|
|
/**
|
* 分销商编辑页
|
* @param int $id
|
* @return string
|
*/
|
public function add(int $id = 0): string
|
{
|
View::assign('menuitem', strtolower('seller-index'));
|
if ($id && is_numeric($id)) {
|
$other['title'] = '编辑分销商信息';
|
} else {
|
$other['title'] = '添加分销商信息';
|
}
|
$guide['one']['text'] = '分销商管理';
|
$guide['two']['text'] = $other['title'];
|
|
$other['id'] = $id;
|
View::assign('guide', $guide);
|
View::assign('other', $other);
|
return View::fetch('add');
|
}
|
|
/**
|
* 获取分销商详细信息
|
* @return array
|
*/
|
public function get_seller_info(): array
|
{
|
try {
|
if (!Request::isPost()) {
|
throw new Exception("请求方式有误");
|
}
|
$seller_id = input('id');
|
if (!$seller_id || !is_numeric($seller_id)) {
|
throw new Exception("参数有误");
|
}
|
$where = [
|
'a.id' => $seller_id
|
];
|
$seller_info = Db::name('seller_account')->where('id', $seller_id)->find();
|
if (!$seller_info) {
|
throw new Exception("分销商信息有误");
|
}
|
unset($seller_info['password']);
|
$base_info = Db::name('seller_base_info')->where('seller_id', $seller_id)->find();
|
if (!$base_info) {
|
$seller_info['base_info'] = [];
|
} else {
|
|
|
$base_info['main_area'] = $base_info['main_area'] ? array_map('intval', explode(',', $base_info['main_area'])) : [];
|
$base_info['main_dis_platform'] = $base_info['main_dis_platform'] ? array_map('intval', explode(',', $base_info['main_dis_platform'])) : [];
|
$cate_code = [];
|
if ($base_info['country_id']) {
|
$cate_code[] = $base_info['country_id'];
|
}
|
if ($base_info['province_id']) {
|
$cate_code[] = $base_info['province_id'];
|
}
|
if ($base_info['city_id']) {
|
$cate_code[] = $base_info['city_id'];
|
}
|
$base_info['cate_code'] = $cate_code;
|
|
$seller_info['base_info'] = $base_info;
|
}
|
$seller_info['end_time'] = date("Y-m-d", $seller_info['end_time']);
|
|
$result = [
|
'code' => 200,
|
'message' => "成功",
|
'data' => $seller_info
|
];
|
} catch (Exception $exc) {
|
$result = [
|
'code' => $exc->getCode(),
|
'message' => $exc->getMessage()
|
];
|
}
|
return $result;
|
}
|
|
/**
|
* 保存分销商帐号
|
* @return array
|
*/
|
public function save_seller_info(): array
|
{
|
try {
|
if (!Request::isPost()) {
|
throw new Exception("请求方式有误");
|
}
|
$params = Request::param();
|
$phone = trim($params['phone'] ?? '');
|
if (!$phone) {
|
throw new Exception("请填写分销商手机号");
|
}
|
|
$seller_id = $params['id'] ?? 0;
|
$where = [];
|
if ($seller_id) {
|
$where[] = ['phone', '=', $phone];
|
$where[] = ['id', '<>', $seller_id];
|
/////更新/////
|
$find = Db::name('seller_account')->where($where)->find();
|
if ($find) {
|
throw new Exception("该手机号已被其它分销商注册");
|
}
|
$seller_info = Db::name('seller_account')->where('id', $seller_id)->find();
|
if (!$seller_info) {
|
throw new Exception("分销商账号信息有误");
|
}
|
$add_data = [
|
'phone' => $phone,
|
'end_time' => strtotime($params['end_time']) + 86400 - 1,
|
'sub_ban_access' => $params['sub_ban_access'] ? 1 : 0,
|
];
|
if ($params['password']) {
|
$add_data['password'] = joinmd5($params['password']);
|
}
|
Db::name('seller_account')->where('id', $seller_id)->update($add_data);
|
$jump_url = "";
|
} else {
|
if (!$params['password']) {
|
throw new Exception("请填写分销商密码");
|
}
|
/////添加/////
|
$where[] = ['phone', '=', trim($phone)];
|
$seller_info = Db::name('seller_account')->where($where)->find();
|
if ($seller_info) {
|
throw new Exception("该手机号已被其它分销商注册");
|
}
|
$add_data = [
|
'phone' => $params['phone'],
|
'password' => joinmd5($params['password']),
|
'end_time' => strtotime($params['end_time']) + 86400 - 1,
|
'sub_ban_access' => $params['sub_ban_access'] ? 1 : 0,
|
'start_time' => time(),
|
'add_time' => time()
|
];
|
$seller_id = Db::name('seller_account')->insertGetId($add_data);
|
if (!$seller_id) {
|
throw new Exception("添加分销商失败");
|
}
|
$jump_url = url('admin/seller/index');
|
}
|
$result = [
|
'code' => 200,
|
'message' => "保存成功",
|
'jump_url' => $jump_url
|
];
|
} catch (Exception $exc) {
|
$result = [
|
'code' => $exc->getCode(),
|
'message' => $exc->getMessage()
|
];
|
}
|
return $result;
|
}
|
/*
|
* 获取国家-省份-城市列表
|
*/
|
public function getCountryCodeList()
|
{
|
if (!Request::isPost()) {
|
throw new Exception(lang('request_method_incorrect'));
|
}
|
try {
|
|
$result['list'] = $this->getCountrychildrenids(0);
|
return $this->successResponse($result);
|
} catch (\Exception $exc) {
|
return $this->errorResponse($exc->getMessage());
|
}
|
}
|
/*
|
* 获取分销平台列表
|
*/
|
public function getDisPlatformList()
|
{
|
try {
|
if (!Request::isPost()) {
|
throw new Exception(lang('request_method_incorrect'));
|
}
|
// $seller_id = $this->sellerId;
|
$condition[] = ['seller_status', '=', 1];
|
$order = 'order_id asc,id asc';
|
$list = Db::name('dis_platform')->field("id,platform_name")->where($condition)->order($order)->select()->toArray();
|
if ($list) {
|
$result['list'] = $list;
|
return $this->successResponse($result);
|
} else {
|
throw new Exception(lang('no_data_found'));
|
}
|
} catch (\Exception $exc) {
|
return $this->errorResponse($exc->getMessage());
|
}
|
}
|
}
|