CompleteController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\admin\controller\order;
  3. use app\admin\validate\coupon\CouponValidate;
  4. use app\admin\validate\device\DeviceValidate;
  5. use app\admin\validate\order\OrderValidate;
  6. use app\controller\Curd;
  7. use app\model\Coupon;
  8. use app\model\Device;
  9. use app\model\Order;
  10. use app\model\OrderSheet;
  11. use app\model\Supplier;
  12. use app\model\SysSerial;
  13. use support\exception\BusinessException;
  14. use support\Request;
  15. use support\Response;
  16. class CompleteController extends Curd
  17. {
  18. public function __construct()
  19. {
  20. $this->model = new Order();
  21. $this->validate = true;
  22. $this->validateClass = new OrderValidate();
  23. }
  24. /**
  25. * @Desc 列表
  26. * @Author Gorden
  27. * @Date 2024/3/28 15:01
  28. *
  29. * @param Request $request
  30. * @return Response
  31. * @throws \support\exception\BusinessException
  32. */
  33. public function select(Request $request): Response
  34. {
  35. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  36. $order = $request->get('order', 'desc');
  37. $field = $field ?? 'order_addtimes';
  38. $where['order_status_system'] = 'CONFIRM';
  39. $where['order_is_complete'] = ['in', ['Y', 'R']];
  40. $query = $this->doSelect($where, $field, $order);
  41. return $this->doFormat($query, $format, $limit);
  42. }
  43. /**
  44. * @Desc 订单商品详情
  45. * @Author Gorden
  46. * @Date 2024/3/29 8:50
  47. *
  48. * @param Request $request
  49. * @return Response
  50. */
  51. public function sheet(Request $request)
  52. {
  53. $orderId = $request->get('order_id');
  54. $orderSheet = OrderSheet::with([
  55. 'member' => function ($query) {
  56. $query->select('member_id', 'member_mobile');
  57. },
  58. 'goods' => function ($query) {
  59. $query->select('goods_id', 'goods_name', 'goods_cover', 'goods_market_price', 'goods_sales_price', 'join_goods_supplier_id');
  60. },
  61. 'memberInfo',
  62. 'cert'
  63. ])->where('join_sheet_order_id', $orderId)
  64. ->get()
  65. ->toArray();
  66. foreach ($orderSheet as &$item) {
  67. $item['goods']['goods_cover'] = getenv('STORAGE_DOMAIN') . $item['goods']['goods_cover'];
  68. $item['goods']['supplier_name'] = '';
  69. if (!empty($item['goods']['join_goods_supplier_id'])) {
  70. $supplier = Supplier::where('supplier_id',$item['goods']['join_goods_supplier_id'])->value('supplier_name');
  71. if ($supplier){
  72. $item['goods']['supplier_name'] = $supplier;
  73. }
  74. }
  75. }
  76. $order = Order::where('order_id', $orderId)->first();
  77. $data = [
  78. 'order' => $order,
  79. 'sheet' => $orderSheet
  80. ];
  81. return json_success('', $data);
  82. }
  83. protected function updateInput(Request $request): array
  84. {
  85. $primary_key = $this->model->getKeyName();
  86. $id = $request->post($primary_key);
  87. $data = $this->inputFilter($request->post());
  88. $data['coupon_begindate'] = strtotime($data['coupon_begindate']);
  89. $data['coupon_enddate'] = strtotime($data['coupon_enddate']);
  90. $model = $this->model->find($id);
  91. if (!$model) {
  92. throw new BusinessException('记录不存在', 2);
  93. }
  94. unset($data[$primary_key]);
  95. return [$id, $data];
  96. }
  97. }