PendingController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\SysSerial;
  12. use support\exception\BusinessException;
  13. use support\Request;
  14. use support\Response;
  15. class PendingController extends Curd
  16. {
  17. public function __construct()
  18. {
  19. $this->model = new Order();
  20. $this->validate = true;
  21. $this->validateClass = new OrderValidate();
  22. }
  23. /**
  24. * @Desc 列表
  25. * @Author Gorden
  26. * @Date 2024/3/28 15:01
  27. *
  28. * @param Request $request
  29. * @return Response
  30. * @throws \support\exception\BusinessException
  31. */
  32. public function select(Request $request): Response
  33. {
  34. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  35. $order = $request->get('order', 'desc');
  36. $field = $field ?? 'order_addtimes';
  37. $where['order_status_system'] = 'WAITING';
  38. $query = $this->doSelect($where, $field, $order);
  39. return $this->doFormat($query, $format, $limit);
  40. }
  41. /**
  42. * @Desc 订单商品详情
  43. * @Author Gorden
  44. * @Date 2024/3/29 8:50
  45. *
  46. * @param Request $request
  47. * @return Response
  48. */
  49. public function sheet(Request $request)
  50. {
  51. $orderId = $request->get('order_id');
  52. $orderSheet = OrderSheet::with([
  53. 'member' => function ($query) {
  54. $query->select('member_id', 'member_mobile');
  55. },
  56. 'goods' => function ($query) {
  57. $query->select('goods_id', 'goods_name', 'goods_cover', 'goods_market_price', 'goods_sales_price');
  58. },
  59. ])->where('join_sheet_order_id', $orderId)
  60. ->get()
  61. ->toArray();
  62. foreach ($orderSheet as &$item) {
  63. $item['goods']['goods_cover'] = getenv('STORAGE_DOMAIN') . $item['goods']['goods_cover'];
  64. }
  65. $order = Order::where('order_id', $orderId)->first();
  66. $data = [
  67. 'order' => $order,
  68. 'sheet' => $orderSheet
  69. ];
  70. return json_success('', $data);
  71. }
  72. protected function updateInput(Request $request): array
  73. {
  74. $primary_key = $this->model->getKeyName();
  75. $id = $request->post($primary_key);
  76. $data = $this->inputFilter($request->post());
  77. $data['coupon_begindate'] = strtotime($data['coupon_begindate']);
  78. $data['coupon_enddate'] = strtotime($data['coupon_enddate']);
  79. $model = $this->model->find($id);
  80. if (!$model) {
  81. throw new BusinessException('记录不存在', 2);
  82. }
  83. unset($data[$primary_key]);
  84. return [$id, $data];
  85. }
  86. }