feat: 前端接口完善

master
yin5th 2023-08-14 17:51:34 +08:00
parent 83d4db7cd4
commit 95fe7bd981
13 changed files with 460 additions and 3 deletions

View File

@ -0,0 +1,89 @@
<?php
namespace app\admin\controller\user;
use app\admin\validate\user\BusinessTeamValidate;
use app\common\basics\AdminBase;
use app\common\server\ConfigServer;
use app\common\server\JsonServer;
use think\exception\ValidateException;
use app\admin\logic\user\BusinessTeamLogic;
class BusinessTeam extends AdminBase
{
public function lists()
{
if($this->request->isAjax()){
$get = $this->request->get();
$lists = BusinessTeamLogic::lists($get);
return JsonServer::success('', $lists);
}
return view();
}
public function add()
{
if($this->request->isAjax()) {
try{
$post = $this->request->post();
validate(BusinessTeamValidate::class)->scene('add')->check($post);
}catch(ValidateException $e) {
return JsonServer::error($e->getError());
}
$result = BusinessTeamLogic::add($post);
if($result === true) {
return JsonServer::success('添加成功');
}
return JsonServer::error(BusinessTeamLogic::getError());
}
return view();
}
public function edit(){
if($this->request->isAjax()){
try{
$post = $this->request->post();
validate(BusinessTeamValidate::class)->scene('edit')->check($post);
}catch(ValidateException $e) {
return JsonServer::error($e->getError());
}
$result = BusinessTeamLogic::edit($post);
if($result === true) {
return JsonServer::success('编辑成功');
}
return JsonServer::error(BusinessTeamLogic::getError());
}
$id = $this->request->get('id', '', 'intval');
$detail = BusinessTeamLogic::getBusinessTeam($id);
return view('', [
'detail' => $detail
]);
}
public function del()
{
$id = $this->request->post('id', '', 'intval');
$result = BusinessTeamLogic::del($id);
if($result === true) {
return JsonServer::success('删除成功');
}
return JsonServer::error(BusinessTeamLogic::getError());
}
// public function set()
// {
// if($this->request->isAjax()) {
// $post = $this->request->post();
// ConfigServer::set('user_level', 'intro', $post['intro']);
// return JsonServer::success('设置成功');
// }
// $intro = ConfigServer::get('user_level', 'intro');
// $intro_default = config('default.user_level.intro');
//
// return view('', [
// 'intro' => $intro,
// 'intro_default' => $intro_default
// ]);
// }
}

View File

