AppointmentController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\admin\controller\order;
  3. use app\admin\service\order\AppointmentService;
  4. use app\model\Appointment;
  5. use app\model\Goods;
  6. use support\Db;
  7. use support\Request;
  8. use support\Response;
  9. class AppointmentController
  10. {
  11. /**
  12. * @Desc 列表
  13. * @Author Gorden
  14. * @Date 2024/3/29 10:44
  15. *
  16. * @param Request $request
  17. * @return Response
  18. * @throws \support\exception\BusinessException
  19. */
  20. public function select(Request $request): Response
  21. {
  22. return AppointmentService::select($request);
  23. }
  24. public function confirm($id): Response
  25. {
  26. return AppointmentService::confirm($id);
  27. }
  28. /**
  29. * 到店
  30. */
  31. public function arrival(Request $request)
  32. {
  33. return AppointmentService::arrival($request);
  34. }
  35. public function done(Request $request)
  36. {
  37. return AppointmentService::done($request);
  38. }
  39. public function add(Request $request)
  40. {
  41. return AppointmentService::add($request);
  42. }
  43. public function update(Request $request)
  44. {
  45. return AppointmentService::update($request);
  46. }
  47. public function cancelApply(Request $request)
  48. {
  49. return AppointmentService::cancelApply($request);
  50. }
  51. public function getTimes(Request $request)
  52. {
  53. return AppointmentService::getTimes($request);
  54. }
  55. public function myAppointments(Request $request)
  56. {
  57. $page = $request->get('page',1);
  58. $pageSize = $request->get('pageSize',1);
  59. $memberId = $request->get('member_id', '');
  60. $datetime = $request->get('order_addtimes',[]);
  61. $goodsName = $request->get('goods_name','');
  62. if (!$memberId) {
  63. return json_fail('查询错误');
  64. }
  65. $goodsIds = [];
  66. if (!empty($goodsName)){
  67. $goodsIds = Goods::where('goods_name','like','%'.$goodsName.'%')->pluck('goods_id')->toArray();
  68. }
  69. // 预约单
  70. $appointments = Db::table('appointment')
  71. // ->leftJoin('member', 'member.member_id', '=', 'appointment.join_appointment_member_id')
  72. // ->leftJoin('member_cert', 'member_cert.join_cert_member_id', '=', 'appointment.join_appointment_member_id')
  73. // ->leftJoin('member_info', 'member_info.join_info_member_id', '=', 'appointment.join_appointment_member_id')
  74. ->leftJoin('goods', 'goods.goods_id', '=', 'appointment.join_appointment_goods_id')
  75. // ->leftJoin('order', 'order.order_id', '=', 'appointment.join_appointment_order_id')
  76. ->leftJoin('member_benefit', 'member_benefit.member_benefit_id', '=', 'appointment.join_appointment_member_benefit_id')
  77. ->leftJoin('goods_sku', 'goods_sku.goods_sku_id', '=', 'appointment.join_appointment_goods_sku_id')
  78. ->where('join_appointment_member_id', $memberId)
  79. ->whereIn('appointment_status', ['WAITING', 'PENDING', 'DOING', 'DONE', 'CANCEL', 'REVOKE'])
  80. ->select('appointment.*',
  81. // 'member.member_mobile',
  82. // 'member_cert.member_cert_name',
  83. // 'member_info.member_info_nickname',
  84. 'goods.goods_name', 'goods.goods_sales_price',
  85. 'goods_sku.goods_sku_specs_json',
  86. // 'order.order_name', 'goods_sku.goods_sku_specs_json', 'order.order_amount_total', 'order.order_amount_pay',
  87. // 'order.order_category', 'order.order_status_system', 'order.order_status_payment', 'order.order_status_storage',
  88. // 'order.order_addtimes',
  89. 'member_benefit.member_benefit_name'
  90. )->when(!empty($goodsIds),function($query) use ($goodsIds){
  91. $query->whereIn('join_appointment_goods_id',$goodsIds);
  92. })
  93. ->when(!empty($datetime), function($query) use ($datetime){
  94. $datetime[0] = strtotime($datetime[0]);
  95. $datetime[1] = strtotime($datetime[1]);
  96. $query->whereBetween('appointment_addtimes',$datetime);
  97. });
  98. $total = $appointments->count();
  99. $rows = $appointments->orderBy('appointment.appointment_addtimes', 'desc')
  100. ->get();
  101. foreach ($rows as &$row) {
  102. $row->appointment_addtimes = date('Y-m-d H:i:s', $row->appointment_addtimes);
  103. if ($row->appointment_category == 'NOFEE') {
  104. $row->member_benefit_name = "后付费预约";
  105. }
  106. if (!empty($row->goods_sku_specs_json)){
  107. $row->goods_sku_specs_json = json_decode($row->goods_sku_specs_json);
  108. }
  109. if (!empty($row->appointment_apply_json)){
  110. $applyJson = json_decode($row->appointment_apply_json,true);
  111. $row->appointment_apply_json = $applyJson;
  112. $row->person = $applyJson['person'] ?? '';
  113. $row->appointment_times = $applyJson['times'] ?? '';
  114. }
  115. }
  116. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  117. }
  118. }