123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace app\api\controller\dinner;
- use app\hander\HelpHander;
- use think\Controller;
- use think\Db;
- class Dinner extends BaseDinner
- {
- public function goods(){
- $day = get_dinner_day();
- $curTime = date('H:i:s');
- $cates = Db::name('dinner_cate')
- ->where('del',0)
- ->where('enable',1)
- ->where('show_start','<=',$curTime)
- ->where('show_end','>=',$curTime)
- ->field('id,title')
- ->order('id asc')
- ->select();
- $cates = $cates?$cates:[];
- $narr = [];
- foreach ($cates as $k=>$v){
- $goods = Db::name('dinner')
- ->where('del',0)
- ->where('enable',1)
- ->where('cate_id',$v['id'])
- ->where('day',$day)
- ->order('sorts desc,id asc')
- ->field('id,title,img,cate_id,remark,price')
- ->select();
- $goods = $goods?$goods:[];
- foreach ($goods as $kk=>$vv){
- $goods[$kk]['img'] = $vv['img']?$vv['img']:request()->domain().'/static/dinner.png';
- $goods[$kk]['cate_title'] = $v['title'];
- }
- if($goods){
- $v['goods'] = $goods;
- $narr[] = $v;
- }
- }
- HelpHander::success(['day'=>$day,'list'=>$narr]);
- }
- public function company(){
- $lists = Db::name('dinner_company')
- ->where('del',0)
- ->where('enable',1)
- ->order('sorts asc,id asc')
- ->field('id,title')
- ->select();
- HelpHander::success($lists?$lists:[],'成功');
- }
- public function book(){
- $data = [
- 'remark' => input('remark','','trim'),
- 'goods' => input('goods','','trim'),
- 'user_id' => $this->userId
- ];
- model('DinnerOrders')->book($data);
- HelpHander::success([],'操作成功');
- }
- public function orders(){
- $page = input('page/d',1);
- $size = input('size/d',10);
- $lists = model('DinnerOrders')->orders($page,$size,$this->userId);
- HelpHander::success($lists);
- }
- public function userinfo(){
- $user = Db::name('dinner_user')->where('id',$this->userId)->field('name')->find();
- HelpHander::success($user);
- }
- public function cancel(){
- $id = input('id/d',0);
- $info = Db::name('dinner_orders')->where('id',$id)->where('del',0)->find();
- if(!$info){
- HelpHander::error('订单不存在');
- }
- if($info['user_id'] != $this->userId){
- HelpHander::error('无权限操作');
- }
- $limitTime = strtotime($info['day'].' 08:30:00');
- if(time() > $limitTime){
- HelpHander::error('该时间段无权限取消订单');
- }
- if($info['status'] == 0){
- HelpHander::error('订单已取消');
- }
- $ret = Db::name('dinner_orders')->where('id',$id)->update(['status'=>0,'update_time'=>date('Y-m-d H:i:s')]);
- if(!$ret){
- HelpHander::error('取消失败');
- }else{
- HelpHander::success([],'取消成功');
- }
- }
- public function modifypass(){
- $data = [
- 'userId' => $this->userId,
- 'oldPass' => input('oldPass','','trim'),
- 'pass' => input('pass','','trim'),
- ];
- model('DinnerUser')->modifyPass($data);
- HelpHander::success([],'操作成功');
- }
- }
|