You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.7 KiB
84 lines
1.7 KiB
<?php
|
|
|
|
|
|
namespace App\Admin\Extensions;
|
|
|
|
|
|
use App\Admin\Common\Rpc;
|
|
use App\Models\Feprint;
|
|
use App\Models\ImsCjdcOrderMain;
|
|
use Dcat\Admin\Grid\RowAction;
|
|
use Graze\GuzzleHttp\JsonRpc\Client;
|
|
use Illuminate\Http\Request;
|
|
|
|
class OrderPrint extends RowAction
|
|
{
|
|
protected $title;
|
|
|
|
public function __construct($title = null)
|
|
{
|
|
parent::__construct($title);
|
|
|
|
}
|
|
|
|
public function handle(Request $request)
|
|
{
|
|
$oid = $this->getKey();
|
|
$result = $this->doPrint($oid);
|
|
if ($result){
|
|
return $this->response()->success('操作成功');
|
|
}else{
|
|
return $this->response()->success('打印失败');
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 设置要POST到接口的数据
|
|
*
|
|
* @return array
|
|
*/
|
|
public function parameters()
|
|
{
|
|
|
|
}
|
|
|
|
public function doPrint($oid)
|
|
{
|
|
$row = ImsCjdcOrderMain::find($oid);
|
|
|
|
//>>1.获取打印机状态
|
|
$result = $this->getPrintStatus($row->market_id);
|
|
|
|
//>>2.调用打印
|
|
if ($result == 1) {
|
|
$res = Rpc::doPrint($row->global_order_id);
|
|
$res = json_decode($res, true)['result'];
|
|
$res = json_decode($res);
|
|
|
|
//>>3.记录打印次数
|
|
if ($res->msg == 'ok' && $res->ret == 0) {
|
|
//记录打印次数
|
|
$row->print_num +=1;
|
|
return $row->save();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @param $oid //主订单ID
|
|
* @return int
|
|
*/
|
|
public function getPrintStatus($mid)
|
|
{
|
|
$fe = Feprint::where('market_id', $mid)->first();
|
|
if ($fe) {
|
|
return $fe->status;
|
|
} else {
|
|
return -1;
|
|
}
|
|
}
|
|
}
|