feat: #10000 打印完成

This commit is contained in:
赵世界 2023-07-29 17:57:36 +08:00
parent 2ed22b91b5
commit b3f2537768
9 changed files with 10940 additions and 10102 deletions

View File

@ -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']);
}
}

View File

@ -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'],

View File

@ -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);

File diff suppressed because it is too large Load Diff

View File

@ -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",

View File

@ -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
});
}

View File

@ -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('');
}
},
};

View File

@ -4,10 +4,6 @@ module.exports = {
devServer: {
open: false, // 设置浏览器自动打开项目
port: 8080, // 开发服务器运行端口号
overlay: {
warnings: false,
errors: true,
},
proxy: {
// 配置代理
"/api": {

View File

@ -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']);