链街Dcat后台
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.

100 lines
2.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Admin\Extensions;
  3. use App\Models\Feprint;
  4. use App\Models\ImsCjdcOrderMain;
  5. use Dcat\Admin\Grid\RowAction;
  6. use Graze\GuzzleHttp\JsonRpc\Client;
  7. use Illuminate\Http\Request;
  8. class OrderPrint extends RowAction
  9. {
  10. protected $title;
  11. public function __construct($title = null)
  12. {
  13. parent::__construct($title);
  14. }
  15. public function handle(Request $request)
  16. {
  17. $oid = $this->getKey();
  18. $result = $this->doPrint($oid);
  19. if ($result){
  20. return $this->response()->success('操作成功');
  21. }else{
  22. return $this->response()->success('打印失败');
  23. }
  24. }
  25. /**
  26. * 设置要POST到接口的数据
  27. *
  28. * @return array
  29. */
  30. public function parameters()
  31. {
  32. }
  33. public function doPrint($oid)
  34. {
  35. $row = ImsCjdcOrderMain::find($oid);
  36. //>>1.获取打印机状态
  37. $result = $this->getPrintStatus($row->market_id);
  38. //>>2.调用打印
  39. if ($result == 1) {
  40. $res = $this->rpcPrint($oid);
  41. $res = json_decode($res, true)['result'];
  42. $res = json_decode($res);
  43. //>>3.记录打印次数
  44. if ($res->msg == 'ok' && $res->ret == 0) {
  45. //记录打印次数
  46. $row->print_num +=1;
  47. return $row->save();
  48. } else {
  49. return false;
  50. }
  51. }
  52. }
  53. /**
  54. * @param $oid //主订单ID
  55. * @return int
  56. */
  57. public function getPrintStatus($mid)
  58. {
  59. $fe = Feprint::where('market_id', $mid)->first();
  60. if ($fe) {
  61. return $fe->status;
  62. } else {
  63. return -1;
  64. }
  65. }
  66. public function rpcPrint($oid)
  67. {
  68. $client = Client::factory(env('RPC_SITE_HOST'));
  69. $request = $client->request(uniqid(), '/feie/doPrint', ['oid' => $oid]);
  70. $response = $client->send($request);
  71. return $response->getBody()->getContents();
  72. }
  73. public function feiErPrint($order_num)
  74. {
  75. include_once app_path('Libs\feier_print\api_php_demo.php');
  76. $result = json_decode(FeiePrint($order_num));
  77. dd($result);
  78. }
  79. }