mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
添加快递公司管理
This commit is contained in:
parent
e006d1461d
commit
6a298cf7ac
@ -3,6 +3,7 @@
|
||||
namespace app\data\controller;
|
||||
|
||||
use app\data\service\OrderService;
|
||||
use app\data\service\TruckService;
|
||||
use think\admin\Controller;
|
||||
use think\exception\HttpResponseException;
|
||||
|
||||
@ -123,7 +124,7 @@ class ShopOrder extends Controller
|
||||
'code.require' => '快递编号不能为空!',
|
||||
'number.require' => '配送单号不能为空!',
|
||||
]);
|
||||
$this->result = OrderService::instance()->trackExpress($data['code'], $data['number']);
|
||||
$this->result = TruckService::instance()->query($data['code'], $data['number']);
|
||||
if (empty($this->result['code'])) $this->error($this->result['info']);
|
||||
$this->fetch('truck_query');
|
||||
} catch (HttpResponseException $exception) {
|
||||
|
112
app/data/controller/ShopTruckCompany.php
Normal file
112
app/data/controller/ShopTruckCompany.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace app\data\controller;
|
||||
|
||||
use app\data\service\TruckService;
|
||||
use app\store\service\OpenCuciService;
|
||||
use think\admin\Controller;
|
||||
use think\admin\service\SystemService;
|
||||
use think\exception\HttpResponseException;
|
||||
|
||||
/**
|
||||
* 配送快递公司管理
|
||||
* Class ShopTruckCompany
|
||||
* @package app\data\controller
|
||||
*/
|
||||
class ShopTruckCompany extends Controller
|
||||
{
|
||||
/**
|
||||
* 绑定数据表
|
||||
* @var string
|
||||
*/
|
||||
private $table = 'ShopTruckCompany';
|
||||
|
||||
/**
|
||||
* 快递公司管理
|
||||
* @auth true
|
||||
* @menu true
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->title = '快递公司管理';
|
||||
$query = $this->_query($this->table);
|
||||
$query->like('name,code')->equal('status')->dateBetween('craete_at');
|
||||
// 加载对应数据
|
||||
$this->type = $this->request->get('type', 'index');
|
||||
if ($this->type === 'index') $query->where(['status' => '1']);
|
||||
elseif ($this->type === 'recycle') $query->where(['status' => '0']);
|
||||
// 列表显示分页
|
||||
$query->where(['deleted' => 0])->order('sort desc,id desc')->page();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加快递公司
|
||||
* @auth true
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$this->title = '添加快递公司';
|
||||
$this->_form($this->table, 'form');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑快递公司
|
||||
* @auth true
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$this->title = '编辑快递公司';
|
||||
$this->_form($this->table, 'form');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改快递公司状态
|
||||
* @auth true
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function state()
|
||||
{
|
||||
$this->_save($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除快递公司
|
||||
* @auth true
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
$this->_delete($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步快递公司
|
||||
* @auth true
|
||||
*/
|
||||
public function synchronize()
|
||||
{
|
||||
try {
|
||||
$result = TruckService::instance()->company();
|
||||
if (empty($result['code'])) $this->error($result['info']);
|
||||
foreach ($result['data'] as $vo) SystemService::instance()->save($this->table, [
|
||||
'code_1' => $vo['code_1'], 'code_2' => $vo['code_2'],
|
||||
'code_3' => $vo['code_3'], 'name' => $vo['title'], 'deleted' => 0,
|
||||
], 'code_1');
|
||||
$this->success('同步快递公司成功!');
|
||||
} catch (HttpResponseException $exception) {
|
||||
throw $exception;
|
||||
} catch (\Exception $exception) {
|
||||
$this->error('同步快递公司数据失败!');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -5,6 +5,7 @@ namespace app\data\controller\api\auth;
|
||||
use app\data\controller\api\Auth;
|
||||
use app\data\service\GoodsService;
|
||||
use app\data\service\OrderService;
|
||||
use app\data\service\TruckService;
|
||||
use app\wechat\service\WechatService;
|
||||
use think\admin\extend\CodeExtend;
|
||||
use think\exception\HttpResponseException;
|
||||
@ -297,7 +298,7 @@ class Order extends Auth
|
||||
$data = $this->_vali([
|
||||
'code.require' => '快递编号不能为空!', 'number.require' => '配送单号不能为空!',
|
||||
]);
|
||||
$result = OrderService::instance()->trackExpress($data['code'], $data['number']);
|
||||
$result = TruckService::instance()->query($data['code'], $data['number']);
|
||||
empty($result['code']) ? $this->error($result['info']) : $this->success('快递追踪信息', $result);
|
||||
} catch (HttpResponseException $exception) {
|
||||
throw $exception;
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace app\data\service;
|
||||
|
||||
use think\admin\Service;
|
||||
use think\admin\service\InterfaceService;
|
||||
|
||||
/**
|
||||
* 订单数据服务
|
||||
@ -48,23 +47,6 @@ class OrderService extends Service
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 楚才开放平台快递查询
|
||||
* @param string $code 快递公司编号
|
||||
* @param string $number 快递配送单号
|
||||
* @return array
|
||||
* @throws \think\admin\Exception
|
||||
*/
|
||||
public function trackExpress($code, $number)
|
||||
{
|
||||
$service = InterfaceService::instance();
|
||||
// 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥
|
||||
$service->setAuth('6998081316132228', '193fc1d9a2aac78475bc8dbeb9a5feb1');
|
||||
return $service->doRequest('https://open.cuci.cc/user/api.auth.express/query', [
|
||||
'type' => 'free', 'express' => $code, 'number' => $number,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定订单详情数据
|
||||
* @param array $data
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace app\data\service;
|
||||
|
||||
use think\admin\Service;
|
||||
use think\admin\service\InterfaceService;
|
||||
|
||||
/**
|
||||
* 快递运输服务
|
||||
@ -11,9 +12,51 @@ use think\admin\Service;
|
||||
*/
|
||||
class TruckService extends Service
|
||||
{
|
||||
/**
|
||||
* 楚才开放平台接口账号
|
||||
* 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥
|
||||
* @var string
|
||||
*/
|
||||
protected $appid = '6998081316132228';
|
||||
|
||||
/**
|
||||
* 楚才开放平台接口密钥
|
||||
* 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥
|
||||
* @var string
|
||||
*/
|
||||
protected $appkey = '193fc1d9a2aac78475bc8dbeb9a5feb1';
|
||||
|
||||
public function amount()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 楚才开放平台快递查询
|
||||
* @param string $code 快递公司编号
|
||||
* @param string $number 快递配送单号
|
||||
* @return array
|
||||
* @throws \think\admin\Exception
|
||||
*/
|
||||
public function query($code, $number)
|
||||
{
|
||||
$service = InterfaceService::instance();
|
||||
$service->setAuth($this->appid, $this->appkey);
|
||||
return $service->doRequest('https://open.cuci.cc/user/api.auth.express/query', [
|
||||
'type' => 'free', 'express' => $code, 'number' => $number,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 楚才开放平台快递公司
|
||||
* @return array
|
||||
* @throws \think\admin\Exception
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
$service = InterfaceService::instance();
|
||||
$service->setAuth($this->appid, $this->appkey);
|
||||
return $service->doRequest('https://open.cuci.cc/user/api.auth.express/getCompany');
|
||||
}
|
||||
|
||||
}
|
42
app/data/view/shop_truck_company/form.html
Normal file
42
app/data/view/shop_truck_company/form.html
Normal file
@ -0,0 +1,42 @@
|
||||
<form onsubmit="return false;" action="{:request()->url()}" data-auto="true" method="post" class='layui-form layui-card' autocomplete="off">
|
||||
|
||||
<div class="layui-card-body padding-left-40">
|
||||
|
||||
<label class="layui-form-item block relative">
|
||||
<span class="color-green font-w7 margin-right-5">快递公司名称</span><span class="nowrap color-desc">Name</span>
|
||||
<input name="name" required value='{$vo.name|default=""}' placeholder="请输入快递公司名称" class="layui-input">
|
||||
<p class="color-desc">必填,快递公司名称用于显示快递配送的公司标识,请尽量保持其精准性。</p>
|
||||
</label>
|
||||
|
||||
<label class="layui-form-item block relative">
|
||||
<span class="color-green font-w7 margin-right-5">快递鸟接口查询编码</span><span class="nowrap color-desc">Code01</span>
|
||||
<input name="code_1" required value='{$vo.code_1|default=""}' placeholder="请输入快递鸟接口查询编码" class="layui-input">
|
||||
<p class="color-desc">必填,快递公司对应在快递鸟接口的编码,可以从快递鸟官方接口文档中获取到。</p>
|
||||
</label>
|
||||
|
||||
<label class="layui-form-item block relative">
|
||||
<span class="color-green font-w7 margin-right-5">快递100百度查询编码</span><span class="nowrap color-desc">Code02</span>
|
||||
<input name="code_2" value='{$vo.code_2|default=""}' placeholder="请输入快递100百度查询编码" class="layui-input">
|
||||
<p class="color-desc">可选,快递公司在百度快递100应用程序搜索时使用的编码,需要使用网络模拟请求抓取。</p>
|
||||
</label>
|
||||
|
||||
<label class="layui-form-item block relative">
|
||||
<span class="color-green font-w7 margin-right-5">快递100接口查询编码</span><span class="nowrap color-desc">Code03</span>
|
||||
<input name="code_3" value='{$vo.code_3|default=""}' placeholder="请输入快递100接口查询编码" class="layui-input">
|
||||
<p class="color-desc">必填,快递公司对应在快递100接口的编码,可以从快递100官方接口文档中获取到。</p>
|
||||
</label>
|
||||
|
||||
<label class="layui-form-item block relative">
|
||||
<span class="color-green font-w7 margin-right-5">快递公司描述</span><span class="nowrap color-desc">Remark</span>
|
||||
<textarea class="layui-textarea" name="remark" placeholder="请输入快递公司描述">{$vo.remark|default=''}</textarea>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}
|
||||
|
||||
<div class="layui-form-item text-center">
|
||||
<button class="layui-btn" type='submit'>保存数据</button>
|
||||
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
|
||||
</div>
|
||||
</form>
|
91
app/data/view/shop_truck_company/index.html
Normal file
91
app/data/view/shop_truck_company/index.html
Normal file
@ -0,0 +1,91 @@
|
||||
{extend name="../../admin/view/main"}
|
||||
|
||||
{block name="button"}
|
||||
<!--{if auth("synchronize") and $type eq 'index'}-->
|
||||
<button data-load='{:url("synchronize")}' data-confirm="确定要同步快递公司数据吗?" class='layui-btn layui-btn-sm layui-btn-primary'>同步公司</button>
|
||||
<!--{/if}-->
|
||||
<!--{if auth("add") and $type eq 'index'}-->
|
||||
<button data-modal='{:url("add")}' data-title="添加快递公司" class='layui-btn layui-btn-sm layui-btn-primary'>添加公司</button>
|
||||
<!--{/if}-->
|
||||
<!--{if auth("state") and $type eq 'index'}-->
|
||||
<button data-action='{:url("state")}' data-confirm="确定要禁用快递公司?" data-rule="id#{key};status#0" class='layui-btn layui-btn-sm layui-btn-primary'>批量禁用</button>
|
||||
<!--{/if}-->
|
||||
<!--{if auth("state") and $type eq 'recycle'}-->
|
||||
<button data-action='{:url("state")}' data-rule="id#{key};status#1" class='layui-btn layui-btn-sm layui-btn-primary'>批量启用</button>
|
||||
<!--{/if}-->
|
||||
<!--{if auth("remove") and $type eq 'recycle'}-->
|
||||
<button data-action='{:url("remove")}' data-csrf="{:systoken('remove')}" data-rule="id#{key}" class='layui-btn layui-btn-sm layui-btn-primary'>批量删除</button>
|
||||
<!--{/if}-->
|
||||
{/block}
|
||||
|
||||
{block name="content"}
|
||||
<div class="layui-badge think-bg-red padding-5 padding-left-10 font-s15 layui-anim layui-anim-upbit">
|
||||
注意:快递公司配置不能随意修改或删除,会影响到物流路径查询!如需添加新快递请联系客服!
|
||||
</div>
|
||||
<div class="layui-tab layui-tab-card think-bg-white">
|
||||
<ul class="layui-tab-title">
|
||||
{foreach ['index'=>'快递公司','recycle'=>'回 收 站'] as $k=>$v}
|
||||
{if $type eq $k}
|
||||
<li data-open="{:url('index')}?type={$k}" class="layui-this">{$v}</li>
|
||||
{else}
|
||||
<li data-open="{:url('index')}?type={$k}">{$v}</li>
|
||||
{/if}{/foreach}
|
||||
</ul>
|
||||
<div class="layui-tab-content think-box-shadow">
|
||||
{include file='shop_truck_company/index_search'}
|
||||
<table class="layui-table" lay-skin="line">
|
||||
{notempty name='list'}
|
||||
<thead>
|
||||
<tr>
|
||||
<th class='list-table-check-td think-checkbox'>
|
||||
<label><input data-auto-none data-check-target='.list-check-box' type='checkbox'></label>
|
||||
</th>
|
||||
<th class='list-table-sort-td'>
|
||||
<button type="button" data-reload class="layui-btn layui-btn-xs">刷 新</button>
|
||||
</th>
|
||||
<th class='text-left nowrap'>快递名称</th>
|
||||
<th class='text-center nowrap'>快递鸟接口编码</th>
|
||||
<th class='text-center nowrap'>快递100百度编码</th>
|
||||
<th class='text-center nowrap'>快递100接口编码</th>
|
||||
<th class="text-center">创建时间</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{/notempty}
|
||||
<tbody>
|
||||
{foreach $list as $key=>$vo}
|
||||
<tr data-dbclick>
|
||||
<td class='list-table-check-td think-checkbox'>
|
||||
<label><input class="list-check-box" value='{$vo.id}' type='checkbox'></label>
|
||||
</td>
|
||||
<td class='list-table-sort-td'>
|
||||
<label>
|
||||
<input data-action-blur="{:request()->url()}" data-value="id#{$vo.id};action#sort;sort#{value}" data-loading="false" value="{$vo.sort}" class="list-sort-input">
|
||||
</label>
|
||||
</td>
|
||||
<td class='text-left nowrap'>{$vo.name|default=''}</td>
|
||||
<td class='text-center nowrap'>{$vo.code_1|default='-'}</td>
|
||||
<td class='text-center nowrap'>{$vo.code_2|default='-'}</td>
|
||||
<td class='text-center nowrap'>{$vo.code_3|default='-'}</td>
|
||||
<td class='text-center nowrap'>{$vo.create_at|format_datetime}</td>
|
||||
<td class='text-left nowrap'>
|
||||
<!--{if auth("edit") and $type eq 'index'}-->
|
||||
<a data-dbclick class="layui-btn layui-btn-xs" data-title="编辑快递公司" data-modal='{:url("edit")}?id={$vo.id}'>编 辑</a>
|
||||
<!--{/if}-->
|
||||
<!--{if $vo.status eq 1 and auth("state")}-->
|
||||
<a class="layui-btn layui-btn-warm layui-btn-xs" data-action="{:url('state')}" data-value="id#{$vo.id};status#0">禁 用</a>
|
||||
<!--{elseif auth("state")}-->
|
||||
<a class="layui-btn layui-btn-warm layui-btn-xs" data-action="{:url('state')}" data-value="id#{$vo.id};status#1">启 用</a>
|
||||
<!--{/if}-->
|
||||
<!--{if auth("remove") and $type eq 'recycle'}-->
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" data-confirm="确定要删除数据吗?" data-action="{:url('remove')}" data-value="id#{$vo.id}">删 除</a>
|
||||
<!--{/if}-->
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
{empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
|
||||
</div>
|
||||
</div>
|
||||
{/block}
|
28
app/data/view/shop_truck_company/index_search.html
Normal file
28
app/data/view/shop_truck_company/index_search.html
Normal file
@ -0,0 +1,28 @@
|
||||
<fieldset>
|
||||
<legend>条件搜索</legend>
|
||||
<form class="layui-form layui-form-pane form-search" action="{:url('')}" onsubmit="return false" method="get" autocomplete="off">
|
||||
<div class="layui-form-item layui-inline">
|
||||
<label class="layui-form-label">快递名称</label>
|
||||
<div class="layui-input-inline">
|
||||
<input name="name" value="{:input('name','')}" placeholder="请输入快递名称" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-inline">
|
||||
<label class="layui-form-label">快递编码</label>
|
||||
<div class="layui-input-inline">
|
||||
<input name="code" value="{:input('code','')}" placeholder="请输入快递编码" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-inline">
|
||||
<label class="layui-form-label">添加时间</label>
|
||||
<div class="layui-input-inline">
|
||||
<input data-date-range name="create_at" value="{:input('create_at','')}" placeholder="请选择添加时间" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-inline">
|
||||
<button class="layui-btn layui-btn-primary"><i class="layui-icon"></i> 搜 索</button>
|
||||
</div>
|
||||
</form>
|
||||
</fieldset>
|
||||
|
||||
<script>form.render()</script>
|
Loading…
x
Reference in New Issue
Block a user