链街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.

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