mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
feat: #10000 打印完成
This commit is contained in:
parent
2ed22b91b5
commit
b3f2537768
@ -154,6 +154,7 @@ class BusinessOrderController extends Controller
|
||||
->where('plat_id', Shop::$PLAT_KTT)
|
||||
->pluck('id');
|
||||
$builder = BusinessOrder::query()
|
||||
->where('order_sn', 'PO-230728-287005797932723')
|
||||
->with('items')
|
||||
->whereIn('shop_id', $shopIds)
|
||||
->filter();
|
||||
@ -168,14 +169,59 @@ class BusinessOrderController extends Controller
|
||||
$contents = $waybill->getContents();
|
||||
// 待打印数据
|
||||
[$documents, $orderIds] = $waybill->getDocumentsAndOrderIds($contents);
|
||||
// 只有订单商品种类2-5的需要配货单
|
||||
if (2 !== $request->get('goods_sku_num')) {
|
||||
$orderIds = [];
|
||||
}
|
||||
|
||||
return response([
|
||||
'documents' => $documents,
|
||||
'order_ids' => $orderIds,
|
||||
'documents' => $this->combinationPrintDocuments($documents),
|
||||
'order_ids' => implode(',', $orderIds),
|
||||
]);
|
||||
}
|
||||
|
||||
private function combinationPrintDocuments($documents)
|
||||
{
|
||||
$documentData = [
|
||||
'data' => [
|
||||
'height' => 240,
|
||||
'list' => [
|
||||
[
|
||||
'fontSize' => 31.2,
|
||||
'height' => 45.68,
|
||||
'left' => 2.08,
|
||||
'text' => '', // 备注
|
||||
'top' => 2.08,
|
||||
'width' => 413.52
|
||||
]
|
||||
],
|
||||
'waterdata' => [
|
||||
'text' => ''
|
||||
],
|
||||
'width' => 560
|
||||
],
|
||||
'templateURL' => 'http://pinduoduoimg.yangkeduo.com/logistics/2019-07-14/5d7e8b5969d954539fcfba3268bbeb3a.xml'
|
||||
];
|
||||
$data = [];
|
||||
foreach ($documents as &$document) {
|
||||
$documentID = $document['documentID'];
|
||||
unset($document['documentID']);
|
||||
$data[] = [
|
||||
'documentID' => $documentID,
|
||||
'contents' => [
|
||||
$document,
|
||||
$documentData
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function printSuccess(Request $request)
|
||||
{
|
||||
$orderIds = $request->input('order_ids');
|
||||
$orderIds = explode(',', $orderIds);
|
||||
BusinessOrder::query()
|
||||
->where('id', $orderIds)
|
||||
->increment('print_status');
|
||||
|
||||
return response(['message' => 'success']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ class WayBillService
|
||||
|
||||
public function getContents()
|
||||
{
|
||||
// 已下单过的订单不再下单
|
||||
$contents = [];
|
||||
foreach ($this->orders as $shopId => $order) {
|
||||
// 花落测试;
|
||||
@ -28,6 +29,7 @@ class WayBillService
|
||||
foreach ($order as $item) {
|
||||
[$sender, $orderInfo, $wpCode] = $this->prepareRequest($item, $shop);
|
||||
$waybill = $this->saveWayBill($item, $shop);
|
||||
if (empty($waybill->id)) {
|
||||
$resp = $faceSheet->getWayBill($sender, $orderInfo, $wpCode);
|
||||
if (isset($resp['pdd_waybill_get_response'])) {
|
||||
$data = $resp['pdd_waybill_get_response']['modules'][0];
|
||||
@ -46,15 +48,28 @@ class WayBillService
|
||||
],
|
||||
'encryptedData' => $printData['encryptedData'],
|
||||
'signature' => $printData['signature'],
|
||||
'templateUrl' => $printData['templateUrl'],
|
||||
'templateUrl' => 'http://pinduoduoimg.yangkeduo.com/print_template/2019-08-01/4f0d85f35ca5729ad7df47314c990c31.xml',
|
||||
'ver' => $printData['ver'],
|
||||
'userid' => $waybill->user_id,
|
||||
'items' => $item['items'],
|
||||
'documentID' => $waybill->id,
|
||||
'order_id' => $item['id']
|
||||
];
|
||||
|
||||
return $contents; //测试
|
||||
}
|
||||
} else {
|
||||
$contents[$waybill->id] = [
|
||||
'addData' => [
|
||||
'sender' => $sender,
|
||||
],
|
||||
'encryptedData' => $waybill->encryptedData,
|
||||
'signature' => $waybill->signature,
|
||||
'templateUrl' => 'http://pinduoduoimg.yangkeduo.com/print_template/2019-08-01/4f0d85f35ca5729ad7df47314c990c31.xml',
|
||||
'ver' => $waybill->ver,
|
||||
'userid' => $waybill->user_id,
|
||||
'items' => json_decode($waybill->items, true),
|
||||
'documentID' => $waybill->id,
|
||||
'order_id' => $item['id']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,7 +107,10 @@ class WayBillService
|
||||
private function saveWayBill($order, $shop)
|
||||
{
|
||||
$senderConfig = $shop->senders[0];
|
||||
$waybill = new Waybill();
|
||||
$waybill = Waybill::query()->firstOrNew(
|
||||
['order_sn' => $order['order_sn']]
|
||||
);
|
||||
|
||||
$waybill->shop_id = $shop->shop_id;
|
||||
$waybill->object_id = $this->objectId;
|
||||
|
||||
@ -114,6 +132,7 @@ class WayBillService
|
||||
$waybill->user_id = $shop->owner_id;
|
||||
$waybill->wp_code = $senderConfig['wp_code'];
|
||||
$waybill->order_sn = $order['order_sn'];
|
||||
$waybill->order_id = $order['id'];
|
||||
$waybill->items = json_encode($order['items'], 256);
|
||||
|
||||
return $waybill;
|
||||
@ -215,6 +234,7 @@ class WayBillService
|
||||
// 订单拆分组合
|
||||
foreach ($orders as $order) {
|
||||
$info = [
|
||||
'id' => $order['id'],
|
||||
'order_sn' => $order['order_sn'],
|
||||
'recipient_province' => $order['receiver_address_province'],
|
||||
'recipient_city' => $order['receiver_address_city'],
|
||||
|
||||
@ -49,6 +49,7 @@ class CreateWaybillsTable extends Migration
|
||||
$table->string('order_channels_type')->default('PDD');
|
||||
|
||||
$table->string('order_sn');
|
||||
$table->integer('order_id');
|
||||
$table->text('items');
|
||||
$table->tinyInteger('cancel')->default(0);
|
||||
|
||||
|
||||
19319
resources/frontend/package-lock.json
generated
19319
resources/frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -14,15 +14,16 @@
|
||||
"nprogress": "^0.2.0",
|
||||
"vue": "^2.6.11",
|
||||
"vue-router": "^3.2.0",
|
||||
"vue-socket.io": "^3.0.10",
|
||||
"vuex": "^3.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "~4.5.0",
|
||||
"@vue/cli-plugin-eslint": "~4.5.0",
|
||||
"@vue/cli-plugin-router": "~4.5.0",
|
||||
"@vue/cli-plugin-vuex": "~4.5.0",
|
||||
"@vue/cli-service": "~4.5.0",
|
||||
"@vue/eslint-config-standard": "^5.1.2",
|
||||
"@vue/cli-plugin-babel": "^5.0.8",
|
||||
"@vue/cli-plugin-eslint": "^5.0.8",
|
||||
"@vue/cli-plugin-router": "^5.0.8",
|
||||
"@vue/cli-plugin-vuex": "^5.0.8",
|
||||
"@vue/cli-service": "^5.0.8",
|
||||
"@vue/eslint-config-standard": "^8.0.1",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"eslint": "^6.7.2",
|
||||
"eslint-plugin-import": "^2.20.2",
|
||||
|
||||
16
resources/frontend/src/api/plat.js
vendored
16
resources/frontend/src/api/plat.js
vendored
@ -54,3 +54,19 @@ export function platOrderExport(params) {
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
export function printOrders(params) {
|
||||
return http({
|
||||
url: "/api/print/orders",
|
||||
method: "get",
|
||||
params
|
||||
});
|
||||
}
|
||||
|
||||
export function printSuccess(params) {
|
||||
return http({
|
||||
url: "/api/print/success",
|
||||
method: "put",
|
||||
params
|
||||
});
|
||||
}
|
||||
|
||||
@ -93,7 +93,8 @@
|
||||
<el-button type="primary" @click="handleChoose">筛选</el-button>
|
||||
<el-button plain @click="handleReChoose">重置筛选</el-button>
|
||||
</el-form-item>
|
||||
<el-button type="primary" @click="dialogVisible = true">打印</el-button>
|
||||
<el-button type="primary" @click="print">打印</el-button>
|
||||
<el-button v-if="form.goods_sku_num === 2" type="primary">配货单导出</el-button>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
@ -142,39 +143,11 @@
|
||||
</el-pagination>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 配货单导出 -->
|
||||
<el-dialog title="配货单导出" :visible.sync="dialogVisible" :close-on-click-modal="false">
|
||||
<el-form ref="exportForm" :model="exportForm" label-width="100px" :rules="exportFormRules">
|
||||
<el-form-item label="店铺:" prop="shop_id">
|
||||
<el-select v-model="exportForm.shop_id" placeholder="店铺" @change="setActivity">
|
||||
<el-option v-for="item in shops" :key="item.id" :label="item.name" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="订单类型">
|
||||
<el-radio-group v-model="exportForm.is_supplier">
|
||||
<el-radio :label="1">自卖团订单</el-radio>
|
||||
<el-radio :label="0">帮卖团订单</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="开始跟团号" prop="start_no">
|
||||
<el-input v-model="exportForm.start_no"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="结束跟团号" prop="end_no">
|
||||
<el-input v-model="exportForm.end_no"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="derivation('exportForm')">导出</el-button>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { platOrderList, activityList } from "../../api/plat";
|
||||
import { platOrderList, activityList, printOrders, printSuccess } from "../../api/plat";
|
||||
import { storeList } from "../../api/shop";
|
||||
import { goodsSkusList } from "../../api/goods";
|
||||
export default {
|
||||
@ -222,18 +195,35 @@ export default {
|
||||
],
|
||||
},
|
||||
confirmAt: [],
|
||||
print_order_ids: '',
|
||||
print_documents: [],
|
||||
socket: null,
|
||||
lockReconnect: false, //是否真正建立连接
|
||||
timeout: 58 * 1000, //58秒一次心跳
|
||||
timeoutObj: null, //心跳心跳倒计时
|
||||
serverTimeoutObj: null, //心跳倒计时
|
||||
timeoutnum: null, //断开 重连倒计时
|
||||
defaultPrinter: null,
|
||||
taskIDArray: [],
|
||||
requestIDGetGlobalConfig: '',
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
// 展示店铺列表
|
||||
this.getShopsList();
|
||||
},
|
||||
created() {
|
||||
this.initConfirmAt();
|
||||
this.getPlatOrderList({
|
||||
confirm_at_start: this.form.confirm_at[0],
|
||||
confirm_at_end: this.form.confirm_at[1]
|
||||
});
|
||||
this.initWebSocket();
|
||||
},
|
||||
mounted() {
|
||||
// 展示店铺列表
|
||||
this.getShopsList();
|
||||
},
|
||||
beforeDestroy() {
|
||||
// 订阅事件记得要取消
|
||||
},
|
||||
destroyed() {
|
||||
},
|
||||
methods: {
|
||||
initConfirmAt() {
|
||||
@ -298,8 +288,8 @@ export default {
|
||||
after_sales_status: "0",
|
||||
// supply_participate_no: "",
|
||||
// participate_no: "",
|
||||
goods_sku_num: "",
|
||||
print_status: "0",
|
||||
goods_sku_num: '',
|
||||
print_status: 0,
|
||||
external_sku_ids: [],
|
||||
confirm_at: this.confirmAt,
|
||||
};
|
||||
@ -333,6 +323,187 @@ export default {
|
||||
} else {
|
||||
this.options = [];
|
||||
}
|
||||
},
|
||||
print() {
|
||||
const print_loading = this.$loading({
|
||||
lock: true,
|
||||
text: 'Loading',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.7)'
|
||||
});
|
||||
printOrders(this.form).then((res) => {
|
||||
this.print_documents = res.data.documents;
|
||||
this.print_order_ids = res.data.order_ids;
|
||||
print_loading.close();
|
||||
this.doPrint();
|
||||
})
|
||||
},
|
||||
handleSelectionChange() {
|
||||
|
||||
},
|
||||
initWebSocket() {
|
||||
//初始化weosocket
|
||||
const wsuri = "ws://127.0.0.1:5000";
|
||||
this.socket = new WebSocket(wsuri);
|
||||
// 客户端接收服务端数据时触发
|
||||
this.socket.onmessage = this.websocketonmessage;
|
||||
// 连接建立时触发
|
||||
this.socket.onopen = this.websocketonopen;
|
||||
// 通信发生错误时触发
|
||||
this.socket.onerror = this.websocketonerror;
|
||||
// 连接关闭时触发
|
||||
this.socket.onclose = this.websocketclose;
|
||||
},
|
||||
// 连接建立时触发
|
||||
websocketonopen() {
|
||||
//开启心跳
|
||||
this.start();
|
||||
if (this.socket.readyState === 1) {
|
||||
// 获取打印机列表
|
||||
this.getPrinters();
|
||||
}
|
||||
},
|
||||
start() {
|
||||
//开启心跳
|
||||
console.log("开启心跳");
|
||||
var self = this;
|
||||
self.timeoutObj && clearTimeout(self.timeoutObj);
|
||||
self.serverTimeoutObj && clearTimeout(self.serverTimeoutObj);
|
||||
self.timeoutObj = setTimeout(function () {
|
||||
//这里发送一个心跳,后端收到后,返回一个心跳消息,
|
||||
if (self.socket.readyState == 1) {
|
||||
//如果连接正常
|
||||
} else {
|
||||
//否则重连
|
||||
self.reconnect();
|
||||
}
|
||||
self.serverTimeoutObj = setTimeout(function () {
|
||||
//超时关闭
|
||||
self.socket.close();
|
||||
}, self.timeout);
|
||||
}, self.timeout);
|
||||
},
|
||||
reconnect() {
|
||||
//重新连接
|
||||
var that = this;
|
||||
if (that.lockReconnect) {
|
||||
return;
|
||||
}
|
||||
that.lockReconnect = true;
|
||||
//没连接上会一直重连,设置延迟避免请求过多
|
||||
that.timeoutnum && clearTimeout(that.timeoutnum);
|
||||
that.timeoutnum = setTimeout(function () {
|
||||
//新连接
|
||||
that.initWebSocket();
|
||||
that.lockReconnect = false;
|
||||
}, 5000);
|
||||
},
|
||||
// 通信发生错误时触发
|
||||
websocketonerror() {
|
||||
console.log("出现错误");
|
||||
this.reconnect();
|
||||
},
|
||||
// 客户端接收服务端数据时触发
|
||||
websocketonmessage(e) {
|
||||
console.log(e);
|
||||
if (JSON.parse(e.data).printers !== undefined) {
|
||||
this.defaultPrinter = JSON.parse(e.data).defaultPrinter;
|
||||
}
|
||||
// JSON.parse 用来解析JSON字符串
|
||||
console.log("默认打印机" + this.defaultPrinter)
|
||||
|
||||
if (JSON.parse(e.data).status === 'success') {
|
||||
console.log("打印就绪..")
|
||||
}
|
||||
if (JSON.parse(e.data).status === 'failed') {
|
||||
console.log("打印未就绪..")
|
||||
}
|
||||
if (JSON.parse(e.data).taskStatus === 'printed') {
|
||||
console.log('出纸成功--打印成功')
|
||||
// 打印成功回调
|
||||
printSuccess({ order_ids: this.print_order_ids }).then((res) => {
|
||||
console.log(res)
|
||||
})
|
||||
}
|
||||
if (JSON.parse(e.data).taskStatus === 'failed') {
|
||||
console.log("打印失败!")
|
||||
}
|
||||
if (JSON.parse(e.data).taskStatus === 'canceled') {
|
||||
console.log("打印取消!")
|
||||
}
|
||||
|
||||
//收到服务器信息,心跳重置
|
||||
this.reset();
|
||||
},
|
||||
reset() {
|
||||
//重置心跳
|
||||
var that = this;
|
||||
//清除时间
|
||||
clearTimeout(that.timeoutObj);
|
||||
clearTimeout(that.serverTimeoutObj);
|
||||
//重启心跳
|
||||
that.start();
|
||||
},
|
||||
websocketsend(Data) {
|
||||
//数据发送
|
||||
this.socket.send(Data);
|
||||
},
|
||||
// 连接关闭时触发
|
||||
websocketclose(e) {
|
||||
//关闭
|
||||
console.log("断开连接", e);
|
||||
//重连
|
||||
this.reconnect();
|
||||
},
|
||||
getPrinters() {
|
||||
var request = this.getRequestObject("getPrinters");
|
||||
this.websocketsend(JSON.stringify(request));
|
||||
},
|
||||
doPrint() {
|
||||
var request = this.getRequestObject("print");
|
||||
request.task = new Object();
|
||||
request.task.taskID = this.getUUID(8, 10);
|
||||
// 把每次打印的任务 taskID 保存到 taskIDArray 数组
|
||||
this.taskIDArray.push(request.task.taskID)
|
||||
// 记录当前打印请求的ID
|
||||
this.requestIDGetGlobalConfig = request.task.taskID
|
||||
request.task.preview = false;
|
||||
request.task.printer = this.defaultPrinter;
|
||||
request.task.documents = this.print_documents;
|
||||
console.log(request.task.documents)
|
||||
|
||||
this.websocketsend(JSON.stringify(request));
|
||||
},
|
||||
getRequestObject(cmd) {
|
||||
var request = new Object();
|
||||
// 必须:请求的ID,用于唯一标识每个请求,每个客户端保证生成唯一的ID
|
||||
request.requestID = this.getUUID(8, 16);
|
||||
//必须: 协议当前版本
|
||||
request.version = "1.0";
|
||||
//必须: 请求命令名称
|
||||
request.cmd = cmd;
|
||||
|
||||
return request;
|
||||
},
|
||||
getUUID(len, radix) {
|
||||
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
||||
var uuid = [], i;
|
||||
radix = radix || chars.length;
|
||||
if (len) {
|
||||
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
|
||||
} else {
|
||||
var r;
|
||||
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
||||
uuid[14] = '4';
|
||||
for (i = 0; i < 36; i++) {
|
||||
if (!uuid[i]) {
|
||||
r = 0 | Math.random() * 16;
|
||||
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return uuid.join('');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
4
resources/frontend/vue.config.js
vendored
4
resources/frontend/vue.config.js
vendored
@ -4,10 +4,6 @@ module.exports = {
|
||||
devServer: {
|
||||
open: false, // 设置浏览器自动打开项目
|
||||
port: 8080, // 开发服务器运行端口号
|
||||
overlay: {
|
||||
warnings: false,
|
||||
errors: true,
|
||||
},
|
||||
proxy: {
|
||||
// 配置代理
|
||||
"/api": {
|
||||
|
||||
@ -64,6 +64,8 @@ Route::middleware(['auth:api', 'check.permissions'])->group(function () {
|
||||
Route::delete('goods_sku_location', [GoodsSkuLocationController::class, 'delete'])->name('goods_sku_location.delete');
|
||||
// 电子面单
|
||||
Route::get('shop/ship', [ShipController::class, 'index']);
|
||||
Route::get('print/orders', [BusinessOrderController::class, 'print']);
|
||||
Route::put('print/success', [BusinessOrderController::class, 'printSuccess']);
|
||||
// 发货信息
|
||||
Route::get('shop/ship/senders', [ShipController::class, 'getSenders']);
|
||||
Route::post('shop/ship/senders', [ShipController::class, 'saveSenders']);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user