完成供应链团队建设

This commit is contained in:
monanxiao 2023-03-03 18:03:28 +08:00
parent 09048ec2e5
commit 85d6b9407a
12 changed files with 744 additions and 66 deletions

View File

@ -69,7 +69,7 @@ class Index extends BaseController
$total = SupplyChain::where($where)->count();
$list = SupplyChain::order('id desc')->select();
$list = SupplyChain::with(['merchant', 'street', 'area'])->order('id desc')->select();
View::assign('url', $this->url);
View::assign('list', $list);
@ -121,7 +121,7 @@ class Index extends BaseController
foreach ($params['mer_id'] as $v) {
$dataLink = [
'mer_id' => $v, // 商户ID
'eb_merchant_id' => $v, // 商户ID
'user_id' => $data['user_id'],
'create_time' => $data['create_time'],
];
@ -161,19 +161,75 @@ class Index extends BaseController
$id = get_params("id");
if(!$id) return to_assign(1, '非法操作!');
$supplyChain = SupplyChain::with(['merchant', 'street', 'area'])->find($id); // 取出当前供应链数据
if (request()->isAjax()) {
$params = get_params();
$data['id'] = $params['id']; // 当前ID
$data['user_id'] = $this->adminInfo['id']; // 操作用户ID
$data['name'] = $params['title']; // 团队名称
$data['tel'] = $params['phone']; // 联系电话
$data['mer_id_list'] = isset($params['mer_id']) ? json_encode($params['mer_id']) : null; // 已选商户
$data['street_id'] = $params['street_id']; // 街道ID
$street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据
$data['lng'] = $street['lng']; // 经度
$data['lat'] = $street['lat']; // 纬度
$area = $street->area; // 区数据
$data['area_id'] = $area['area_id']; // 区县id
$city = $area->city; // 获取市级
$data['address'] = $city['city_name'] . $area['area_name'] . $street['street_name']; // 实际地址
$data['create_time'] = date('Y-m-d H:i:s');
// 数据更新
$supplyChain = SupplyChain::with(['linkMerchant'])->find($data['id']);
$res = $supplyChain->update($data);
// 获取关联数据一对一---曲线救国
$linkMerchant = $supplyChain['linkMerchant'];
// $linkMerchantArr = $linkMerchant->column('id');
// 先删除关联数据-- 曲线救国
$linkMerchant->delete();
// 关联商户状态
if($data['mer_id_list'])
{
// 再重新将关联数据入库
foreach ($params['mer_id'] as $v) {
$dataLink = [
'eb_merchant_id' => $v, // 商户ID
'user_id' => $data['user_id'],
'create_time' => $data['create_time'],
];
$supplyChain->linkMerchant()->save($dataLink);
}
}
if ($res){
return to_assign(0,'操作成功',['aid'=>$res]);
}
return to_assign(1, '操作失败,原因:'.$res);
}else{
$supplyChain = SupplyChain::with(['merchant', 'street', 'area'])->find($id); // 取出当前供应链数据
View::assign('detail', $supplyChain);
// 取出正常的商家
$merchant = Merchant::where('status', 1)->column('mer_id, real_name');
// 区域模型
$arealist = GeoArea::where('city_code', '510500')->select();
View::assign('arealist', $arealist);
View::assign('merchant', $merchant);
View::assign('url', $this->url);
return view();
}
View::assign('detail', $supplyChain);
// 取出正常的商家
$merchant = Merchant::where('status', 1)->column('mer_id, real_name');
// 区域模型
$arealist = GeoArea::where('city_code', '510500')->select();
View::assign('arealist', $arealist);
View::assign('merchant', $merchant);
View::assign('url', $this->url);
return view();
}
/**
@ -183,7 +239,19 @@ class Index extends BaseController
*/
public function delete()
{
return view();
$id = get_params("id");
if(!$id) return to_assign(1, '非法操作!');
$supplyChain = SupplyChain::with(['linkMerchant'])->find($id);
// 删除关联模型
$res = $supplyChain->together(['linkMerchant'])->delete();
if ($res){
return to_assign(0,'操作成功',['aid'=>$res]);
}
return to_assign(1, '操作失败,原因:'.$res);
}
}

