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

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