Sk.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\controller\admin;
  3. use laytp\controller\Backend;
  4. use think\facade\Config;
  5. use laytp\library\CommonFun;
  6. /**
  7. * 会员卡
  8. */
  9. class Sk extends Backend
  10. {
  11. /**
  12. * member模型对象
  13. * @var \app\model\Sk
  14. */
  15. protected $model;
  16. protected $hasSoftDel=1;//是否拥有软删除功能
  17. protected $noNeedLogin = []; // 无需登录即可请求的方法
  18. protected $noNeedAuth = ['index']; // 无需鉴权即可请求的方法
  19. public function _initialize()
  20. {
  21. $this->model = new \app\model\Sk();
  22. }
  23. //查看和搜索列表
  24. public function index(){
  25. global $_W;
  26. $where = $this->buildSearchParams();
  27. $where[] = ['uniacid','=',$_W['uniacid']];
  28. $order = $this->buildOrder();
  29. $data = $this->model->where($where)->order($order);
  30. $paging = $this->request->param('paging', false);
  31. if ($paging) {
  32. $limit = $this->request->param('limit', Config::get('paginate.limit'));
  33. $data = $data->paginate($limit)->toArray();
  34. $data['data'] = $this->getSelectedData($data['data']);
  35. } else {
  36. $data = $data->select()->toArray();
  37. }
  38. return $this->success('数据获取成功', $data);
  39. }
  40. //设置积分
  41. public function setStatus()
  42. {
  43. $id = $this->request->post('id');
  44. $fieldVal = $this->request->post('field_val');
  45. $isRecycle = $this->request->post('is_recycle');
  46. $update['status'] = $fieldVal;
  47. try {
  48. if($isRecycle) {
  49. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  50. } else {
  51. $updateRes = $this->model->where('id', '=', $id)->update($update);
  52. }
  53. if ($updateRes) {
  54. return $this->success('操作成功');
  55. } else if ($updateRes === 0) {
  56. return $this->success('未作修改');
  57. } else {
  58. return $this->error('操作失败');
  59. }
  60. } catch (\Exception $e) {
  61. return $this->error('数据库异常,操作失败');
  62. }
  63. }
  64. }