Member.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 Member extends Backend
  10. {
  11. /**
  12. * member模型对象
  13. * @var \app\model\Member
  14. */
  15. protected $model;
  16. protected $hasSoftDel=1;//是否拥有软删除功能
  17. protected $noNeedLogin = []; // 无需登录即可请求的方法
  18. protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
  19. public function _initialize()
  20. {
  21. $this->model = new \app\model\Member();
  22. }
  23. //查看和搜索列表
  24. public function index(){
  25. global $_W;
  26. $where = $this->buildSearchParams();
  27. $where[] = ['uniacid','=',$_W['uniacid']];
  28. // $order = $this->buildOrder();
  29. $order = ['sort' => 'DESC','id'=>'DESC'];
  30. $data = $this->model->where($where)->order($order);
  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. //查看详情
  42. public function info()
  43. {
  44. $id = $this->request->param('id');
  45. $info = $this->model->find($id);
  46. return $this->success('获取成功', $info);
  47. }
  48. //设置价格
  49. public function setPrice()
  50. {
  51. $id = $this->request->post('id');
  52. $fieldVal = $this->request->post('field_val');
  53. $isRecycle = $this->request->post('is_recycle');
  54. $update['price'] = $fieldVal;
  55. try {
  56. if($isRecycle) {
  57. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  58. } else {
  59. $updateRes = $this->model->where('id', '=', $id)->update($update);
  60. }
  61. if ($updateRes) {
  62. return $this->success('操作成功');
  63. } else if ($updateRes === 0) {
  64. return $this->success('未作修改');
  65. } else {
  66. return $this->error('操作失败');
  67. }
  68. } catch (\Exception $e) {
  69. return $this->error('数据库异常,操作失败');
  70. }
  71. }
  72. //设置积分
  73. public function setCoin()
  74. {
  75. $id = $this->request->post('id');
  76. $fieldVal = $this->request->post('field_val');
  77. $isRecycle = $this->request->post('is_recycle');
  78. $update['coin'] = $fieldVal;
  79. try {
  80. if($isRecycle) {
  81. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  82. } else {
  83. $updateRes = $this->model->where('id', '=', $id)->update($update);
  84. }
  85. if ($updateRes) {
  86. return $this->success('操作成功');
  87. } else if ($updateRes === 0) {
  88. return $this->success('未作修改');
  89. } else {
  90. return $this->error('操作失败');
  91. }
  92. } catch (\Exception $e) {
  93. return $this->error('数据库异常,操作失败');
  94. }
  95. }
  96. //设置积分
  97. public function setDay()
  98. {
  99. $id = $this->request->post('id');
  100. $fieldVal = $this->request->post('field_val');
  101. $isRecycle = $this->request->post('is_recycle');
  102. $update['day'] = $fieldVal;
  103. try {
  104. if($isRecycle) {
  105. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  106. } else {
  107. $updateRes = $this->model->where('id', '=', $id)->update($update);
  108. }
  109. if ($updateRes) {
  110. return $this->success('操作成功');
  111. } else if ($updateRes === 0) {
  112. return $this->success('未作修改');
  113. } else {
  114. return $this->error('操作失败');
  115. }
  116. } catch (\Exception $e) {
  117. return $this->error('数据库异常,操作失败');
  118. }
  119. }
  120. //设置排序
  121. public function setSort()
  122. {
  123. $id = $this->request->post('id');
  124. $fieldVal = $this->request->post('field_val');
  125. $isRecycle = $this->request->post('is_recycle');
  126. $update['sort'] = $fieldVal;
  127. try {
  128. if($isRecycle) {
  129. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  130. } else {
  131. $updateRes = $this->model->where('id', '=', $id)->update($update);
  132. }
  133. if ($updateRes) {
  134. return $this->success('操作成功');
  135. } else if ($updateRes === 0) {
  136. return $this->success('未作修改');
  137. } else {
  138. return $this->error('操作失败');
  139. }
  140. } catch (\Exception $e) {
  141. return $this->error('数据库异常,操作失败');
  142. }
  143. }
  144. }