AnotherPayDetailController.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2018/1/18
  5. * Time: 下午2:19
  6. */
  7. namespace app\frontend\modules\order\controllers;
  8. use app\common\components\ApiController;
  9. use app\common\models\DispatchType;
  10. use app\framework\Http\Request;
  11. use app\frontend\models\AnotherPayOrder;
  12. use app\frontend\models\OrderAddress;
  13. use app\frontend\modules\order\services\VideoDemandOrderGoodsService;
  14. class AnotherPayDetailController extends ApiController
  15. {
  16. public function index(Request $request)
  17. {
  18. $this->validate([
  19. 'order_id' => 'required'
  20. ]);
  21. $order_ids = explode(',', $request->query('order_id'));
  22. foreach ($order_ids as $orderId) {
  23. $order = $this->getOrder()->with(['hasManyOrderGoods','orderDeduction','orderDiscount','orderCoupon','orderFees'])->find($orderId);
  24. if (is_null($order)) {
  25. return $this->errorJson($msg = '未找到数据', []);
  26. }
  27. $data = $order->toArray();
  28. $backups_button = $data['button_models'];
  29. $data['button_models'] = array_merge($data['button_models'],$order->getStatusService()->getRefundButtons($order));
  30. //todo 配送类型
  31. if ($order['dispatch_type_id'] == DispatchType::EXPRESS) {
  32. $data['address_info'] = OrderAddress::select('address', 'mobile', 'realname')->where('order_id', $order['id'])->first();
  33. }
  34. if(app('plugins')->isEnabled('store-cashier')){
  35. //临时解决
  36. $storeObj = \Yunshop\StoreCashier\common\models\Store::getStoreByCashierId($order->hasManyOrderGoods[0]->goods_id)->first();
  37. if ($storeObj) {
  38. $data['button_models'] = $backups_button;
  39. }
  40. if ($order['dispatch_type_id'] == DispatchType::SELF_DELIVERY) {
  41. $data['address_info'] = \Yunshop\StoreCashier\common\models\SelfDelivery::where('order_id', $order['id'])->first();
  42. }elseif($order['dispatch_type_id'] == DispatchType::STORE_DELIVERY){
  43. $data['address_info'] = \Yunshop\StoreCashier\common\models\StoreDelivery::where('order_id', $order['id'])->first();
  44. }
  45. }
  46. //todo 临时解决
  47. if (!$order) {
  48. return $this->errorJson($msg = '未找到数据', []);
  49. } else {
  50. //视频点播
  51. if (VideoDemandOrderGoodsService::whetherEnabled()) {
  52. foreach ($data['has_many_order_goods'] as &$value) {
  53. $value['is_course'] = VideoDemandOrderGoodsService::whetherCourse($value['goods_id']);
  54. }
  55. }
  56. }
  57. $result[] = $data;
  58. }
  59. return $this->successJson($msg = 'ok', $result);
  60. }
  61. protected function getOrder()
  62. {
  63. return new AnotherPayOrder();
  64. }
  65. }