1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace app\controller\admin;
- use laytp\controller\Backend;
- use think\facade\Config;
- use laytp\library\CommonFun;
- use laytp\library\Random;
- /**
- * 示例文本
- */
- class Kami extends Backend
- {
- /**
- * member模型对象
- * @var \app\model\Kami
- */
- protected $model;
- protected $hasSoftDel=1;//是否拥有软删除功能
- protected $noNeedLogin = []; // 无需登录即可请求的方法
- protected $noNeedAuth = ['index']; // 无需鉴权即可请求的方法
- public function _initialize()
- {
- $this->model = new \app\model\Kami();
- }
- //查看和搜索列表
- public function index(){
- global $_W;
- $where = $this->buildSearchParams();
- $where[] = ['uniacid','=',$_W['uniacid']];
- $order = $this->buildOrder();
- $data = $this->model->where($where)->order($order)->with('userInfo');
- $paging = $this->request->param('paging', false);
- if ($paging) {
- $limit = $this->request->param('limit', Config::get('paginate.limit'));
- $data = $data->paginate($limit)->toArray();
- $data['data'] = $this->getSelectedData($data['data']);
- } else {
- $data = $data->select()->toArray();
- }
- return $this->success('数据获取成功', $data);
- }
- public function add()
- {
- global $_W;
- $post = $this->request->post();
- $value = $this->request->post('value',0);
- $number = $this->request->post('number',0);
- $type = $this->request->post('type',1);
- if($type == 1){
- $name = '次数卡';
- }else{
- $name = '时长卡';
- }
- if(!$value){
- return $this->error('请填写大于0的数字');
- }
- if(!$number){
- return $this->error('请填写大于0的数字');
- }
- for($i=0;$i<$number;$i++){
- $res2 = $this->model->create(['name'=>$name,'value'=>$value,"type"=>$type,'code'=>Random::alpha(12),'uniacid'=>$_W['uniacid']]);
- }
- return $this->success('数据获取成功');
- }
- //设置积分
- public function setType()
- {
- $id = $this->request->post('id');
- $fieldVal = $this->request->post('field_val');
- $isRecycle = $this->request->post('is_recycle');
- $update['type'] = $fieldVal;
- try {
- if($isRecycle) {
- $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
- } else {
- $updateRes = $this->model->where('id', '=', $id)->update($update);
- }
- if ($updateRes) {
- return $this->success('操作成功');
- } else if ($updateRes === 0) {
- return $this->success('未作修改');
- } else {
- return $this->error('操作失败');
- }
- } catch (\Exception $e) {
- return $this->error('数据库异常,操作失败');
- }
- }
- }
|