| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020/12/3
- * Time: 14:42
- */
- namespace app\backend\modules\order\controllers;
- use app\common\components\BaseController;
- use app\common\models\Order;
- use app\common\models\order\ManualRefundLog;
- use app\common\models\PayType;
- use app\frontend\modules\order\services\OrderService;
- use app\common\models\order\Remark;
- use app\common\exceptions\AppException;
- use Illuminate\Support\Facades\DB;
- use app\framework\Http\Request;
- class VueOperationController extends BaseController
- {
- protected $param;
- /**
- * @var Order
- */
- protected $order;
- public $transactionActions = ['pay','send','addOrderExpress','separateSend','cancelSend','receive','close'];
- /**
- * @return mixed|void
- * @throws AppException
- */
- public function preAction()
- {
- parent::preAction();
- $this->param = request()->input();
- if (!isset($this->param['order_id'])) {
- throw new AppException('order_id不能为空!');
- }
- $this->order = Order::find($this->param['order_id']);
- if (!isset($this->order)) {
- throw new AppException('未找到该订单!');
- }
- }
- /**
- * 支付
- * @return \Illuminate\Http\JsonResponse
- * @throws \app\common\exceptions\AppException
- */
- public function pay()
- {
- $this->order->backendPay();
- return $this->successJson('操作成功');
- }
- /**
- * 确认发货
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function send()
- {
- OrderService::orderSend($this->param);
- return $this->successJson('操作成功');
- }
- /**
- * 多包裹继续返回
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function addOrderExpress()
- {
- OrderService::addOrderExpress($this->param);
- return $this->successJson('操作成功');
- }
- /**
- * 多包裹发货
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function separateSend()
- {
- if ($this->order->status == Order::WAIT_SEND) {
- OrderService::orderSend($this->param);
- } else {
- OrderService::addOrderExpress($this->param);
- }
- return $this->successJson('操作成功');
- }
- /**
- * 取消发货
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function cancelSend()
- {
- OrderService::orderCancelSend($this->param);
- return $this->successJson('操作成功');
- }
- /**
- * 确认收货
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function receive()
- {
- OrderService::orderReceive($this->param);
- return $this->successJson('操作成功');
- }
- /**
- * 关闭订单
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function close()
- {
- OrderService::orderClose($this->param);
- return $this->successJson('操作成功');
- }
- /**
- * 退款并关闭订单
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function manualRefund()
- {
- if ($this->order->isPending()) {
- throw new AppException("订单已锁定,无法继续操作");
- }
- if ($this->order->hasOneRefundApply && $this->order->hasOneRefundApply->isRefunding()) {
- throw new AppException('订单有售后记录待处理,无法继续操作');
- }
- \app\backend\modules\refund\services\RefundOperationService::orderCloseAndRefund($this->order);
- //$result = $this->order->refund();
- ManualRefundLog::saveLog($this->order->id);
- return $this->successJson('操作成功');
- }
- public function partRefund(Request $request)
- {
- $order = Order::find($request->input('order_id'));
- if (!isset($order)) {
- throw new AppException('订单不存在');
- }
- if ($order->status < Order::WAIT_SEND) {
- throw new AppException('订单未付款,无法退款');
- }
- if ($order->hasOneRefundApply && $order->hasOneRefundApply->isRefunding()) {
- throw new AppException('申请已提交,处理中');
- }
- $refundApply = new \app\backend\modules\refund\services\operation\RefundApply(['uid'=>$order->uid]);
- $refundApply->setRelation('order',$order);
- DB::transaction(function()use($refundApply){
- $refundApply->execute();
- });
- // $order = Order::find($request->input('order_id'));
- return $this->successJson('操作成功',$refundApply->id);
- }
- public function remarks()
- {
- $order = Order::find(request()->input('order_id'));
- if(!$order){
- throw new AppException("未找到该订单".request()->input('order_id'));
- }
- if(request()->has('remark')){
- $remark = $order->hasOneOrderRemark;
- if (!$remark) {
- $remark = new Remark([
- 'order_id' => request()->input('order_id'),
- 'remark' => request()->input('remark')
- ]);
- if(!$remark->save()){
- return $this->errorJson('订单备注保存失败');
- }
- } else {
- $reUp = Remark::where('order_id', request()->input('order_id') )
- ->where('remark', $remark->remark)
- ->update(['remark'=> request()->input('remark')]);
- if (!$reUp) {
- return $this->errorJson('订单备注保存失败');
- }
- }
- }
- return $this->successJson('订单备注保存成功');
- }
- public function invoice()
- {
- $order = Order::with(['orderInvoice'])->find(request()->input('order_id'));
- if(!$order){
- throw new AppException("未找到该订单".request()->input('order_id'));
- }
- if (!request()->has('invoice')) {
- throw new AppException('未上传图片');
- }
- $orderInvoice = $order->orderInvoice;
- if ($orderInvoice) {
- $orderInvoice->invoice = request()->input('invoice');
- $orderInvoice->save();
- }
- $order->invoice = request()->input('invoice');
- $order->save();
- //发邮件
- // $flag = \Illuminate\Support\Facades\Mail::to('email')->subjuet('订单发票')->send(new \app\Mail\OrderInvoice(yz_tomedia(request()->input('invoice'))));
- return $this->successJson('订单发票保存成功');
- }
- public function setOrder($order)
- {
- $this->order = $order;
- }
- public function setParam($param)
- {
- $this->param = $param;
- }
- }
|