mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
修改配送区域管理
This commit is contained in:
parent
05711afcdc
commit
d073d692b7
@ -39,13 +39,19 @@ class ShopTruckTemplate extends Controller
|
|||||||
* 配送区域管理
|
* 配送区域管理
|
||||||
* @auth true
|
* @auth true
|
||||||
* @menu true
|
* @menu true
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
*/
|
*/
|
||||||
public function region()
|
public function region()
|
||||||
{
|
{
|
||||||
if ($this->request->isGet()) {
|
if ($this->request->isGet()) {
|
||||||
$this->title = '配送区域管理';
|
$this->title = '配送区域管理';
|
||||||
$this->citys = TruckService::instance()->region(3);
|
$this->citys = TruckService::instance()->region(3, null);
|
||||||
$this->fetch('form_region');
|
$this->fetch('form_region');
|
||||||
|
} else {
|
||||||
|
$data = $this->_vali(['nos.default' => '', 'oks.default' => '']);
|
||||||
|
if ($data['nos']) $this->app->db->name('ShopTruckRegion')->whereIn('id', explode(',', $data['nos']))->update(['status' => 0]);
|
||||||
|
if ($data['oks']) $this->app->db->name('ShopTruckRegion')->whereIn('id', explode(',', $data['oks']))->update(['status' => 1]);
|
||||||
|
$this->success('修改配送区域成功!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +91,7 @@ class ShopTruckTemplate extends Controller
|
|||||||
$data['code'] = CodeExtend::uniqidDate(12, 'T');
|
$data['code'] = CodeExtend::uniqidDate(12, 'T');
|
||||||
}
|
}
|
||||||
if ($this->request->isGet()) {
|
if ($this->request->isGet()) {
|
||||||
$this->citys = TruckService::instance()->region(2);
|
$this->citys = TruckService::instance()->region(2, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,28 +14,38 @@ use think\admin\service\InterfaceService;
|
|||||||
class TruckService extends Service
|
class TruckService extends Service
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 楚才开放平台接口账号
|
* 模拟计算快递费用
|
||||||
* 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥
|
* @return string
|
||||||
* @var string
|
|
||||||
*/
|
*/
|
||||||
protected $appid = '6998081316132228';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 楚才开放平台接口密钥
|
|
||||||
* 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $appkey = '193fc1d9a2aac78475bc8dbeb9a5feb1';
|
|
||||||
|
|
||||||
public function amount()
|
public function amount()
|
||||||
{
|
{
|
||||||
|
return '0.00';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function region($level = 3)
|
/**
|
||||||
|
* 配送区域树型数据
|
||||||
|
* @param integer $level 最大级别
|
||||||
|
* @param integer $status 状态筛选
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function region($level = 3, $status = null)
|
||||||
{
|
{
|
||||||
$items = $this->app->db->name('ShopTruckRegion')->where('level', '<=', $level)->column('id,pid,name,status', 'id');
|
$query = $this->app->db->name('ShopTruckRegion');
|
||||||
return DataExtend::arr2tree($items, 'id', 'pid', 'subs');
|
if (is_numeric($level)) $query->where('level', '<=', $level);
|
||||||
|
if (is_numeric($status)) $query->where(['status' => $status]);
|
||||||
|
$items = DataExtend::arr2tree($query->column('id,pid,name,status', 'id'), 'id', 'pid', 'subs');
|
||||||
|
// 排序子集为空的省份和城市
|
||||||
|
foreach ($items as $ik => $item) {
|
||||||
|
foreach ($item['subs'] as $ck => $city) {
|
||||||
|
if (isset($city['subs']) && empty($city['subs'])) {
|
||||||
|
unset($items[$ik]['subs'][$ck]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($item['subs']) && empty($item['subs'])) {
|
||||||
|
unset($items[$ik]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,9 +57,7 @@ class TruckService extends Service
|
|||||||
*/
|
*/
|
||||||
public function query($code, $number)
|
public function query($code, $number)
|
||||||
{
|
{
|
||||||
$service = InterfaceService::instance();
|
return $this->_getInterface()->doRequest('https://open.cuci.cc/user/api.auth.express/query', [
|
||||||
$service->setAuth($this->appid, $this->appkey);
|
|
||||||
return $service->doRequest('https://open.cuci.cc/user/api.auth.express/query', [
|
|
||||||
'type' => 'free', 'express' => $code, 'number' => $number,
|
'type' => 'free', 'express' => $code, 'number' => $number,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -60,10 +68,20 @@ class TruckService extends Service
|
|||||||
* @throws \think\admin\Exception
|
* @throws \think\admin\Exception
|
||||||
*/
|
*/
|
||||||
public function company()
|
public function company()
|
||||||
|
{
|
||||||
|
return $this->_getInterface()->doRequest('https://open.cuci.cc/user/api.auth.express/getCompany');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取楚才开放平台接口实例
|
||||||
|
* @return InterfaceService
|
||||||
|
*/
|
||||||
|
private function _getInterface(): InterfaceService
|
||||||
{
|
{
|
||||||
$service = InterfaceService::instance();
|
$service = InterfaceService::instance();
|
||||||
$service->setAuth($this->appid, $this->appkey);
|
// 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥
|
||||||
return $service->doRequest('https://open.cuci.cc/user/api.auth.express/getCompany');
|
$service->setAuth("6998081316132228", "193fc1d9a2aac78475bc8dbeb9a5feb1");
|
||||||
|
return $service;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,36 +4,33 @@
|
|||||||
<div class="think-box-shadow" id="TruckForm">
|
<div class="think-box-shadow" id="TruckForm">
|
||||||
<div class="padding-40">
|
<div class="padding-40">
|
||||||
<div class="layui-card">
|
<div class="layui-card">
|
||||||
<div class="layui-card-header">配送区域</div>
|
<div class="layui-card-header layui-bg-gray">配送区域</div>
|
||||||
<div class="layui-card-body">
|
<div class="layui-card-body">
|
||||||
<div ng-repeat="x in items" ng-click="SetActiveProvince(x)" ng-class="{false:'layui-btn-warm'}[x.status]" class="layui-btn layui-btn-radius margin-left-0 margin-right-5 margin-bottom-5">
|
<div ng-repeat="x in items" ng-click="SetActiveProvince(x)" ng-class="{true:'layui-btn-normal',false:'layui-btn-warm'}[x.status]" class="layui-btn layui-btn-radius margin-left-0 margin-right-5 margin-bottom-5">
|
||||||
<label class="think-checkbox margin-right-0"><input ng-change="SetChangeCity(x,x.status)" type="checkbox" ng-model="x.status"></label>
|
<label class="think-checkbox margin-right-0"><input ng-change="SetChangeCity(x,x.status)" type="checkbox" ng-model="x.status"></label><span ng-bind="x.name"></span>
|
||||||
<span ng-bind="x.name"></span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-card">
|
<div class="layui-card">
|
||||||
<div class="layui-card-header"><b class="color-green">{{province.name}}</b> 可选区域</div>
|
<div class="layui-card-header layui-bg-gray"><b class="color-green" ng-bind="province.name"></b> 可选区域</div>
|
||||||
<div class="layui-card-body">
|
<div class="layui-card-body">
|
||||||
<div ng-repeat="x in province.subs" ng-click="SetActiveCity(x)" ng-class="{false:'layui-btn-warm'}[x.status]" class="layui-btn layui-btn-radius margin-left-0 margin-right-5 margin-bottom-5">
|
<div ng-repeat="x in province.subs" ng-click="SetActiveCity(x)" ng-class="{true:'layui-btn-normal',false:'layui-btn-warm'}[x.status]" class="layui-btn layui-btn-radius margin-left-0 margin-right-5 margin-bottom-5">
|
||||||
<label class="think-checkbox margin-right-0"><input ng-change="SetChangeCity(x,x.status)" type="checkbox" ng-model="x.status"></label>
|
<label class="think-checkbox margin-right-0"><input ng-change="SetChangeCity(x,x.status)" type="checkbox" ng-model="x.status"></label><span ng-bind="x.name"></span>
|
||||||
<span ng-bind="x.name"></span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-card">
|
<div class="layui-card">
|
||||||
<div class="layui-card-header"><b class="color-green">{{city.name}}</b> 可选区域</div>
|
<div class="layui-card-header layui-bg-gray"><b class="color-green" ng-bind="city.name"></b> 可选区域</div>
|
||||||
<div class="layui-card-body">
|
<div class="layui-card-body">
|
||||||
<div ng-repeat="x in city.subs" ng-class="{false:'layui-btn-warm'}[x.status]" class="layui-btn layui-btn-radius margin-left-0 margin-right-5 margin-bottom-5">
|
<div ng-repeat="x in city.subs" ng-class="{true:'layui-btn-normal',false:'layui-btn-warm'}[x.status]" class="layui-btn layui-btn-radius margin-left-0 margin-right-5 margin-bottom-5">
|
||||||
<label class="think-checkbox margin-right-0"><input ng-change="SetChangeCity(x,x.status)" type="checkbox" ng-model="x.status"></label>
|
<label class="think-checkbox margin-right-0"><input type="checkbox" ng-model="x.status"></label><span ng-bind="x.name"></span>
|
||||||
<span ng-bind="x.name"></span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="hr-line-dashed"></div>
|
</div>
|
||||||
<div class="layui-form-item text-center">
|
<div class="hr-line-dashed margin-top-40"></div>
|
||||||
<button class="layui-btn" ng-click="SetRuleItem()">确定修改</button>
|
<div class="layui-form-item text-center">
|
||||||
</div>
|
<button class="layui-btn" ng-click="Confirm()">确定修改</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -43,11 +40,14 @@
|
|||||||
<script>
|
<script>
|
||||||
require(['angular'], function () {
|
require(['angular'], function () {
|
||||||
var app = angular.module("TruckForm", []).run(callback);
|
var app = angular.module("TruckForm", []).run(callback);
|
||||||
var _data = document.getElementById('RegionData').value || '[]';
|
var data = document.getElementById('RegionData').value || '[]';
|
||||||
angular.bootstrap(document.getElementById(app.name), [app.name]);
|
angular.bootstrap(document.getElementById(app.name), [app.name]);
|
||||||
|
|
||||||
function callback($rootScope) {
|
function callback($rootScope) {
|
||||||
$rootScope.items = angular.fromJson(_data);
|
$rootScope.items = angular.fromJson(data);
|
||||||
|
$rootScope.province = $rootScope.items[0];
|
||||||
|
$rootScope.city = $rootScope.province.subs[0];
|
||||||
|
/*! 数据显示状态转换 */
|
||||||
$rootScope.items.forEach(function (province) {
|
$rootScope.items.forEach(function (province) {
|
||||||
province.status = !!province.status;
|
province.status = !!province.status;
|
||||||
if (province.subs) province.subs.forEach(function (city) {
|
if (province.subs) province.subs.forEach(function (city) {
|
||||||
@ -57,8 +57,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$rootScope.province = $rootScope.items[0];
|
/*! 切换下级区域选中状态 */
|
||||||
$rootScope.city = $rootScope.province.subs[0];
|
|
||||||
$rootScope.SetChangeCity = function (item, status) {
|
$rootScope.SetChangeCity = function (item, status) {
|
||||||
if (item.subs) item.subs.forEach(function (item) {
|
if (item.subs) item.subs.forEach(function (item) {
|
||||||
item.status = status;
|
item.status = status;
|
||||||
@ -67,13 +66,43 @@
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
/*! 切换显示省份对象 */
|
||||||
$rootScope.SetActiveProvince = function (province) {
|
$rootScope.SetActiveProvince = function (province) {
|
||||||
$rootScope.city = province.subs[0];
|
$rootScope.city = province.subs[0];
|
||||||
$rootScope.province = province;
|
$rootScope.province = province;
|
||||||
};
|
};
|
||||||
|
/*! 切换显示城市对象 */
|
||||||
$rootScope.SetActiveCity = function (city) {
|
$rootScope.SetActiveCity = function (city) {
|
||||||
$rootScope.city = city;
|
$rootScope.city = city;
|
||||||
}
|
}
|
||||||
|
/*! 数据监听切换同步 */
|
||||||
|
$rootScope.$watch('province', function () {
|
||||||
|
$rootScope.province.status = $rootScope.province.subs.some(function (city) {
|
||||||
|
if (city.status) return true;
|
||||||
|
});
|
||||||
|
}, true);
|
||||||
|
$rootScope.$watch('city', function () {
|
||||||
|
$rootScope.city.status = $rootScope.city.subs.some(function (area) {
|
||||||
|
if (area.status) return true;
|
||||||
|
});
|
||||||
|
}, true);
|
||||||
|
/*! 确认并更新到数据库 */
|
||||||
|
$rootScope.Confirm = function () {
|
||||||
|
var nos = [], oks = [];
|
||||||
|
$rootScope.items.forEach(function (province) {
|
||||||
|
province.status ? oks.push(province.id) : nos.push(province.id);
|
||||||
|
if (province.subs) province.subs.forEach(function (city) {
|
||||||
|
city.status ? oks.push(city.id) : nos.push(city.id);
|
||||||
|
if (city.subs) city.subs.forEach(function (area) {
|
||||||
|
area.status ? oks.push(area.id) : nos.push(area.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
/*! 提交数据并返回结果 */
|
||||||
|
$.form.load('{:url("region")}', {nos: nos.join(','), oks: oks.join(',')}, 'post', function (ret) {
|
||||||
|
return ret.code ? $.msg.success(ret.info) : $.msg.error(ret.info), false;
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user