作者 jinglong
1 个管道 的构建 通过 耗费 6 秒

增加物流接口

... ... @@ -3,7 +3,8 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
use EasyWeChat\Factory;
/**
* 订单管理
*
... ... @@ -73,4 +74,107 @@ class Order extends Backend
}
return $this->view->fetch();
}
/**
* 录入物流单号
*/
public function code($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$params['status'] = config('verify.status')[5];
//查询快递公司名称
$company = Db::name('logistics')->where(['logi_code'=>$params['LogisticCode']])->field('id,logi_name')->find();
$params['LogisticCompany'] = $company['logi_name'];
$result = $row->allowField(true)->save($params);
if($result){
$this->success('发货成功');
}else{
$this->error('失败');
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$arr = [];
$ship = Db::name('logistics')->select();
foreach($ship as $value){
$arr[$value['logi_code']] = $value['logi_name'];
}
$this->view->assign('order_id',$ids);
$this->view->assign('ship',$arr);
return $this->view->fetch();
}
/**
* 申请退款
*/
public function adoptRefund($ids)
{
if ($ids) {
$pk = $this->model->getPk();
$res = Db::name('order')->where($pk,$ids)->field('id,pay_order_sn,total_goods_price')->find();
$status = config('verify.status');
$res1 = $this->model->where($pk, '=', $ids)->update(['status'=>$status[4]]);
if($res1){
$this->success('成功');
}else{
$this->error('失败');
}
//处理退款逻辑
// $config = config('verify.wx_pay');
// $app = Factory::payment($config);
// $security_price = $res['total_goods_price']*100;
// $refundNumber = $this->genPayOrderSn('refund');//商户退款单号
// $result = $app->refund->byOutTradeNumber($res['pay_order_sn'], $refundNumber, $security_price, $security_price, [
// // 可在此处传入其他参数,详细参数见微信支付文档
// ]);
// if($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS'){
// $this->model->where($pk, '=', $ids)->update(['status'=>$status[4]]);
// $this->success('成功');
// }else{
// $this->error('退款失败');
// }
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
/**
* 申请退换货
*/
public function adoptReturn($ids)
{
if ($ids) {
$pk = $this->model->getPk();
$status = config('verify.status');
$res = $this->model->where($pk, '=', $ids)->update(['status'=>$status[7]]);
if($res){
$this->success('成功');
}else{
$this->error('失败');
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
//支付订单号
public static function genPayOrderSn($letter = '') {
$time = explode (" ", microtime ());
$timeArr = explode('.',$time [0]);
$mtime = array_pop($timeArr);
$fulltime = $letter.$time[1].$mtime.mt_rand(1000,9999);
return $fulltime;
}
}
... ...
... ... @@ -9,11 +9,15 @@ return [
'Receive_name' => '收货人',
'Receive_mobile' => '收获联系方式',
'Receive_address' => '收货地址',
'ShipperCode' => '快递单号',
'LogisticCompany' => '快递公司',
'Refund_reason' => '退款原因',
'Return_reason' => '退换货原因',
'Leave_message' => '留言',
'Discount_price' => '优惠价格',
'Total_goods_price' => '商品总金额',
'Total_expense_price' => '运费总金额',
'Total_price' => '支付总金额(商+运-优惠)',
'Total_price' => '支付总金额',
'Coupon_id' => '优惠券id',
'Createtime' => '创建时间',
'Updatetime' => '更新时间',
... ...
... ... @@ -7,8 +7,8 @@
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('ogoods/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('ogoods/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<!--<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('ogoods/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
<!--<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('ogoods/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>-->
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('ogoods/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('ogoods/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>-->
... ...
<form id="code-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<input type="hidden" name="row[id]" data-rule="required" value="{$order_id}">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">快递公司</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[LogisticCode]', $ship, null, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">单号</label>
<div class="col-xs-12 col-sm-8">
<input id="c-ShipperCode" data-rule="required" class="form-control" name="row[ShipperCode]" type="text" value="" placeholder="请录入快递单号">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Uid')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-uid" data-rule="required" class="form-control" name="row[uid]" type="number" value="{$row.uid|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-status" data-rule="required" class="form-control" name="row[status]" type="number" value="{$row.status|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Order_sn')}:</label>
<div class="col-xs-12 col-sm-8">
... ... @@ -43,6 +30,30 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('ShipperCode')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-ShipperCode" data-rule="required" class="form-control" name="row[ShipperCode]" type="text" value="{$row.ShipperCode|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('LogisticCompany')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-LogisticCompany" data-rule="required" class="form-control" name="row[LogisticCompany]" type="text" value="{$row.LogisticCompany|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Refund_reason')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-refund_reason" data-rule="required" class="form-control" name="row[refund_reason]" type="text" value="{$row.refund_reason|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Return_reason')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-return_reason" data-rule="required" class="form-control" name="row[return_reason]" type="text" value="{$row.return_reason|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Leave_message')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-leave_message" data-rule="required" class="form-control" name="row[leave_message]" type="text" value="{$row.leave_message|htmlentities}">
... ... @@ -72,16 +83,10 @@
<input id="c-total_price" class="form-control" step="0.01" name="row[total_price]" type="number" value="{$row.total_price|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-coupon_id" data-rule="required" data-source="coupon/index" class="form-control selectpage" name="row[coupon_id]" type="text" value="{$row.coupon_id|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<!--<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>-->
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
... ...
... ... @@ -7,7 +7,7 @@
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('order/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<!--<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('order/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('order/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('order/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('order/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>-->
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\api\controller;
use app\admin\model\Order;
use app\common\controller\Api;
use think\Db;
use think\Validate;
/**
* 物流接口
*/
class Express extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = '*';
protected $uid = '';//token存贮user_id
public function _initialize()
{
parent::_initialize();
$this->uid = $this->auth->getUserId();
}
/**
* @ApiTitle (调用查询物流轨迹)
* @ApiSummary (调用查询物流轨迹)
* @ApiMethod (GET)
* @ApiRoute (/api/express/getExpress)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="order_id", type="inter", required=true, description="订单id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1575532542",
"data": {
"LogisticCode": "75317246876602",//快递单号
"ShipperCode": "ZTO",//快递编码
"Traces": [
{
"AcceptStation": "【东莞市】 【东莞厚街】(0769-86947628) 的 张小姐(18027104980) 已揽收",//轨迹
"AcceptTime": "2019-12-03 18:43:03"//时间
},
{
"AcceptStation": "【东莞市】 快件离开 【东莞厚街】 已发往 【天津中转部】",
"AcceptTime": "2019-12-04 00:18:01"
},
{
"AcceptStation": "【天津市】 快件离开 【天津中转部】 已发往 【天津南开六部】",
"AcceptTime": "2019-12-05 14:35:03"
}
],
"State": "2",
"EBusinessID": "1442433",
"Success": true,
"LogisticCompany": "中通快递"//快递公司
}
})
*
*/
public function getExpress(){
$order_id = $this->request->get('order_id');
$rule = config('verify.order_detail');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['order_id'=>$order_id])) {
$this->error($validate->getError());
}
$where = ['id'=>$order_id,'uid'=>$this->uid];
$order = Common::findSoftWhereData('order',$where,'id,ShipperCode,LogisticCode,LogisticCompany');
if($order){
$logisticResult = $this->getOrderTracesByJson($order['LogisticCode'],$order['ShipperCode']);//快递编码,单号
$data = json_decode($logisticResult,true);
if($data['Success'] == true){//返回信息成功
$data['LogisticCompany'] = $order['LogisticCompany'];
$this->success('成功',$data);
}
$this->error('未找到物流踪迹');
}
$this->error('未找到物流踪迹');
}
/**
* 物流
* @ApiInternal
*/
public function getOrderTracesByJson($kgs,$number){
$express = config('verify.express');
$EBusinessID = $express['EBusinessID'];
$appKey = $express['appKey'];
$url = $express['url'];
$requestData= "{'OrderCode':'','ShipperCode':'$kgs','LogisticCode':'$number'}";
$data = array(
'EBusinessID' => $EBusinessID,
'RequestType' => '1002',
'RequestData' => urlencode($requestData) ,
'DataType' => '2',
);
$data['DataSign'] = $this->encrypt($requestData.$appKey);
$result = $this->auth->http_post($url, $data);
return $result;
}
/**
* 签名
* @ApiInternal
*/
public function encrypt($str) {
return urlencode(base64_encode(md5($str)));
}
}
... ...
... ... @@ -5,6 +5,12 @@ return [
'app_id' => 'wx322817859bfe5db1',//app_id
'secret' => '9166e17b56427e9eae2a5f49cfd3aeaf',//秘钥
],
//快递鸟配置
'express'=>[
'EBusinessID' =>'1442433',
'appKey' =>'59387773-4d1c-4006-a5c6-159261ed4fef',
'url' =>'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx',//请求地址
],
//微信支付配置
'wx_pay' => [
'app_id' => 'wx322817859bfe5db1',
... ...
此 diff 太大无法显示。
... ... @@ -7,7 +7,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
extend: {
index_url: 'ogoods/index' + location.search,
add_url: 'ogoods/add',
edit_url: 'ogoods/edit',
// edit_url: 'ogoods/edit',
del_url: 'ogoods/del',
multi_url: 'ogoods/multi',
table: 'ogoods',
... ...
... ... @@ -34,7 +34,71 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'user.nickname', title: __('User.nickname')},
{field: 'user.avatar', title: __('User.avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
{
name: 'detail',
text: __('录入单号'),
title: __('录入单号'),
classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-list',
url: 'order/code',
callback: function (data) {
//Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
},
visible: function (row) {
//返回true时按钮显示,返回false隐藏
if(row.status == 2){
return true;
}else{
return false;
}
}
},
{
name: 'detail',
text: __('同意'),
title: __('申请退款'),
classname: 'btn btn-xs btn-primary btn-ajax',
icon: 'fa fa-magic',
url: 'order/adoptRefund',
confirm: '确认通过?',
success: function (data, ret) {
$(".btn-refresh").trigger("click");
},
error: function (data, ret) {
return false;
},
visible: function (row) {
if(row.status == 3){
return true;
}else{
return false;
}
}
},
{
name: 'detail',
text: __('同意'),
title: __('申请退换货'),
classname: 'btn btn-xs btn-primary btn-ajax',
icon: 'fa fa-magic',
url: 'order/adoptReturn',
confirm: '确认通过?',
success: function (data, ret) {
$(".btn-refresh").trigger("click");
},
error: function (data, ret) {
return false;
},
visible: function (row) {
if(row.status == 6){
return true;
}else{
return false;
}
}
}
]}
]
]
});
... ... @@ -107,6 +171,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
edit: function () {
Controller.api.bindevent();
},
code: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
... ...