AppointmentService.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\admin\service\order;
  3. use app\model\Appointment;
  4. use support\Db;
  5. use support\Request;
  6. use function _PHPStan_cc8d35ffb\RingCentral\Psr7\str;
  7. class AppointmentService
  8. {
  9. public static function select(Request $request)
  10. {
  11. $page = $request->get('page');
  12. $pageSize = $request->get('pageSize');
  13. $id = $request->get('id', '');
  14. $mobile = $request->get('mobile', '');
  15. $rows = Db::table('appointment')
  16. ->leftJoin('member', 'member.member_id', '=', 'appointment.join_appointment_member_id')
  17. ->leftJoin('goods', 'goods.goods_id', '=', 'appointment.join_appointment_goods_id')
  18. ->leftJoin('order', 'order.order_id', '=', 'appointment.join_appointment_order_id')
  19. ->leftJoin('member_benefit', 'member_benefit.member_benefit_id', '=', 'appointment.join_appointment_member_benefit_id')
  20. ->leftJoin('goods_sku', 'goods_sku.goods_sku_id', '=', 'appointment.join_appointment_goods_sku_id')
  21. ->when($id != '', function ($query) use ($id) {
  22. $query->where('appointment.appointment_id', 'like', '%' . $id . '%');
  23. })->when($mobile != '', function ($query) use ($mobile) {
  24. $query->where('member.member_mobile', 'like', '%' . $mobile . '%');
  25. });
  26. $total = $rows->count('member.member_id');
  27. $rows = $rows->select('member.member_mobile', 'appointment.*', 'goods.goods_name', 'goods.goods_cover',
  28. 'order.order_name', 'goods_sku.goods_sku_specs_json', 'order.order_amount_total', 'order.order_amount_pay',
  29. 'order.order_category', 'order.order_status_system', 'order.order_status_payment', 'order.order_status_storage',
  30. 'order.order_addtimes',
  31. 'member_benefit.member_benefit_name'
  32. )
  33. ->orderBy('appointment.appointment_addtimes', 'desc')
  34. ->forPage($page, $pageSize)
  35. ->get();
  36. foreach ($rows as &$row) {
  37. $row->goods_cover = getenv('STORAGE_DOMAIN') . $row->goods_cover;
  38. $row->goods_sku_specs_json = !empty($row->goods_sku_specs_json) ? json_decode($row->goods_sku_specs_json, true) : [];
  39. $row->appointment_addtimes = date('Y-m-d H:i:s', $row->appointment_addtimes);
  40. }
  41. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  42. }
  43. public static function confirm($id)
  44. {
  45. $appointment = Appointment::where('appointment_id', $id)->where('appointment_status', 'WAITING')->first();
  46. if (!$appointment) {
  47. return json_fail('数据异常');
  48. }
  49. try {
  50. $appointment->appointment_status = 'PENDING';
  51. $appointment->save();
  52. return json_success('操作成功');
  53. } catch (\Exception $e) {
  54. dump($e->getMessage());
  55. return json_fail("操作失败");
  56. }
  57. }
  58. public static function update(Request $request)
  59. {
  60. $appointmentId = $request->post('appointment_id');
  61. if (!Appointment::where('appointment_id', $appointmentId)->exists()) {
  62. return json_fail("数据不存在");
  63. }
  64. $params = $request->post();
  65. try {
  66. $data = [
  67. 'appointment_status'=>$params['appointment_status'],
  68. 'appointment_datetime'=>$params['appointment_datetime'] ? date('Y-m-d H:i:s',strtotime($params['appointment_datetime'])) : null,
  69. 'appointment_apply_datetime'=>$params['appointment_apply_datetime'] ? date('Y-m-d H:i:s',strtotime($params['appointment_apply_datetime'])) : null,
  70. 'appointment_doing_datetime'=>$params['appointment_doing_datetime'] ? date('Y-m-d H:i:s',strtotime($params['appointment_doing_datetime'])) : null,
  71. 'appointment_done_datetime'=>$params['appointment_done_datetime'] ? date('Y-m-d H:i:s',strtotime($params['appointment_done_datetime'])) : null,
  72. 'appointment_cancel_datetime'=>$params['appointment_cancel_datetime'] ? date('Y-m-d H:i:s',strtotime($params['appointment_cancel_datetime'])) : null,
  73. 'appointment_remark'=>$params['appointment_remark'] ?? '',
  74. ];
  75. Appointment::where('appointment_id', $appointmentId)->update($data);
  76. return json_success("数据更新成功");
  77. }catch (\Exception $e){
  78. dump($e->getMessage());
  79. return json_fail("数据更新失败");
  80. }
  81. }
  82. }