Times.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 抢购时间管理
  7. */
  8. namespace app\fastshop\controller;
  9. use app\common\controller\Manage;
  10. class Times extends Manage{
  11. public function initialize() {
  12. parent::initialize();
  13. if(!model('auth')->getAuth($this->user->id,1)){
  14. $this->error('无权限,你非【内容管理员】');
  15. }
  16. $this->assign('pathMaps',[['name'=>'抢购时段管理','url'=>url("fastshop/times/index")]]);
  17. }
  18. /**
  19. * 列表
  20. */
  21. public function index(){
  22. $view['lists'] = model('Times')->where(['member_miniapp_id' => $this->member_miniapp_id])->order('sort desc,id desc')->paginate(20);
  23. return view()->assign($view);
  24. }
  25. /**
  26. * 添加
  27. */
  28. public function add(){
  29. if(request()->isAjax()){
  30. $data = [
  31. 'name' => input('post.name/s'),
  32. 'sort' => input('post.sort/d'),
  33. 'start_time' => input('post.start_time/d'),
  34. 'end_time' => input('post.end_time/d'),
  35. 'member_miniapp_id' => $this->member_miniapp_id,
  36. ];
  37. $validate = $this->validate($data,'Times.save');
  38. if(true !== $validate){
  39. return json(['code'=>0,'msg'=>$validate]);
  40. }
  41. $result = model('Times')->edit($data);
  42. if($result){
  43. return json(['code'=>200,'url'=>url('times/index'),'msg'=>'操作成功']);
  44. }else{
  45. return json(['code'=>0,'msg'=>'操作失败']);
  46. }
  47. }else{
  48. return view();
  49. }
  50. }
  51. //编辑
  52. public function edit(){
  53. if(request()->isAjax()){
  54. $data = [
  55. 'id' => input('post.id/s'),
  56. 'name' => input('post.name/s'),
  57. 'sort' => input('post.sort/d'),
  58. 'start_time' => input('post.start_time/d'),
  59. 'end_time' => input('post.end_time/d'),
  60. 'member_miniapp_id' => $this->member_miniapp_id,
  61. ];
  62. $validate = $this->validate($data,'Times.save');
  63. if(true !== $validate){
  64. return json(['code'=>0,'msg'=>$validate]);
  65. }
  66. $result = model('Times')->edit($data);
  67. if($result){
  68. return json(['code'=>200,'url'=>url('times/index'),'msg'=>'操作成功']);
  69. }else{
  70. return json(['code'=>0,'msg'=>'操作失败']);
  71. }
  72. }else{
  73. $id = input('get.id/d');
  74. $view['info'] = model('Times')->get($id);
  75. return view('edit',$view);
  76. }
  77. }
  78. /**
  79. * 排序
  80. */
  81. public function sort(){
  82. if(request()->isAjax()){
  83. $data = [
  84. 'sort' => input('post.sort/d'),
  85. 'id' => input('post.id/d'),
  86. ];
  87. $validate = $this->validate($data,'Times.sort');
  88. if(true !== $validate){
  89. return json(['code'=>0,'msg'=>$validate]);
  90. }
  91. $result = model('Times')->save(['sort'=>$data['sort']],['id' => $data['id']]);
  92. if($result){
  93. return json(['code'=>200,'msg'=>'操作成功']);
  94. }else{
  95. return json(['code'=>0,'msg'=>'操作失败']);
  96. }
  97. }
  98. }
  99. //删除
  100. public function delete(){
  101. $id = input('get.id/d');
  102. $sale = model('Sale')->get(['category_id' => $id]);
  103. if($sale){
  104. return json(['code'=>403,'msg'=>'删除失败,其中还有活动']);
  105. }
  106. $result = model('Times')->destroy(['id' => $id,'member_miniapp_id' => $this->member_miniapp_id]);
  107. if($result){
  108. return json(['code'=>200,'msg'=>'操作成功']);
  109. }else{
  110. return json(['code'=>403,'msg'=>'删除失败']);
  111. }
  112. }
  113. }