PreOrder.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use app\common\service\UserService;
  6. /**
  7. * 预约单
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class PreOrder extends Backend
  12. {
  13. /**
  14. * PreOrder模型对象
  15. * @var \app\admin\model\PreOrder
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\PreOrder;
  22. $this->view->assign("preOrderStatusList", $this->model->getPreOrderStatusList());
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. $this->relationSearch = true; //开启关联
  35. //设置过滤方法
  36. $this->request->filter(['strip_tags', 'trim']);
  37. if ($this->request->isAjax()) {
  38. //如果发送的来源是Selectpage,则转发到Selectpage
  39. if ($this->request->request('keyField')) {
  40. return $this->selectpage();
  41. }
  42. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  43. //只能看自己的
  44. $where_op = [];
  45. if($this->auth->company_id){
  46. $where_op['pre_order.company_id'] = $this->auth->company_id;
  47. }
  48. $list = $this->model->with(['user','company','servicetype'])
  49. ->where($where)
  50. ->where($where_op)
  51. ->order($sort, $order)
  52. ->paginate($limit);
  53. foreach ($list as $row) {
  54. $row->getRelation('user')->visible(['nickname']);
  55. $row->getRelation('company')->visible(['name']);
  56. $row->getRelation('servicetype')->visible(['title']);
  57. }
  58. $result = array("total" => $list->total(), "rows" => $list->items());
  59. return json($result);
  60. }
  61. return $this->view->fetch();
  62. }
  63. /**
  64. * 取消
  65. */
  66. public function cancel(){
  67. $id = input('id',0);
  68. if(!$this->request->post()){
  69. $this->assign('id',$id);
  70. return $this->view->fetch();
  71. }
  72. $cancel_reason = input('cancel_reason','');
  73. $update = [
  74. 'cancel_reason' => $cancel_reason,
  75. 'cancel_time' => time(),
  76. 'updatetime' => time(),
  77. 'pre_order_status' => 0,
  78. ];
  79. Db::name('pre_order')->where('id',$id)->update($update);
  80. $userService = new UserService();
  81. $params['pre_order_id'] = $id;
  82. $userService->msgPreOrder($params);
  83. $this->success('取消成功');
  84. }
  85. /**
  86. * 开单
  87. */
  88. public function submitorder(){
  89. $info = Db::name('pre_order')->find();
  90. }
  91. }