OperationController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/3
  6. * Time: 下午2:30
  7. */
  8. namespace app\backend\modules\order\controllers;
  9. use app\common\components\BaseController;
  10. use app\common\models\Order;
  11. use app\common\models\PayType;
  12. use app\frontend\modules\order\services\OrderService;
  13. use app\common\models\order\Remark;
  14. use app\common\exceptions\AppException;
  15. class OperationController extends BaseController
  16. {
  17. protected $param;
  18. /**
  19. * @var Order
  20. */
  21. protected $order;
  22. public $transactionActions = ['*'];
  23. public function preAction()
  24. {
  25. parent::preAction();
  26. $this->param = request()->input();
  27. if (!isset($this->param['order_id'])) {
  28. return $this->message('order_id不能为空!', '', 'error');
  29. }
  30. $this->order = Order::find($this->param['order_id']);
  31. if (!isset($this->order)) {
  32. return $this->message('未找到该订单!', '', 'error');
  33. }
  34. }
  35. /**
  36. * @return \Illuminate\Http\JsonResponse
  37. * @throws \app\common\exceptions\AppException
  38. */
  39. public function pay()
  40. {
  41. $this->order->backendPay();
  42. return $this->successJson();
  43. }
  44. /**
  45. * @return mixed
  46. * @throws \app\common\exceptions\AppException
  47. */
  48. public function cancelPay()
  49. {
  50. OrderService::orderCancelPay($this->param);
  51. return $this->message('操作成功');
  52. }
  53. /**
  54. * @return mixed
  55. * @throws \app\common\exceptions\AppException
  56. */
  57. public function addOrderExpress()
  58. {
  59. OrderService::addOrderExpress($this->param);
  60. return $this->message('操作成功');
  61. }
  62. /**
  63. * @return mixed
  64. * @throws \app\common\exceptions\AppException
  65. */
  66. public function send()
  67. {
  68. OrderService::orderSend($this->param);
  69. return $this->message('操作成功');
  70. }
  71. /**
  72. * @return mixed
  73. * @throws \app\common\exceptions\AppException
  74. */
  75. public function fClose(){
  76. $this->order->refund();
  77. return $this->message('强制退款成功');
  78. }
  79. /**
  80. * @return mixed
  81. * @throws \app\common\exceptions\AppException
  82. */
  83. public function cancelSend()
  84. {
  85. OrderService::orderCancelSend($this->param);
  86. return $this->message('操作成功');
  87. }
  88. /**
  89. * @return mixed
  90. * @throws \app\common\exceptions\AppException
  91. */
  92. public function receive()
  93. {
  94. OrderService::orderReceive($this->param);
  95. return $this->message('操作成功');
  96. }
  97. /**
  98. * @return mixed
  99. * @throws \app\common\exceptions\AppException
  100. */
  101. public function close()
  102. {
  103. OrderService::orderClose($this->param);
  104. return $this->message('操作成功');
  105. }
  106. /**
  107. * @return mixed
  108. * @throws \app\common\exceptions\AppException
  109. */
  110. public function manualRefund()
  111. {
  112. if ($this->order->isPending()) {
  113. throw new AppException("订单已锁定,无法继续操作");
  114. }
  115. if ($this->order->hasOneRefundApply && $this->order->hasOneRefundApply->isRefunding()) {
  116. throw new AppException('订单有售后待处理,无法继续操作');
  117. }
  118. // $result = $this->order->refund();
  119. \app\backend\modules\refund\services\RefundOperationService::orderCloseAndRefund($this->order);
  120. \app\common\models\order\ManualRefundLog::saveLog($this->order->id);
  121. return $this->message('操作成功');
  122. }
  123. /**
  124. * @return mixed
  125. * @throws \app\common\exceptions\AppException
  126. */
  127. public function delete()
  128. {
  129. OrderService::orderDelete($this->param);
  130. return $this->message('操作成功');
  131. }
  132. public function remarks()
  133. {
  134. $order = Order::find(request()->input('order_id'));
  135. if(!$order){
  136. throw new AppException("未找到该订单".request()->input('order_id'));
  137. }
  138. if(request()->has('remark')){
  139. $remark = $order->hasOneOrderRemark;
  140. if (!$remark) {
  141. $remark = new Remark([
  142. 'order_id' => request()->input('order_id'),
  143. 'remark' => request()->input('remark')
  144. ]);
  145. if(!$remark->save()){
  146. return $this->errorJson();
  147. }
  148. } else {
  149. $reUp = Remark::where('order_id', request()->input('order_id') )
  150. ->where('remark', $remark->remark)
  151. ->update(['remark'=> request()->input('remark')]);
  152. if (!$reUp) {
  153. return $this->errorJson();
  154. }
  155. }
  156. }
  157. //(new \app\common\services\operation\OrderLog($remark, 'special'));
  158. echo json_encode(["data" => '', "result" => 1]);
  159. }
  160. public function invoice()
  161. {
  162. $order = Order::with(['orderInvoice'])->find(request()->input('order_id'));
  163. if(!$order){
  164. throw new AppException("未找到该订单".request()->input('order_id'));
  165. }
  166. if (!request()->has('invoice')) {
  167. throw new AppException('未上传图片');
  168. }
  169. $orderInvoice = $order->orderInvoice;
  170. if ($orderInvoice) {
  171. $orderInvoice->invoice = request()->input('invoice');
  172. $orderInvoice->save();
  173. }
  174. $order->invoice = request()->input('invoice');
  175. $order->save();
  176. //发邮件
  177. // $flag = \Illuminate\Support\Facades\Mail::to('email')->subjuet('订单发票')->send(new \app\Mail\OrderInvoice(yz_tomedia(request()->input('invoice'))));
  178. echo json_encode(["data" => '', "result" => 1]);
  179. }
  180. }