Preorder.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\api\controller\company;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. /**
  6. * 预约管理
  7. */
  8. class Preorder extends Apic
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //列表
  13. public function lists(){
  14. $pre_order_status = input('pre_order_status',1);
  15. $where = [
  16. 'po.company_id' => $this->auth->company_id,
  17. 'po.pre_order_status' => $pre_order_status,
  18. ];
  19. $list = Db::name('pre_order')->alias('po')->field('po.*,servicetype.title')
  20. ->join('servicetype','po.servicetype_id = servicetype.id','LEFT')
  21. ->where($where)->order('po.id desc')->autopage()->select();
  22. $this->success(1,$list);
  23. }
  24. //取消
  25. public function cancel(){
  26. $id = input('pre_order_id',0);
  27. $cancel_reason = input('cancel_reason','');
  28. $update = [
  29. 'cancel_reason' => $cancel_reason,
  30. 'cancel_time' => time(),
  31. 'updatetime' => time(),
  32. 'pre_order_status' => 0,
  33. ];
  34. Db::name('pre_order')->where('id',$id)->where('company_id',$this->auth->company_id)->update($update);
  35. $this->success('取消成功');
  36. }
  37. //详情
  38. public function info(){
  39. $id = input('pre_order_id',0);
  40. $info = Db::name('pre_order')->where('id',$id)->find();
  41. $this->success(1,$info);
  42. }
  43. //预约开单 在线开单
  44. public function submit_order(){
  45. $pre_order_id = input('pre_order_id',0); //预约单id
  46. $data = request_post_hub([
  47. 'user_name','user_car_number','user_mobile','user_address',
  48. 'servicetype_id','server_time','server_info','server_images','pay_fee'
  49. ]);
  50. //检查用户
  51. $user_info = Db::name('user')->where('mobile',$data['user_mobile'])->find();
  52. if(empty($user_info)){
  53. $this->error('不存在的用户');
  54. }
  55. $data['user_id'] = $user_info['id'];
  56. //预约单
  57. $pre_order = [];
  58. if($pre_order_id > 0){
  59. $pre_order = Db::name('pre_order')->where('id',$pre_order_id)->find();
  60. if(empty($pre_order)){
  61. $this->error('不存在的预约单');
  62. }else{
  63. $data['pre_order_id'] = $pre_order_id;
  64. }
  65. }
  66. //检索car_id,没必要了
  67. //准备数据
  68. $data['orderno'] = createUniqueNo('O',$this->auth->id);
  69. $data['ordertype'] = ($pre_order_id > 0) ? 1 : 2; //类型:1=预约下单,2=在线下单,3=套餐订单
  70. $data['company_id'] = $this->auth->company_id;
  71. $data['staff_id'] = $this->auth->id;
  72. $data['createtime'] = time();
  73. $order_id = Db::name('order')->insertGetId($data);
  74. $this->success('下单完成',$order_id);
  75. }
  76. //查看预约单下的订单
  77. }