where($condition)->count(); $list = Db::name('platform_logistics_product')->field("*")->where($condition)->order($order)->page($p, $other['page_size'])->select()->toArray(); $other['count'] = $count; if (!$list) { $list = []; } $result['other'] = $other; $result['list'] = $list; return $this->successResponse($result); } catch (Exception $exc) { return $this->errorResponse($exc->getMessage()); } } } /** *保存货运属性 */ public function save() { //开始事务 Db::startTrans(); try { if (!Request::isPost()) { throw new Exception(lang('request_method_incorrect')); } $data = Request::post(); $validate = new PlatformLogisticsProductValidate(); $check_result = $validate->check($data); if (!$check_result) { throw new Exception($validate->getError()); } $id = input('post.id'); if (is_numeric($id)) { //更新数据 $update_result = Db::name('platform_logistics_product')->where('id', $id)->withoutField('id')->save($data); if ($update_result === FALSE) { throw new Exception(lang('editing_failed')); } //提交事务 Db::commit(); return $this->successResponse('修改成功!'); } else { //添加数据 unset($data['id']); $add_result = Db::name('platform_logistics_product')->insertGetId($data); if (!$add_result) { throw new Exception(lang('add_failed')); } Db::name('platform_logistics_product')->where('id', $add_result)->save(['order_id' => $add_result]); //提交事务 Db::commit(); return $this->successResponse('添加成功!'); } } catch (Exception $exc) { // 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } /** * 删除货运属性 * @return array|int[] */ public function delete() { //开始事务 Db::startTrans(); try { if (!Request::isPost()) { throw new Exception(lang('request_method_incorrect')); } $id = input('id'); if (!is_numeric($id)) { throw new Exception(lang('parameter_error')); } $condition['id'] = $id; $info = Db::name('platform_logistics_product')->field('id')->where($condition)->find(); if (!$info) { throw new Exception(lang('parameter_error')); } Db::name('platform_logistics_product')->where('id', $id)->delete(); //提交事务 Db::commit(); return $this->successResponse('删除成功!'); } catch (Exception $exc) { // 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } }