diff --git a/app/Admin/Actions/Order/ShowWxShareFinish.php b/app/Admin/Actions/Order/ShowWxShareFinish.php new file mode 100644 index 00000000..62fa11b7 --- /dev/null +++ b/app/Admin/Actions/Order/ShowWxShareFinish.php @@ -0,0 +1,36 @@ +getKey()); + $service = new WxpayService(); + $sn = serial_number(); + $result = $service->finishShare($order->out_trade_no, $sn); + if (data_get($result, 'return_code') != 'SUCCESS') { + return $this->response()->error(data_get($result, 'return_msg')); + } + if (data_get($result, 'result_code') != 'SUCCESS') { + return $this->response()->error(data_get($result, 'err_code') . ':' . data_get($result, 'err_code_des')); + } + $attributes = ['finish_sn' => $sn, 'status' => 'N']; + $order->update(['wx_share' => $order->wx_share ? array_merge($order->wx_share, $attributes) : $attributes]); + return $this->response()->success('成功!'); + } + + public function confirm() + { + return ['确定要解冻资金?', '解冻资金后将无法进行分账']; + } +} diff --git a/app/Admin/Controllers/OrderController.php b/app/Admin/Controllers/OrderController.php index 3f5fa334..aa61e530 100644 --- a/app/Admin/Controllers/OrderController.php +++ b/app/Admin/Controllers/OrderController.php @@ -6,6 +6,7 @@ use App\Admin\Actions\Grid\Exports\ShippingOrder as ExportShippingOrder; use App\Admin\Actions\Grid\KuaidiInfo; use App\Admin\Actions\Grid\OrderSetTag; use App\Admin\Actions\Order\RowWxShareFinish; +use App\Admin\Actions\Order\ShowWxShareFinish; use App\Admin\Actions\Show\OrderConsigneeInfo; use App\Admin\Actions\Show\OrderCreatePackage; use App\Admin\Actions\Show\OrderPay; @@ -275,9 +276,9 @@ class OrderController extends AdminController $actions->append(new OrderSetTag()); } - if ($row->pay_at && data_get($row->wx_share, 'status') != 'N') { - $actions->append(new RowWxShareFinish()); - } + // if ($row->pay_at && data_get($row->wx_share, 'status') != 'N') { + // $actions->append(new RowWxShareFinish()); + // } }); $grid->footer(function ($collection) use ($grid) { @@ -320,7 +321,7 @@ class OrderController extends AdminController * * @param mixed $id * - * @return Show + * @return \Closure|Show */ protected function detail($id) { @@ -421,6 +422,10 @@ class OrderController extends AdminController if ($show->model()->isPending() || $show->model()->isWaitShipping() || $show->model()->isShipping()) { $tools->append(new OrderConsigneeInfo()); } + + if ($show->model()->pay_at && data_get($show->model()->wx_share, 'status') != 'N') { + $tools->append(new ShowWxShareFinish()); + } }); })); }); diff --git a/app/Services/DistributeService.php b/app/Services/DistributeService.php index ddb294e1..90acda25 100644 --- a/app/Services/DistributeService.php +++ b/app/Services/DistributeService.php @@ -234,21 +234,24 @@ class DistributeService throw new BizException('用户 '.$item->user_id.' 没有 openid'); } $item->update(['pay_way' => PayWay::WxPayShare, 'pay_no' => $sn, 'status' => 1]); - array_push($receivers, [ - "type" => "PERSONAL_SUB_OPENID", - "account" => $openid, - "amount" => $item->money * 100, - "description" => "推荐返利" - ]); + if ($item->money > 0) { + array_push($receivers, [ + "type" => "PERSONAL_SUB_OPENID", + "account" => $openid, + "amount" => $item->money * 100, + "description" => "推荐返利" + ]); + } + } + $status = 'FINISHED'; + if (count($receivers) > 0) { + $result = (new WxpayService())->share($order->out_trade_no, $sn, $receivers); + $status = data_get($result, 'status'); + logger('DistributeService@wechatShare, order:' . $order->id, $result); } - - $result = (new WxpayService())->share($order->out_trade_no, $sn, $receivers); - - $attributes = ['share_sn' => $sn, 'status' => 'N']; - $order->update(['wx_share' => $order->wx_share ? array_merge($order->wx_share, $attributes) : $attributes]); - - $status = data_get($result, 'status'); if ($status == 'FINISHED') { + $attributes = ['share_sn' => $sn, 'status' => 'N']; + $order->update(['wx_share' => $order->wx_share ? array_merge($order->wx_share, $attributes) : $attributes]); $this->success($list, $result); } }