where($map) ->order($order) ->page($page, $row) ->select(); $data['count'] = $this->where($map)->count(); return $data; } /** * 数据保存 * @param string $id * @return bool|mixed * author: xmy 280564871@qq.com */ public function saveData($id=""){ $data = $this->create(); if(!$data){ return false; } //计算激活码数量 if($data['good_type'] == 2 && !empty($data['good_key'])){ $data['number'] = $this->countJson($data['good_key']); } if(empty($id)){ return $this->add($data); }else{ return $this->where(['id'=>$id])->save($data); } } /** * 数据格式化 * @param $str * @return array|string * author: xmy 280564871@qq.com */ public function formatStr($str){ if (empty($str)){ return $str; } $data = str2arr($str,"\r\n"); $data = array_filter($data);//去空 $result = json_encode($data); return $result; } /** * 获取数据 * @param $id * @return mixed * author: xmy 280564871@qq.com */ public function getData($id){ $data = $this->find($id); $good_key = json_decode($data['good_key']); $data['good_key'] = arr2str($good_key,"\r\n"); return $data; } public function countJson($str){ $good_key = json_decode($str); $num = count($good_key); return $num; } }