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

85 lines
2.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
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\Admin\Forms\RefundNote;
  5. use App\Models\ImsCjdcOrder;
  6. use App\Models\ImsCjdcOrderMain;
  7. use Dcat\Admin\Grid\Displayers\Modal;
  8. use Dcat\Admin\Grid\RowAction;
  9. use Dcat\Admin\Layout\Content;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\Log;
  12. class OrderStateHandle extends RowAction
  13. {
  14. protected $model;
  15. protected $state;
  16. protected $title;
  17. protected $content;
  18. public function __construct($title=null,$state=null)
  19. {
  20. parent::__construct($title);
  21. $this->state = $state;
  22. }
  23. /**
  24. * 处理请求
  25. *
  26. * @param Request $request
  27. *
  28. * @return \Dcat\Admin\Actions\Response
  29. */
  30. public function handle(Request $request)
  31. {
  32. // 获取当前行ID
  33. $id = $this->getKey();
  34. $orderMain = new ImsCjdcOrderMain();
  35. $order = $orderMain::where('id',$id)->first();
  36. $state = $request->get('state');
  37. if ($state==4){
  38. //记录分账流水
  39. $result = json_decode(Rpc::separateAccounts($order->global_order_id,$order->user_id),true)['result'];
  40. if ($result['code']!=0){
  41. Log::error('订单完成时分账接口调用失败',$result);
  42. return $this->response()->error('操作失败')->refresh();
  43. }
  44. return $this->response()->success('操作成功')->refresh();
  45. }elseif ($state==9){//同意退款
  46. $result = json_decode(Rpc::orderRefund($order->global_order_id,$order->user_id),true)['result'];
  47. if (isset($result['code'])&&$result['code']!=0){
  48. Log::error('订单退款接口调用失败',$result);
  49. return $this->response()->error($result['message'])->refresh();
  50. }
  51. $orderMain->modifyState($id,$state);
  52. return $this->response()->success($result['message'])->refresh();
  53. }elseif ($state==3){//接单
  54. $res = $orderMain->modifyState($id,$state);
  55. if ($res==true){
  56. $storeIds = ImsCjdcOrder::where('order_main_id',$order->global_order_id)->pluck('store_id')->toArray();
  57. Rpc::doByOrder($order->user_id,$storeIds,$order->global_order_id,$state);
  58. return $this->response()->success('操作成功')->refresh();
  59. }else{
  60. return $this->response()->error('操作失败');
  61. }
  62. }elseif($state==2){
  63. $orderMain->modifyState($id,$state);
  64. return $this->response()->success('操作成功')->refresh();
  65. }
  66. }
  67. /**
  68. * 设置要POST到接口的数据
  69. *
  70. * @return array
  71. */
  72. public function parameters()
  73. {
  74. return [
  75. 'state' => $this->state,
  76. ];
  77. }
  78. }