RefusereasonController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /**
  3. * 拒绝退款理由
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. class RefusereasonController extends AdminbaseController {
  9. protected function getStatus($k=''){
  10. $status=array(
  11. '0'=>'隐藏',
  12. '1'=>'显示',
  13. );
  14. if($k===''){
  15. return $status;
  16. }
  17. return isset($status[$k])?$status[$k]:'';
  18. }
  19. /*分类列表*/
  20. function index(){
  21. $data = $this->request->param();
  22. $map=[];
  23. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  24. if($keyword!=''){
  25. $map[]=['name','like','%'.$keyword.'%'];
  26. }
  27. $lists = Db::name("shop_refuse_reason")
  28. ->where($map)
  29. ->order("list_order asc,id DESC")
  30. ->paginate(20);
  31. $lists->appends($data);
  32. $page = $lists->render();
  33. $this->assign('lists', $lists);
  34. $this->assign("page", $page);
  35. $this->assign("status", $this->getStatus());
  36. return $this->fetch();
  37. }
  38. //分类排序
  39. function listOrder() {
  40. $model = DB::name('shop_refuse_reason');
  41. parent::listOrders($model);
  42. $this->resetcache();
  43. $action="更新卖家拒绝退款原因列表排序";
  44. setAdminLog($action);
  45. $this->success("排序更新成功!");
  46. }
  47. /*分类删除*/
  48. function del(){
  49. $id = $this->request->param('id', 0, 'intval');
  50. $rs = DB::name('shop_refuse_reason')->where("id={$id}")->delete();
  51. if(!$rs){
  52. $this->error("删除失败!");
  53. }
  54. $this->resetcache();
  55. $action="删除卖家拒绝退款原因列表ID: ".$id;
  56. setAdminLog($action);
  57. $this->success("删除成功!");
  58. }
  59. /*分类添加*/
  60. function add(){
  61. $this->assign("status", $this->getStatus());
  62. return $this->fetch();
  63. }
  64. /*分类添加提交*/
  65. function add_post(){
  66. if ($this->request->isPost()) {
  67. $data = $this->request->param();
  68. $name=$data['name'];
  69. if($name==""){
  70. $this->error("请填写拒绝退款原因");
  71. }
  72. $isexist=DB::name('shop_refuse_reason')->where(['name'=>$name])->find();
  73. if($isexist){
  74. $this->error("退款原因已存在");
  75. }
  76. $data['addtime']=time();
  77. $id = DB::name('shop_refuse_reason')->insertGetId($data);
  78. if(!$id){
  79. $this->error("添加失败!");
  80. }
  81. $this->resetcache();
  82. $action="添加卖家拒绝退款原因列表ID: ".$id;
  83. setAdminLog($action);
  84. $this->success("添加成功!");
  85. }
  86. }
  87. /*分类编辑*/
  88. function edit(){
  89. $id = $this->request->param('id', 0, 'intval');
  90. $data=Db::name('shop_refuse_reason')
  91. ->where("id={$id}")
  92. ->find();
  93. if(!$data){
  94. $this->error("信息错误");
  95. }
  96. $this->assign('status',$this->getStatus());
  97. $this->assign('data', $data);
  98. return $this->fetch();
  99. }
  100. /*分类编辑提交*/
  101. function edit_post(){
  102. if ($this->request->isPost()){
  103. $data = $this->request->param();
  104. $name=$data['name'];
  105. $id=$data['id'];
  106. if($name==""){
  107. $this->error("请填写拒绝退款原因");
  108. }
  109. $isexist=DB::name('shop_refuse_reason')->where([['id','<>',$id],['name','=',$name]])->find();
  110. if($isexist){
  111. $this->error("拒绝退款原因已存在");
  112. }
  113. if(mb_strlen($name)>30){
  114. $this->error("字数不超过30字");
  115. }
  116. $data['edittime']=time();
  117. $rs = DB::name('shop_refuse_reason')->update($data);
  118. if($rs===false){
  119. $this->error("修改失败!");
  120. }
  121. $this->resetcache();
  122. $action="编辑卖家拒绝退款原因列表ID: ".$id;
  123. setAdminLog($action);
  124. $this->success("修改成功!");
  125. }
  126. }
  127. // 写入物流信息缓存
  128. function resetcache(){
  129. $key='getRefundRefuseReason';
  130. $rs=DB::name('shop_refuse_reason')
  131. ->field("id,name")
  132. ->where('status=1')
  133. ->order("list_order asc,id desc")
  134. ->select();
  135. if($rs){
  136. setcaches($key,$rs);
  137. }
  138. return 1;
  139. }
  140. }