@ -30,6 +30,7 @@ class BasicLogic extends Logic
'pc_client_login_logo' => ConfigServer::get('website', 'pc_client_login_logo'),
'user_image' => ConfigServer::get('website', 'user_image'),
'goods_image' => ConfigServer::get('website', 'goods_image'),
'order_contract_template' => ConfigServer::get('website', 'order_contract_template'),
'platform_login_logo' => ConfigServer::get('website_platform', 'platform_login_logo'),
'platform_login_image' => ConfigServer::get('website_platform', 'platform_login_image'),
@ -65,6 +66,7 @@ class BasicLogic extends Logic
ConfigServer::set('website', 'pc_client_login_logo', UrlServer::setFileUrl($post['pc_client_login_logo'] ?? ''));
ConfigServer::set('website', 'user_image', UrlServer::setFileUrl($post['user_image'] ?? ''));
ConfigServer::set('website', 'goods_image', UrlServer::setFileUrl($post['goods_image'] ?? ''));
ConfigServer::set('website', 'order_contract_template', UrlServer::setFileUrl($post['order_contract_template'] ?? ''));
}
/**

View File

@ -0,0 +1,90 @@
<?php
namespace app\admin\logic\user;
use app\common\basics\Logic;
use app\common\model\BusinessTeam;
use think\facade\Db;
class BusinessTeamLogic extends Logic
{
public static function lists($get)
{
$count = BusinessTeam::count();
$lists = BusinessTeam::order('id', 'desc')->page($get['page'], $get['limit'])->select()->toArray();
return ['count' => $count, 'lists' => $lists];
}
public static function add($post)
{
try{
$userLevel = BusinessTeam::where(['name'=>trim($post['name'])])->findOrEmpty();
if(!$userLevel->isEmpty()) {
throw new \think\Exception('名称已被使用,请更换后重试');
}
$time = time();
$data = [
'name' => trim($post['name']),
'phone' => trim($post['phone']),
'create_time' => $time,
];
BusinessTeam::create($data);
return true;
}catch(\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
public static function edit($post)
{
try{
$userLevel = BusinessTeam::where([
['name', '=', trim($post['name'])],
['id', '<>', $post['id']]
])->findOrEmpty();
if(!$userLevel->isEmpty()) {
throw new \think\Exception('名称已被使用,请更换后重试');
}
$data = [
'id' => $post['id'],
'name' => trim($post['name']),
'phone' => trim($post['phone']),
];
BusinessTeam::update($data);
return true;
}catch(\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
public static function del($id)
{
try{
BusinessTeam::where('id', $id)->delete();
return true;
}catch(\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
public static function getBusinessTeamList()
{
$levelArr = BusinessTeam::field('id,name,phone')
->select()
->toArray();
$levelArr[0] = ['id'=>0, 'name'=>'暂无团队', 'phone' => ''];
return $levelArr;
}
public static function getBusinessTeam($id){
$detail = BusinessTeam::where(['id'=>$id])->findOrEmpty();
if($detail->isEmpty()) {
return [];
}
$detail = $detail->toArray();
return $detail;
}
}

View File

@ -7,6 +7,7 @@ use app\common\enum\ClientEnum;
use app\common\enum\OrderEnum;
use app\common\logic\AccountLogLogic;
use app\common\model\AccountLog;
use app\common\model\BusinessTeam;
use app\common\model\user\User;
use app\common\model\user\UserLevel;
use app\common\model\user\UserTag;
@ -30,6 +31,11 @@ class UserLogic extends Logic
$where[] = ['disable', '=', $get['disable']];
}
//业务团队
if(isset($get['team_id']) && $get['team_id'] !== ''){
$where[] = ['team_id','=',$get['team_id']];
}
//等级查询
if(isset($get['level']) && $get['level'] !== ''){
$where[] = ['level','=',$get['level']];
@ -64,12 +70,14 @@ class UserLogic extends Logic
$user_count = User::where($where)->count();
$user_list = User::where($where)
->field('id,sn,nickname,avatar,level,total_order_amount,tag_ids,client,login_time,create_time,user_growth,user_money,earnings,first_leader,disable')
->field('id,sn,nickname,avatar,level,total_order_amount,tag_ids,client,login_time,create_time,user_growth,user_money,earnings,first_leader,disable,team_id')
->page($get['page'],$get['limit'])
->order('id desc')
->select()
->toArray();
// 业务团队
$business_team = BusinessTeam::order('id desc')->column('name','id');
//会员等级
$user_level = UserLevel::where(['del'=>0])->column('name','id');
// 会员标签
@ -82,6 +90,8 @@ class UserLogic extends Logic
$item['earnings'] = empty($item['earnings']) ? 0 : $item['earnings'];
// 总资产
$item['total_amount'] = $item['user_money'] + $item['earnings'];
// 业务团队
$item['team_name'] = $business_team[$item['team_id']] ?? '无';
// 会员等级
$item['level_name'] = '暂无等级';
if(isset($user_level[$item['level']])){

View File

@ -0,0 +1,21 @@
<?php
namespace app\admin\validate\user;
use think\Validate;
class BusinessTeamValidate extends Validate
{
protected $rule = [
'id|ID' => 'require',
'name|名称' => 'require',
'phone|电话' => 'require',
];
public function sceneAdd() {
return $this->only(['name', 'phone']);
}
public function sceneEdit() {
return $this->only(['id', 'name', 'phone']);
}
}

View File

@ -109,7 +109,7 @@
<label class="layui-form-label">商品默认封面图:</label>
<div class="layui-input-inline">
<div class="like-upload-image">
{if !empty($config.user_image)}
{if !empty($config.goods_image)}
<div class="upload-image-div">
<img src="{$config.file_url}{$config.goods_image}" alt="img" style="background-color:#EEEEEE;height: 80px;width:auto">
<input name="goods_image" type="hidden" value="{$config.goods_image}">
@ -127,6 +127,32 @@
</div>
</div>
<!--合同模版-->
<div class="layui-form-item">
<label class="layui-form-label">合同模版:</label>
<div class="layui-inline">
<div class="pay-cert" id="kkk">
<input class="text" type="hidden" name="order_contract_template" value="{$config.order_contract_template | default = ''}" >
{if !empty($config.order_contract_template)}
<div class="file-add" style="display: none;cursor: pointer;">
<a class="upload-cert-a">+ 添加文件</a>
</div>
<div class="pay-li">
<img class="pay-img" src="/static/common/image/default/upload.png">
<a class="pay-img-del-x" style="display: none">x</a>
</div>
{else/}
<div class="file-add" style="cursor: pointer;">
<a class="upload-cert-a">+ 添加文件</a>
</div>
{/if}
</div>
<div class=" layui-form-mid layui-word-aux">
前置订单的合同模版建议大小不超过10M。pdf格式
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn layui-btn-sm {$view_theme_color}" lay-submit lay-filter="setWebsite">确认
@ -135,3 +161,45 @@
</div>
</div>
<script>
layui.use(['form'], function(){
var $ = layui.$
,form = layui.form;
like.delUpload();
// $(document).on("click", ".add-upload-image", function () {
// like.imageUpload({
// limit: 1,
// field: "image",
// that: $(this)
// });
// });
//删除图片/证书
$(document).on('click', '.pay-img-del-x', function () {
$(this).parent().siblings('input').val('');
$(this).parent().siblings().css('display','block');
$(this).parent().remove();
});
//==========================================上传证书start=========================================================
like.fileUpload('.file-add', '{:url("file/other")}?local=1&sub_dir=contract', '{$storageUrl}');
//==========================================上传证书end===========================================================
// 删除按钮的显示与隐藏
$(document).on('mouseover', '.pay-img', function () {
$(this).next().show();
});
$(document).on('mouseout', '.pay-img', function () {
$(this).next().hide();
});
$(document).on('mouseover', '.pay-img-del-x', function () {
$(this).show();
});
$(document).on('mouseout', '.pay-img-del-x', function () {
$(this).hide();
});
})
</script>

View File

@ -0,0 +1,92 @@
<?php
namespace app\api\controller;
use app\common\basics\Api;
use app\common\model\Demand As thisModel;
use app\common\model\DemandReport;
use app\common\server\JsonServer;
use think\facade\Validate;
use think\response\Json;
//需求相关
class Demand extends Api
{
public $like_not_need_login = ['lists', 'detail'];
/***
* 列表
*/
public function lists()
{
try {
$page = input('page_size/d', 1);
$limit = input('page_no/d', 10);
$page = $page ?: 1;
$limit = $limit ?: 10;
$where = [];
$order = [
'id' => 'desc'
];
$count = thisModel::where($where)->count();
$list = thisModel::field(['id', 'name', 'create_time'])
->where($where)
->order($order)
->page($page,$limit)
->select()
->toArray();
$data = [
'list' => $list,
'page_no' => $page,
'page_size' => $limit,
'count' => $count,
];
return JsonServer::success('获取成功', $data);
} catch (\Exception $e) {
return JsonServer::error('获取失败');
}
}
public function detail()
{
$id = input('id/d', 0);
if (!$item = thisModel::where('id', $id)->find()) {
return JsonServer::error('记录不存在');
}
return JsonServer::success('获取成功', $item->toArray());
}
public function report(): Json
{
$input = input('post.');
$rule = [
'demand_id|需求' => 'require|number',
'name|姓名' => 'require|min:2|max:50',
'phone|手机' => 'require|mobile',
// 'company|公司' => '',
// 'price|报价' => '',
];
$validate = Validate::rule($rule);
if (!$validate->check($input)) {
return JsonServer::error($validate->getError());
}
DemandReport::create([
'demand_id' => $input['demand_id'],
'name' => $input['name'],
'phone' => $input['phone'],
'company' => $input['company'] ?: '',
'price' => $input['price'] ?: '',
'create_time' => time(),
]);
return JsonServer::success('报名成功');
}
}