View File

@ -9,12 +9,30 @@ namespace app\admin\controller\supplychain;
use app\admin\BaseController;
use think\facade\Db;
use think\facade\View;
use app\admin\model\Merchant as MerchantModel; // 商户模型
use app\admin\model\StoreOrder as StoreOrderModel; // 商户订单模型
use app\admin\model\GeoCity; // 省市模型
use app\admin\model\GeoArea; // 区域模型
use app\admin\model\GeoStreet; // 街道模型
use app\admin\model\SupplyChain; // 供应链模型
use app\admin\model\SupplyChainLinkMerchant; // 供应链关联商户模型
use app\api\model\Area as AreaModel; // 市场区域模型
use app\api\model\AreaManager as AreaManagerModel; // 区域负责人模型
class Merchant extends BaseController
{
public function __construct()
{
$this->adminInfo = get_login_admin();
$this->category_id=354;
$this->url=[
'/admin/supplychain.index/index?category_id='.$this->category_id,
'/admin/supplychain.index/add',
'/admin/supplychain.index/edit',
'/admin/supplychain.index/delete',
'/admin/supplychain.merchant/index',
'/admin/supplychain.merchant/bill',
];
}
/**
@ -24,7 +42,55 @@ class Merchant extends BaseController
*/
public function index()
{
return view();
if (request()->isAjax()) {
$params= get_params();
$where = [];
if (isset($params['keywords']) && !empty($params['keywords'])){
$where[]= ['name','like','%'.$params['keywords'].'%'];
}
if($this->adminInfo['position_id'] != 1){ //不是超级管理员
$www['admin_id'] = $this->adminInfo['id'];
$user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find();
if ($user_address){
if($user_address['auth_range'] == 1){
$where[] = ['village_id','=',$user_address['village_id']];
}elseif ($user_address['auth_range'] == 2){
$where[] = ['street_id','=',$user_address['street_id']];
}elseif ($user_address['auth_range'] == 3){
$where[] = ['area_id','=',$user_address['area_id']];
}else{
$where[] = ['village_id','=',$user_address['village_id']];
}
}else{
$where[] = ['village_id','=',''];
}
}
$total = SupplyChainLinkMerchant::where($where)->count();
$list = SupplyChainLinkMerchant::with(['supplyChain', 'merchant'])->order('id desc')->select();
View::assign('url', $this->url);
View::assign('list', $list);
$result = ['total' => $total, 'data' => $list];
return table_assign(0, '', $result);
}else{
$total = SupplyChainLinkMerchant::count();
$list = SupplyChainLinkMerchant::with(['merchant', 'supplyChain'])->select();
View::assign('url', $this->url);
View::assign('list', $list);
$result = ['total' => $total, 'data' => $list];
return view();
}
}
/**
@ -34,7 +100,55 @@ class Merchant extends BaseController
*/
public function bill()
{
return view();
if (request()->isAjax()) {
$params= get_params();
$where = [];
if (isset($params['keywords']) && !empty($params['keywords'])){
$where[]= ['name','like','%'.$params['keywords'].'%'];
}
if($this->adminInfo['position_id'] != 1){ //不是超级管理员
$www['admin_id'] = $this->adminInfo['id'];
$user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find();
if ($user_address){
if($user_address['auth_range'] == 1){
$where[] = ['village_id','=',$user_address['village_id']];
}elseif ($user_address['auth_range'] == 2){
$where[] = ['street_id','=',$user_address['street_id']];
}elseif ($user_address['auth_range'] == 3){
$where[] = ['area_id','=',$user_address['area_id']];
}else{
$where[] = ['village_id','=',$user_address['village_id']];
}
}else{
$where[] = ['village_id','=',''];
}
}
$total = StoreOrderModel::where($where)->count();
$list = StoreOrderModel::with(['merchant'])->order('order_id desc')->select();
View::assign('url', $this->url);
View::assign('list', $list);
$result = ['total' => $total, 'data' => $list];
return table_assign(0, '', $result);
}else{
$total = StoreOrderModel::count();
$list = StoreOrderModel::with(['merchant'])->select();
View::assign('url', $this->url);
View::assign('list', $list);
$result = ['total' => $total, 'data' => $list];
return view();
}
}

View File

@ -0,0 +1,22 @@
<?php
/**
* 时间2023年03月02日
* 作者:墨楠小
* 邮箱monanxiao@qq.com
* 订单模型
*
*/
namespace app\admin\model;
use think\Model;
class EbStoreProduct extends Model
{
// 设置当前模型的数据库连接
protected $connection = 'shop';
// 设置当前模型对应的完整数据表名称
protected $table = 'eb_store_product';
protected $pk = 'product_id';
}

View File

@ -0,0 +1,40 @@
<?php
/**
* 时间2023年03月02日
* 作者:墨楠小
* 邮箱monanxiao@qq.com
* 购物车模型
*
*/
namespace app\admin\model;
use think\Model;
class StoreCart extends Model
{
// 设置当前模型的数据库连接
protected $connection = 'shop';
// 设置当前模型对应的完整数据表名称
protected $table = 'eb_store_cart';
protected $pk = 'cart_id';
/**
* 所属商品
*
*/
public function product()
{
return $this->hasOne(EbStoreProduct::class, 'product_id', 'product_id');
}
/**
*
* 所属用户
*
*/
public function user()
{
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
}
}

View File

@ -0,0 +1,64 @@
<?php
/**
* 时间2023年03月02日
* 作者:墨楠小
* 邮箱monanxiao@qq.com
* 订单模型
*
*/
namespace app\admin\model;
use think\Model;
class StoreOrder extends Model
{
// 设置当前模型的数据库连接
protected $connection = 'shop';
// 设置当前模型对应的完整数据表名称
protected $table = 'eb_store_order';
protected $pk = 'order_id';
/**
* 所属商户
* 一对一
*
*/
public function merchant()
{
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
}
/**
* 所属商品
*
*/
public function cart()
{
return $this->hasOne(StoreCart::class, 'cart_id', 'cart_id');
}
/**
* 获取购物车商品
*
*/
public function getCartIdAttr($value)
{
// 分割为数组
$cartId = explode(',', $value);
// 购物车ID
$scartList = StoreCart::whereIn('cart_id', $cartId)->with(['product'])->select();
return $scartList;
}
/**
*
* 所属用户
*
*/
public function user()
{
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
}
}

View File

@ -12,17 +12,20 @@
class SupplyChain extends Model
{
// 设置当前模型的数据库连接
protected $connection = 'mysql';
// 设置当前模型对应的完整数据表名称
protected $table = 'fa_supply_chain';
/**
* 关联拥有多个商户
* 远程一对多
*
* 关联模型、中间模型
*/
public function merchant()
{
return $this->belongsToMany(Merchant::class, SupplyChainLinkMerchant::class, 'eb_merchant_id', 'fa_supply_chain_id');
return $this->hasManyThrough(Merchant::class, SupplyChainLinkMerchant::class, 'fa_supply_chain_id', 'mer_id', 'id', 'eb_merchant_id');
}
/**
@ -32,7 +35,7 @@
*/
public function linkMerchant()
{
return $this->hasMany(SupplyChainLinkMerchant::class);
return $this->hasMany(SupplyChainLinkMerchant::class, 'fa_supply_chain_id');
}
/**

View File

@ -28,7 +28,7 @@
*/
public function supplyChain()
{
return $this->hasOne(SupplyChain::class);
return $this->hasOne(SupplyChain::class, 'id', 'fa_supply_chain_id');
}
/**
@ -39,6 +39,6 @@
*/
public function merchant()
{
return $this->hasOne();
return $this->hasOne(Merchant::class, 'mer_id', 'eb_merchant_id');
}
}

View File

@ -180,7 +180,8 @@
data: [],
radio: true,
initValue: [],
disabled: group_access == 2 || group_access==4 ? true : false
disabled: group_access == 2 || group_access==4 ? true : false,
});
$.get('/api/geo/street?pcode=' + id, function (result) {

View File

@ -19,6 +19,7 @@
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
<input type="hidden" name="id" value="{$detail.id}">
<h3 class="pb-3">编辑</h3>
<table class="layui-table layui-table-form">
<tr>
@ -37,12 +38,12 @@
<tr>
<td colspan="4">
<div class="layui-col-md4">
<div class="layui-col-md12">
<label class="layui-form-label">已选商户<font>*</font></label>
<div class="layui-input-block" id="merchantList" >
{$detail}
{volist name='arealist' id='vo'}
{/volist}
{volist name='detail.merchant' id='vo'}
<input type="checkbox" name="mer_id[]" value="{$vo.mer_id}" title="{$vo.mer_name}" checked>
{/volist}
</div>
</div>
</td>
@ -86,14 +87,12 @@
{else /}
<option value="{$vo.area_code}" >{$vo.area_name}</option>
{/if}
<option value="{$vo.area_code}" >{$vo.area_name}</option>
{/volist}
</select>
</div>
<div class="layui-col-md4">
<label class="layui-form-label">街道/镇</label>
<div class="layui-input-block">
{$detail.address}
<div id="demo1"></div>
</div>
</div>
@ -114,6 +113,7 @@
{block name="script"}
<script src="/static/assets/js/jquery.min.js"></script>
<script src="/static/assets/js/addrHelper.js"></script>
<script src="/static/assets/js/xm-select.js"></script>
<script>
var moduleInit = ['tool','tinymce'];
@ -153,7 +153,7 @@ function gouguInit() {
}
}
tool.post('{$url[1]}', data.field, callback);
tool.post('{$url[2]}', data.field, callback);
return false;
});
@ -173,6 +173,8 @@ function gouguInit() {
var group_access = "{:session('gougu_admin')['group_access']}";
street("{$detail.area.area_code}");
function street (id) {
if(id == null || id == '')
{
@ -188,7 +190,7 @@ function gouguInit() {
},
data: [],
radio: true,
initValue: [],
initValue: ['{$detail.street_id}'],
disabled: group_access == 2 || group_access==4 ? true : false
});

View File

@ -73,8 +73,7 @@
align: 'center',
templet: function (d)
{
var html = 11;
return html;
return d.area.area_name + d.street.street_name;
},
width:120,
},{
@ -89,7 +88,7 @@
},
},{
field: 'name',
title: '名',
title: '名',
align: 'center',
width:120,
},{
@ -122,7 +121,7 @@
title: '取消支付订单数量',
align: 'center',
width:150,
},,{
},{
field: 'status',
title: '状态',
align: 'center',

View File

@ -0,0 +1,280 @@
{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
<form class="layui-form gg-form-bar border-t border-x">
<div class="layui-input-inline" style="width:300px;">
<input type="text" name="keywords" placeholder="请输入商户名称" class="layui-input" autocomplete="off" />
</div>
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">搜索</button>
</form>
<table class="layui-hide" id="article" lay-filter="article"></table>
</div>
<script type="text/html" id="status">
<i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
</script>
<script type="text/html" id="is_home">
<i class="layui-icon {{# if(d.is_home == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
</script>
<script type="text/html" id="thumb">
</script>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
{if {:auth_cache(session('gougu_admin')['id'],$url[1])}==true}
<span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加">+ 添加</span>
{/if}
</div>
</script>
<script type="text/html" id="barDemo">
<div class="layui-btn-group">
<!-- {if {:auth_cache(session('gougu_admin')['id'],$url[4])}==true}
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">查看</a>
{/if} -->
{if {:auth_cache(session('gougu_admin')['id'],$url[2])}==true}
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
{/if}
{if {:auth_cache(session('gougu_admin')['id'],$url[3])}==true}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
{/if}
</div>
</script>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
const moduleInit = ['tool'];
function gouguInit() {
var table = layui.table,tool = layui.tool, form = layui.form;
layui.pageTable = table.render({
elem: '#article',
title: '列表',
toolbar: '#toolbarDemo',
url: '{$url[5]}',
page: true,
limit: 20,
cols: [
[
{
fixed: 'left',
field: 'order_id',
title: '编号',
align: 'center',
width:80,
},{
fixed: 'left',
field: 'order_sn',
title: '订单号',
align: 'center',
width:200,
},{
field: 'merchant',
title: '商户',
align: 'center',
templet: function (d)
{
return d.merchant.mer_name;
},
width:120,
},{
field: 'cart_id',
title: '商品名称',
align: 'center',
templet: function (d)
{
var cart = d.cart_id;
var html = '';
for (let index = 0; index < cart.length; index++) {
const element = cart[index];
html+= element.product.store_name;
}
return html;
},
width:120,
},{
field: 'total_num',
title: '商品数量',
align: 'center',
width:120,
},{
field: 'total_price',
title: '订单金额',
align: 'center',
width:120,
},{
field: 'pay_price',
title: '支付金额',
align: 'center',
width:150,
},{
field: 'uid',
title: '用户',
align: 'center',
templet: function (d)
{
var html = d.uid;
return html;
},
width:150,
},{
field: 'paid',
title: '支付状态',
align: 'center',
templet: function (d)
{
switch (d.paid) {
case 0:
var html = '未支付';
break;
case 1:
var html = '已支付';
break;
}
return html;
},
width:150,
},{
field: 'delivery_type',
title: '物品类型',
align: 'center',
templet: function (d)
{
switch (d.delivery_type) {
case 1:
var html = '发货';
break;
case 2:
var html = '送货';
break;
case 3:
var html = '虚拟';
break;
default:
var html = '待定';
break;
}
return html;
},
width:150,
},{
field: 'pay_type',
title: '支付方式',
align: 'center',
templet: function (d)
{
switch (d.pay_type) {
case 0:
var html = '余额';
break;
case 1:
var html = '微信';
break;
case 2:
var html = '小程序';
break;
case 3:
var html = 'h5';
break;
case 4:
var html = '支付宝';
break;
case 5:
var html = '支付宝扫码';
break;
case 6:
var html = '微信扫码';
break;
default:
var html = '未知的支付方式';
break;
}
return html;
},
width:150,
},{
field: 'mark',
title: '备注',
align: 'center',
width:150,
},{
field: 'verify_time',
title: '核销时间',
align: 'center',
width:150,
},{
field: 'pay_time',
title: '支付时间',
align: 'center',
width:150,
},{
field: 'create_time',
title: '下单时间',
align: 'center',
width:150,
}
]
]
});
//监听表头工具栏事件
table.on('toolbar(article)', function(obj){
if (obj.event === 'add') {
tool.side('{$url[1]}');
return false;
}
});
//监听表格行工具事件
table.on('tool(article)', function(obj) {
var data = obj.data;
if (obj.event === 'read') {
tool.side('{$url[4]}?id='+obj.data.id);
}
else if (obj.event === 'edit') {
tool.side('{$url[2]}?id='+obj.data.id);
}
else if (obj.event === 'del') {
layer.confirm('确定要删除该记录吗?', {
icon: 3,
title: '提示'
}, function(index) {
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
obj.del();
}
}
tool.delete('{$url[3]}', { id: data.id }, callback);
layer.close(index);
});
}
return false;
});
//监听搜索提交
form.on('submit(searchform)', function(data) {
layui.pageTable.reload({
where: {
keywords: data.field.keywords,
cate_id: data.field.cate_id
},
page: {
curr: 1
}
});
return false;
});
}
</script>
{/block}
<!-- /脚本 -->

