| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?php
- /**
- * Created by PhpStorm.
- * Author: 芸众商城 www.yunzshop.com
- * Date: 2017/3/3
- * Time: 下午2:30
- */
- namespace app\backend\modules\order\controllers;
- use app\common\components\BaseController;
- use app\common\models\Order;
- use app\common\models\PayType;
- use app\frontend\modules\order\services\OrderService;
- use app\common\models\order\Remark;
- use app\common\exceptions\AppException;
- class OperationController extends BaseController
- {
- protected $param;
- /**
- * @var Order
- */
- protected $order;
- public $transactionActions = ['*'];
- public function preAction()
- {
- parent::preAction();
- $this->param = request()->input();
- if (!isset($this->param['order_id'])) {
- return $this->message('order_id不能为空!', '', 'error');
- }
- $this->order = Order::find($this->param['order_id']);
- if (!isset($this->order)) {
- return $this->message('未找到该订单!', '', 'error');
- }
- }
- /**
- * @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 cancelPay()
- {
- OrderService::orderCancelPay($this->param);
- return $this->message('操作成功');
- }
- /**
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function addOrderExpress()
- {
- OrderService::addOrderExpress($this->param);
- return $this->message('操作成功');
- }
- /**
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function send()
- {
- OrderService::orderSend($this->param);
- return $this->message('操作成功');
- }
- /**
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function fClose(){
- $this->order->refund();
- return $this->message('强制退款成功');
- }
- /**
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function cancelSend()
- {
- OrderService::orderCancelSend($this->param);
- return $this->message('操作成功');
- }
- /**
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function receive()
- {
- OrderService::orderReceive($this->param);
- return $this->message('操作成功');
- }
- /**
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function close()
- {
- OrderService::orderClose($this->param);
- return $this->message('操作成功');
- }
- /**
- * @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('订单有售后待处理,无法继续操作');
- }
- // $result = $this->order->refund();
- \app\backend\modules\refund\services\RefundOperationService::orderCloseAndRefund($this->order);
- \app\common\models\order\ManualRefundLog::saveLog($this->order->id);
- return $this->message('操作成功');
- }
- /**
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function delete()
- {
- OrderService::orderDelete($this->param);
- return $this->message('操作成功');
- }
- 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();
- }
- }
- }
- //(new \app\common\services\operation\OrderLog($remark, 'special'));
- echo json_encode(["data" => '', "result" => 1]);
- }
- 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'))));
- echo json_encode(["data" => '', "result" => 1]);
- }
- }
|