View File

@ -6,11 +6,33 @@ use app\api\logic\OrderInvoiceLogic;
use app\api\logic\OrderLogic;
use app\api\validate\OrderValidate;
use app\common\basics\Api;
use app\common\server\ConfigServer;
use app\common\server\JsonServer;
class Order extends Api
{
public $like_not_need_login = ['contractDownload'];
/**
* @notes 合同下载
* @return \think\response\Json
* @throws \think\Exception
* @author suny
* @date 2021/7/13 6:11 下午
*/
public function contractDownload()
{
$path = ConfigServer::get('website', 'order_contract_template');
return JsonServer::success('下单成功!', ['path' => $path, 'domain' => request()->domain()]);
}
public function contractUpload()
{
return JsonServer::success('上传成功!');
}
/**
* @notes 下单
* @return \think\response\Json

View File

@ -4,6 +4,7 @@ namespace app\api\logic;
use app\api\controller\Account;
use app\common\basics\Logic;
use app\common\logic\ChatLogic;
use app\common\model\BusinessTeam;
use app\common\model\goods\GoodsCollect;
use app\common\model\kefu\ChatRecord;
use app\common\model\kefu\ChatRelation;
@ -75,12 +76,28 @@ class UserLogic extends Logic
if(!$user_level->isEmpty()){
$user['next_level_tips'] = '距离升级还差'.intval($user_level['growth_value'] - $user['user_growth']);
}
$team = [
'id' => 0,
'name' => '',
'phone' => '',
];
// 团队信息
$teamInfo = BusinessTeam::where('id', $user['team_id'])->find();
if (!empty($teamInfo)) {
$team['id'] = $teamInfo['id'] ?? 0;
$team['name'] = $teamInfo['name'] ?: '';
$team['phone'] = $teamInfo['phone'] ?: '';
}
// 是否设置支付密码
$user['hasPayPassword'] = $user['pay_password'] ? 1: 0;
$user->visible(['id','nickname','sn','avatar', 'mobile', 'hasPayPassword','next_level_tips','user_money','total_order_amount','total_recharge_amount',
'coupon','user_integral','level','wait_pay','wait_take','wait_delivery',
'wait_comment','after_sale', 'distribution_setting', 'distribution_code', 'notice_num', 'collect','level_name','vip']);
'wait_comment','after_sale', 'distribution_setting', 'distribution_code', 'notice_num', 'collect','level_name','vip','team_id']);
$user = $user->toArray();
$user['team_info'] = $team;
return $user;
}

View File

@ -0,0 +1,9 @@
<?php
namespace app\common\model;
use app\common\basics\Models;
class BusinessTeam extends Models
{
}

View File

@ -0,0 +1,9 @@
<?php
namespace app\common\model;
use app\common\basics\Models;
class Demand extends Models
{
}

View File

@ -0,0 +1,9 @@
<?php
namespace app\common\model;
use app\common\basics\Models;
class DemandReport extends Models
{
}

View File

@ -306,6 +306,25 @@ var like = {
$(element).css('display','none');
}
});
},
// 文件上传
fileUpload:function (element, url, domain) {
layui.upload.render({
elem: element
,url: url
,accept:'file'
,exts:'pdf'
,done: function(res, index, upload) {
var html = '<div class="pay-li">\n' +
'<img class="pay-img" ' +
'src="/static/common/image/default/upload.png">' +
'<a class="pay-img-del-x" style="display: none">x</a>' +
'</div>';
$(element).prev().val(res.data[1].uri);
$(element).after(html);
$(element).css('display','none');
}
});
}
};