Kami.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\controller\admin;
  3. use laytp\controller\Backend;
  4. use think\facade\Config;
  5. use laytp\library\CommonFun;
  6. use laytp\library\Random;
  7. /**
  8. * 示例文本
  9. */
  10. class Kami extends Backend
  11. {
  12. /**
  13. * member模型对象
  14. * @var \app\model\Kami
  15. */
  16. protected $model;
  17. protected $hasSoftDel=1;//是否拥有软删除功能
  18. protected $noNeedLogin = []; // 无需登录即可请求的方法
  19. protected $noNeedAuth = ['index']; // 无需鉴权即可请求的方法
  20. public function _initialize()
  21. {
  22. $this->model = new \app\model\Kami();
  23. }
  24. //查看和搜索列表
  25. public function index(){
  26. global $_W;
  27. $where = $this->buildSearchParams();
  28. $where[] = ['uniacid','=',$_W['uniacid']];
  29. $order = $this->buildOrder();
  30. $data = $this->model->where($where)->order($order)->with('userInfo');
  31. $paging = $this->request->param('paging', false);
  32. if ($paging) {
  33. $limit = $this->request->param('limit', Config::get('paginate.limit'));
  34. $data = $data->paginate($limit)->toArray();
  35. $data['data'] = $this->getSelectedData($data['data']);
  36. } else {
  37. $data = $data->select()->toArray();
  38. }
  39. return $this->success('数据获取成功', $data);
  40. }
  41. public function add()
  42. {
  43. global $_W;
  44. $post = $this->request->post();
  45. $value = $this->request->post('value',0);
  46. $number = $this->request->post('number',0);
  47. $type = $this->request->post('type',1);
  48. if($type == 1){
  49. $name = '次数卡';
  50. }else{
  51. $name = '时长卡';
  52. }
  53. if(!$value){
  54. return $this->error('请填写大于0的数字');
  55. }
  56. if(!$number){
  57. return $this->error('请填写大于0的数字');
  58. }
  59. for($i=0;$i<$number;$i++){
  60. $res2 = $this->model->create(['name'=>$name,'value'=>$value,"type"=>$type,'code'=>Random::alpha(12),'uniacid'=>$_W['uniacid']]);
  61. }
  62. return $this->success('数据获取成功');
  63. }
  64. //设置积分
  65. public function setType()
  66. {
  67. $id = $this->request->post('id');
  68. $fieldVal = $this->request->post('field_val');
  69. $isRecycle = $this->request->post('is_recycle');
  70. $update['type'] = $fieldVal;
  71. try {
  72. if($isRecycle) {
  73. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  74. } else {
  75. $updateRes = $this->model->where('id', '=', $id)->update($update);
  76. }
  77. if ($updateRes) {
  78. return $this->success('操作成功');
  79. } else if ($updateRes === 0) {
  80. return $this->success('未作修改');
  81. } else {
  82. return $this->error('操作失败');
  83. }
  84. } catch (\Exception $e) {
  85. return $this->error('数据库异常,操作失败');
  86. }
  87. }
  88. }