enterpriseId = $enterpriseId; $this->userCenterId = $userCenterId; parent::__construct($this->enterpriseId, $this->userCenterId); $this->obj = new DShopKey('default'); } /** * 列表 * @param $where * @return mixed */ public function list($where) { $limit = $where['limit']; unset($where['limit']); $offset = $where['offset']; unset($where['offset']); $file = ' a.* '; $sql = 'SELECT'.$file.'FROM qianniao_shop_template AS a WHERE shop_id = '. $where['shop_id']; if(isset($where['name'])) { $sql .= ' AND a.name LIKE "%' . $where['name'] . '%"'; } $total = count((array) $this->obj->query($sql)); $sql .= ' ORDER BY createTime DESC LIMiT '.$offset.','.$limit; $dbResult = $this->obj->query($sql); if ($dbResult === false) { return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror); } $return = [ 'data' => $dbResult, 'total' => ($total) ? intval($total) : 0, ]; if($return === false){ return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror); }else{ return ResultWrapper::success($return); } } /** * 详情 * @param $where * @return mixed */ public function details($where) { $where['enterprise_id'] = $this->enterpriseId; if(empty($where)){ return ResultWrapper::success($where); } $dbResult = $this->obj->get($where); if($dbResult === false){ return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror); } return ResultWrapper::success(self::formatInfo($dbResult)); } /** * Doc: (des="添加") * User: XMing * Date: 2020/7/15 * Time: 10:42 上午 * @throws Exception * @param array $params * @return ResultWrapper */ public function insert(array $params) { $params['enterprise_id'] = $this->enterpriseId; $res = $this->obj->insert($params); if ($res){ return ResultWrapper::success('添加成功'); }else{ return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror); } } public function update($params, $id) { $data = $this->obj->get($id); if (!$data){ return ResultWrapper::fail('数据不存在', ErrorCode::$dberror); } $dbResult = $this->obj->update($params,$id); if($dbResult === false){ return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror); } return ResultWrapper::success('修改成功'); } /** * 格式数据详情 * @param $data * @return mixed */ public function formatInfo($data) { return $data; } public function delete($id) { $res = $this->obj->delete(['id' => $id]); if ($res){ return ResultWrapper::success('删除成功'); } return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror); } }