View File

@ -5,7 +5,7 @@
<div class="p-3">
<form class="layui-form gg-form-bar border-t border-x">
<div class="layui-input-inline" style="width:300px;">
<input type="text" name="keywords" placeholder="请输入负责人姓名" class="layui-input" autocomplete="off" />
<input type="text" name="keywords" placeholder="请输入商户名称" class="layui-input" autocomplete="off" />
</div>
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">搜索</button>
</form>
@ -56,7 +56,7 @@
elem: '#article',
title: '列表',
toolbar: '#toolbarDemo',
url: '{$url[0]}',
url: '{$url[4]}',
page: true,
limit: 20,
cols: [
@ -68,53 +68,138 @@
align: 'center',
width:80,
},{
field: 'area',
title: '区域',
fixed: 'left',
field: 'supplyChain',
title: '供应链',
align: 'center',
templet: function (d)
{
var html = '【' + d['area']['area_name'] + '】'
var html = d.supplyChain.name;
return html;
},
width:120,
},{
field: 'name',
title: '姓名',
align: 'center',
width:120,
},{
field: 'duty',
title: '职务',
align: 'center',
width:150,
},{
field: 'phone',
title: '电话',
align: 'center',
width:150,
},{
field: 'status',
title: '状态',
field: 'brokerage',
title: '团队负责人',
align: 'center',
templet: function (d)
{
var html = '<span style="color:#fbbc05">禁用</span>';
if (d.status == '0') {
var html = d.principal ? '是': '否';
return html;
},
width:150,
},{
field: 'merchant',
title: '商户',
align: 'center',
templet: function (d)
{
var html = d.merchant.mer_name;
return html;
},
width:120,
},{
field: 'merchant',
title: '姓名',
align: 'center',
templet: function (d)
{
var html = d.merchant.real_name;
return html;
},
width:150,
},{
field: 'merchant',
title: '联系电话',
align: 'center',
templet: function (d)
{
var html = d.merchant.mer_phone;
return html;
},
width:150,
},{
field: 'merchant',
title: '店铺状态',
align: 'center',
templet: function (d)
{
var html = '<span style="color:#fbbc05">锁定</span>';
if (d.merchant.status == 1) {
html = '<span style="color:#12bb37">正常</span>';
}
return html;
},
},{
field: 'created_at',
title: '添加时间',
field: 'merchant',
title: '产品数量',
align: 'center',
templet: function (d)
{
var html = d.merchant.mer_phone;
return html;
},
width:150,
},{
field: 'merchant',
title: '产品数量',
align: 'center',
templet: function (d)
{
var html = d.merchant.mer_phone;
return html;
},
width:150,
},{
field: 'merchant',
title: '余额',
align: 'center',
templet: function (d)
{
var html = d.merchant.mer_money;
return html;
},
width:150,
},{
field: 'merchant',
title: '保证金',
align: 'center',
templet: function (d)
{
var html = d.merchant.margin;
return html;
},
width:150,
},{
field: 'order_number',
title: '销量',
align: 'center',
templet: function (d)
{
var html = d.merchant.sales;
return html;
},
width:150,
},{
field: 'merchant',
title: '商户地址',
templet: function (d)
{
var html = d.merchant.mer_address;
return html;
},
align: 'center',
width:150,
},{
fixed: 'right',
field: 'right',
title: '操作',
toolbar: '#barDemo',
align: 'center'
field: 'merchant',
title: '入驻时间',
align: 'center',
templet: function (d)
{
var html = d.merchant.create_time;
return html;
},
width:150,
}
]
]