Dinner.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class Dinner extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->table='dinner';
  10. $this->model= new \app\common\model\Dinner();
  11. }
  12. public function index(){
  13. if(request()->isAjax()){
  14. //分页参数
  15. $length = input('rows',10,'intval'); //每页条数
  16. $page = input('page',1,'intval'); //第几页
  17. $start = ($page - 1) * $length; //分页开始位置
  18. //排序
  19. $sortRow = input('sidx','id','trim'); //排序列
  20. $sort = input('sord','desc','trim'); //排序方式
  21. $order = $sortRow.' '.$sort;
  22. $title = input('title','','trim');
  23. if($title){
  24. $map[] = ['name','like','%'.$title.'%'];
  25. }
  26. $enable = input('enable','','trim');
  27. if($enable != ''){
  28. $map[] = ['enable','=',$enable];
  29. }
  30. $type = input('type','','trim');
  31. if($type){
  32. $map[] = ['dinner_type_id','=',$type];
  33. }
  34. $map[] = ['org_id','=',$this->orgId];
  35. $map[] = ['cate','=',0];
  36. $map= empty($map) ? true: $map;
  37. //数据查询
  38. $lists = Db::name($this->table)->where($map)->limit($start,$length)->order(
  39. ['sort'=>'asc','id'=>'desc']
  40. )->select();
  41. foreach ($lists as $k=>$v){
  42. $lists[$k]['type'] = Db::name('dinner_type')
  43. ->field('name,color')
  44. ->where('id',$v['dinner_type_id'])
  45. ->find();
  46. $img = $v['imgs']?explode(',',$v['imgs']):[];
  47. $lists[$k]['img'] = $img?$img[0]:'';
  48. }
  49. //数据返回
  50. $totalCount = Db::name($this->table)->where($map)->count();
  51. $totalPage = ceil($totalCount/$length);
  52. $result['page'] = $page;
  53. $result['total'] = $totalPage;
  54. $result['records'] = $totalCount;
  55. $result['rows'] = $lists;
  56. return json($result);
  57. }else{
  58. $typeList = model('DinnerType')->getList($this->orgId);
  59. $this->assign('typeList',$typeList);
  60. return $this->fetch();
  61. }
  62. }
  63. // 特殊人群菜单
  64. public function index2(){
  65. if(request()->isAjax()){
  66. //分页参数
  67. $length = input('rows',10,'intval'); //每页条数
  68. $page = input('page',1,'intval'); //第几页
  69. $start = ($page - 1) * $length; //分页开始位置
  70. //排序
  71. $sortRow = input('sidx','id','trim'); //排序列
  72. $sort = input('sord','desc','trim'); //排序方式
  73. $order = $sortRow.' '.$sort;
  74. $title = input('title','','trim');
  75. if($title){
  76. $map[] = ['name','like','%'.$title.'%'];
  77. }
  78. $enable = input('enable','','trim');
  79. if($enable != ''){
  80. $map[] = ['enable','=',$enable];
  81. }
  82. $type = input('type','','trim');
  83. if($type){
  84. $map[] = ['dinner_type_id','=',$type];
  85. }
  86. $map[] = ['org_id','=',$this->orgId];
  87. $map[] = ['cate','=',1];
  88. $map= empty($map) ? true: $map;
  89. //数据查询
  90. $lists = Db::name($this->table)->where($map)->limit($start,$length)->order(
  91. ['sort'=>'asc','id'=>'desc']
  92. )->select();
  93. foreach ($lists as $k=>$v){
  94. $lists[$k]['dinner_type'] = Db::name('dinner_type')
  95. ->field('name,color')
  96. ->where('id',$v['dinner_type_id'])
  97. ->find();
  98. $img = $v['imgs']?explode(',',$v['imgs']):[];
  99. $lists[$k]['img'] = $img?$img[0]:'';
  100. }
  101. //数据返回
  102. $totalCount = Db::name($this->table)->where($map)->count();
  103. $totalPage = ceil($totalCount/$length);
  104. $result['page'] = $page;
  105. $result['total'] = $totalPage;
  106. $result['records'] = $totalCount;
  107. $result['rows'] = $lists;
  108. return json($result);
  109. }else{
  110. $typeList = model('DinnerType')->getList($this->orgId);
  111. $this->assign('typeList',$typeList);
  112. return $this->fetch();
  113. }
  114. }
  115. /**
  116. * 新增/编辑
  117. */
  118. public function add($id=0){
  119. if(request()->isPost()){
  120. $res = $this->model->updates(0);
  121. if($res){
  122. $this->success('操作成功',url('index'));
  123. }else{
  124. $this->error($this->model->getError());
  125. }
  126. }else{
  127. if($id){
  128. $info =Db::name($this->table)->where('id',$id)->find();
  129. $this->assign('info',$info);
  130. }
  131. $typeList = model('DinnerType')->getList($this->orgId);
  132. $this->assign('typeList',$typeList);
  133. return $this->fetch();
  134. }
  135. }
  136. public function add2($id=0){
  137. if(request()->isPost()){
  138. $res = $this->model->updates(1);
  139. if($res){
  140. $this->success('操作成功',url('index2'));
  141. }else{
  142. $this->error($this->model->getError());
  143. }
  144. }else{
  145. if($id){
  146. $info =Db::name($this->table)->where('id',$id)->find();
  147. $this->assign('info',$info);
  148. }
  149. $typeList = model('DinnerType')->getList($this->orgId);
  150. $this->assign('typeList',$typeList);
  151. return $this->fetch();
  152. }
  153. }
  154. /**
  155. * 删除记录
  156. * @param int $id
  157. */
  158. public function del($id=0){
  159. if(!$id){
  160. $this->error('参数错误');
  161. }
  162. $res = db($this->table)->where('id',$id)->setField('del',1);
  163. if($res){
  164. $this->success('删除成功');
  165. }else{
  166. $this->error('删除失败');
  167. }
  168. }
  169. public function detail($id){
  170. $res = db($this->table)->where('id',$id)->find();
  171. $res['imgs'] = explode(',',$res['imgs']);
  172. $this->assign('info',$res);
  173. return $this->fetch();
  174. }
  175. /**
  176. * 改变字段值
  177. * @param int $fv
  178. * @param string $fn
  179. * @param int $fv
  180. */
  181. public function changeField($id=0,$fn='',$fv=0){
  182. if(!$fn||!$id){
  183. $this->error('参数错误');
  184. }
  185. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  186. if($res){
  187. $name = '菜单管理:';
  188. $content = '';
  189. if($fn == 'enable'){
  190. $content = $name.'预约餐下架';
  191. if($fv == 1){
  192. $content = $name.'预约餐上架';
  193. }
  194. }elseif ($fn == 'today_enable'){
  195. $content = $name.'当天餐下架';
  196. if($fv == 1){
  197. $content = $name.'当天餐上架';
  198. }
  199. }
  200. $this->success('操作成功');
  201. }else{
  202. $this->error('操作失败');
  203. }
  204. }
  205. public function disableall(){
  206. $res = db($this->table)
  207. ->where('org_id',$this->orgId)
  208. ->update([
  209. 'enable'=>0,
  210. 'update_time'=>getTime()
  211. ]);
  212. if($res){
  213. $ids = db($this->table)
  214. ->where('org_id',$this->orgId)
  215. ->column('id');
  216. $this->success('操作成功');
  217. }else{
  218. $this->error('操作失败');
  219. }
  220. }
  221. public function enableall(){
  222. $res = db($this->table)
  223. ->where('org_id',$this->orgId)
  224. ->update([
  225. 'enable'=>1,
  226. 'update_time'=>getTime()
  227. ]);
  228. if($res){
  229. $this->success('操作成功');
  230. }else{
  231. $this->error('操作失败');
  232. }
  233. }
  234. public function disablealltoday(){
  235. $res = db($this->table)
  236. ->where('org_id',$this->orgId)
  237. ->update([
  238. 'today_enable'=>0,
  239. 'update_time'=>getTime()
  240. ]);
  241. if($res){
  242. $ids = db($this->table)
  243. ->where('org_id',$this->orgId)
  244. ->column('id');
  245. $this->success('操作成功');
  246. }else{
  247. $this->error('操作失败');
  248. }
  249. }
  250. public function enablealltoday(){
  251. $res = db($this->table)
  252. ->where('org_id',$this->orgId)
  253. ->update([
  254. 'today_enable'=>1,
  255. 'update_time'=>getTime()
  256. ]);
  257. if($res){
  258. $this->success('操作成功');
  259. }else{
  260. $this->error('操作失败');
  261. }
  262. }
  263. }