Dinner.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\api\controller\dinner;
  3. use app\hander\HelpHander;
  4. use think\Controller;
  5. use think\Db;
  6. class Dinner extends BaseDinner
  7. {
  8. public function goods(){
  9. $day = get_dinner_day();
  10. $curTime = date('H:i:s');
  11. $cates = Db::name('dinner_cate')
  12. ->where('del',0)
  13. ->where('enable',1)
  14. ->where('show_start','<=',$curTime)
  15. ->where('show_end','>=',$curTime)
  16. ->field('id,title')
  17. ->order('id asc')
  18. ->select();
  19. $cates = $cates?$cates:[];
  20. $narr = [];
  21. foreach ($cates as $k=>$v){
  22. $goods = Db::name('dinner')
  23. ->where('del',0)
  24. ->where('enable',1)
  25. ->where('cate_id',$v['id'])
  26. ->where('day',$day)
  27. ->order('sorts desc,id asc')
  28. ->field('id,title,img,cate_id,remark,price')
  29. ->select();
  30. $goods = $goods?$goods:[];
  31. foreach ($goods as $kk=>$vv){
  32. $goods[$kk]['img'] = $vv['img']?$vv['img']:request()->domain().'/static/dinner.png';
  33. $goods[$kk]['cate_title'] = $v['title'];
  34. }
  35. if($goods){
  36. $v['goods'] = $goods;
  37. $narr[] = $v;
  38. }
  39. }
  40. HelpHander::success(['day'=>$day,'list'=>$narr]);
  41. }
  42. public function company(){
  43. $lists = Db::name('dinner_company')
  44. ->where('del',0)
  45. ->where('enable',1)
  46. ->order('sorts asc,id asc')
  47. ->field('id,title')
  48. ->select();
  49. HelpHander::success($lists?$lists:[],'成功');
  50. }
  51. public function book(){
  52. $data = [
  53. 'remark' => input('remark','','trim'),
  54. 'goods' => input('goods','','trim'),
  55. 'user_id' => $this->userId
  56. ];
  57. model('DinnerOrders')->book($data);
  58. HelpHander::success([],'操作成功');
  59. }
  60. public function orders(){
  61. $page = input('page/d',1);
  62. $size = input('size/d',10);
  63. $lists = model('DinnerOrders')->orders($page,$size,$this->userId);
  64. HelpHander::success($lists);
  65. }
  66. public function userinfo(){
  67. $user = Db::name('dinner_user')->where('id',$this->userId)->field('name')->find();
  68. HelpHander::success($user);
  69. }
  70. public function cancel(){
  71. $id = input('id/d',0);
  72. $info = Db::name('dinner_orders')->where('id',$id)->where('del',0)->find();
  73. if(!$info){
  74. HelpHander::error('订单不存在');
  75. }
  76. if($info['user_id'] != $this->userId){
  77. HelpHander::error('无权限操作');
  78. }
  79. $limitTime = strtotime($info['day'].' 08:30:00');
  80. if(time() > $limitTime){
  81. HelpHander::error('该时间段无权限取消订单');
  82. }
  83. if($info['status'] == 0){
  84. HelpHander::error('订单已取消');
  85. }
  86. $ret = Db::name('dinner_orders')->where('id',$id)->update(['status'=>0,'update_time'=>date('Y-m-d H:i:s')]);
  87. if(!$ret){
  88. HelpHander::error('取消失败');
  89. }else{
  90. HelpHander::success([],'取消成功');
  91. }
  92. }
  93. public function modifypass(){
  94. $data = [
  95. 'userId' => $this->userId,
  96. 'oldPass' => input('oldPass','','trim'),
  97. 'pass' => input('pass','','trim'),
  98. ];
  99. model('DinnerUser')->modifyPass($data);
  100. HelpHander::success([],'操作成功');
  101. }
  102. }