Preorder.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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')->alias('po')
  41. ->field('po.*,servicetype.title as servicetype_title')
  42. ->join('servicetype','po.servicetype_id = servicetype.id','LEFT')
  43. ->where('po.id',$id)->find();
  44. $this->success(1,$info);
  45. }
  46. //预约开单 在线开单
  47. public function submit_order(){
  48. $pre_order_id = input('pre_order_id',0); //预约单id
  49. $data = request_post_hub([
  50. 'user_name','user_car_number','user_mobile','user_address',
  51. 'servicetype_id','server_time','server_info','server_images','pay_fee'
  52. ]);
  53. //检查用户
  54. $user_info = Db::name('user')->where('mobile',$data['user_mobile'])->find();
  55. if(empty($user_info)){
  56. $this->error('不存在的用户');
  57. }
  58. $data['user_id'] = $user_info['id'];
  59. //预约单
  60. $pre_order = [];
  61. if($pre_order_id > 0){
  62. $map = ['id'=>$pre_order_id,'company_id'=>$this->auth->company_id,'pre_order_status'=>1];
  63. $pre_order = Db::name('pre_order')->where($map)->find();
  64. if(empty($pre_order)){
  65. $this->error('不存在的预约单');
  66. }else{
  67. $data['pre_order_id'] = $pre_order_id;
  68. //数据一致性
  69. if($pre_order['user_id'] != $data['user_id']){
  70. $this->error('预约单用户非当前用户');
  71. }
  72. }
  73. //修改状态
  74. $update = [
  75. 'order_time' => time(),
  76. 'updatetime' => time(),
  77. 'pre_order_status' => 2,
  78. ];
  79. Db::name('pre_order')->where('id',$pre_order_id)->update($update);
  80. }else{
  81. $data['pre_order_id'] = 0;
  82. }
  83. //检索car_id,没必要了
  84. //准备数据
  85. $data['orderno'] = createUniqueNo('O',$this->auth->id);
  86. $data['ordertype'] = ($pre_order_id > 0) ? 1 : 2; //类型:1=预约下单,2=在线下单,3=套餐订单
  87. $data['company_id'] = $this->auth->company_id;
  88. $data['staff_id'] = $this->auth->id;
  89. $data['status'] = 2; //2=已支付,待处理
  90. $data['createtime'] = time();
  91. $order_id = Db::name('order')->insertGetId($data);
  92. $this->success('下单完成',$order_id);
  93. }
  94. //查看预约单下的订单
  95. }